Ejemplo n.º 1
0
 def get_context_data(self, **kwargs):
     context = super(BioactiveSearchFilterMixin, self).get_context_data(**kwargs)
     context.update({
         'compound_search': BioactiveSearchForm(),
         'protein_search': ProteinSearchForm(),
     })
     return context
Ejemplo n.º 2
0
 def get_context_data(self, **kwargs):
     context = super(MechanismListView, self).get_context_data(**kwargs)
     context.update({
         'filter_form': ClassficationChoiceForm,
         'is_filtered': self.is_filtered,
         'compound_search': BioactiveSearchForm(),
         'protein_search': ProteinSearchForm(),
     })
     selected_mechanisms = self.request.GET.getlist('selected_mechanisms')
     if selected_mechanisms:
         context.update({
             'choice_form': ChemDataChoiceSubmitForm,
             'data_display': 'true',
         })
         id_list = [int(a) for a in selected_mechanisms if a]
         if self.request.GET.get('mean_data'):
             averages = Activity.bioactives_data_stats(id_list)
             for chem_prop, val in averages.items():
                 plot = self.make_plot(val, chem_prop, 'mean')
                 if plot:
                     script, div = components(plot, CDN)
                     context['plot_script' + '_' + chem_prop] = script
                     context['plot_div' + '_' + chem_prop] = div
             stats_arrays = Activity.bioactives_data_stats(id_list,
                                                           std_dev=True)
             sds = {}
             for cp in chemical_properties_label_map.keys():
                 sds[cp] = [(a[0], a[1][cp].std()) for a in stats_arrays]
             for chem_prop, val in sds.items():
                 plot = self.make_plot(val, chem_prop, 'std dev in')
                 if plot:
                     script, div = components(plot, CDN)
                     context['sd_plot_script' + '_' + chem_prop] = script
                     context['sd_plot_div' + '_' + chem_prop] = div
     return context
Ejemplo n.º 3
0
 def get_context_data(self, **kwargs):
     context = super(UserCompoundSourceListView,
                     self).get_context_data(**kwargs)
     context.update({
         'form':
         self.form_class(),
         'upload_form':
         UserSourceCsvUploadForm(),
         'compound':
         self.compound,
         'compound_search':
         OdorantSearchForm()
         if isinstance(self.compound, Odorant) else BioactiveSearchForm()
     })
     if self.user_compound:
         user_cpd_model = 'user_odorant' if isinstance(
             self.compound, Odorant) else 'user_bioactive'
         cs_kwargs = {
             'source__isnull': False,
             user_cpd_model: self.user_compound,
         }
         context.update({
             'rel_sources_list':
             CompoundSource.objects.filter(**cs_kwargs)
         })
     return context
Ejemplo n.º 4
0
 def get_context_data(self, **kwargs):
     context = super(CompoundSourceListView,
                     self).get_context_data(**kwargs)
     context.update({
         'form':
         self.form_class(width=200),
         'compound':
         self.compound,
         'compound_search':
         OdorantSearchForm()
         if isinstance(self.compound, Odorant) else BioactiveSearchForm()
     })
     return context
Ejemplo n.º 5
0
 def get_context_data(self, **kwargs):
     context = super(LiteratureRefsView, self).get_context_data(**kwargs)
     context['body_systems'] = Activity.classified_actions_mechs()
     if self.model == Activity:
         self.mechanism_context(context)
     else:
         context.update({
             'user_literature':
             self.records[0],
             'literature':
             self.records[1],
             'compound':
             self.compound,
             'compound_search':
             OdorantSearchForm()
             if self.model == Odorant else BioactiveSearchForm(),
         })
     return context
Ejemplo n.º 6
0
 def mechanism_context(self, context):
     mechanism = get_object_or_404(self.model, pk=self.kwargs.get('pk'))
     if not mechanism.name:
         raise Http404
     split_name = mechanism.name.split()
     query = split_name[0]
     for item in split_name[1:]:
         if item != 'and':
             query += '%5b%5d+AND+{}'.format(item)
     lit_data = self.get_mech_literature(split_name, query)
     context.update({
         'mechanism':
         True,
         'literature':
         lit_data,
         'compound':
         'Recent literature: {}'.format(mechanism.name),
         'compound_search':
         BioactiveSearchForm(),
     })
     return context
Ejemplo n.º 7
0
 def get_context_data(self, **kwargs):
     context = super(ActivityProteinListView,
                     self).get_context_data(**kwargs)
     if self.action_id:
         mechanisms = Activity.objects.mechanisms().filter(
             action_id=self.action_id)
         proteins = Enzyme.objects.filter(mechanism__in=mechanisms)
         context['page_header'] = 'Drug action: {}'.format(
             self.kwargs['action_name'].replace('-', ' '))
         if not proteins.exists():
             messages.info(self.request, 'No proteins matched the query')
             proteins = Enzyme.objects.exclude(notes__isnull=True)
     else:
         proteins = self.process_search_query(self.search_term)
         context.update({
             'results_label':
             ' {} drug targets'.format(self.results_label)
             if self.results_label else None,
             'page_header':
             'Protein search query: {}'.format(self.search_term)
         })
     context.update({
         'body_systems':
         Activity.classified_actions_mechs(),
         'drug_actions':
         Activity.objects.actions().order_by('name'),
         'search_form':
         ProteinSearchForm(),
         'compound_search':
         BioactiveSearchForm(),
         'proteins':
         proteins.exists(),
         'proteins_json':
         json.dumps([{
             'citation': a['citation'],
             'notes': a['notes'],
             'pdb_number': a['pdb_number']
         } for a in proteins.values('pdb_number', 'notes', 'citation')]),
     })
     return context