diff --git a/ippisite/ippidb/management/commands/cache_compound_properties.py b/ippisite/ippidb/management/commands/cache_compound_properties.py new file mode 100644 index 0000000000000000000000000000000000000000..9fdc5e095f5c52998804c1195ce2e68f9ba3364f --- /dev/null +++ b/ippisite/ippidb/management/commands/cache_compound_properties.py @@ -0,0 +1,13 @@ +from django.core.management import BaseCommand + +from ippidb.models import update_compound_cached_properties + +class Command(BaseCommand): + + help = "Cache compound properties in the main 'Compound' table" + + def handle(self, *args, **options): + self.stdout.write(self.style.SUCCESS('Generating the compound properties cache...')) + n = update_compound_cached_properties() + self.stdout.write( + self.style.SUCCESS('Successfully generated compound properties cache for %s compounds' % n)) \ No newline at end of file diff --git a/ippisite/ippidb/management/commands/lle_le.py b/ippisite/ippidb/management/commands/lle_le.py index 7a964dc59658a773991c69d4a6398b72ab996ee0..26a28e2c010ae746a432c1207586015907fd023c 100644 --- a/ippisite/ippidb/management/commands/lle_le.py +++ b/ippisite/ippidb/management/commands/lle_le.py @@ -20,10 +20,10 @@ class Command(BaseCommand): if comp.le is not None: le = round(comp.le, 7) lle = round(comp.lle, 7) - le_lle_data.append({'x': le, 'y': lle, 'id': comp.id, 'family_name': comp.best_pXC50_activity_ppi_family, 'smiles': comp.canonical_smile}) + le_lle_data.append({'x': le, 'y': lle, 'id': comp.id, 'family_name': comp.best_activity_ppi_family_name, 'smiles': comp.canonical_smile}) else: self.stdout.write( - self.style.WARNING('compound %s has no LE (probably because no pXC50 activity results have been registered)' % comp.id)) + self.style.WARNING('compound %s has no LE' % comp.id)) le_lle_json = json.dumps(le_lle_data, separators=(',',':')) new = LeLleBiplotData() new.le_lle_biplot_data = le_lle_json diff --git a/ippisite/ippidb/management/commands/pca.py b/ippisite/ippidb/management/commands/pca.py index abdf5a72db02631ff516a09c8522b9a3fb0768bb..47b10fd5bbcdbf876cce5bfbbdfe49d2d28d3792 100644 --- a/ippisite/ippidb/management/commands/pca.py +++ b/ippisite/ippidb/management/commands/pca.py @@ -45,7 +45,7 @@ class Command(BaseCommand): l = [] for comp in Compound.objects.all(): values = model_to_dict(comp, fields=features + ['id','family']) - values['family'] = comp.best_pXC50_activity_ppi_family + values['family'] = comp.best_activity_ppi_family_name l.append(values) df = pd.DataFrame(l) x = df.loc[:, features].values diff --git a/ippisite/ippidb/migrations/0023_auto_20190524_1456.py b/ippisite/ippidb/migrations/0023_auto_20190524_1456.py new file mode 100644 index 0000000000000000000000000000000000000000..a06a2393011299b94ba027a5089aeabdf98db371 --- /dev/null +++ b/ippisite/ippidb/migrations/0023_auto_20190524_1456.py @@ -0,0 +1,28 @@ +# Generated by Django 2.0.13 on 2019-05-24 14:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ippidb', '0022_auto_20190319_1537'), + ] + + operations = [ + migrations.AlterField( + model_name='bibliography', + name='authors_list', + field=models.TextField(verbose_name='Authors list'), + ), + migrations.AlterField( + model_name='bibliography', + name='journal_name', + field=models.TextField(blank=True, null=True, verbose_name='Journal name'), + ), + migrations.AlterField( + model_name='bibliography', + name='title', + field=models.TextField(verbose_name='Title'), + ), + ] diff --git a/ippisite/ippidb/migrations/0024_auto_20190602_1546.py b/ippisite/ippidb/migrations/0024_auto_20190602_1546.py new file mode 100644 index 0000000000000000000000000000000000000000..59598ee442381c945679e18f6cd47fcc03b58e39 --- /dev/null +++ b/ippisite/ippidb/migrations/0024_auto_20190602_1546.py @@ -0,0 +1,158 @@ +# Generated by Django 2.2.1 on 2019-06-02 15:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ippidb', '0023_auto_20190524_1456'), + ] + + operations = [ + migrations.AddField( + model_name='compound', + name='best_activity', + field=models.DecimalField(blank=True, decimal_places=10, max_digits=12, null=True, verbose_name='Best activity'), + ), + migrations.AddField( + model_name='compound', + name='binding_role', + field=models.BooleanField(blank=True, null=True, verbose_name='Binding role'), + ), + migrations.AddField( + model_name='compound', + name='bindtest_av', + field=models.BooleanField(blank=True, null=True, verbose_name='Binding tests performed'), + ), + migrations.AddField( + model_name='compound', + name='celltest_av', + field=models.BooleanField(blank=True, null=True, verbose_name='Cellular tests performed'), + ), + migrations.AddField( + model_name='compound', + name='cytoxtest_av', + field=models.BooleanField(blank=True, null=True, verbose_name='Cytotoxicity tests performed'), + ), + migrations.AddField( + model_name='compound', + name='hba_hbd', + field=models.IntegerField(blank=True, null=True, verbose_name='Sum of Hydrogen bond acceptors and donors'), + ), + migrations.AddField( + model_name='compound', + name='inhibition_role', + field=models.BooleanField(blank=True, null=True, verbose_name='Inhibition role'), + ), + migrations.AddField( + model_name='compound', + name='inhitest_av', + field=models.BooleanField(blank=True, null=True, verbose_name='Inhibition tests performed'), + ), + migrations.AddField( + model_name='compound', + name='insilico_av', + field=models.BooleanField(blank=True, null=True, verbose_name='In silico tests performed'), + ), + migrations.AddField( + model_name='compound', + name='le', + field=models.FloatField(blank=True, null=True, verbose_name='Ligand efficiency'), + ), + migrations.AddField( + model_name='compound', + name='lipinsky', + field=models.BooleanField(blank=True, null=True, verbose_name='Lipinsky ok'), + ), + migrations.AddField( + model_name='compound', + name='lipinsky_a_log_p', + field=models.BooleanField(blank=True, null=True, verbose_name='A log P ok for Lipinsky'), + ), + migrations.AddField( + model_name='compound', + name='lipinsky_hba', + field=models.BooleanField(blank=True, null=True, verbose_name='Hydrogen bond acceptors ok for Lipinsky'), + ), + migrations.AddField( + model_name='compound', + name='lipinsky_hbd', + field=models.BooleanField(blank=True, null=True, verbose_name='Hydrogen bond donors ok for Lipinsky'), + ), + migrations.AddField( + model_name='compound', + name='lipinsky_mw', + field=models.BooleanField(blank=True, null=True, verbose_name='MW ok for Lipinsky'), + ), + migrations.AddField( + model_name='compound', + name='lipinsky_score', + field=models.IntegerField(blank=True, null=True, verbose_name='Lipinsky score'), + ), + migrations.AddField( + model_name='compound', + name='lle', + field=models.FloatField(blank=True, null=True, verbose_name='Lipophilic efficiency'), + ), + migrations.AddField( + model_name='compound', + name='pdb_ligand_av', + field=models.BooleanField(blank=True, null=True, verbose_name='PDB ligand available'), + ), + migrations.AddField( + model_name='compound', + name='pfizer', + field=models.BooleanField(blank=True, null=True, verbose_name='Pfizer ok'), + ), + migrations.AddField( + model_name='compound', + name='pfizer_a_log_p', + field=models.BooleanField(blank=True, null=True, verbose_name='A log P ok for Pfizer'), + ), + migrations.AddField( + model_name='compound', + name='pfizer_tpsa', + field=models.BooleanField(blank=True, null=True, verbose_name='TPSA ok for Pfizer'), + ), + migrations.AddField( + model_name='compound', + name='pktest_av', + field=models.BooleanField(blank=True, null=True, verbose_name='Pharmacokinetic tests performed'), + ), + migrations.AddField( + model_name='compound', + name='pubs', + field=models.IntegerField(blank=True, null=True, verbose_name='Number of publications'), + ), + migrations.AddField( + model_name='compound', + name='stabilisation_role', + field=models.BooleanField(blank=True, null=True, verbose_name='Stabilisation role'), + ), + migrations.AddField( + model_name='compound', + name='tests_av', + field=models.IntegerField(blank=True, null=True, verbose_name='Number of tests available'), + ), + migrations.AddField( + model_name='compound', + name='veber', + field=models.BooleanField(blank=True, null=True, verbose_name='Veber ok'), + ), + migrations.AddField( + model_name='compound', + name='veber_hba_hbd', + field=models.BooleanField(blank=True, null=True, verbose_name='HBA+HBD ok for Veber'), + ), + migrations.AddField( + model_name='compound', + name='veber_rb', + field=models.BooleanField(blank=True, null=True, verbose_name='Rotatable bonds ok for Veber'), + ), + migrations.AddField( + model_name='compound', + name='veber_tpsa', + field=models.BooleanField(blank=True, null=True, verbose_name='TPSA ok for Veber'), + ), + ] diff --git a/ippisite/ippidb/migrations/0025_compound_stabtest_av.py b/ippisite/ippidb/migrations/0025_compound_stabtest_av.py new file mode 100644 index 0000000000000000000000000000000000000000..aceea55276782b02fd9a40edfb77ce6cd4f8c368 --- /dev/null +++ b/ippisite/ippidb/migrations/0025_compound_stabtest_av.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.1 on 2019-06-03 14:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ippidb', '0024_auto_20190602_1546'), + ] + + operations = [ + migrations.AddField( + model_name='compound', + name='stabtest_av', + field=models.BooleanField(blank=True, null=True, verbose_name='Stabilisation tests performed'), + ), + ] diff --git a/ippisite/ippidb/migrations/0026_auto_20190604_1937.py b/ippisite/ippidb/migrations/0026_auto_20190604_1937.py new file mode 100644 index 0000000000000000000000000000000000000000..243293dc757d51c3165c7e49397565f76ed57378 --- /dev/null +++ b/ippisite/ippidb/migrations/0026_auto_20190604_1937.py @@ -0,0 +1,17 @@ +# Generated by Django 2.2.1 on 2019-06-04 19:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ippidb', '0025_compound_stabtest_av'), + ] + + operations = [ + migrations.AddIndex( + model_name='compound', + index=models.Index(fields=['molecular_weight'], name='ippidb_comp_molecul_6c82bb_idx'), + ), + ] diff --git a/ippisite/ippidb/migrations/0027_auto_20190604_1947.py b/ippisite/ippidb/migrations/0027_auto_20190604_1947.py new file mode 100644 index 0000000000000000000000000000000000000000..42835bc921efbee8ad5cd7c40ae1103845062e32 --- /dev/null +++ b/ippisite/ippidb/migrations/0027_auto_20190604_1947.py @@ -0,0 +1,49 @@ +# Generated by Django 2.2.1 on 2019-06-04 19:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ippidb', '0026_auto_20190604_1937'), + ] + + operations = [ + migrations.AddIndex( + model_name='compound', + index=models.Index(fields=['a_log_p'], name='ippidb_comp_a_log_p_d6ed66_idx'), + ), + migrations.AddIndex( + model_name='compound', + index=models.Index(fields=['nb_donor_h'], name='ippidb_comp_nb_dono_0dff51_idx'), + ), + migrations.AddIndex( + model_name='compound', + index=models.Index(fields=['nb_acceptor_h'], name='ippidb_comp_nb_acce_2d9049_idx'), + ), + migrations.AddIndex( + model_name='compound', + index=models.Index(fields=['tpsa'], name='ippidb_comp_tpsa_4a45ab_idx'), + ), + migrations.AddIndex( + model_name='compound', + index=models.Index(fields=['nb_rotatable_bonds'], name='ippidb_comp_nb_rota_c38661_idx'), + ), + migrations.AddIndex( + model_name='compound', + index=models.Index(fields=['nb_aromatic_sssr'], name='ippidb_comp_nb_arom_de89e2_idx'), + ), + migrations.AddIndex( + model_name='compound', + index=models.Index(fields=['nb_chiral_centers'], name='ippidb_comp_nb_chir_d779eb_idx'), + ), + migrations.AddIndex( + model_name='compound', + index=models.Index(fields=['fsp3'], name='ippidb_comp_fsp3_bfbbb7_idx'), + ), + migrations.AddIndex( + model_name='compound', + index=models.Index(fields=['pubs'], name='ippidb_comp_pubs_168d42_idx'), + ), + ] diff --git a/ippisite/ippidb/migrations/0028_auto_20190604_2058.py b/ippisite/ippidb/migrations/0028_auto_20190604_2058.py new file mode 100644 index 0000000000000000000000000000000000000000..1b99d0b6e663565293c1fde95b61d9164683c932 --- /dev/null +++ b/ippisite/ippidb/migrations/0028_auto_20190604_2058.py @@ -0,0 +1,30 @@ +# Generated by Django 2.2.1 on 2019-06-04 20:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ippidb', '0027_auto_20190604_1947'), + ] + + operations = [ + migrations.AddField( + model_name='compound', + name='best_activity_ppi_family_name', + field=models.CharField(blank=True, max_length=30, null=True, unique=True, verbose_name='Best activity PPI family name'), + ), + migrations.AddIndex( + model_name='compound', + index=models.Index(fields=['best_activity'], name='ippidb_comp_best_ac_98454a_idx'), + ), + migrations.AddIndex( + model_name='compound', + index=models.Index(fields=['le'], name='ippidb_comp_le_e4dac5_idx'), + ), + migrations.AddIndex( + model_name='compound', + index=models.Index(fields=['lle'], name='ippidb_comp_lle_1f7980_idx'), + ), + ] diff --git a/ippisite/ippidb/migrations/0029_auto_20190605_0606.py b/ippisite/ippidb/migrations/0029_auto_20190605_0606.py new file mode 100644 index 0000000000000000000000000000000000000000..6623de441610df1176653ce5d81a10d28cab1b46 --- /dev/null +++ b/ippisite/ippidb/migrations/0029_auto_20190605_0606.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.1 on 2019-06-05 06:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ippidb', '0028_auto_20190604_2058'), + ] + + operations = [ + migrations.AlterField( + model_name='compound', + name='best_activity_ppi_family_name', + field=models.CharField(blank=True, max_length=30, null=True, verbose_name='Best activity PPI family name'), + ), + ] diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index d085312ae5c6ea1b6af6f0c0004c41ae383a2837..a94fc95e3785f9ee80671bae19e9ecb177c826ec 100644 --- a/ippisite/ippidb/models.py +++ b/ippisite/ippidb/models.py @@ -12,7 +12,7 @@ from django.contrib.auth import get_user_model from django.core.exceptions import ValidationError from django.db import models, transaction from django.db.models import FloatField, IntegerField, BooleanField -from django.db.models import Max, Count, F, Q, Case, When +from django.db.models import Max, Count, F, Q, Case, When, Subquery, OuterRef from django.db.models.functions import Cast from django.urls import reverse from django.utils.translation import ugettext_lazy as _ @@ -450,7 +450,7 @@ class CompoundManager(models.Manager): of the database query, used for filters and compound card """ - def get_queryset(self): + def get_queryset_old(self): # @formatter:off qs = super().get_queryset() # with number of publications @@ -811,8 +811,77 @@ class Compound(AutoFillableModel): null=True, ) + pubs = models.IntegerField( + verbose_name='Number of publications', null=True, blank=True + ) + best_activity = models.DecimalField( + 'Best activity', max_digits=12, decimal_places=10, null=True, blank=True) + best_activity_ppi_family_name = models.CharField('Best activity PPI family name', max_length=30, null=True, blank=True) + le = models.FloatField( + verbose_name='Ligand efficiency', null=True, blank=True + ) + lle = models.FloatField( + verbose_name='Lipophilic efficiency', null=True, blank=True + ) + lipinsky_mw = models.BooleanField('MW ok for Lipinsky', null=True, blank=True) + lipinsky_hba = models.BooleanField('Hydrogen bond acceptors ok for Lipinsky', null=True, blank=True) + lipinsky_hbd = models.BooleanField('Hydrogen bond donors ok for Lipinsky', null=True, blank=True) + lipinsky_a_log_p = models.BooleanField('A log P ok for Lipinsky', null=True, blank=True) + lipinsky_score = models.IntegerField( + verbose_name='Lipinsky score', null=True, blank=True + ) + lipinsky = models.BooleanField('Lipinsky ok', null=True, blank=True) + hba_hbd = models.IntegerField( + verbose_name='Sum of Hydrogen bond acceptors and donors', null=True, blank=True + ) + veber_hba_hbd = models.BooleanField('HBA+HBD ok for Veber', null=True, blank=True) + veber_tpsa = models.BooleanField('TPSA ok for Veber', null=True, blank=True) + veber_rb = models.BooleanField('Rotatable bonds ok for Veber', null=True, blank=True) + veber = models.BooleanField('Veber ok', null=True, blank=True) + pfizer_a_log_p = models.BooleanField('A log P ok for Pfizer', null=True, blank=True) + pfizer_tpsa = models.BooleanField('TPSA ok for Pfizer', null=True, blank=True) + pfizer = models.BooleanField('Pfizer ok', null=True, blank=True) + pdb_ligand_av = models.BooleanField('PDB ligand available', null=True, blank=True) + inhibition_role = models.BooleanField('Inhibition role', null=True, blank=True) + binding_role = models.BooleanField('Binding role', null=True, blank=True) + stabilisation_role = models.BooleanField('Stabilisation role', null=True, blank=True) + celltest_av = models.BooleanField('Cellular tests performed', null=True, blank=True) + inhitest_av = models.BooleanField('Inhibition tests performed', null=True, blank=True) + stabtest_av = models.BooleanField('Stabilisation tests performed', null=True, blank=True) + bindtest_av = models.BooleanField('Binding tests performed', null=True, blank=True) + pktest_av = models.BooleanField('Pharmacokinetic tests performed', null=True, blank=True) + cytoxtest_av = models.BooleanField('Cytotoxicity tests performed', null=True, blank=True) + insilico_av = models.BooleanField('In silico tests performed', null=True, blank=True) + tests_av = models.IntegerField(verbose_name='Number of tests available', null=True, blank=True) + + class Meta: ordering = ['id'] + indexes = [ + models.Index(fields=['molecular_weight']), + models.Index(fields=['a_log_p']), + models.Index(fields=['nb_donor_h']), + models.Index(fields=['nb_acceptor_h']), + models.Index(fields=['tpsa']), + models.Index(fields=['nb_rotatable_bonds']), + models.Index(fields=['nb_aromatic_sssr']), + models.Index(fields=['nb_chiral_centers']), + models.Index(fields=['fsp3']), + models.Index(fields=['pubs']), + models.Index(fields=['best_activity']), + models.Index(fields=['le']), + models.Index(fields=['lle']), + ] + # indexes = [ + # models.Index(fields=['lipinsky']), + # models.Index(fields=['veber']), + # models.Index(fields=['pfizer']), + # models.Index(fields=['pdb_ligand_av']), + # models.Index(fields=['inhibition_role']), + # models.Index(fields=['binding_role']), + # models.Index(fields=['stabilisation_role']), + # models.Index(fields=['binding_role']), + # ] def compute_drugbank_compound_similarity(self): """ compute Tanimoto similarity to existing DrugBank compounds """ @@ -868,33 +937,11 @@ class Compound(AutoFillableModel): @property def best_pXC50_compound_activity_result(self): - best_pXC50_activity = self.best_pXC50_activity + best_pXC50_activity = self.best_activity if best_pXC50_activity is None: return None return self.compoundactivityresult_set.filter(activity=best_pXC50_activity)[0] - @property - def best_pXC50_activity_ppi_name(self): - """ - Name of the PPI corresponding to the best PXC50 activity - """ - best_activity_car = self.best_pXC50_compound_activity_result - if best_activity_car is None: - return None - ppi_name = best_activity_car.test_activity_description.ppi.name - return ppi_name - - @property - def best_pXC50_activity_ppi_family(self): - """ - Family of the PPI corresponding to the best PXC50 activity - """ - best_activity_car = self.best_pXC50_compound_activity_result - if best_activity_car is None: - return None - ppi_family = best_activity_car.test_activity_description.ppi.family.name - return ppi_family - @property def bioch_tests_count(self): """ @@ -1296,3 +1343,225 @@ class Contribution(models.Model): def get_absolute_url(self): return reverse('contribution-detail', kwargs={'contribution_pk': self.pk}) + +def update_compound_cached_properties(): + return Compound.objects.update( + pubs=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _pubs=Count('refcompoundbiblio', distinct=True) + ).values('_pubs')[:1] + ), + best_activity=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _best_activity=Max('compoundactivityresult__activity') + ).values('_best_activity')[:1] + ), + best_activity_ppi_family_name = Subquery( + CompoundActivityResult.objects.filter( + compound_id=OuterRef('id') + ).filter(activity=OuterRef('best_activity')).annotate( + _best_activity_ppi_family_name=F('test_activity_description__ppi__family__name') + ).values('_best_activity_ppi_family_name')[:1] + ), + le=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _le=Cast(1.37 * Max('compoundactivityresult__activity') / F('nb_atom_non_h'), FloatField()) + ).values('_le')[:1] + ), + lle=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _lle=Cast(Max('compoundactivityresult__activity') - F('a_log_p'), FloatField()) + ).values('_lle')[:1] + ), + lipinsky_mw=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _lipinsky_mw=Case(When(molecular_weight__lte=500, then=True), default=False, output_field=BooleanField()) + ).values('_lipinsky_mw')[:1] + ), + lipinsky_hba=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _lipinsky_hba=Case(When(nb_acceptor_h__lte=10, then=True), default=False, output_field=BooleanField()) + ).values('_lipinsky_hba')[:1] + ), + lipinsky_hbd=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _lipinsky_hbd=Case(When(nb_donor_h__lte=5, then=True), default=False, output_field=BooleanField()) + ).values('_lipinsky_hbd')[:1] + ), + lipinsky_a_log_p=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _lipinsky_a_log_p=Case(When(a_log_p__lte=5, then=True), default=False, output_field=BooleanField()) + ).values('_lipinsky_a_log_p')[:1] + ), + lipinsky_score=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _lipinsky_score=Cast(F('lipinsky_mw'), IntegerField()) + Cast(F('lipinsky_hba'), IntegerField()) + + Cast(F('lipinsky_hbd'), IntegerField()) + Cast(F('lipinsky_a_log_p'), IntegerField()) + ).values('_lipinsky_score')[:1] + ), + lipinsky=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _lipinsky=Case(When(lipinsky_score__gte=3, then=True), default=False, output_field=BooleanField()) + ).values('_lipinsky')[:1] + ), + hba_hbd=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _hba_hbd=F('nb_acceptor_h')+F('nb_donor_h'), + ).values('_hba_hbd')[:1] + ), + veber_hba_hbd=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _veber_hba_hbd=Case(When(hba_hbd__lte=12, then=True), default=False, output_field=BooleanField()), + ).values('_veber_hba_hbd')[:1] + ), + veber_tpsa=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _veber_tpsa=Case(When(tpsa__lte=140, then=True), default=False, output_field=BooleanField()), + ).values('_veber_tpsa')[:1] + ), + veber_rb=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _veber_rb=Case(When(nb_rotatable_bonds__lte=10, then=True), default=False, output_field=BooleanField()), + ).values('_veber_rb')[:1] + ), + veber=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _veber=Case(When(Q(Q(nb_rotatable_bonds__lte=10) & (Q(hba_hbd__lte=12) | Q(tpsa__lte=140))), then=True), default=False, output_field=BooleanField()), + ).values('_veber')[:1] + ), + pfizer_a_log_p=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _pfizer_a_log_p=Case(When(a_log_p__lte=3, then=True), default=False, output_field=BooleanField()), + ).values('_pfizer_a_log_p')[:1] + ), + pfizer_tpsa=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _pfizer_tpsa=Case(When(tpsa__gte=75, then=True), default=False, output_field=BooleanField()), + ).values('_pfizer_tpsa')[:1] + ), + pfizer=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _pfizer=Case(When(Q(Q(a_log_p__lte=3) & Q(tpsa__gte=75)), then=True), default=False, output_field=BooleanField()), + ).values('_pfizer')[:1] + ), + pdb_ligand_av=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _pdb_ligand_av=Cast(Max(Case(When(compoundaction__ligand_id__isnull=False, then=1), default=0, output_field=IntegerField())), BooleanField()), + ).values('_pdb_ligand_av')[:1] + ), + inhibition_role=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _inhibition_role=Case(When(compoundactivityresult__modulation_type='I', then=True), default=False, output_field=BooleanField()), + ).values('_inhibition_role')[:1] + ), + binding_role=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _binding_role=Case(When(compoundactivityresult__modulation_type='I', then=True), default=False, output_field=BooleanField()), + ).values('_binding_role')[:1] + ), + stabilisation_role=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _stabilisation_role=Case(When(compoundactivityresult__modulation_type='S', then=True), default=False, output_field=BooleanField()), + ).values('_stabilisation_role')[:1] + ), + celltest_av=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _celltest_av=Cast(Max(Case(When(compoundactivityresult__test_activity_description__test_type='CELL', then=1), default=0, output_field=IntegerField())), BooleanField()), + ).values('_celltest_av')[:1] + ), + inhitest_av=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _inhitest_av=Cast(Max(Case(When(compoundactivityresult__test_activity_description__test_modulation_type='I', then=1), default=0, output_field=IntegerField())), BooleanField()), + ).values('_inhitest_av')[:1] + ), + stabtest_av=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _stabtest_av=Cast(Max(Case(When(compoundactivityresult__test_activity_description__test_modulation_type='S', then=1), default=0, output_field=IntegerField())), BooleanField()), + ).values('_stabtest_av')[:1] + ), + bindtest_av=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _bindtest_av=Cast(Max(Case(When(compoundactivityresult__test_activity_description__test_modulation_type='I', then=1), default=0, output_field=IntegerField())), BooleanField()), + ).values('_bindtest_av')[:1] + ), + pktest_av=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _pktest_av=Cast(Max(Case(When(refcompoundbiblio__bibliography__pharmacokinetic=True, then=1), default=0, output_field=IntegerField())), BooleanField()), + ).values('_pktest_av')[:1] + ), + cytoxtest_av=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _cytoxtest_av=Cast(Max(Case(When(refcompoundbiblio__bibliography__cytotox=True, then=1), default=0, output_field=IntegerField())), BooleanField()), + ).values('_cytoxtest_av')[:1] + ), + insilico_av=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _insilico_av=Cast(Max(Case(When(refcompoundbiblio__bibliography__in_silico=True, then=1), default=0, output_field=IntegerField())), BooleanField()), + ).values('_insilico_av')[:1] + ), + tests_av=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _tests_av=Count('compoundactivityresult', distinct=True), + ).values('_tests_av')[:1] + ) + ) \ No newline at end of file diff --git a/ippisite/ippidb/templates/compound_card.html b/ippisite/ippidb/templates/compound_card.html index 55c649ed312e10b044cb6460ab6ea3342c522dcc..9edd0371abf009e1a60ce88b4567ec1d706e0533 100644 --- a/ippisite/ippidb/templates/compound_card.html +++ b/ippisite/ippidb/templates/compound_card.html @@ -126,7 +126,7 @@ <canvas id="pca_biplot" style="width:600px; height:600px;"></canvas> <script> - drawCompoundsBiplotChart('pca_biplot', {{ compound.id }}, '{{ compound.best_pXC50_activity_ppi_family|default_if_none:"No target family identified" }}', {{ pca_biplot_data | safe }}, 'physicochemistry'); + drawCompoundsBiplotChart('pca_biplot', {{ compound.id }}, '{{ compound.best_activity_ppi_family_name|default_if_none:"No target family identified" }}', {{ pca_biplot_data | safe }}, 'physicochemistry'); </script> </div> </div> @@ -144,7 +144,7 @@ <div class="card-body"> <canvas id="le_lle_biplot"></canvas> <script> - drawCompoundsBiplotChart('le_lle_biplot', {{ compound.id }}, '{{ compound.best_pXC50_activity_ppi_family|default_if_none:"No target family identified" }}', {{ le_lle_biplot_data | safe }}, 'pharmacology'); + drawCompoundsBiplotChart('le_lle_biplot', {{ compound.id }}, '{{ compound.best_activity_ppi_family_name|default_if_none:"No target family identified" }}', {{ le_lle_biplot_data | safe }}, 'pharmacology'); </script> </div> </div> diff --git a/ippisite/ippidb/templates/compound_v_item.html b/ippisite/ippidb/templates/compound_v_item.html index 77d4ee9edc62da4ecae654cc66641cbb8d1208fd..72d60848faa90325c01f6012996f18a8f41769d0 100644 --- a/ippisite/ippidb/templates/compound_v_item.html +++ b/ippisite/ippidb/templates/compound_v_item.html @@ -7,7 +7,7 @@ {% endif %} <div class="card-body" style="overflow:hidden; word-wrap:break-word;"> {%if compound.common_name %}<p title="Common name">{{ compound.common_name }}</p>{% endif %} - <p title="PPI Family">{{ compound.best_pXC50_activity_ppi_family }}</p> + <p title="PPI Family">{{ compound.best_activity_ppi_family_name }}</p> <p title="Molecular Weight">{{ compound.molecular_weight }} g/mol</p> </div> </div>