Collection
Class used to represent a collection in MetagenomeDB.
-
class MetagenomeDB.Collection(properties)
Create a new Collection object.
- Parameters:
- properties: properties of this sequence, as a dictionary.
Must contain at least a ‘name’ property, or a
InvalidObjectError exception is thrown.
Note
Collection names are unique in the database; if attempting to
commit a collection while another collection already exists with
the same name a DuplicateObjectError exception
is thrown.
-
add_to_collection(collection, relationship=None)
Add this collection to a (super) collection.
- Parameters:
- collection: collection to add this collection to.
- relationship: properties of the relationship from this
collection to collection, as a dictionary (optional). See
Annotations.
Note
- If collection has never been committed to the database a
UncommittedObjectError is thrown.
- This collection 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_related_collections(direction=0, collection_filter=None, relationship_filter=None)
Count all collections this collection is linked to, or have links to it.
- Parameters:
- direction: direction of the relationship (optional). If set to
Direction.INGOING, will count collections that are linked to
this collection (i.e., sub-collections). If set to
Direction.OUTGOING, will count collections this collection is
linked to (i.e., super-collections). If set to Direction.BOTH
(default), all neighboring collections are counted. See
Relationships.
- collection_filter: filter for the collections to count (optional).
See Queries.
- relationship_filter: filter for the relationships between this
collection and neighbor collections (optional). See Queries.
Note
- If direction is set to Direction.BOTH or Direction.OUTGOING,
relationship_filter is set and this collection is not committed,
a UncommittedObjectError exception is thrown.
See also
list_related_collections()
-
count_sequences(sequence_filter=None, relationship_filter=None)
Count sequences this collection contains.
- Parameters:
- sequence_filter: filter for the sequences to count (optional).
See Queries.
- relationship_filter: filter for the relationship linking
sequences to this collection (optional). See Queries.
See also
list_sequences()
-
count_sub_collections(collection_filter=None, relationship_filter=None)
Count all collections that are linked to this collection.
- Parameters:
- collection_filter: filter for the sub-collections (optional).
See Queries.
- relationship_filter: filter for the relationships linking
sub-collections to this collection (optional). See Queries.
See also
list_sub_collections(),
list_super_collections(),
count_super_collections()
-
count_super_collections(collection_filter=None, relationship_filter=None)
Count all collections this collection is linked to.
- Parameters:
- collection_filter: filter for the super-collections (optional).
See Queries.
- relationship_filter: filter for the relationships linking this
collection to super-collections (optional). See Queries.
Note
- If this collection is not committed and relationship_filter is
set a UncommittedObjectError exception is thrown.
See Relationships.
See also
list_super_collections(),
list_sub_collections(),
count_sub_collections()
-
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_related_collections(direction=0, collection_filter=None, relationship_filter=None)
List all collections this collection is linked to, or have links to it.
- Parameters:
- direction: direction of the relationship (optional). If set to
Direction.INGOING, will list collections that are linked to
this collection (i.e., sub-collections). If set to
Direction.OUTGOING, will list collections this collection is
linked to (i.e., super-collections). If set to Direction.BOTH
(default), all neighboring collections are listed. See
Relationships.
- collection_filter: filter for the collections to list (optional).
See Queries.
- relationship_filter: filter for the relationships between this
collection and neighbor collections (optional). See Queries.
Note
- If direction is set to Direction.BOTH or Direction.OUTGOING,
relationship_filter is set and this collection is not committed,
a UncommittedObjectError exception is thrown.
See also
count_related_collections()
-
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()
-
list_sequences(sequence_filter=None, relationship_filter=None)
List sequences this collection contains.
- Parameters:
- sequence_filter: filter for the sequences to list (optional).
See Queries.
- relationship_filter: filter for the relationship linking
sequences to this collection (optional). See Queries.
See also
count_sequences()
-
list_sub_collections(collection_filter=None, relationship_filter=None)
List all collections that are linked to this collection.
- Parameters:
- collection_filter: filter for the sub-collections (optional).
See Queries.
- relationship_filter: filter for the relationships linking
sub-collections to this collection (optional). See Queries.
See also
count_sub_collections(),
list_super_collections(),
count_super_collections()
-
list_super_collections(collection_filter=None, relationship_filter=None)
List all collections this collection is linked to.
- Parameters:
- collection_filter: filter for the super-collections (optional).
See Queries.
- relationship_filter: filter for the relationships linking this
collection to super-collections (optional). See Queries.
Note
- If this collection is not committed and relationship_filter is
set a UncommittedObjectError exception is thrown.
See Relationships.
See also
count_super_collections(),
list_sub_collections(),
count_sub_collections()
-
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 collection from another (super) collection.
- Parameters:
- collection: collection to remove this collection from.
- relationship_filter: relationships to remove (optional).
If none provided, all relationships linking this collection
to collection are removed. See Queries.
Note
- If this collection and collection have no relationship, a
MetagenomeDBError exception is thrown.
- If this collection is not committed and relationship_filter is
set a UncommittedObjectError exception is thrown.
See Relationships.
See also
add_to_collection()