database package

database.db module

Created on Fri May 21 18:09:08 2021

@author: Paolo Cozzi <paolo.cozzi@ibba.cnr.it>

database.db.initialize_db(app)[source]

database.models module

Created on Fri May 21 18:09:30 2021

@author: Paolo Cozzi <paolo.cozzi@ibba.cnr.it>

class database.models.Breed(*args, **values)[source]

Bases: Document

exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

aliases

A list field that wraps a standard field, allowing multiple instances of the field to be used as a list in the database.

If using with ReferenceFields see: Many to Many with ListFields

Note

Required means it cannot be empty - as the default for ListFields is []

code

A unicode string field.

id

A field wrapper around MongoDB’s ObjectIds.

n_individuals

32-bit integer field.

name

A unicode string field.

objects

The default QuerySet Manager.

Custom QuerySet Manager functions can extend this class and users can add extra queryset functionality. Any custom manager methods must accept a Document class as its first argument, and a QuerySet as its second argument.

The method function should return a QuerySet , probably the same one that was passed in, but modified in some way.

species

A unicode string field.

class database.models.BreedAlias(*args, **kwargs)[source]

Bases: EmbeddedDocument

country

A unicode string field.

dataset

A reference to a document that will be automatically dereferenced on access (lazily).

Note this means you will get a database I/O access everytime you access this field. This is necessary because the field returns a Document which precise type can depend of the value of the _cls field present in the document in database. In short, using this type of field can lead to poor performances (especially if you access this field only to retrieve it pk field which is already known before dereference). To solve this you should consider using the LazyReferenceField.

Use the reverse_delete_rule to handle what should happen if the document the field is referencing is deleted. EmbeddedDocuments, DictFields and MapFields does not support reverse_delete_rule and an InvalidDocumentError will be raised if trying to set on one of these Document / Field types.

The options are:

  • DO_NOTHING (0) - don’t do anything (default).

  • NULLIFY (1) - Updates the reference to null.

  • CASCADE (2) - Deletes the documents associated with the reference.

  • DENY (3) - Prevent the deletion of the reference object.

  • PULL (4) - Pull the reference from a ListField of references

Alternative syntax for registering delete rules (useful when implementing bi-directional delete rules)

class Org(Document):
    owner = ReferenceField('User')

class User(Document):
    org = ReferenceField('Org', reverse_delete_rule=CASCADE)

User.register_delete_rule(Org, 'owner', DENY)
fid

A unicode string field.

class database.models.Consequence(*args, **kwargs)[source]

Bases: EmbeddedDocument

class database.models.Country(*args, **values)[source]

Bases: Document

A helper class to deal with countries object. Each record is created after data import, when database status is updated

exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

alpha_2

A unicode string field.

alpha_3

A unicode string field.

id

A field wrapper around MongoDB’s ObjectIds.

name

A unicode string field.

numeric

32-bit integer field.

objects

The default QuerySet Manager.

Custom QuerySet Manager functions can extend this class and users can add extra queryset functionality. Any custom manager methods must accept a Document class as its first argument, and a QuerySet as its second argument.

The method function should return a QuerySet , probably the same one that was passed in, but modified in some way.

official_name

A unicode string field.

species

A list field that wraps a standard field, allowing multiple instances of the field to be used as a list in the database.

If using with ReferenceFields see: Many to Many with ListFields

Note

Required means it cannot be empty - as the default for ListFields is []

class database.models.Dataset(*args, **values)[source]

Bases: Document

Describe a dataset instace with fields owned by data types

exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

breed

A unicode string field.

chip_name

A unicode string field.

contents

A list field that wraps a standard field, allowing multiple instances of the field to be used as a list in the database.

If using with ReferenceFields see: Many to Many with ListFields

Note

Required means it cannot be empty - as the default for ListFields is []

country

A unicode string field.

doi

The publication DOI of this dataset

file

A unicode string field.

gene_array

A unicode string field.

id

A field wrapper around MongoDB’s ObjectIds.

n_of_individuals

32-bit integer field.

n_of_records

32-bit integer field.

objects

The default QuerySet Manager.

Custom QuerySet Manager functions can extend this class and users can add extra queryset functionality. Any custom manager methods must accept a Document class as its first argument, and a QuerySet as its second argument.

The method function should return a QuerySet , probably the same one that was passed in, but modified in some way.

partner

A unicode string field.

size_

A unicode string field.

species

A unicode string field.

trait

A unicode string field.

type_

A list field that wraps a standard field, allowing multiple instances of the field to be used as a list in the database.

If using with ReferenceFields see: Many to Many with ListFields

Note

Required means it cannot be empty - as the default for ListFields is []

uploader

A unicode string field.

class database.models.Location(*args, **kwargs)[source]

Bases: EmbeddedDocument

affymetrix_ab

A unicode string field.

alleles

A unicode string field.

chrom

A unicode string field.

consequences

A list field that wraps a standard field, allowing multiple instances of the field to be used as a list in the database.

If using with ReferenceFields see: Many to Many with ListFields

Note

Required means it cannot be empty - as the default for ListFields is []

date

Datetime field.

Uses the python-dateutil library if available alternatively use time.strptime to parse the dates. Note: python-dateutil’s parser is fully featured and when installed you can utilise it to convert varying types of date formats into valid python datetime objects.

Note: To default the field to the current datetime, use: DateTimeField(default=datetime.utcnow)

Note: Microseconds are rounded to the nearest millisecond.

Pre UTC microsecond support is effectively broken. Use ComplexDateTimeField if you need accurate microsecond support.

illumina

A unicode string field.

illumina_forward

A unicode string field.

illumina_strand

A unicode string field.

property illumina_top

Return genotype in illumina top format

imported_from

A unicode string field.

position

32-bit integer field.

ss_id

A unicode string field.

strand

A unicode string field.

version

A unicode string field.

class database.models.Phenotype(*args, **kwargs)[source]

Bases: DynamicEmbeddedDocument

A class to deal with Phenotype. A dynamic document and not a generic DictField since that there can be attributes which could be enforced to have certain values. All other attributes could be set without any assumptions

chest_girth

Floating point number field.

height

Floating point number field.

length

Floating point number field.

purpose

A unicode string field.

class database.models.Probeset(*args, **kwargs)[source]

Bases: EmbeddedDocument

chip_name

A unicode string field.

probeset_id

A list field that wraps a standard field, allowing multiple instances of the field to be used as a list in the database.

If using with ReferenceFields see: Many to Many with ListFields

Note

Required means it cannot be empty - as the default for ListFields is []

class database.models.SAMPLETYPE(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

BACKGROUND = 'background'
FOREGROUND = 'foreground'
class database.models.SEX(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: bytes, Enum

FEMALE = 2
MALE = 1
UNKNOWN = 0
class database.models.SampleGoat(*args, **values)[source]

Bases: SampleSpecies

exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

father_id

A really lazy reference to a document. Unlike the ReferenceField it will not be automatically (lazily) dereferenced on access. Instead, access will return a LazyReference class instance, allowing access to pk or manual dereference by using fetch() method.

id

A field wrapper around MongoDB’s ObjectIds.

mother_id

A really lazy reference to a document. Unlike the ReferenceField it will not be automatically (lazily) dereferenced on access. Instead, access will return a LazyReference class instance, allowing access to pk or manual dereference by using fetch() method.

objects

The default QuerySet Manager.

Custom QuerySet Manager functions can extend this class and users can add extra queryset functionality. Any custom manager methods must accept a Document class as its first argument, and a QuerySet as its second argument.

The method function should return a QuerySet , probably the same one that was passed in, but modified in some way.

species

A unicode string field.

species_class = 'Goat'
class database.models.SampleSheep(*args, **values)[source]

Bases: SampleSpecies

exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

father_id

A really lazy reference to a document. Unlike the ReferenceField it will not be automatically (lazily) dereferenced on access. Instead, access will return a LazyReference class instance, allowing access to pk or manual dereference by using fetch() method.

id

A field wrapper around MongoDB’s ObjectIds.

mother_id

A really lazy reference to a document. Unlike the ReferenceField it will not be automatically (lazily) dereferenced on access. Instead, access will return a LazyReference class instance, allowing access to pk or manual dereference by using fetch() method.

objects

The default QuerySet Manager.

Custom QuerySet Manager functions can extend this class and users can add extra queryset functionality. Any custom manager methods must accept a Document class as its first argument, and a QuerySet as its second argument.

The method function should return a QuerySet , probably the same one that was passed in, but modified in some way.

species

A unicode string field.

species_class = 'Sheep'
class database.models.SampleSpecies(*args, **values)[source]

Bases: Document

alias

A unicode string field.

breed

A unicode string field.

breed_code

A unicode string field.

chip_name

A unicode string field.

country

A unicode string field.

dataset

A reference to a document that will be automatically dereferenced on access (lazily).

Note this means you will get a database I/O access everytime you access this field. This is necessary because the field returns a Document which precise type can depend of the value of the _cls field present in the document in database. In short, using this type of field can lead to poor performances (especially if you access this field only to retrieve it pk field which is already known before dereference). To solve this you should consider using the LazyReferenceField.

Use the reverse_delete_rule to handle what should happen if the document the field is referencing is deleted. EmbeddedDocuments, DictFields and MapFields does not support reverse_delete_rule and an InvalidDocumentError will be raised if trying to set on one of these Document / Field types.

The options are:

  • DO_NOTHING (0) - don’t do anything (default).

  • NULLIFY (1) - Updates the reference to null.

  • CASCADE (2) - Deletes the documents associated with the reference.

  • DENY (3) - Prevent the deletion of the reference object.

  • PULL (4) - Pull the reference from a ListField of references

Alternative syntax for registering delete rules (useful when implementing bi-directional delete rules)

class Org(Document):
    owner = ReferenceField('User')

class User(Document):
    org = ReferenceField('Org', reverse_delete_rule=CASCADE)

User.register_delete_rule(Org, 'owner', DENY)
locations

A GeoJSON field storing a list of Points.

The data is represented as:

{'type' : 'MultiPoint' ,
 'coordinates' : [[x1, y1], [x2, y2]]}

You can either pass a dict with the full information or a list to set the value.

Requires mongodb >= 2.6

metadata

A dictionary field that wraps a standard Python dictionary. This is similar to an embedded document, but the structure is not defined.

Note

Required means it cannot be empty - as the default for DictFields is {}

original_id

A unicode string field.

phenotype

An embedded document field - with a declared document_type. Only valid values are subclasses of EmbeddedDocument.

sex

Enumeration Field. Values are stored underneath as is, so it will only work with simple types (str, int, etc) that are bson encodable

Example usage:

class Status(Enum):
    NEW = 'new'
    ONGOING = 'ongoing'
    DONE = 'done'

class ModelWithEnum(Document):
    status = EnumField(Status, default=Status.NEW)

ModelWithEnum(status='done')
ModelWithEnum(status=Status.DONE)

Enum fields can be searched using enum or its value:

ModelWithEnum.objects(status='new').count()
ModelWithEnum.objects(status=Status.NEW).count()

The values can be restricted to a subset of the enum by using the choices parameter:

class ModelWithEnum(Document):
    status = EnumField(Status, choices=[Status.NEW, Status.DONE])
smarter_id

A unicode string field.

species_class = None
type_

Enumeration Field. Values are stored underneath as is, so it will only work with simple types (str, int, etc) that are bson encodable

Example usage:

class Status(Enum):
    NEW = 'new'
    ONGOING = 'ongoing'
    DONE = 'done'

class ModelWithEnum(Document):
    status = EnumField(Status, default=Status.NEW)

ModelWithEnum(status='done')
ModelWithEnum(status=Status.DONE)

Enum fields can be searched using enum or its value:

ModelWithEnum.objects(status='new').count()
ModelWithEnum.objects(status=Status.NEW).count()

The values can be restricted to a subset of the enum by using the choices parameter:

class ModelWithEnum(Document):
    status = EnumField(Status, choices=[Status.NEW, Status.DONE])
exception database.models.SmarterDBException[source]

Bases: Exception

class database.models.SmarterInfo(*args, **values)[source]

Bases: Document

A class to track database status informations

exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

id

A unicode string field.

last_updated

Datetime field.

Uses the python-dateutil library if available alternatively use time.strptime to parse the dates. Note: python-dateutil’s parser is fully featured and when installed you can utilise it to convert varying types of date formats into valid python datetime objects.

Note: To default the field to the current datetime, use: DateTimeField(default=datetime.utcnow)

Note: Microseconds are rounded to the nearest millisecond.

Pre UTC microsecond support is effectively broken. Use ComplexDateTimeField if you need accurate microsecond support.

objects

The default QuerySet Manager.

Custom QuerySet Manager functions can extend this class and users can add extra queryset functionality. Any custom manager methods must accept a Document class as its first argument, and a QuerySet as its second argument.

The method function should return a QuerySet , probably the same one that was passed in, but modified in some way.

A dictionary field that wraps a standard Python dictionary. This is similar to an embedded document, but the structure is not defined.

Note

Required means it cannot be empty - as the default for DictFields is {}

version

A unicode string field.

working_assemblies

A dictionary field that wraps a standard Python dictionary. This is similar to an embedded document, but the structure is not defined.

Note

Required means it cannot be empty - as the default for DictFields is {}

class database.models.SupportedChip(*args, **values)[source]

Bases: Document

exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

id

A field wrapper around MongoDB’s ObjectIds.

manufacturer

A unicode string field.

n_of_snps

32-bit integer field.

name

A unicode string field.

objects

The default QuerySet Manager.

Custom QuerySet Manager functions can extend this class and users can add extra queryset functionality. Any custom manager methods must accept a Document class as its first argument, and a QuerySet as its second argument.

The method function should return a QuerySet , probably the same one that was passed in, but modified in some way.

species

A unicode string field.

class database.models.VariantGoat(*args, **values)[source]

Bases: VariantSpecies

exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

id

A field wrapper around MongoDB’s ObjectIds.

objects

The default QuerySet Manager.

Custom QuerySet Manager functions can extend this class and users can add extra queryset functionality. Any custom manager methods must accept a Document class as its first argument, and a QuerySet as its second argument.

The method function should return a QuerySet , probably the same one that was passed in, but modified in some way.

class database.models.VariantSheep(*args, **values)[source]

Bases: VariantSpecies

exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

id

A field wrapper around MongoDB’s ObjectIds.

objects

The default QuerySet Manager.

Custom QuerySet Manager functions can extend this class and users can add extra queryset functionality. Any custom manager methods must accept a Document class as its first argument, and a QuerySet as its second argument.

The method function should return a QuerySet , probably the same one that was passed in, but modified in some way.

class database.models.VariantSpecies(*args, **values)[source]

Bases: Document

affy_snp_id

A unicode string field.

chip_name

A list field that wraps a standard field, allowing multiple instances of the field to be used as a list in the database.

If using with ReferenceFields see: Many to Many with ListFields

Note

Required means it cannot be empty - as the default for ListFields is []

cust_id

A unicode string field.

illumina_top

A unicode string field.

locations

A list field that wraps a standard field, allowing multiple instances of the field to be used as a list in the database.

If using with ReferenceFields see: Many to Many with ListFields

Note

Required means it cannot be empty - as the default for ListFields is []

name

A unicode string field.

probesets

A list field that wraps a standard field, allowing multiple instances of the field to be used as a list in the database.

If using with ReferenceFields see: Many to Many with ListFields

Note

Required means it cannot be empty - as the default for ListFields is []

rs_id

A list field that wraps a standard field, allowing multiple instances of the field to be used as a list in the database.

If using with ReferenceFields see: Many to Many with ListFields

Note

Required means it cannot be empty - as the default for ListFields is []

sender

A unicode string field.

sequence

A dictionary field that wraps a standard Python dictionary. This is similar to an embedded document, but the structure is not defined.

Note

Required means it cannot be empty - as the default for DictFields is {}

to_mongo(*args, **kwargs)[source]

Override flask-mongoengine method

database.models.complement(genotype: str)[source]