diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index 22e9533293cb56f77f187ca3004347859c8d4fcb..5cd1496915c30d27cf8bc97713639f3dc1d37578 100644 --- a/ippisite/ippidb/models.py +++ b/ippisite/ippidb/models.py @@ -314,6 +314,12 @@ class CompoundManager(models.Manager): qs = qs.annotate(pfizer=Case(When(Q(Q(a_log_p__lte=3) & Q(tpsa__gte=75)), then=True), default=False, output_field=BooleanField())) # PDB ligand available qs = qs.annotate(pdb_ligand_av=Case(When(compoundaction__ppi__pdb_id__isnull=False, then=True), default=False, output_field=BooleanField())) + # inhibition role + qs = qs.annotate(inhibition_role=Case(When(compoundactivityresult__modulation_type='I', then=True), default=False, output_field=BooleanField())) + # binding role + qs = qs.annotate(binding_role=Case(When(compoundactivityresult__modulation_type='B', then=True), default=False, output_field=BooleanField())) + # stabilisation role + qs = qs.annotate(stabilisation_role=Case(When(compoundactivityresult__modulation_type='S', then=True), default=False, output_field=BooleanField())) return qs class Compound(AutoFillableModel): diff --git a/ippisite/ippidb/templates/compound_list.html b/ippisite/ippidb/templates/compound_list.html index c1beb3030aadf10e1024b7200818441db40720b8..893bd1b68fc5073605e73ea19d8b40e96c089818 100644 --- a/ippisite/ippidb/templates/compound_list.html +++ b/ippisite/ippidb/templates/compound_list.html @@ -77,6 +77,10 @@ </button> <div class="dropdown-menu" aria-labelledby="mmoaMenuButton"> {% include "dropdown_checkbox.html" with label="PDB ligand available" param_name="pdb_ligand_av" value=pdb_ligand_av %} + <div class="dropdown-divider"></div> + {% include "dropdown_checkbox.html" with label="Inhibition role" param_name="inhibition_role" value=inhibition_role %} + {% include "dropdown_checkbox.html" with label="Stabilisation role" param_name="stabilisation_role" value=stabilisation_role %} + {% include "dropdown_checkbox.html" with label="Binding role" param_name="binding_role" value=binding_role %} </div> </div> <div class="dropdown btn-group" style="display: inline-flex;"> @@ -152,6 +156,9 @@ {% include "slider_badge.html" with param_name="lle" param_value=lle param_value_min=lle_value_min param_value_max=lle_value_max param_label="LLE" %} {% include "boolean_badge.html" with param_name="pdb_ligand_av" param_value=pdb_ligand_av label="PDB ligand available"%} + {% include "boolean_badge.html" with param_name="inhibition_role" param_value=inhibition_role label="Inhibition role"%} + {% include "boolean_badge.html" with param_name="stabilisation_role" param_value=stabilisation_role label="Stabilisation role"%} + {% include "boolean_badge.html" with param_name="binding_role" param_value=binding_role label="Binding role"%} {% include "selected_badge.html" with param_name="boundcomplex" values=selected_boundcomplex %} {% include "selected_badge.html" with param_name="family" values=selected_family %} diff --git a/ippisite/ippidb/views/compound_query.py b/ippisite/ippidb/views/compound_query.py index 2ec47df90d75f5c98426ed771b85923124d92e39..fda158bf0a65f72ec805b8c2ddacc4890b506837 100644 --- a/ippisite/ippidb/views/compound_query.py +++ b/ippisite/ippidb/views/compound_query.py @@ -205,7 +205,7 @@ class TrueFilterHandler(FilterHandler): if self.value: # filter queryset on the values being True filter_dict = { - self.parameter_name: True, + self.parameter_name: self.value=='true', } queryset = queryset.filter(**filter_dict) return queryset @@ -215,6 +215,34 @@ class TrueFilterHandler(FilterHandler): pass +class TrueListFilterHandler(object): + + def __init__(self, parameter_name_list, filter_context, request_get): + self.parameter_name_list = parameter_name_list + self.filter_context = filter_context + self.values = {} + for parameter_name in self.parameter_name_list: + if request_get.get(parameter_name): + self.values[parameter_name] = request_get.get(parameter_name).strip() + self.filter_context[parameter_name] = self.values[parameter_name] + + def process(self, queryset): + """ to be called during queryset filtering """ + # if a value has been set for this filter + + if len(self.values)>0: + q = Q() + for parameter_name, value in self.values.items(): + q = q | Q(**{parameter_name:value=='true'}) + queryset = queryset.filter(q) + print(q) + return queryset + + def post_process(self, compound_ids, queryset): + """ to be called after queryset filtering """ + pass + + class CompoundListView(ListView): model = Compound @@ -306,6 +334,7 @@ class CompoundListView(ListView): CompoundSimilarityFilterHandler('similar_to', self.filter_context, self.request.GET), TextSearchFilterHandler('q', self.filter_context, self.request.GET), TrueFilterHandler('pdb_ligand_av', self.filter_context, self.request.GET), + TrueListFilterHandler(['inhibition_role', 'stabilisation_role', 'binding_role'], self.filter_context, self.request.GET) ] for cfh in cfhs: qs = cfh.process(qs)