Package intermine :: Module model :: Class Model
[hide private]
[frames] | no frames]

Class Model

source code

object --+
         |
        Model

A class for representing the data model of an InterMine datawarehouse

An abstraction of the database schema

SYNOPSIS

>>> service = Service("http://www.flymine.org/query/service")
>>> model = service.model
>>> model.get_class("Gene")
<intermine.model.Class: Gene>

OVERVIEW

This class represents the data model - ie. an abstraction of the database schema. It can be used to introspect what data is available and how it is inter-related

Instance Methods [hide private]
 
__init__(self, source, service=None)
You will most like not need to create a model directly, instead get one from the Service object:
source code
 
parse_model(self, source)
The xml can be provided as a file, url or string.
source code
 
vivify(self)
This method ensures the model is internally consistent.
source code
list(intermine.model.Class)
to_ancestry(self, cd)
Returns the class' parents, and all the class' parents' parents
source code
list(intermine.model.Class)
to_classes(self, classnames)
This simply maps from a list of strings to a list of classes in the calling model.
source code
 
column(self, path, *rest) source code
 
__getattr__(self, name) source code
intermine.model.Class
get_class(self, name)
This is the recommended way of retrieving a class from the model.
source code
intermine.model.Path
make_path(self, path, subclasses={})
This is recommended manner of constructing path objects.
source code
 
validate_path(self, path_string, subclasses={})
When you don't need to interrogate relationships between paths, simply using this method to validate a path string is enough.
source code
 
parse_path_string(self, path_string, subclasses={})
This method is used when making paths from a model, and when validating path strings.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, source, service=None)
(Constructor)

source code 

Constructor

>>> model = Model(xml)

You will most like not need to create a model directly, instead get one from the Service object:

Parameters:
  • source - the model.xml, as a local file, string, or url
Overrides: object.__init__

parse_model(self, source)

source code 

Create classes, attributes, references and collections from the model.xml

The xml can be provided as a file, url or string. This method is called during instantiation - it does not need to be called directly.

Parameters:
  • source - the model.xml, as a local file, string, or url
Raises:

vivify(self)

source code 

Make names point to instances and insert inherited fields

This method ensures the model is internally consistent. This method is called during instantiaton. It does not need to be called directly.

Raises:
  • ModelError - if the names point to non-existent objects

to_classes(self, classnames)

source code 

take a list of class names and return a list of classes

>>> classes = model.to_classes(["Gene", "Protein", "Organism"])

This simply maps from a list of strings to a list of classes in the calling model.

Returns: list(intermine.model.Class)
Raises:
  • ModelError - if the list of class names includes ones that don't exist

get_class(self, name)

source code 

Get a class by its name, or by a dotted path

>>> model = Model("http://www.flymine.org/query/service/model")
>>> model.get_class("Gene")
<intermine.model.Class: Gene>
>>> model.get_class("Gene.proteins")
<intermine.model.Class: Protein>

This is the recommended way of retrieving a class from the model. As well as handling class names, you can also pass in a path such as "Gene.proteins" and get the corresponding class back (<intermine.model.Class: Protein>)

Returns: intermine.model.Class
Raises:
  • ModelError - if the class name refers to a non-existant object

make_path(self, path, subclasses={})

source code 

Return a path object for the given path string

>>> path = Model.make_path("Gene.organism.name")
<intermine.model.Path: Gene.organism.name>

This is recommended manner of constructing path objects.

Parameters:
  • path (str)
  • subclasses (dict)
Returns: intermine.model.Path
Raises:

validate_path(self, path_string, subclasses={})

source code 

Validate a path

>>> try:
...     model.validate_path("Gene.symbol")
...     return "path is valid"
... except PathParseError:
...     return "path is invalid"
"path is valid"

When you don't need to interrogate relationships between paths, simply using this method to validate a path string is enough. It guarantees that there is a descriptor for each section of the string, with the appropriate relationships

Raises:

parse_path_string(self, path_string, subclasses={})

source code 

Parse a path string into a list of descriptors - one for each section

>>> parts = Model.parse_path_string(string)

This method is used when making paths from a model, and when validating path strings. It probably won't need to be called directly.