Uid App

All stuff related with image The Unified Internal Database and site pages like index and about are defined in this module.

uid.models

Submission and user data

Inside model library, you can manage The Unified Internal Database objects. The main object is uid.models.Submission which is the object that a registered user create when starts creating a new submission. Animals and Samples data loaded by user are manged by the uid.models.Animal and uid.models.Sample class. The original name of such objects (defined as Data source id from the IMAGE metadata rules) is managed by uid.models.Animal and uid.models.Sample respectively which track also the biosample_id of such objects and its Common statuses. Here are presented the relations between uid.models.Submission objects:

../_images/uid_submission.1degree.png

Through relationship, you could rerieve all animal belonging to a submission, for example:

from uid.models import Submission, Animal

submission = Submission.objects.get(pk=1)
animals = Animal.objects.filter(submission=submission)

in this example animals is a django.db.models.query.QuerySet instance with all animals defined in selected submission. You can also fecth all animals from the submission instance itself:

animals = submission.animal_set

This command is equivalent of the previous.

Private data

Submission data (Animals, Samples) are considered private to the user when they are stored in The Unified Internal Database. Each table (django.models.Model) has an owner column in which a relation to django.contrib.auth.models.User is defined. In such way, is possible to get all objects belonging to such user:

from uid.models import User

user = User.objects.get(username="test")
user_animals = Animal.objects.filter(owner=user)

django.contrib.auth.models.User are also contained in authenticated sessions, and could be used in Views:

user_animals = Animal.objects.filter(owner=request.user)

The common.views.OwnerMixin extends the default get_queryset of django.views.generic.detail.SingleObjectMixin in order to filter QuerySet using self.request.user. Such Mixin can be inherited by all django.views.generic.detail.SingleObjectMixin and django.views.generic.list.MultipleObjectMixin derived classes in order to filter objects relying on django authenticated sessions:

from django.views.generic import DetailView, ListView

from uid.models import Submission
from common.views import OwnerMixin

class DetailSubmissionView(OwnerMixin, DetailView):
    model = Submission
    template_name = "submissions/submission_detail.html"

class ListSubmissionsView(OwnerMixin, ListView):
    model = Submission
    template_name = "submissions/submission_list.html"
    ordering = ['-created_at']
    paginate_by = 10

since common.views.OwnerMixin inherits from django.contrib.auth.mixins.LoginRequiredMixin, an authentication sessions is required to access to derived views. The login redirect will be managed if the session is anonymous

uid.models module contents

class uid.models.Animal(*args, **kwargs)[source]

Bases: uid.mixins.BioSampleMixin, uid.models.Name

Class to model Animal (Organism). Inherits from BioSampleMixin, related to Name through OneToOne relationship to model Animal name (Data source id), and with the same relationship to model mother and father of such animal. In case that parents are unknown, could be linked with Unkwnon animals for cryoweb data or doens’t have relationship.Linked to DictBreed dictionary table to model info on species and breed. Linked to Sample to model Samples (Specimen from organims):

from uid.models import Animal

# get animal using primary key
animal = Animal.objects.get(pk=1)

# get animal name
data_source_id = animal.name

# get animal's parents
mother = animal.mother
father = animal.father

# get breed and species info
print(animal.breed.supplied_breed)
print(animal.breed.specie.label)

# get all samples (specimen) for this animals
samples = animal.sample_set.all()
exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

get_attributes()[source]

Return attributes like biosample needs

get_father_relationship()[source]

Get a relationship with father if possible

get_mother_relationship()[source]

Get a relationship with mother if possible

get_relationship(nature='derived from')[source]

Get a relationship to this animal (call this method from a related object to get a connection to this element)

Parameters

nature (str) – set relationship nature (child of, derived_from, …)

to_biosample(release_date=None)[source]

get a json from animal for biosample submission

class uid.models.Confidence(*args, **kwargs)[source]

Bases: uid.mixins.BaseMixin, django.db.models.base.Model

Abstract class which add confidence to models

class uid.models.DictBase(*args, **kwargs)[source]

Bases: uid.mixins.BaseMixin, django.db.models.base.Model

Abstract class to be inherited to all dictionary tables. It models fields like label (the revised term like submitter or blood) and term (the ontology id as the final part of the URI link)

The fixed part of the URI could be customized from Ontology by setting library_name class attribute accordingly:

class DictRole(DictBase):
    library_name = 'EFO'
format_attribute()[source]

Format an object instance as a dictionary used by biosample, for example:

[{
    'value': 'submitter',
    'terms': [{'url': 'http://www.ebi.ac.uk/efo/EFO_0001741'}]
}]

the fixed part of URI link is defined by library_name class attribute

class uid.models.DictBreed(*args, **kwargs)[source]

Bases: uid.models.Confidence

A class to deal with breed objects and their ontologies

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

format_attribute()[source]

Format mapped_breed attribute (with its ontology). Return None if no mapped_breed

property mapped_breed

Alias for label attribute. Return general label if no term is found

property mapped_breed_term

Alias for term attribute. Return general term if no term is found

class uid.models.DictCountry(*args, **kwargs)[source]

Bases: uid.models.DictBase, uid.models.Confidence

A class to model contries defined by NCI Thesaurus OBO Edition https://www.ebi.ac.uk/ols/ontologies/ncit

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

class uid.models.DictDevelStage(*args, **kwargs)[source]

Bases: uid.models.DictBase, uid.models.Confidence

A class to developmental stages defined as descendants of descendants of EFO_0000399

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

class uid.models.DictPhysioStage(*args, **kwargs)[source]

Bases: uid.models.DictBase, uid.models.Confidence

A class to physiological stages defined as descendants of descendants of PATO_0000261

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

class uid.models.DictRole(*args, **kwargs)[source]

Bases: uid.models.DictBase

A class to model roles defined as childs of http://www.ebi.ac.uk/efo/EFO_0002012

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

class uid.models.DictSex(*args, **kwargs)[source]

Bases: uid.models.DictBase

A class to model sex as defined in PATO

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

class uid.models.DictSpecie(*args, **kwargs)[source]

Bases: uid.models.DictBase, uid.models.Confidence

A class to model species defined by NCBI organismal classification http://www.ebi.ac.uk/ols/ontologies/ncbitaxon

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

classmethod get_by_synonym(synonym, language)[source]

return an instance by synonym in supplied language or default one

classmethod get_specie_check_synonyms(species_label, language)[source]

get a DictSpecie object. Species are in latin names, but I can find also a common name in translation tables

class uid.models.DictUberon(*args, **kwargs)[source]

Bases: uid.models.DictBase, uid.models.Confidence

A class to model anatomies modeled in uberon

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

class uid.models.Name(*args, **kwargs)[source]

Bases: uid.mixins.BaseMixin, django.db.models.base.Model

Model UID names: define a name (sample or animal) unique for each data submission

property validationresult

return the first validationresult object (should be uinique)

class uid.models.Ontology(id, library_name, library_uri, comment)[source]

Bases: uid.mixins.BaseMixin, django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

class uid.models.Organization(id, name, address, country, URI, role)[source]

Bases: uid.mixins.BaseMixin, django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

class uid.models.Person(id, user, initials, affiliation, role)[source]

Bases: uid.mixins.BaseMixin, django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

class uid.models.Publication(id, doi)[source]

Bases: uid.mixins.BaseMixin, django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

class uid.models.Replace(*args, **kwargs)[source]

Bases: django.db.models.expressions.Func

class uid.models.Sample(id, name, submission, biosample_id, owner, status, last_changed, last_submitted, publication, alternative_id, description, material, animal, protocol, collection_date, collection_place_latitude, collection_place_longitude, collection_place, collection_place_accuracy, organism_part, developmental_stage, physiological_stage, animal_age_at_collection, animal_age_at_collection_units, availability, storage, storage_processing, preparation_interval, preparation_interval_units)[source]

Bases: uid.mixins.BioSampleMixin, uid.models.Name

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

get_attributes()[source]

Return attributes like biosample needs

to_biosample(release_date=None)[source]

get a json from sample for biosample submission

class uid.models.Submission(id, title, project, description, gene_bank_name, gene_bank_country, datasource_type, datasource_version, organization, uploaded_file, created_at, updated_at, status, message, owner)[source]

Bases: uid.mixins.BaseMixin, django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

can_delete()[source]

return True if I can delete the submission

can_edit()[source]

Returns True if I can edit a submission

can_submit()[source]

Return yes if I can submit a submission to BioSamples

get_uploaded_file_path()[source]

Return uploaded file path in docker container

uid.models.missing_terms()[source]

Get informations about dictionary terms without ontologies

uid.models.truncate_database()[source]

Truncate image database

uid.models.truncate_filled_tables()[source]

Truncate filled tables by import processes

uid.models.uid_report(user)[source]

Performs a statistic on UID database to find issues. require user as request.user

uid.mixins

uid.mixins module contents

Created on Fri Jun 28 14:46:39 2019

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

Define mixins classes for uid.models

class uid.mixins.BaseMixin[source]

Bases: object

Base class for UID tables. It implement common stuff for all UID tables:

from uid.models import BaseMixin

class Submission(BaseMixin):
    pass
classmethod truncate()[source]

Truncate table data and restart indexes from 0:

from uid.models import Submission

Submission.truncate()
class uid.mixins.BioSampleMixin[source]

Bases: uid.mixins.BaseMixin

Common methods for animal and samples useful in biosample generation Need to called with data into biosample or animals:

from uid.models import Animal

animal = Animal.objects.get(pk=1)
biosample_data = animal.to_biosample()
can_delete()[source]

Returns True if I can delete a sample/animal according to submission status

Returns

bool

can_edit()[source]

Returns True if I can edit a sample/animal according to submission status

Returns

bool

property data_source_id

Get Data source id (original animal/sample name)

property gene_bank_country

Return DictCountry relationship from related Submission object

property gene_bank_name

Return gene bank name from related Submission object

get_attributes()[source]

Common attribute definition required from Animal and samples. Need to be called inside Animal/sample get_atribute method. Keys is the name in metadata rules

Returns

a dictionary object

Return type

dict

property organization

Return Organization relationship from related Submission object

property person

Retrieve Person information from owner relationship

property specie
to_biosample(release_date=None)[source]

Common stuff to generate a biosample object. Need to be called inside Animal/Sample to_biosample method

Parameters

release_date (str) – data will no be published before this day (YYYY-MM-DD)

Returns

a dictionary object

Return type

dict

uid.views

uid.views module contents

Created on Tue Feb 6 15:04:07 2018

@author: Paolo Cozzi <paolo.cozzi@ptp.it>

class uid.views.AboutSubmissionView(**kwargs)[source]

Bases: django.views.generic.base.TemplateView

template_name = 'uid/about_submission.html'
class uid.views.AboutUploadingView(**kwargs)[source]

Bases: django.views.generic.base.TemplateView

template_name = 'uid/uploading_data.html'
class uid.views.AboutView(**kwargs)[source]

Bases: django.views.generic.base.TemplateView

template_name = 'uid/about.html'
class uid.views.DashBoardView(**kwargs)[source]

Bases: django.contrib.auth.mixins.LoginRequiredMixin, django.views.generic.base.TemplateView

get_context_data(**kwargs)[source]
template_name = 'uid/dashboard.html'
class uid.views.IndexView(**kwargs)[source]

Bases: django.views.generic.base.TemplateView

template_name = 'uid/index.html'
class uid.views.PrivacyView(**kwargs)[source]

Bases: django.views.generic.base.TemplateView

template_name = 'uid/privacy_policy.html'
class uid.views.SummaryView(**kwargs)[source]

Bases: django.contrib.auth.mixins.LoginRequiredMixin, django.views.generic.base.TemplateView

get_context_data(**kwargs)[source]
template_name = 'uid/summary.html'
class uid.views.TermsView(**kwargs)[source]

Bases: django.views.generic.base.TemplateView

template_name = 'uid/terms_and_conditions.html'
class uid.views.UpdateOrganizationView(**kwargs)[source]

Bases: common.views.FormInvalidMixin, django.contrib.auth.mixins.LoginRequiredMixin, django.views.generic.edit.UpdateView

form_class

alias of uid.forms.OrganizationForm

get_object()[source]

Get the organization which this user belongs to

model

alias of uid.models.Organization

success_url
template_name = 'uid/organization_form.html'
uid.views.protected_view(request, path)[source]

Redirect the request to the path used by nginx for protected media.