From c280cccc7bd810477b22ea554925aede76ebc99b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20=20MENAGER?= <herve.menager@pasteur.fr> Date: Sat, 10 Feb 2018 18:44:35 +0100 Subject: [PATCH] continue working on compound query interface (#43), WIP - three visualization modes now - most of the requested primary information is there Former-commit-id: 9d5310f273011035e53643d4baf153d4769b6ca8 --- ippisite/ippidb/models.py | 10 +++++ .../ippidb/templates/compound_grid_item.html | 28 -------------- ...d_table_item.html => compound_l_item.html} | 0 ippisite/ippidb/templates/compound_list.html | 37 +++++++++++++++---- .../ippidb/templates/compound_t_item.html | 10 +++++ .../ippidb/templates/compound_v_item.html | 8 ++++ ippisite/ippidb/views.py | 6 ++- 7 files changed, 62 insertions(+), 37 deletions(-) delete mode 100644 ippisite/ippidb/templates/compound_grid_item.html rename ippisite/ippidb/templates/{compound_table_item.html => compound_l_item.html} (100%) create mode 100644 ippisite/ippidb/templates/compound_t_item.html create mode 100644 ippisite/ippidb/templates/compound_v_item.html diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index eecaaf86..81350553 100644 --- a/ippisite/ippidb/models.py +++ b/ippisite/ippidb/models.py @@ -341,6 +341,16 @@ class Compound(models.Model): pfam_ids.add(bound_complex.complex.domain.pfam_id) return pfam_ids + @property + def compound_action_pdb_ids(self): + """ + return all PDB codes of the corresponding compound actions + """ + pdb_ids = set() + for ca in self.compoundaction_set.all(): + pdb_ids.add(ca.pdb_id) + return pdb_ids + class MDDRActivityClass(models.Model): name = models.CharField('Activity Class', max_length=100, unique=True) diff --git a/ippisite/ippidb/templates/compound_grid_item.html b/ippisite/ippidb/templates/compound_grid_item.html deleted file mode 100644 index b4e225c0..00000000 --- a/ippisite/ippidb/templates/compound_grid_item.html +++ /dev/null @@ -1,28 +0,0 @@ -<div class="card m-2 border border-info" style="width: 300px"> - <a href="/compound/{{ compound.id }}">{% include "pubchem_img.html" %}</a> - <div class="card-body" style="overflow:hidden; word-wrap:break-word;"> - <span class="badge badge-dark"><a href="/compound/{{ compound.id }}">{{ compound.id }}</a></span> - <p>{% for pfam_id in compound.pfam_ids %}{{ pfam_id }}{% endfor %}</p> - <p>Molecular Weight: {{ compound.molecular_weight }} g/mol</p> - </div> -</div> -<!-- -<div class="col-md-4 border border-info bg-light"> - <div class="row border-info d-flex justify-content-center align-content-center"> - <a href="/compound/{{ compound.id }}">{% include "pubchem_img.html" %}</a> - </div> - <div class="row"> - <ul class="list-group"> - {% if compound.common_name %} - <li class="list-group-item">Common name: {{ compound.common_name }}</li> - {% endif %} - {% if compound.canonical_smile %} - <li class="list-group-item">Canonical SMILES: {{ compound.canonical_smile }}</li> - {% endif %} - {% if compound.iupac_name %} - <li class="list-group-item">IUPAC name: {{ compound.iupac_name }}</li> - {% endif %} - </ul> - </div> -</div> ---> diff --git a/ippisite/ippidb/templates/compound_table_item.html b/ippisite/ippidb/templates/compound_l_item.html similarity index 100% rename from ippisite/ippidb/templates/compound_table_item.html rename to ippisite/ippidb/templates/compound_l_item.html diff --git a/ippisite/ippidb/templates/compound_list.html b/ippisite/ippidb/templates/compound_list.html index accb8284..593dc1ca 100644 --- a/ippisite/ippidb/templates/compound_list.html +++ b/ippisite/ippidb/templates/compound_list.html @@ -67,27 +67,50 @@ {% endif %} </span> <span class="btn-group float-right"> - <a class="btn btn-default btn-outline-primary {% if not display_list %}active{% endif %}" href="#" {% if display_list %}onclick="modifyUrl('display_list', null)"{% endif %}> + <a class="btn btn-default btn-outline-primary {% if display == 'v' %}active{% endif %}" href="#" {% if display != 'v' %}onclick="modifyUrl('display', 'v')"{% endif %}> <i class="fa fa-th" title="Vignettes"></i> </a> - <a class="btn btn-default btn-outline-primary {% if display_list %}active{% endif %}" href="#" {% if not display_list %}onclick="modifyUrl('display_list', true)"{% endif %}> + <a class="btn btn-default btn-outline-primary {% if display == 'l' %}active{% endif %}" href="#" {% if display != 'l' %}onclick="modifyUrl('display', 'l')"{% endif %}> <i class="fa fa-bars" title="List"></i> </a> + <a class="btn btn-default btn-outline-primary {% if display == 't' %}active{% endif %}" href="#" {% if display != 't' %}onclick="modifyUrl('display', 't')"{% endif %}> + <i class="fa fa-table" title="Table"></i> + </a> </span> </div> </form> {% if compounds %} - {% if display_list %} + <div class="row"> + {% if display == 'v' %} + {% for compound in compounds %} + {% include "compound_v_item.html" with compound=compound %} + {% endfor %} + {% elif display == 'l'%} {% for compound in compounds %} - {% include "compound_table_item.html" with compound=compound %} + {% include "compound_l_item.html" with compound=compound %} {% endfor %} {% else %} - <div class="row"> + <table class="table"> + <thead> + <tr> + <th scope="col">#</th> + <th scope="col">Common name</th> + <th scope="col">Molecular weight</th> + <th scope="col">AlogP</th> + <th scope="col">PDB ligand</th> + <th scope="col">MDDR phase</th> + <th scope="col">Available tests</th> + <th scope="col">Available publications</th> + </tr> + </thead> + <tbody> {% for compound in compounds %} - {% include "compound_grid_item.html" with compound=compound %} + {% include "compound_t_item.html" with compound=compound %} {% endfor %} - </div> + </tbody> + </table> {% endif %} + </div> {% else %} <p>Nothing found there!</p> {% endif %} diff --git a/ippisite/ippidb/templates/compound_t_item.html b/ippisite/ippidb/templates/compound_t_item.html new file mode 100644 index 00000000..57faae85 --- /dev/null +++ b/ippisite/ippidb/templates/compound_t_item.html @@ -0,0 +1,10 @@ +<tr> + <th scope="col"><span class="badge badge-dark"><a href="/compound/{{ compound.id }}">{{ compound.id }}</a></span></th> + <th scope="col">{{ compound.common_name|default_if_none:"-" }}</th> + <th scope="col">{{ compound.molecular_weight}} g/mol</th> + <th scope="col">{{ compound.a_log_p }}</th> + <th scope="col">{% for pdb_id in compound.compound_action_pdb_ids %}{{ pdb_id }}{% endfor %}</th> + <th scope="col"> ? </th> + <th scope="col"> ? </th> + <th scope="col">{{ compound.biblio_refs|length }}</th> +</tr> diff --git a/ippisite/ippidb/templates/compound_v_item.html b/ippisite/ippidb/templates/compound_v_item.html new file mode 100644 index 00000000..e6e54ecd --- /dev/null +++ b/ippisite/ippidb/templates/compound_v_item.html @@ -0,0 +1,8 @@ +<div class="card m-2 border border-info" style="width: 300px"> + <a href="/compound/{{ compound.id }}">{% include "pubchem_img.html" %}</a> + <div class="card-body" style="overflow:hidden; word-wrap:break-word;"> + <span class="badge badge-dark"><a href="/compound/{{ compound.id }}">{{ compound.id }}</a></span> + <p>{% for pfam_id in compound.pfam_ids %}{{ pfam_id }}{% endfor %}</p> + <p>Molecular Weight: {{ compound.molecular_weight }} g/mol</p> + </div> +</div> diff --git a/ippisite/ippidb/views.py b/ippisite/ippidb/views.py index c1753120..0895e0a9 100644 --- a/ippisite/ippidb/views.py +++ b/ippisite/ippidb/views.py @@ -211,7 +211,9 @@ def compound_list(request): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. compounds = paginator.page(paginator.num_pages) - display_list = request.GET.get('display_list') + display = request.GET.get('display') + if display not in ['l', 't']: + display = 'v' return render(request, 'compound_list.html', {'compounds': compounds, 'count': count, 'selected_ppis': selected_ppis, @@ -226,7 +228,7 @@ def compound_list(request): 'selected_boundcomplexes': selected_boundcomplexes, 'boundcomplexes': boundcomplexes, 'boundcomplexes_all': boundcomplexes_all, - 'display_list': display_list + 'display': display }) def compound_card(request, compound_id): -- GitLab