Skip to content
Snippets Groups Projects
Commit 543dba4b authored by Bryan BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

formatting models

parent 5826d95b
Branches
Tags
No related merge requests found
Pipeline #9262 passed
...@@ -202,6 +202,7 @@ class Domain(AutoFillableModel): ...@@ -202,6 +202,7 @@ class Domain(AutoFillableModel):
pfam_id = models.CharField('Pfam Family Identifier', max_length=20) pfam_id = models.CharField('Pfam Family Identifier', max_length=20)
pfam_description = models.CharField('Pfam Description', max_length=100) pfam_description = models.CharField('Pfam Description', max_length=100)
domain_family = models.CharField('Domain family', max_length=25) domain_family = models.CharField('Domain family', max_length=25)
# TODO: what is this field? check database # TODO: what is this field? check database
# contents # contents
...@@ -277,11 +278,13 @@ class Symmetry(models.Model): ...@@ -277,11 +278,13 @@ class Symmetry(models.Model):
class Disease(models.Model): class Disease(models.Model):
name = models.CharField('Disease', max_length=30, unique=True) name = models.CharField('Disease', max_length=30, unique=True)
# is there any database/nomenclature for diseases? # is there any database/nomenclature for diseases?
def __str__(self): def __str__(self):
return self.name return self.name
class PpiFamily(models.Model): class PpiFamily(models.Model):
""" """
PPI Family PPI Family
...@@ -358,6 +361,7 @@ class CompoundManager(models.Manager): ...@@ -358,6 +361,7 @@ class CompoundManager(models.Manager):
""" """
def get_queryset(self): def get_queryset(self):
# @formatter:off
qs = super().get_queryset() qs = super().get_queryset()
# with number of publications # with number of publications
qs = qs.annotate(pubs=Count('refcompoundbiblio', distinct=True)) qs = qs.annotate(pubs=Count('refcompoundbiblio', distinct=True))
...@@ -418,8 +422,10 @@ class CompoundManager(models.Manager): ...@@ -418,8 +422,10 @@ class CompoundManager(models.Manager):
qs = qs.annotate(cytoxtest_av=Cast(Max(Case(When(refcompoundbiblio__bibliography__cytotox=True, then=1), default=0, output_field=IntegerField())), BooleanField())) qs = qs.annotate(cytoxtest_av=Cast(Max(Case(When(refcompoundbiblio__bibliography__cytotox=True, then=1), default=0, output_field=IntegerField())), BooleanField()))
# in silico st performed # in silico st performed
qs = qs.annotate(insilico_av=Cast(Max(Case(When(refcompoundbiblio__bibliography__in_silico=True, then=1), default=0, output_field=IntegerField())), BooleanField())) qs = qs.annotate(insilico_av=Cast(Max(Case(When(refcompoundbiblio__bibliography__in_silico=True, then=1), default=0, output_field=IntegerField())), BooleanField()))
#@formatter:on
return qs return qs
class Compound(AutoFillableModel): class Compound(AutoFillableModel):
""" """
Chemical compound Chemical compound
...@@ -513,7 +519,11 @@ class Compound(AutoFillableModel): ...@@ -513,7 +519,11 @@ class Compound(AutoFillableModel):
tanimoto_dict = dict(sorted(tanimoto_dict.items(), key=operator.itemgetter(1), reverse=True)[:15]) tanimoto_dict = dict(sorted(tanimoto_dict.items(), key=operator.itemgetter(1), reverse=True)[:15])
dbcts = [] dbcts = []
for id_, tanimoto in tanimoto_dict.items(): for id_, tanimoto in tanimoto_dict.items():
dbcts.append(DrugbankCompoundTanimoto(compound=self, drugbank_compound=DrugBankCompound.objects.get(id=id_), tanimoto=tanimoto)) dbcts.append(DrugbankCompoundTanimoto(
compound=self,
drugbank_compound=DrugBankCompound.objects.get(id=id_),
tanimoto=tanimoto,
))
DrugbankCompoundTanimoto.objects.bulk_create(dbcts) DrugbankCompoundTanimoto.objects.bulk_create(dbcts)
@property @property
...@@ -613,6 +623,7 @@ class Compound(AutoFillableModel): ...@@ -613,6 +623,7 @@ class Compound(AutoFillableModel):
def __str__(self): def __str__(self):
return 'Compound #{}'.format(self.id) return 'Compound #{}'.format(self.id)
class CompoundTanimoto(models.Model): class CompoundTanimoto(models.Model):
canonical_smiles = models.TextField( canonical_smiles = models.TextField(
'Canonical Smile') 'Canonical Smile')
...@@ -625,6 +636,7 @@ class CompoundTanimoto(models.Model): ...@@ -625,6 +636,7 @@ class CompoundTanimoto(models.Model):
unique_together = ( unique_together = (
('canonical_smiles', 'fingerprint', 'compound')) ('canonical_smiles', 'fingerprint', 'compound'))
def create_tanimoto(smiles_query, fingerprint): def create_tanimoto(smiles_query, fingerprint):
""" """
Compute the Tanimoto similarity between a given SMILES and the compounds Compute the Tanimoto similarity between a given SMILES and the compounds
...@@ -638,9 +650,11 @@ def create_tanimoto(smiles_query, fingerprint): ...@@ -638,9 +650,11 @@ def create_tanimoto(smiles_query, fingerprint):
# 2. insert results in a table with three fields: SMILES query, compound id, tanimoto index # 2. insert results in a table with three fields: SMILES query, compound id, tanimoto index
cts = [] cts = []
for id_, smiles in smiles_dict.items(): for id_, smiles in smiles_dict.items():
cts.append(CompoundTanimoto(canonical_smiles=smiles_query, fingerprint=fingerprint, compound=Compound.objects.get(id=id_), tanimoto=tanimoto_dict[id_])) cts.append(CompoundTanimoto(canonical_smiles=smiles_query, fingerprint=fingerprint,
compound=Compound.objects.get(id=id_), tanimoto=tanimoto_dict[id_]))
CompoundTanimoto.objects.bulk_create(cts) CompoundTanimoto.objects.bulk_create(cts)
class PcaBiplotData(models.Model): class PcaBiplotData(models.Model):
""" """
PCA biplot data PCA biplot data
...@@ -686,21 +700,48 @@ class TestActivityDescription(models.Model): ...@@ -686,21 +700,48 @@ class TestActivityDescription(models.Model):
('F', 'Full length'), ('F', 'Full length'),
('U', 'Unspecified') ('U', 'Unspecified')
) )
biblio = models.ForeignKey(Bibliography, models.CASCADE) biblio = models.ForeignKey(
Bibliography,
on_delete=models.CASCADE,
)
protein_domain_bound_complex = models.ForeignKey( protein_domain_bound_complex = models.ForeignKey(
ProteinDomainBoundComplex, models.CASCADE) ProteinDomainBoundComplex,
on_delete=models.CASCADE,
)
ppi = models.ForeignKey(Ppi, models.CASCADE, blank=True, null=True) ppi = models.ForeignKey(Ppi, models.CASCADE, blank=True, null=True)
test_name = models.CharField('Test name', max_length=100) test_name = models.CharField(
is_primary = models.BooleanField('Is primary') verbose_name='Test name',
max_length=100,
)
is_primary = models.BooleanField(
verbose_name='Is primary',
)
protein_bound_construct = models.CharField( protein_bound_construct = models.CharField(
'Protein bound construct', max_length=5, choices=PROTEIN_BOUND_CONSTRUCTS, blank=True, null=True) verbose_name='Protein bound construct',
test_type = models.CharField('Test type', max_length=5, choices=TEST_TYPES) max_length=5,
choices=PROTEIN_BOUND_CONSTRUCTS,
blank=True,
null=True,
)
test_type = models.CharField(
verbose_name='Test type',
max_length=5,
choices=TEST_TYPES,
)
test_modulation_type = models.CharField( test_modulation_type = models.CharField(
'Test modulation type', max_length=1, choices=TEST_MODULATION_TYPES) verbose_name='Test modulation type',
max_length=1,
choices=TEST_MODULATION_TYPES,
)
nb_active_compounds = models.IntegerField( nb_active_compounds = models.IntegerField(
'Total number of active compounds') verbose_name='Total number of active compounds',
)
cell_line = models.ForeignKey( cell_line = models.ForeignKey(
CellLine, models.CASCADE, blank=True, null=True) CellLine,
on_delete=models.CASCADE,
blank=True,
null=True,
)
def get_complexes(self): def get_complexes(self):
""" """
...@@ -758,7 +799,11 @@ class CompoundActivityResult(models.Model): ...@@ -758,7 +799,11 @@ class CompoundActivityResult(models.Model):
('compound', 'test_activity_description', 'activity_type'),) ('compound', 'test_activity_description', 'activity_type'),)
def __str__(self): def __str__(self):
return 'Compound activity result for {} test {} on {}'.format(self.activity_type, self.test_activity_description.id, self.compound.id) return 'Compound activity result for {} test {} on {}'.format(
self.activity_type,
self.test_activity_description.id,
self.compound.id,
)
def is_best(self): def is_best(self):
return self.compound.best_pXC50_compound_activity_result.id == self.id return self.compound.best_pXC50_compound_activity_result.id == self.id
...@@ -788,7 +833,10 @@ class CompoundCytotoxicityResult(models.Model): ...@@ -788,7 +833,10 @@ class CompoundCytotoxicityResult(models.Model):
unique_together = (('compound', 'test_cytotoxicity_description'),) unique_together = (('compound', 'test_cytotoxicity_description'),)
def __str__(self): def __str__(self):
return 'Compound cytotoxicity result for test {} on {}'.format(self.test_cytotoxicity_description.id, self.compound.id) return 'Compound cytotoxicity result for test {} on {}'.format(
self.test_cytotoxicity_description.id,
self.compound.id,
)
class TestPKDescription(models.Model): class TestPKDescription(models.Model):
...@@ -871,6 +919,7 @@ class CompoundAction(models.Model): ...@@ -871,6 +919,7 @@ class CompoundAction(models.Model):
def __str__(self): def __str__(self):
return 'Action of {} on {}'.format(self.compound, self.ppi) return 'Action of {} on {}'.format(self.compound, self.ppi)
class RefCompoundBiblio(models.Model): class RefCompoundBiblio(models.Model):
""" """
Compound-Bibliographic reference association Compound-Bibliographic reference association
...@@ -883,6 +932,7 @@ class RefCompoundBiblio(models.Model): ...@@ -883,6 +932,7 @@ class RefCompoundBiblio(models.Model):
class Meta: class Meta:
unique_together = (('compound', 'bibliography'),) unique_together = (('compound', 'bibliography'),)
class DrugBankCompound(models.Model): class DrugBankCompound(models.Model):
""" """
Drugbank compound Drugbank compound
...@@ -893,6 +943,7 @@ class DrugBankCompound(models.Model): ...@@ -893,6 +943,7 @@ class DrugBankCompound(models.Model):
canonical_smiles = models.TextField( canonical_smiles = models.TextField(
'Canonical SMILES') 'Canonical SMILES')
class DrugbankCompoundTanimoto(models.Model): class DrugbankCompoundTanimoto(models.Model):
""" """
Drugbank compound-compound tanimoto similarity Drugbank compound-compound tanimoto similarity
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment