def __call__(self, a, b):
        if isinstance(a, basestring):
            a = normalize_composition(a)
            b = normalize_composition(b)
        keys = self.key_order(sorted(set(a) | set(b), key=self.sorter))

        for key in keys:
            if a[key] < b[key]:
                return -1
            elif a[key] > b[key]:
                return 1
            else:
                continue
        return 0
Пример #2
0
    def __call__(self, a, b):
        if isinstance(a, basestring):
            a = normalize_composition(a)
            b = normalize_composition(b)
        keys = self.key_order(sorted(set(a) | set(b), key=self.sorter))

        for key in keys:
            if a[key] < b[key]:
                return -1
            elif a[key] > b[key]:
                return 1
            else:
                continue
        return 0
Пример #3
0
 def __call__(self, obj):
     obj = normalize_composition(obj)
     for rule, color in self.rule_color_map.items():
         if rule(obj):
             return color
     if self.default:
         return self.default
     raise ValueError("Could not classify %r" % obj)
 def __call__(self, obj):
     obj = normalize_composition(obj)
     for rule, color in self.rule_color_map.items():
         if rule(obj):
             return color
     if self.default:
         return self.default
     raise ValueError("Could not classify %r" % obj)
Пример #5
0
    def _infer_compositions(self):
        residues = set()
        for item in self._input_series:
            if isinstance(item, basestring):
                item = normalize_composition(item)
            residues.update(item)

        residues = sorted(residues, key=_degree_monosaccharide_alteration)
        self.residues = self.order_chooser.key_order(residues)
    def _infer_compositions(self):
        residues = set()
        for item in self._input_series:
            if isinstance(item, basestring):
                item = normalize_composition(item)
            residues.update(item)

        residues = sorted(residues, key=_degree_monosaccharide_alteration)
        self.residues = self.order_chooser.key_order(residues)
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)
Пример #8
0
 def transform(self):
     for item in self._input_series:
         if isinstance(item, basestring):
             item = normalize_composition(item)
         counts = [str(item[r]) for r in self.residues]
         yield '[%s]' % '; '.join(counts)
 def transform(self):
     for item in self._input_series:
         if isinstance(item, basestring):
             item = normalize_composition(item)
         counts = [str(item[r]) for r in self.residues]
         yield '[%s]' % '; '.join(counts)