コード例 #1
0
def details_for(analysis_uuid, chromatogram_id):
    view = get_view(analysis_uuid)
    with view:
        snapshot = view.get_items_for_display()
        with snapshot.bind(view.session):
            model = view.analysis.parameters.get('scoring_model')
            chroma = snapshot[chromatogram_id].convert(chromatogram_scoring_model=model)
            plot = SmoothingChromatogramArtist(
                [chroma], colorizer=lambda *a, **k: 'green', ax=figax()).draw(
                label_function=lambda *a, **k: "", legend=False).ax
            plot.set_title("Aggregated\nExtracted Ion Chromatogram", fontsize=24)
            chroma_svg = report.svguri_plot(
                plot, bbox_inches='tight', height=5, width=9, svg_width="100%")

            glycan_composition = normalize_composition(chroma.glycan_composition)

            membership = [neigh.name for neigh in view.neighborhoods if neigh(glycan_composition)]

            mass_shift_separation = ""
            if len(chroma.mass_shifts) > 1:
                mass_shifts = list(chroma.mass_shifts)
                labels = {}
                rest = chroma
                for mass_shift in mass_shifts:
                    with_mass_shift, rest = rest.bisect_mass_shift(mass_shift)
                    labels[mass_shift] = with_mass_shift
                mass_shift_plot = SmoothingChromatogramArtist(
                    labels.values(),
                    colorizer=lambda *a, **k: 'green', ax=figax()).draw(
                    label_function=lambda *a, **k: tuple(a[0].mass_shifts)[0].name,
                    legend=False).ax
                mass_shift_plot.set_title(
                    "Adduct-Separated\nExtracted Ion Chromatogram", fontsize=24)
                mass_shift_separation = report.svguri_plot(
                    mass_shift_plot, bbox_inches='tight', height=5, width=9, svg_width="100%")

            charge_separation = ""
            if len(chroma.charge_states) > 1:
                charge_separating_plot = ChargeSeparatingSmoothingChromatogramArtist(
                    [chroma], ax=figax()).draw(
                    label_function=lambda x, *a, **kw: str(tuple(x.charge_states)[0]), legend=False).ax
                charge_separating_plot.set_title("Charge-Separated\nExtracted Ion Chromatogram", fontsize=24)
                charge_separation = report.svguri_plot(
                    charge_separating_plot, bbox_inches='tight', height=5, width=9,
                    svg_width="100%")

            return render_template(
                "/view_glycan_search/detail_modal.templ", chromatogram=chroma,
                chromatogram_svg=chroma_svg, mass_shift_separation_svg=mass_shift_separation,
                charge_chromatogram_svg=charge_separation,
                logitscore=logitsum(chroma.score_components()),
                membership=membership)
コード例 #2
0
def details_for_unidentified(analysis_uuid, chromatogram_id):
    view = get_view(analysis_uuid)
    with view:
        snapshot = view.get_items_for_display()
        with snapshot.bind(view.session):
            chroma = snapshot.unidentified_id_map[chromatogram_id].convert()
            plot = SmoothingChromatogramArtist(
                [chroma], colorizer=lambda *a, **k: 'green',
                ax=figax()).draw(label_function=lambda *a, **k: "",
                                 legend=False).ax
            plot.set_title("Aggregated\nExtracted Ion Chromatogram",
                           fontsize=24)
            chroma_svg = report.svguri_plot(plot,
                                            bbox_inches='tight',
                                            height=5,
                                            width=9,
                                            svg_width="100%")

            adduct_separation = ""
            if len(chroma.adducts) > 1:
                adducts = list(chroma.adducts)
                labels = {}
                rest = chroma
                for adduct in adducts:
                    with_adduct, rest = rest.bisect_adduct(adduct)
                    labels[adduct] = with_adduct
                adduct_plot = SmoothingChromatogramArtist(
                    labels.values(),
                    colorizer=lambda *a, **k: 'green',
                    ax=figax()).draw(label_function=lambda *a, **k: tuple(a[
                        0].adducts)[0].name,
                                     legend=False).ax
                adduct_plot.set_title(
                    "Adduct-Separated\nExtracted Ion Chromatogram",
                    fontsize=24)
                adduct_separation = report.svguri_plot(adduct_plot,
                                                       bbox_inches='tight',
                                                       height=5,
                                                       width=9,
                                                       svg_width="100%")

            charge_separation = ""
            if len(chroma.charge_states) > 1:
                charge_separating_plot = ChargeSeparatingSmoothingChromatogramArtist(
                    [chroma],
                    ax=figax()).draw(legend=False,
                                     label_function=lambda x, *a, **kw: str(
                                         tuple(x.charge_states)[0])).ax
                charge_separating_plot.set_title(
                    "Charge-Separated\nExtracted Ion Chromatogram",
                    fontsize=24)
                charge_separation = report.svguri_plot(charge_separating_plot,
                                                       bbox_inches='tight',
                                                       height=5,
                                                       width=9,
                                                       svg_width="100%")

            return render_template("/view_glycan_search/detail_modal.templ",
                                   chromatogram=chroma,
                                   chromatogram_svg=chroma_svg,
                                   adduct_separation_svg=adduct_separation,
                                   charge_chromatogram_svg=charge_separation,
                                   logitscore=logitsum(
                                       chroma.score_components()),
                                   membership=[])
コード例 #3
0
try:
    matplotlib.use("agg")
except Exception:
    pass
from matplotlib import pyplot as plt, rcParams
import numpy as np
from scipy import stats
from glycan_profiling.scoring.chromatogram_solution import logitsum

rcParams['figure.figsize'] = 12, 8

rng = np.random.RandomState(500)

simulation_data = (rng.uniform(size=(100000, 5)).T)

simulation_scores = logitsum(simulation_data)
dist = stats.norm(loc=np.mean(simulation_scores),
                  scale=np.std(simulation_scores))

plt.hist(simulation_scores, bins='fd', density=1)
plt.vlines(0,
           0,
           .11,
           color='black',
           linestyle='--',
           label='Never Considered (p = %0.3f)' % (1 - dist.cdf(0)))
plt.vlines(5,
           0,
           .11,
           color='red',
           linestyle='--',