Пример #1
0
 def get_context_data(self, **kwargs):
     context = super(BioactiveCoreListView, self).get_context_data(**kwargs)
     medicinals = BioactiveCore.objects.medicinal().prefetch_related('bioactives').order_by('name')
     context.update({
         'body_systems': Activity.classified_actions_mechs(),
         'substructure_sets': [
             {'subset': medicinals,
              'label': 'Medicinal'},
             {'subset': BioactiveCore.objects.food().exclude(name='Oligosaccharides').order_by('name'),
              'label': 'Nutraceutical'},
         ],
         'choice_form': ChemDataChoiceSubmitForm,
     })
     if self.request.GET.get('stats_data'):
         averages, stats_arrays = BioactiveCore.compound_sets_stats(core_set=medicinals)
         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
         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
         context['data_display'] = 'true'
     return context
Пример #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
Пример #3
0
 def get_context_data(self, **kwargs):
     context = super(SubstructureListView, self).get_context_data(**kwargs)
     context.update({
         'substructure_sets': [
             {
                 'subset': Substructure.objects.acyclic_terpenoids(),
                 'label': 'Acyclic Terpenoids'
             },
             {
                 'subset': Substructure.objects.cyclic_terpenoids(),
                 'label': 'Cyclic Terpenoids'
             },
             {
                 'subset': Substructure.objects.cycloaliphatics(),
                 'label': 'Cycloaliphatics'
             },
             {
                 'subset': Substructure.objects.aromatic_compounds(),
                 'label': 'Aromatics'
             },
         ],
         'choice_form':
         ChemDataChoiceSubmitForm,
         'odor_types':
         OdorType.objects.values('term'),
     })
     if self.request.GET.get('stats_data'):
         for cp in chemical_properties_label_map.keys():
             plot = self.make_plot(cp)
             if plot:
                 script, div = components(plot, CDN)
                 context['plot_script' + '_' + cp] = script
                 context['plot_div' + '_' + cp] = div
         context['data_display'] = 'true'
     return context
Пример #4
0
 def bioactive_set_properties(self):
     chem_props = {
         k:
         np.array([a.chemical_properties[k] for a in self.bioactives.all()])
         for k in chemical_properties_label_map.keys()
     }
     cleaned_arrays = {
         k: v[v != np.array(None)]
         for k, v in chem_props.items()
     }
     return cleaned_arrays
Пример #5
0
 def compound_sets_stats(cls, core_set):
     chem_properties = chemical_properties_label_map.keys()
     avg_data = {chem_prop: [] for chem_prop in chem_properties}
     bioactive_properties = []
     for core in core_set:
         bioactive_properties.append(
             (core.name, core.bioactive_set_properties))
         for chem_prop in chem_properties:
             avg_data[chem_prop].append(
                 (core.name, core.bioactives.all().chemical_property_avg(
                     chem_prop).get('as_float__avg')))
     return avg_data, bioactive_properties
Пример #6
0
 def bioactives_data_stats(cls, id_list, std_dev=False):
     properties = chemical_properties_label_map.keys()
     activities = cls.objects.filter(
         id__in=id_list).prefetch_related('bioactives')
     if std_dev:
         return [(a.name, a.mechanism_bioactives_properties)
                 for a in activities]
     data = {}
     for chem_prop in properties:
         average_data = [(a.name, a.bioactives.all().chemical_property_avg(
             chem_prop).get('as_float__avg')) for a in activities]
         data[chem_prop] = [ad for ad in average_data if ad[1]]
     return data
Пример #7
0
 def get_context_data(self, **kwargs):
     context = super(BioactiveCoreMatchList, self).get_context_data(**kwargs)
     context['page_header'] = self.bioactive_core.name
     if self.bioactive_vals:
         context.update({
             'choice_form': ChemDataChoiceSubmitForm,
             'page_title': self.bioactive_core.name,
             'data_display': 'true',
             'cid_numbers': [{'number': b['cid_number_2'] or b['cid_number'],
                              'name': b['chemical_name'][:23] + '...' if len(b['chemical_name']) > 25
                              else b['chemical_name'][:23] or b['iupac_name'][:32]}
                             for b in self.bioactive_vals],
         })
         properties = chemical_properties_label_map.keys()
         for cp in properties:
             plot = self.make_plot(cp)
             script, div = components(plot, CDN)
             context['plot_script' + '_' + cp] = script
             context['plot_div' + '_' + cp] = div
     return context