diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index d340d1abb85f89bad8f88c57f33de5dce7c4db71..5752f2b5a1a201906f6b3200b199258e2dbe06a8 100644 --- a/ippisite/ippidb/models.py +++ b/ippisite/ippidb/models.py @@ -543,6 +543,11 @@ class PpiComplex(models.Model): class CompoundsManager(models.Manager): + """ + Model manager for the `Compound` class + provides selections to `validated` or `user-visible` compounds + """ + def for_user(self, current_user): """ Get compounds visible to a given user @@ -876,7 +881,9 @@ class Compound(AutoFillableModel): # ] def compute_drugbank_compound_similarity(self): - """ compute Tanimoto similarity to existing DrugBank compounds """ + """ + Compute Tanimoto similarity to existing DrugBank compounds + """ self.save() # fingerprints to compute drugbank similarities are in settings module, default FP2 fingerprinter = FingerPrinter(getattr(settings, "DRUGBANK_FINGERPRINTS", "FP2")) @@ -901,14 +908,14 @@ class Compound(AutoFillableModel): @property def biblio_refs(self): """ - return all RefCompoundBiblio related to this compound + Return all RefCompoundBiblio related to this compound """ return RefCompoundBiblio.objects.filter(compound=self) @property def pfam_ids(self): """ - return all PFAM ids for the domain of the proteins of the bound + Return all PFAM ids for the domain of the proteins of the bound complexes in the PPIs this compound has an action on """ pfam_ids = set() @@ -920,6 +927,9 @@ class Compound(AutoFillableModel): @property def best_pXC50_compound_activity_result(self): + """ + Return the best pXC50 activity + """ best_pXC50_activity = self.best_activity if best_pXC50_activity is None: return None @@ -932,7 +942,7 @@ class Compound(AutoFillableModel): @property def bioch_tests_count(self): """ - return the number of associated biochemical tests + Return the number of associated biochemical tests """ return ( self.compoundactivityresult_set.all() @@ -943,7 +953,7 @@ class Compound(AutoFillableModel): @property def cell_tests_count(self): """ - return the number of associated cell tests + Return the number of associated cell tests """ return ( self.compoundactivityresult_set.all() @@ -953,9 +963,16 @@ class Compound(AutoFillableModel): @property def sorted_similar_drugbank_compounds(self): + """ + Return the similar Drugbank compounds, + sorted by decreasing similarity + """ return self.drugbankcompoundtanimoto_set.order_by("-tanimoto") def is_validated(self): + """ + Return the compound validation status + """ # if compound is not linked to any CompoundAction this is # because it was dereferenced because of duplication by # `replace_compound_references` @@ -969,21 +986,38 @@ class Compound(AutoFillableModel): is_validated.boolean = True def autofill(self): + """ + Finalize the computation of the Compound + by computing InChi, InChiKey and Drugbank similarity + """ # compute InChi and InChiKey self.inchi = smi2inchi(self.canonical_smile) self.inchikey = smi2inchikey(self.canonical_smile) self.compute_drugbank_compound_similarity() def compute_fsp3(self): + """ + Compute FSP3 from CSP3 and number of carbons + """ self.fsp3 = self.nb_csp3 / self.nb_c def __str__(self): + """ + String representation + """ return "Compound #{}".format(self.id) def get_absolute_url(self): + """ + Get absolute URL to the Compound page + """ return reverse("compound_card", kwargs={"pk": self.pk}) def clean(self): + """ + Perform additional checks: + - check common name for the Compound is unique + """ if ( self.common_name is not None and self.common_name != "" @@ -994,11 +1028,14 @@ class Compound(AutoFillableModel): self.add_error("common_name", "A compound with this name already exists") def get_jobs(self): + """ + Retrieve the jobs for the compound + """ return CompoundJob.objects.filter(compound=self) def replace_compound_references(self, replacing_compound): """ - replace the references to a given compound in the data with + Replace the references to a given compound in the data with references to another new compound. used to deal with duplicates in the database """