Skip to content
Snippets Groups Projects
Commit 337617bf authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

allow filter on number of publications

cf #67


Former-commit-id: 58370bc0ace2881cd3d453ec390e44cd6b0f5bcd
parent aef7e53d
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
{% include "slider_button.html" with label="Molecular weight" param_name="molecular_weight" %} {% include "slider_button.html" with label="Molecular weight" param_name="molecular_weight" %}
{% include "slider_button.html" with label="AlogP" param_name="a_log_p" %} {% include "slider_button.html" with label="AlogP" param_name="a_log_p" %}
{% include "slider_button.html" with label="H donors" param_name="nb_donor_h" %} {% include "slider_button.html" with label="H donors" param_name="nb_donor_h" %}
{% include "slider_button.html" with label="Publications" param_name="pubs" %}
</div> </div>
<div class="m-2 d-flex "> <div class="m-2 d-flex ">
<span>{{ compounds.paginator.count }} compounds</span> <span>{{ compounds.paginator.count }} compounds</span>
...@@ -152,5 +153,6 @@ ...@@ -152,5 +153,6 @@
{% include "slider_modal.html" with label="Molecular Weight" param_name="molecular_weight" param_min=molecular_weight_min param_max=molecular_weight_max param_value=molecular_weight step='50' param_label='Select a cutoff value for the molecular weight of the compounds to be selected'%} {% include "slider_modal.html" with label="Molecular Weight" param_name="molecular_weight" param_min=molecular_weight_min param_max=molecular_weight_max param_value=molecular_weight step='50' param_label='Select a cutoff value for the molecular weight of the compounds to be selected'%}
{% include "slider_modal.html" with label="AlogP" param_name="a_log_p" param_min=a_log_p_min param_max=a_log_p_max param_value=a_log_p step='1' param_label='Select a cutoff value for the AlogP of the compounds to be selected'%} {% include "slider_modal.html" with label="AlogP" param_name="a_log_p" param_min=a_log_p_min param_max=a_log_p_max param_value=a_log_p step='1' param_label='Select a cutoff value for the AlogP of the compounds to be selected'%}
{% include "slider_modal.html" with label="H donors" param_name="nb_donor_h" param_min=nb_donor_h_min param_max=nb_donor_h_max param_value=nb_donor_h step='1' param_label='Select a cutoff value for the number of H donors in the compounds to be selected'%} {% include "slider_modal.html" with label="H donors" param_name="nb_donor_h" param_min=nb_donor_h_min param_max=nb_donor_h_max param_value=nb_donor_h step='1' param_label='Select a cutoff value for the number of H donors in the compounds to be selected'%}
{% include "slider_modal.html" with label="Publications" param_name="pubs" param_min=pubs_min param_max=pubs_max param_value=pubs step='1' param_label='Select a cutoff value for the number of publications mentioning the compounds to be selected'%}
{% endblock %} {% endblock %}
...@@ -137,9 +137,10 @@ class IppiWizard(NamedUrlSessionWizardView): ...@@ -137,9 +137,10 @@ class IppiWizard(NamedUrlSessionWizardView):
}) })
def process_cutoff_value(name, context, request): def process_cutoff_value(name, context, request, annotation=None):
context[name+'_max'] = str(int(math.ceil(float(Compound.objects.all().aggregate(Max(name))[name + '__max'])))) c = context['compounds']
context[name+'_min'] = str(int(math.floor(float(Compound.objects.all().aggregate(Min(name))[name + '__min'])))) context[name+'_max'] = str(int(math.ceil(float(c.aggregate(Max(name))[name + '__max']))))
context[name+'_min'] = str(int(math.floor(float(c.aggregate(Min(name))[name + '__min']))))
if request.GET.get(name): if request.GET.get(name):
context[name] = request.GET.get(name) context[name] = request.GET.get(name)
filter_dict = {name + '__lte': context[name]} filter_dict = {name + '__lte': context[name]}
...@@ -153,22 +154,23 @@ def compound_list(request): ...@@ -153,22 +154,23 @@ def compound_list(request):
Display the list of compounds Display the list of compounds
""" """
context = {} context = {}
compounds = Compound.objects.all() # pubs is the number of publications referring to the compound
compounds = Compound.objects.annotate(pubs=Count('refcompoundbiblio'))
context['compounds'] = compounds
if request.GET.get('family'): if request.GET.get('family'):
compounds = compounds.filter(compoundaction__ppi__family__id__in=request.GET.getlist('family')) context['compounds'] = context['compounds'].filter(compoundaction__ppi__family__id__in=request.GET.getlist('family'))
# if filtering on "action on PPI"
if request.GET.get('ppi'): if request.GET.get('ppi'):
compounds = compounds.filter(compoundaction__ppi__id__in=request.GET.getlist('ppi')) context['compounds'] = context['compounds'].filter(compoundaction__ppi__id__in=request.GET.getlist('ppi'))
if request.GET.get('disease'): if request.GET.get('disease'):
compounds = compounds.filter(compoundaction__ppi__diseases__id__in=request.GET.getlist('disease')) context['compounds'] = context['compounds'].filter(compoundaction__ppi__diseases__id__in=request.GET.getlist('disease'))
if request.GET.get('taxonomy'): if request.GET.get('taxonomy'):
compounds = compounds.filter(compoundaction__ppi_id__ppicomplex__complex__protein__organism__id__in=request.GET.getlist('taxonomy')) context['compounds'] = context['compounds'].filter(compoundaction__ppi_id__ppicomplex__complex__protein__organism__id__in=request.GET.getlist('taxonomy'))
if request.GET.get('boundcomplex'): if request.GET.get('boundcomplex'):
compounds = compounds.filter(compoundaction__ppi_id__ppicomplex__complex__id__in=request.GET.getlist('boundcomplex')) context['compounds'] = context['compounds'].filter(compoundaction__ppi_id__ppicomplex__complex__id__in=request.GET.getlist('boundcomplex'))
context['compounds'] = compounds
context = process_cutoff_value('molecular_weight', context, request) context = process_cutoff_value('molecular_weight', context, request)
context = process_cutoff_value('a_log_p', context, request) context = process_cutoff_value('a_log_p', context, request)
context = process_cutoff_value('nb_donor_h', context, request) context = process_cutoff_value('nb_donor_h', context, request)
context = process_cutoff_value('pubs', context, request)
selected_families = PpiFamily.objects.filter(id__in=request.GET.getlist('family')) selected_families = PpiFamily.objects.filter(id__in=request.GET.getlist('family'))
families = PpiFamily.objects.exclude(id__in=request.GET.getlist('family')) families = PpiFamily.objects.exclude(id__in=request.GET.getlist('family'))
selected_ppis = Ppi.objects.filter(id__in=request.GET.getlist('ppi')) selected_ppis = Ppi.objects.filter(id__in=request.GET.getlist('ppi'))
...@@ -181,8 +183,6 @@ def compound_list(request): ...@@ -181,8 +183,6 @@ def compound_list(request):
boundcomplexes = ProteinDomainBoundComplex.objects.exclude(id__in=request.GET.getlist('boundcomplex')) boundcomplexes = ProteinDomainBoundComplex.objects.exclude(id__in=request.GET.getlist('boundcomplex'))
sort_by_option_ids = ['id', 'molecular_weight', 'a_log_p', 'nb_aromatic_sssr', 'nb_chiral_centers', 'pubs'] sort_by_option_ids = ['id', 'molecular_weight', 'a_log_p', 'nb_aromatic_sssr', 'nb_chiral_centers', 'pubs']
sort_by = request.GET.get('sort_by', 'id') sort_by = request.GET.get('sort_by', 'id')
if sort_by in ['pubs', '-pubs']:
context['compounds'] = context['compounds'].annotate(pubs=Count('refcompoundbiblio'))
context['compounds'] = context['compounds'].order_by(sort_by) context['compounds'] = context['compounds'].order_by(sort_by)
context['compounds'] = context['compounds'].distinct() context['compounds'] = context['compounds'].distinct()
# handle pagination in compounds list # handle pagination in compounds list
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment