diff --git a/ippisite/ippidb/templates/compound_card.html b/ippisite/ippidb/templates/compound_card.html index a2a98987519467e27a43461dc5b11ca5cf1e3a07..eff17990d7d7392829d852b22aa341cff18ee5d2 100644 --- a/ippisite/ippidb/templates/compound_card.html +++ b/ippisite/ippidb/templates/compound_card.html @@ -313,6 +313,7 @@ </div> </div> </div> + {% if pca_biplot_data %} <div class="row d-flex justify-content-center"> <div class="col-sm-12 col-md-9"> <h5 class="card_title">PCA : iPPI-DB chemical space</h5> @@ -331,8 +332,10 @@ </div> </div> </div> + {% endif %} </div> <div class="tab-pane fade" id="pharmacology" role="tabpanel" aria-labelledby="pharmacology-tab"> + {% if le_lle_biplot_data %} <div class="row d-flex justify-content-center"> <div class="col-sm-12 col-md-9" style="margin: 10px;"> <h5 class="card_title">Efficiencies: iPPI-DB biplot LE versus LLE <span class="info_point" @@ -371,7 +374,9 @@ </script> </div> </div> + </div> + {% endif %} <div class="row d-flex justify-content-center"> <div class="col-sm-12 col-md-9" style="margin: 10px;"> <h5 class="card_title">Summary</h5> diff --git a/ippisite/ippidb/tests/tests.py b/ippisite/ippidb/tests/tests.py index f52e623c7d33823b060f0570a29263be2acf3142..77580144394dfa4368b9819a1762b6a52f48109a 100644 --- a/ippisite/ippidb/tests/tests.py +++ b/ippisite/ippidb/tests/tests.py @@ -10,7 +10,6 @@ from django.test import TestCase from django.urls import reverse import requests - from ippidb import models from ippidb.ws import ( get_uniprot_info, @@ -38,6 +37,7 @@ from ippidb.models import ( DrugBankCompound, Protein, ) +from .utils import create_dummy_compound, create_dummy_drugbank_compound class MolSmiTestCase(TestCase): @@ -94,65 +94,6 @@ class MolSmiTestCase(TestCase): self.assertEqual(response.status_code, 400) -def create_dummy_compound(id_, smiles): - c = Compound() - c.id = id_ - c.canonical_smile = smiles - c.is_macrocycle = True - c.aromatic_ratio = 0.0 - c.balaban_index = 0.0 - c.fsp3 = 0.0 - c.gc_molar_refractivity = 0.0 - c.log_d = 0.0 - c.a_log_p = 0.0 - c.gc_molar_refractivity = 0.0 - c.mean_atom_vol_vdw = 0.0 - c.molecular_weight = 0.0 - c.nb_acceptor_h = 0 - c.nb_aliphatic_amines = 0 - c.nb_aromatic_bonds = 0 - c.nb_aromatic_ether = 0 - c.nb_aromatic_sssr = 0 - c.nb_atom = 0 - c.nb_atom_non_h = 0 - c.nb_benzene_like_rings = 0 - c.nb_bonds = 0 - c.nb_bonds_non_h = 0 - c.nb_br = 0 - c.nb_c = 0 - c.nb_chiral_centers = 0 - c.nb_circuits = 0 - c.nb_cl = 0 - c.nb_csp2 = 0 - c.nb_csp3 = 0 - c.nb_donor_h = 0 - c.nb_double_bonds = 0 - c.nb_f = 0 - c.nb_i = 0 - c.nb_multiple_bonds = 0 - c.nb_n = 0 - c.nb_o = 0 - c.nb_rings = 0 - c.nb_rotatable_bonds = 0 - c.randic_index = 0 - c.rdf070m = 0 - c.rotatable_bond_fraction = 0 - c.sum_atom_polar = 0 - c.sum_atom_vol_vdw = 0 - c.tpsa = 0 - c.ui = 0 - c.wiener_index = 0 - c.save(autofill=True) - return c - - -def create_dummy_drugbank_compound(id_, smiles): - dbc = DrugBankCompound() - dbc.id = id_ - dbc.common_name = "DrugBankCompound" + str(id_) - dbc.canonical_smiles = smiles - dbc.save() - class CompoundTanimotoTestCase(TestCase): def setUp(self): diff --git a/ippisite/ippidb/tests/tests_views.py b/ippisite/ippidb/tests/tests_views.py index 36099df66e3707d7b1e162120d832ad5ef7b9bba..81a4412d8e33ee395a936d520ccc858cbebafd94 100644 --- a/ippisite/ippidb/tests/tests_views.py +++ b/ippisite/ippidb/tests/tests_views.py @@ -3,8 +3,11 @@ iPPI-DB views tests """ from django.test import TestCase from django.urls import reverse +from django.core.management import call_command from parameterized import parameterized +from .utils import create_dummy_compound + tested_urlpatterns = [ "index", "general", @@ -37,3 +40,32 @@ class ViewTest(TestCase): def test_url(self, url_name): response = self.client.get(reverse(url_name)) self.assertEqual(response.status_code, 200) + + +class CompoundCardViewTest(TestCase): + """ + Tests for compound card + """ + + def setUp(self): + create_dummy_compound(1, "CC") + + def test_compound_card(self): + """ + basic test for compound card + """ + + call_command("lle_le") + call_command("pca") + response = self.client.get(reverse("compound_card", kwargs={"pk": 1})) + self.assertEqual(response.status_code, 200) + + + def test_compound_card_no_lelleplot_data(self): + """ + test that compound card is ok even if LE-LLE plot + data are missing (which can happen during LE-LLE recomputing) + """ + + response = self.client.get(reverse("compound_card", kwargs={"pk": 1})) + self.assertEqual(response.status_code, 200) diff --git a/ippisite/ippidb/tests/utils.py b/ippisite/ippidb/tests/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..3bee4a1e2ad13ed76ce13dfb8ba74eae6fa5982e --- /dev/null +++ b/ippisite/ippidb/tests/utils.py @@ -0,0 +1,61 @@ +from ippidb.models import Compound, DrugBankCompound + + +def create_dummy_compound(id_, smiles): + c = Compound() + c.id = id_ + c.canonical_smile = smiles + c.is_macrocycle = True + c.aromatic_ratio = 0.0 + c.balaban_index = 0.0 + c.fsp3 = 0.0 + c.gc_molar_refractivity = 0.0 + c.log_d = 0.0 + c.a_log_p = 0.0 + c.gc_molar_refractivity = 0.0 + c.mean_atom_vol_vdw = 0.0 + c.molecular_weight = 0.0 + c.nb_acceptor_h = 0 + c.nb_aliphatic_amines = 0 + c.nb_aromatic_bonds = 0 + c.nb_aromatic_ether = 0 + c.nb_aromatic_sssr = 0 + c.nb_atom = 0 + c.nb_atom_non_h = 0 + c.nb_benzene_like_rings = 0 + c.nb_bonds = 0 + c.nb_bonds_non_h = 0 + c.nb_br = 0 + c.nb_c = 0 + c.nb_chiral_centers = 0 + c.nb_circuits = 0 + c.nb_cl = 0 + c.nb_csp2 = 0 + c.nb_csp3 = 0 + c.nb_donor_h = 0 + c.nb_double_bonds = 0 + c.nb_f = 0 + c.nb_i = 0 + c.nb_multiple_bonds = 0 + c.nb_n = 0 + c.nb_o = 0 + c.nb_rings = 0 + c.nb_rotatable_bonds = 0 + c.randic_index = 0 + c.rdf070m = 0 + c.rotatable_bond_fraction = 0 + c.sum_atom_polar = 0 + c.sum_atom_vol_vdw = 0 + c.tpsa = 0 + c.ui = 0 + c.wiener_index = 0 + c.save(autofill=True) + return c + + +def create_dummy_drugbank_compound(id_, smiles): + dbc = DrugBankCompound() + dbc.id = id_ + dbc.common_name = "DrugBankCompound" + str(id_) + dbc.canonical_smiles = smiles + dbc.save() diff --git a/ippisite/ippidb/views/compound_query.py b/ippisite/ippidb/views/compound_query.py index 94ac8fe42d359e72acc23df55cf64b5edbd58fe3..9d78f4871e3acc768bed434ee9aeeb1ce28b1abd 100644 --- a/ippisite/ippidb/views/compound_query.py +++ b/ippisite/ippidb/views/compound_query.py @@ -759,9 +759,17 @@ class CompoundDetailView(DetailView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context["le_lle_biplot_data"] = LeLleBiplotData.objects.get().le_lle_biplot_data - pca_biplot = json.loads(PcaBiplotData.objects.get().pca_biplot_data) - context["pca_biplot_data"] = json.dumps(pca_biplot["data"]) + try: + context[ + "le_lle_biplot_data" + ] = LeLleBiplotData.objects.get().le_lle_biplot_data + except LeLleBiplotData.DoesNotExist: + context["le_lle_biplot_data"] = [] + try: + pca_biplot = json.loads(PcaBiplotData.objects.get().pca_biplot_data) + except PcaBiplotData.DoesNotExist: + pca_biplot = {"data": [], "correlation_circle": ""} + context["pca_biplot_data"] = pca_biplot["data"] context["pca_biplot_cc"] = pca_biplot["correlation_circle"] return context