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

fix step value in value range sliders for compounds list

fix #117


Former-commit-id: 6184f9a4029928dbedf0563027a91e0bd5d4f10b
parent d3a444a1
No related branches found
No related tags found
No related merge requests found
......@@ -254,15 +254,15 @@
{% 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 param_value_min=a_log_p_value_min param_value_max=a_log_p_value_max 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 param_value_min=nb_donor_h_value_min param_value_max=nb_donor_h_value_max 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 acceptors" param_name="nb_acceptor_h" param_min=nb_acceptor_h_min param_max=nb_acceptor_h_max param_value=nb_acceptor_h param_value_min=nb_acceptor_h_value_min param_value_max=nb_acceptor_h_value_max step='1' param_label='Select a cutoff value for the number of H acceptors in the compounds to be selected'%}
{% include "slider_modal.html" with label="TPSA" param_name="tpsa" param_min=tpsa_min param_max=tpsa_max param_value=tpsa param_value_min=tpsa_value_min param_value_max=tpsa_value_max step='1' param_label='Select a cutoff value for the TPSA of the compounds to be selected'%}
{% include "slider_modal.html" with label="TPSA" param_name="tpsa" param_min=tpsa_min param_max=tpsa_max param_value=tpsa param_value_min=tpsa_value_min param_value_max=tpsa_value_max step='50' param_label='Select a cutoff value for the TPSA of the compounds to be selected'%}
{% include "slider_modal.html" with label="Nb rotatable bonds" param_name="nb_rotatable_bonds" param_min=nb_rotatable_bonds_min param_max=nb_rotatable_bonds_max param_value=nb_rotatable_bonds param_value_min=nb_rotatable_bonds_value_min param_value_max=nb_rotatable_bonds_value_max step='1' param_label='Select a cutoff value for the number of rotatable bounds in the compounds to be selected'%}
{% include "slider_modal.html" with label="Nb aromatic SSSR" param_name="nb_aromatic_sssr" param_min=nb_aromatic_sssr_min param_max=nb_aromatic_sssr_max param_value=nb_aromatic_sssr param_value_min=nb_aromatic_sssr_value_min param_value_max=nb_aromatic_sssr_value_max step='1' param_label='Select a cutoff value for the number of aromatic SSSR in the compounds to be selected'%}
{% include "slider_modal.html" with label="Nb chiral centers" param_name="nb_chiral_centers" param_min=nb_chiral_centers_min param_max=nb_chiral_centers_max param_value=nb_chiral_centers param_value_min=nb_chiral_centers_value_min param_value_max=nb_chiral_centers_value_max step='1' param_label='Select a cutoff value for the number of chiral centers in the compounds to be selected'%}
{% include "slider_modal.html" with label="FSP3" param_name="fsp3" param_min=fsp3_min param_max=fsp3_max param_value=fsp3 param_value_min=fsp3_value_min param_value_max=fsp3_value_max step='1' param_label='Select a cutoff value for the FSP3 of the compounds to be selected'%}
{% include "slider_modal.html" with label="FSP3" param_name="fsp3" param_min=fsp3_min param_max=fsp3_max param_value=fsp3 param_value_min=fsp3_value_min param_value_max=fsp3_value_max step='0.1' param_label='Select a cutoff value for the FSP3 of 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 param_value_min=pubs_value_min param_value_max=pubs_value_max step='1' param_label='Select a cutoff value for the number of publications mentioning the compounds to be selected'%}
{% include "marvinjs_modal.html" with smiles=similar_to_query fingerprint=similar_to_fingerprint %}
{% include "slider_modal.html" with label="Best Activiry" param_name="qs_ba" param_min=qs_ba_min param_max=qs_ba_max param_value=qs_ba param_value_min=qs_ba_value_min param_value_max=qs_ba_value_max step='1' param_label='Select a cutoff value for the best activity of the compounds to be selected'%}
{% include "slider_modal.html" with label="LE" param_name="qs_le" param_min=qs_le_min param_max=qs_le_max param_value=qs_le param_value_min=qs_le_value_min param_value_max=qs_le_value_max step='1' param_label='Select a cutoff value for the LE of the compounds to be selected'%}
{% include "slider_modal.html" with label="LE" param_name="qs_le" param_min=qs_le_min param_max=qs_le_max param_value=qs_le param_value_min=qs_le_value_min param_value_max=qs_le_value_max step='0.1' param_label='Select a cutoff value for the LE of the compounds to be selected'%}
{% include "slider_modal.html" with label="LLE" param_name="qs_lle" param_min=qs_lle_min param_max=qs_lle_max param_value=qs_lle param_value_min=qs_lle_value_min param_value_max=qs_lle_value_max step='1' param_label='Select a cutoff value for the LLE of the compounds to be selected'%}
{% endblock %}
......@@ -251,10 +251,11 @@ class TextSearchFilterHandler(object):
class CompoundRangeFilterHandler(object):
def __init__(self, parameter_name, filter_context, request_get):
def __init__(self, parameter_name, filter_context, request_get, step=1):
self.parameter_name = parameter_name
self.filter_context = filter_context
self.value = None
self.step = step or 1
if request_get.get(parameter_name):
self.value = request_get.get(parameter_name)
self.value_min, self.value_max = self.value.split(',')
......@@ -291,16 +292,27 @@ class CompoundRangeFilterHandler(object):
# with LLE
elif self.parameter_name == 'qs_lle':
qs = qs.annotate(qs_lle=Cast(Max('compoundactivityresult__activity') - F('a_log_p'),FloatField()))
self.filter_context[self.parameter_name+'_max'] = str(int(math.ceil(float(qs.aggregate(Max(self.parameter_name))[self.parameter_name + '__max'] or 0))))
self.filter_context[self.parameter_name+'_min'] = str(int(math.floor(float(qs.aggregate(Min(self.parameter_name))[self.parameter_name + '__min'] or 0))))
self.filter_context[self.parameter_name+'_max'] = self.get_max(qs)
self.filter_context[self.parameter_name+'_min'] = self.get_min(qs)
return queryset
def get_max(self, qs):
val = float(qs.aggregate(Max(self.parameter_name))[self.parameter_name + '__max'] or 0)
val = val - val % self.step + self.step
return str(val)
def get_min(self, qs):
val = float(qs.aggregate(Min(self.parameter_name))[self.parameter_name + '__min'] or 0)
val = val - val % self.step + self.step
return str(val)
def post_process(self, compound_ids, queryset):
""" to be called after queryset filtering """
# if no value has been set for this filter
if not self.value:
self.filter_context[self.parameter_name+'_max'] = str(int(math.ceil(float(queryset.aggregate(Max(self.parameter_name))[self.parameter_name + '__max'] or 0))))
self.filter_context[self.parameter_name+'_min'] = str(int(math.floor(float(queryset.aggregate(Min(self.parameter_name))[self.parameter_name + '__min'] or 0))))
self.filter_context[self.parameter_name+'_max'] = self.get_max(queryset)
self.filter_context[self.parameter_name+'_min'] = self.get_min(queryset)
class ExistsFilterHandler(object):
......@@ -401,18 +413,18 @@ class CompoundListView(ListView):
CompoundListFilterHandler(Disease, 'compoundaction__ppi__diseases', 'ppi__compoundaction__compound', 'disease', self.filter_context, self.request.GET),
CompoundListFilterHandler(Taxonomy, 'compoundaction__ppi_id__ppicomplex__complex__protein__organism', 'protein__proteindomaincomplex__ppicomplex__ppi__compoundaction__compound', 'taxonomy', self.filter_context, self.request.GET),
CompoundListFilterHandler(ProteinDomainBoundComplex, 'compoundaction__ppi_id__ppicomplex__complex', 'ppicomplex__ppi__compoundaction__compound', 'boundcomplex', self.filter_context, self.request.GET),
CompoundRangeFilterHandler('molecular_weight', self.filter_context, self.request.GET),
CompoundRangeFilterHandler('molecular_weight', self.filter_context, self.request.GET, 50),
CompoundRangeFilterHandler('a_log_p', self.filter_context, self.request.GET),
CompoundRangeFilterHandler('nb_donor_h', self.filter_context, self.request.GET),
CompoundRangeFilterHandler('nb_acceptor_h', self.filter_context, self.request.GET),
CompoundRangeFilterHandler('tpsa', self.filter_context, self.request.GET),
CompoundRangeFilterHandler('tpsa', self.filter_context, self.request.GET, 50),
CompoundRangeFilterHandler('nb_rotatable_bonds', self.filter_context, self.request.GET),
CompoundRangeFilterHandler('nb_aromatic_sssr', self.filter_context, self.request.GET),
CompoundRangeFilterHandler('nb_chiral_centers', self.filter_context, self.request.GET),
CompoundRangeFilterHandler('fsp3', self.filter_context, self.request.GET),
CompoundRangeFilterHandler('fsp3', self.filter_context, self.request.GET, 0.1),
CompoundRangeFilterHandler('pubs', self.filter_context, self.request.GET),
CompoundRangeFilterHandler('qs_ba', self.filter_context, self.request.GET),
CompoundRangeFilterHandler('qs_le', self.filter_context, self.request.GET),
CompoundRangeFilterHandler('qs_le', self.filter_context, self.request.GET, 0.1),
CompoundRangeFilterHandler('qs_lle', self.filter_context, self.request.GET),
ExistsFilterHandler('pubchem_id', self.filter_context, self.request.GET),
ExistsFilterHandler('chemspider_id', self.filter_context, self.request.GET),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment