def xic_detail(request, dataset_pk, mcfid, adduct_pk): dataset = get_object_or_404(Dataset, pk=dataset_pk) standard = get_object_or_404(Standard, inventory_id=mcfid) adduct = get_object_or_404(Adduct, pk=adduct_pk) mz = standard.molecule.get_mz(adduct) delta_mz = mz * dataset.mass_accuracy_ppm * 1e-6 # xics=Xic.objects.all().filter(dataset=dataset).filter(mz__gte=mz-delta_mz).filter(mz__lte=mz+delta_mz) xic = Xic.objects.all().filter(standard=standard, adduct=adduct, dataset=dataset)[0] frag_specs = FragmentationSpectrum.objects.all().filter( dataset=dataset).filter(precursor_mz__gte=mz - delta_mz).filter( precursor_mz__lte=mz + delta_mz).order_by('-ms1_intensity')[:10] form = FragSpecReview(request.POST or None, extra=list([fs.pk for fs in frag_specs]), user=request.user) if form.is_valid(): for (fragSpecId, response) in form.get_response(): # todo update fields in frag spectra logging.debug((form.user, fragSpecId, response)) tools.update_fragSpec(fragSpecId, response, standard, adduct, request.user.username) return redirect('dataset-detail', dataset_pk) else: data = { 'form': form, 'extra': { 'x_is_date': False, 'x_axis_format': '', 'tag_script_js': True, 'jquery_on_ready': True, }, "mz": mz, "dataset": dataset, "standard": standard, "adduct": adduct, "xic": xic, "frag_specs": frag_specs, "xic_plot": plots.xic_plot(xic.rt, xic.xic, [spectrum.rt for spectrum in frag_specs], [spectrum.ms1_intensity for spectrum in frag_specs]), "frag_info": zip(frag_specs, [ plots.fragment_plot( spectrum.centroid_mzs, spectrum.centroid_ints, spectrum.precursor_mz) for spectrum in frag_specs ]) } return render(request, 'mcf_standards_browse/mcf_xic_detail.html', context=data)
def molecule_detail(request, pk): molecule = get_object_or_404(Molecule, pk=pk) standards = Standard.objects.all().filter(molecule=molecule) frag_specs = [] for standard in standards: frag_specs.extend(FragmentationSpectrum.objects.all().filter(standard=standard)) chart_type = 'line' chart_height = 300 _frag_specs = [] for standard in standards: _frag_specs.append( [(spectrum, plots.fragment_plot(spectrum.centroid_mzs, spectrum.centroid_ints, spectrum.precursor_mz)) for spectrum in FragmentationSpectrum.objects.all().filter(standard=standard)] ) data = { 'molecule': molecule, "standards": zip(standards, _frag_specs), "frag_spec_highchart": [{ "chart_id": 'frag_spec{}'.format(spec.id), "chart": {"type": chart_type, "height": chart_height, "zoomType": "x"}, "title": {"text": ''}, "xAxis": {"title": {"text": 'm/z'},}, "yAxis": {"title": {"text": 'Intensity'}}, "series": [ {"name": 'fragment spectrum', "data": [[x + d, y * m] for x, y in zip(np.round(spec.centroid_mzs, 5), spec.centroid_ints) for d, m in zip([-0.00, 0, 0.00], [0, 1, 0])] }, ],} for spec in frag_specs], } return render(request, 'mcf_standards_browse/mcf_molecule_detail.html', data)
def standard_detail(request, mcfid): standard = get_object_or_404(Standard, inventory_id=mcfid) frag_specs = FragmentationSpectrum.objects.all().filter(standard=standard) xics = Xic.objects.all().filter(standard=standard) xic_plots = "" if frag_specs: xic_plots = plots.multixic([ (xic.rt, xic.xic, [spectrum.rt for spectrum in frag_specs], [spectrum.ms1_intensity for spectrum in frag_specs]) for xic in xics ]) data = { 'extra': { 'x_is_date': False, 'x_axis_format': '', 'tag_script_js': True, 'jquery_on_ready': True, }, "standard": standard, "xics": xics, "frag_specs": frag_specs, "xic_plot": xic_plots, "frag_info": zip(frag_specs, [ plots.fragment_plot(spectrum.centroid_mzs, spectrum.centroid_ints, spectrum.precursor_mz) for spectrum in frag_specs ]) } return render(request, 'mcf_standards_browse/mcf_standard_detail.html', data)
def fragmentSpectrum_detail(request, pk): spectrum = get_object_or_404(FragmentationSpectrum, pk=pk) xic = Xic.objects.all().filter(standard=spectrum.standard, adduct=spectrum.adduct, dataset=spectrum.dataset)[0] splash_payload = json.dumps({ "ions": [{"mass": mz, "intensity": int_} for mz, int_ in zip(spectrum.centroid_mzs, spectrum.centroid_ints)], "type": "MS"}) data = { 'specdata': { 'spectrum': spectrum, 'centroids': [spectrum.centroid_mzs, spectrum.centroid_ints], }, "splash_payload": splash_payload, "fragment_plot": plots.fragment_plot(spectrum.centroid_mzs, spectrum.centroid_ints, pk), "xic_plot": plots.xic_plot(xic.rt, xic.xic, [spectrum.rt,], [spectrum.ms1_intensity,],) } return render(request, 'mcf_standards_browse/mcf_fragmentSpectrum_detail.html', data)