Sequence
Class used to represent a sequence in MetagenomeDB.
-
class MetagenomeDB.Sequence(properties)
Create a new Sequence object.
- Parameters:
- properties: properties of this sequence, as a dictionary.
Must contain at least a ‘name’ and ‘sequence’ property, or a
InvalidObjectError exception is thrown. A
‘length’ property is automatically calculated and would overwrite
any such property if provided.
Note
The ‘name’ property is unique within a collection, but not across
the whole database. It means that two sequences with the same name
can coexist in the database as long as they belong to two different
collections (or if they are not related to any collection).
-
add_to_collection(collection, relationship=None)
Add this sequence to a collection.
- Parameters:
- collection: collection to add this sequence to.
- relationship: properties of the relationship linking this
sequence to collection, as a dictionary (optional). See
Annotations.
Note
- If the collection already contains a sequence with the same name
a DuplicateObjectError exception is thrown.
- If the collection has never been committed to the database a
UncommittedObjectError is thrown.
- This sequence will need to be committed to the database for the
information about its relationship to collection to be stored
and queried. See Relationships.
See also
remove_from_collection()
-
commit()
Commit this object to the database.
Note
- The commit will not be performed if the object has already been
committed once and no modification (property manipulation) has
been performed since then.
- If an object already exists in the database with the same values
for properties flagged as unique a DuplicateObjectError
exception is thrown.
-
classmethod count(filter=None)
Count the number of objects of this type in the database.
- Parameters:
- filter: filter for the objects to count (optional); see
Queries.
-
count_collections(collection_filter=None, relationship_filter=None)
Count collections this sequence is linked to.
- Parameters:
- collection_filter: filter for the collections (optional). See Queries.
- relationship_filter: filter for the relationship linking this
sequence to collections (optional). See Queries.
Note
- If this sequence is not committed and relationship_filter is
set a UncommittedObjectError exception is thrown.
See Relationships.
See also
list_collections()
-
count_related_sequences(direction=0, sequence_filter=None, relationship_filter=None)
Count sequences this sequence is related to.
- Parameters:
- direction: direction of the relationship (optional). If set to
Direction.INGOING, will count sequences that are linked to
this sequence. If set to Direction.OUTGOING, will count
sequences this sequence is linked to. If set to Direction.BOTH
(default), all neighboring sequences are counted. See
Relationships
- sequence_filter: filter for the sequences to count (optional).
See Queries.
- relationship_filter: filter for the relationship between this
sequence and neighboring sequences (optional). See Queries.
Note
- If direction is set to Direction.BOTH or Direction.OUTGOING,
relationship_filter is set and this sequence is not committed,
a UncommittedObjectError exception is thrown.
See also
list_related_sequences()
-
dissociate_from_sequence(sequence, relationship_filter=None)
Remove links between this sequence and another sequence.
- Parameters:
- sequence: sequence to unlink this sequence from.
- relationship_filter: relationships to remove (optional).
If none provided, all relationships from this sequence
to sequence are removed. See Queries.
Note
- If this sequence and sequence have no relationship, a
MetagenomeDBError exception is thrown.
- If this sequence is not committed and relationship_filter is
set a UncommittedObjectError exception is thrown.
See Relationships.
See also
relate_to_sequence()
-
classmethod distinct(property)
For each value found in the database for a given property, return
the number of objects that have this value.
- Parameters:
- property: property to count objects for.
- Return:
- A dictionary with all values found for this property as keys, and
number of objects having this value as values.
-
classmethod find(filter=None)
Find all objects of this type that match a query.
- Parameters:
- filter: filter for the objects to select (optional); see
Queries.
- Return:
- A generator.
See also
count(), find_one()
-
classmethod find_one(filter)
Find the first (or only) object of this type that match a query.
- Parameters:
- filter: filter for the object to select; see Queries.
- Return:
- An object, or None if no object found.
-
get_properties()
Return a copy of all of this object’s properties, as a dictionary.
-
get_property(key, default=None)
Return the value for a given property.
- Parameters:
-
See also
get_properties()
-
has_relationships_with(target)
Test if this object has relationship(s) with another object.
- Parameters:
- target: object to test for the existence of relationships with.
See also
list_relationships_with()
-
is_committed()
- Test if this object has been committed to the database since
- its latest modification.
-
list_collections(collection_filter=None, relationship_filter=None)
List collections this sequence is linked to.
- Parameters:
- collection_filter: filter for the collections (optional). See
Queries.
- relationship_filter: filter for the relationship linking this
sequence to collections (optional). See Queries.
Note
- If this sequence is not committed and relationship_filter is
set a UncommittedObjectError exception is thrown.
See Relationships.
See also
count_collections()
-
list_related_sequences(direction=0, sequence_filter=None, relationship_filter=None)
List sequences this sequence is related to.
- Parameters:
- direction: direction of the relationship (optional). If set to
Direction.INGOING, will list sequences that are linked to the
present sequence. If set to Direction.OUTGOING, will list
sequences this sequence is linked to. If set to Direction.BOTH
(default), both neighboring sequences are listed. See
Relationships.
- sequence_filter: filter for the sequences to list (optional).
See Queries.
- relationship_filter: filter for the relationship between this
sequence and neighboring sequences (optional). See Queries.
Note
- If direction is set to Direction.BOTH or Direction.OUTGOING,
relationship_filter is set and this sequence is not committed,
a UncommittedObjectError exception is thrown.
See also
count_related_sequences()
-
list_relationships_with(target)
List relationship(s), if any, from this object to others.
- Parameters:
- target: object to list relationships with.
- Return:
- A list.
See also
has_relationships_with()
-
relate_to_sequence(sequence, relationship=None)
Link this sequence to another sequence.
- Parameters:
- sequence: sequence to link this sequence to.
- relationship: description of the relationship linking this
sequence to sequence, as a dictionary (optional).
Note
- If sequence has never been committed to the database a
UncommittedObjectError is thrown.
- This sequence will need to be committed to the database for the
information about its relationship to sequence to be stored
and queried. See Relationships.
See also
dissociate_from_sequence()
-
remove()
Remove this object from the database.
Note
- Relationships from and to this object are removed as well.
- The object remains in memory, flagged as uncommitted.
-
classmethod remove_all()
Remove all objects of this type from the database.
Note
- Relationships from and to these objects are removed as well.
- Instanciated objects remain in memory, flagged as uncommitted.
-
remove_from_collection(collection, relationship_filter=None)
Remove this sequence from a collection.
- Parameters:
- collection: collection to remove this collection from.
- relationship_filter: relationships to remove (optional).
If none provided, all relationships linking this sequence to
collection are removed. See Queries.
Note
- If this sequence and collection have no relationship, a
MetagenomeDBError exception is thrown.
- If this sequence is not committed and relationship_filter is
set a UncommittedObjectError exception is thrown.
See Relationships.
See also
add_to_collection()