diff --git a/ippisite/ippidb/templates/compound_list.html b/ippisite/ippidb/templates/compound_list.html index 84e6011d7ad8dc03e69aff5db0bfb4616dbb1fb9..7aa032fb2de3be52ddaeb3ccaf7bf9dc2cc565e7 100644 --- a/ippisite/ippidb/templates/compound_list.html +++ b/ippisite/ippidb/templates/compound_list.html @@ -27,6 +27,7 @@ {% 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="H donors" param_name="nb_donor_h" %} + {% include "slider_button.html" with label="Publications" param_name="pubs" %} </div> <div class="m-2 d-flex "> <span>{{ compounds.paginator.count }} compounds</span> @@ -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="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="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 %} diff --git a/ippisite/ippidb/views.py b/ippisite/ippidb/views.py index e98eb1004b7885072a7a07ea858b2a724c8d13cd..d55203679ebc9cd912ee2fe99236dadd0720eb1d 100644 --- a/ippisite/ippidb/views.py +++ b/ippisite/ippidb/views.py @@ -137,9 +137,10 @@ class IppiWizard(NamedUrlSessionWizardView): }) -def process_cutoff_value(name, context, request): - context[name+'_max'] = str(int(math.ceil(float(Compound.objects.all().aggregate(Max(name))[name + '__max'])))) - context[name+'_min'] = str(int(math.floor(float(Compound.objects.all().aggregate(Min(name))[name + '__min'])))) +def process_cutoff_value(name, context, request, annotation=None): + c = context['compounds'] + 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): context[name] = request.GET.get(name) filter_dict = {name + '__lte': context[name]} @@ -153,22 +154,23 @@ def compound_list(request): Display the list of compounds """ 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'): - compounds = compounds.filter(compoundaction__ppi__family__id__in=request.GET.getlist('family')) - # if filtering on "action on PPI" + context['compounds'] = context['compounds'].filter(compoundaction__ppi__family__id__in=request.GET.getlist('family')) 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'): - 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'): - 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'): - compounds = compounds.filter(compoundaction__ppi_id__ppicomplex__complex__id__in=request.GET.getlist('boundcomplex')) - context['compounds'] = compounds + context['compounds'] = context['compounds'].filter(compoundaction__ppi_id__ppicomplex__complex__id__in=request.GET.getlist('boundcomplex')) context = process_cutoff_value('molecular_weight', context, request) context = process_cutoff_value('a_log_p', 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')) families = PpiFamily.objects.exclude(id__in=request.GET.getlist('family')) selected_ppis = Ppi.objects.filter(id__in=request.GET.getlist('ppi')) @@ -181,8 +183,6 @@ def compound_list(request): 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 = 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'].distinct() # handle pagination in compounds list