def chromatogram_figures(chroma):
    figures = []
    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 = svguri_plot(plot,
                             bbox_inches='tight',
                             height=5,
                             width=9,
                             svg_width="100%")
    figures.append(chroma_svg)
    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 = svguri_plot(adduct_plot,
                                        bbox_inches='tight',
                                        height=5,
                                        width=9,
                                        svg_width="100%")
        figures.append(adduct_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 = svguri_plot(charge_separating_plot,
                                        bbox_inches='tight',
                                        height=5,
                                        width=9,
                                        svg_width="100%")
        figures.append(charge_separation)
    return figures
Example #2
0
def chromatogram_figures(chroma):
    figures = []
    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 = svguri_plot(
        plot, bbox_inches='tight', height=5, width=9, svg_width="100%")
    figures.append(chroma_svg)
    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(
            "mass_shift-Separated\nExtracted Ion Chromatogram", fontsize=24)
        mass_shift_separation = svguri_plot(
            mass_shift_plot, bbox_inches='tight', height=5, width=9, svg_width="100%")
        figures.append(mass_shift_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 = svguri_plot(
            charge_separating_plot, bbox_inches='tight', height=5, width=9,
            svg_width="100%")
        figures.append(charge_separation)
    return figures
Example #3
0
 def site_specific_abundance_plots(self, glycoprotein):
     axes = OrderedDict()
     for glyco_type in glycoprotein.glycosylation_types:
         for site in sorted(glycoprotein.glycosylation_sites_for(glyco_type)):
             spanning_site = glycoprotein.site_map[glyco_type][site]
             if len(spanning_site) == 0:
                 continue
             bundle = BundledGlycanComposition.aggregate(spanning_site)
             if len(bundle) == 0:
                 continue
             ax = figax()
             AggregatedAbundanceArtist(
                 bundle, ax=ax, colorizer=glycan_colorizer_type_map[glyco_type]).draw()
             ax.set_title("%s Glycans\nat Site %d" % (glyco_type.name, site + 1,), fontsize=18)
             axes[site, glyco_type] = svguri_plot(ax, bbox_inches='tight')
     return axes
 def site_specific_abundance_plots(self, glycoprotein):
     axes = OrderedDict()
     for glyco_type in glycoprotein.glycosylation_types:
         for site in sorted(
                 glycoprotein.glycosylation_sites_for(glyco_type)):
             spanning_site = glycoprotein.site_map[glyco_type][site]
             if len(spanning_site) == 0:
                 continue
             bundle = BundledGlycanComposition.aggregate(spanning_site)
             ax = figax()
             AggregatedAbundanceArtist(
                 bundle,
                 ax=ax,
                 colorizer=glycan_colorizer_type_map[glyco_type]).draw()
             ax.set_title("%s Glycans\nat Site %d" % (
                 glyco_type.name,
                 site,
             ),
                          fontsize=18)
             axes[site, glyco_type] = svguri_plot(ax, bbox_inches='tight')
     return axes
    def make_template_stream(self):
        template_obj = self.env.get_template("overview.templ")

        ads = serialize.AnalysisDeserializer(
            self.database_connection._original_connection,
            analysis_id=self.analysis_id)

        self.glycan_chromatograms = gcs = ads.load_glycan_composition_chromatograms(
        )
        # und = ads.load_unidentified_chromatograms()
        self.unidentified_chromatograms = und = ChromatogramFilter(
            ads.query(serialize.UnidentifiedChromatogram).filter(
                serialize.UnidentifiedChromatogram.analysis_id ==
                self.analysis_id).all())

        if len(gcs) == 0:
            self.log(
                "No glycan compositions were identified. Skipping report building"
            )
            templ = Template('''
                <html>
                <style>
                body {
                    font-family: sans-serif;
                }
                </style>
                <body>
                    <h3>No glycan compositions were identified</h3>
                </body>
                </html>
                ''')
            return templ.stream()

        summary_plot = summaries.GlycanChromatographySummaryGraphBuilder(
            filter(lambda x: x.score > self.threshold, gcs + und))
        lcms_plot, composition_abundance_plot = summary_plot.draw(min_score=5)

        try:
            lcms_plot.ax.legend_.set_visible(False)
        except AttributeError:
            # The legend may not have been created
            pass
        lcms_plot.ax.set_title("Glycan Composition\nLC-MS Aggregated EICs",
                               fontsize=24)

        fig = lcms_plot.ax.figure
        fig.set_figwidth(fig.get_figwidth() * 2.)
        fig.set_figheight(fig.get_figheight() * 2.)

        composition_abundance_plot.ax.set_title(
            "Glycan Composition\nTotal Abundances", fontsize=24)
        composition_abundance_plot.ax.set_xlabel(
            composition_abundance_plot.ax.get_xlabel(), fontsize=14)

        def resolve_key(key):
            match = gcs.find_key(key)
            if match is None:
                match = und.find_key(key)
            return match

        template_stream = (template_obj.stream(
            analysis=ads.analysis,
            lcms_plot=svguri_plot(lcms_plot.ax,
                                  bbox_inches='tight',
                                  patchless=True,
                                  svg_width="100%"),
            composition_abundance_plot=svguri_plot(
                composition_abundance_plot.ax,
                bbox_inches='tight',
                patchless=True,
                svg_width="100%"),
            glycan_chromatograms=gcs,
            unidentified_chromatograms=und,
            resolve_key=resolve_key))
        return template_stream
Example #6
0
    def make_template_stream(self):
        template_obj = self.env.get_template("overview.templ")

        ads = serialize.AnalysisDeserializer(
            self.database_connection._original_connection,
            analysis_id=self.analysis_id)

        self.glycan_chromatograms = gcs = ads.load_glycan_composition_chromatograms()
        # und = ads.load_unidentified_chromatograms()
        self.unidentified_chromatograms = und = ChromatogramFilter(
            ads.query(serialize.UnidentifiedChromatogram).filter(
                serialize.UnidentifiedChromatogram.analysis_id == self.analysis_id).all())

        if len(gcs) == 0:
            self.log("No glycan compositions were identified. Skipping report building")
            templ = Template('''
                <html>
                <style>
                body {
                    font-family: sans-serif;
                }
                </style>
                <body>
                    <h3>No glycan compositions were identified</h3>
                </body>
                </html>
                ''')
            return templ.stream()

        summary_plot = summaries.GlycanChromatographySummaryGraphBuilder(
            filter(lambda x: x.score > self.threshold, gcs + und))
        lcms_plot, composition_abundance_plot = summary_plot.draw(min_score=5)

        try:
            lcms_plot.ax.legend_.set_visible(False)
        except AttributeError:
            # The legend may not have been created
            pass
        lcms_plot.ax.set_title("Glycan Composition\nLC-MS Aggregated EICs", fontsize=24)

        fig = lcms_plot.ax.figure
        fig.set_figwidth(fig.get_figwidth() * 2.)
        fig.set_figheight(fig.get_figheight() * 2.)

        composition_abundance_plot.ax.set_title("Glycan Composition\nTotal Abundances", fontsize=24)
        composition_abundance_plot.ax.set_xlabel(
            composition_abundance_plot.ax.get_xlabel(), fontsize=14)

        def resolve_key(key):
            match = gcs.find_key(key)
            if match is None:
                match = und.find_key(key)
            return match

        template_stream = (template_obj.stream(
            analysis=ads.analysis, lcms_plot=svguri_plot(
                lcms_plot.ax, bbox_inches='tight', patchless=True,
                svg_width="100%"),
            composition_abundance_plot=svguri_plot(
                composition_abundance_plot.ax, bbox_inches='tight', patchless=True,
                svg_width="100%"),
            glycan_chromatograms=gcs,
            unidentified_chromatograms=und,
            resolve_key=resolve_key
        ))
        return template_stream