mgkit.db.mongo module

New in version 0.2.1.

This module contains functions and classes to use for a DB like representation of annotations using the pymongo package, a driver to MongoDB.

In a MongoDB document, exported from an annotation, using the method, the keys that are defined are:

seq_id, source, feat_type, start, end, score, strand,
phase, gene_id, taxon_id, bitscore, exp_nonsyn, exp_syn,
length, dbq, coverage, map

These are defined because they have values that are not strings (defined as properties in The rest of the attributes defined are kept as well, but no ckeck for the data type is made.


lineage is added as a key, whose values are taxon_id, if a function has been passed to

The exception is the map key in the document. It store both the EC mappings (EC attribute in the GFF), as well as all mappings whose attribute starts with map_. The former is usually accessed from while the latter from or

These 3 methods return a list and this list is used in the MongoDB document. The MongoDB document will contain a map key where the values are the type of mappings, and the values the list of IDs the annoation maps to.

Example for the map dictionary
Type GFF Annotation MongoDB Document MongoDB Query
EC EC get_ec ec
KO map_KO get_mapping(‘ko’) ko map.ko
eggNOG map_EGGNOG get_mapping(‘eggnog’) eggnog map.eggnog
class mgkit.db.mongo.GFFDB(db, collection, uri=None, timeout=5)

Bases: future.types.newobject.newobject

Changed in version 0.3.4: added timeout parameter

Wrapper to a MongoDB connection/db. It is used to automate the convertion of MongoDB records into instances.


New in version 0.3.1.

Retrieves an annotation from the DB by its uid


New in version 0.3.1.

Iterates over all annotations

conn = None

Changed in version 0.3.1: removes lineage from the attributes

Converts the record (a dictionary instance) to an Annotation


Returns a cursor for the query

db = None

Iterate over a cursor created using query and yields each record after converting it to a instance, using mgkit.db.mongo.GFFDB.convert_record().


New in version 0.3.4.

Inserts annotations into the DB


The object must be a


New in version 0.3.4.

Inserts an annotation into the DB

Raises:TypeError – if the passed object is not an annotation

New in version 0.3.1.

Iterates over all the annotations in the db/collection, yielding a tuple (annotation.uid, annotation)


New in version 0.3.1.

Alias for GFFDB.items()


New in version 0.3.1.

Alias for GFFDB.values()


New in version 0.3.1.

Iterates over all the uid in the db/collection


New in version 0.3.1.

Iterates over all the annotations in the db/collection