def cfg_plot(record): if "svg_plot" in record.report_data: return base64.decodestring(record.report_data["svg_plot"]) s = record.structure.clone() composition_transform.strip_derivatization(s) dtree, ax = plot.plot(s, orientation='h', squeeze=1.4, scale=.135) fmap = {f.name: f for f in record.fragments} for match in record.matches: match_key = match.match_key.split(":")[0] order = len(match_key.split("-")) if order == 1: dtree.draw_cleavage(ax=ax, fragment=fmap[match_key], color='red', label=True) else: for key in match_key.split("-"): dtree.draw_cleavage(fragment=fmap[key], ax=ax, color='orange', label=True) ax.axis('off') fig = ax.get_figure() fig.tight_layout(pad=0.2) img_buffer = StringIO() fig.savefig(img_buffer, format="svg") plt.close(fig) root, ids = ET.XMLID(img_buffer.getvalue()) root.set("id", dtree.uuid) svg = ET.tostring(root) record.report_data["svg_plot"] = base64.encodestring(svg) record.update() return svg
def test_strip_derivatize(self): glycan = load("common_glycan") glycan.reducing_end = ReducedEnd() mass = glycan.mass() composition_transform.derivatize(glycan, 'methyl') self.assertNotEqual(mass, glycan.mass()) composition_transform.strip_derivatization(glycan) self.assertAlmostEqual(glycan.mass(), mass, 3)
def is_dhex(residue): try: return is_a( strip_derivatization(residue.clone( monosaccharide_type=MonosaccharideResidue)), dhex) except TypeError: if not isinstance(residue, MonosaccharideResidue): return False else: raise
def is_dhex(residue): try: return is_a( strip_derivatization( residue.clone(monosaccharide_type=MonosaccharideResidue)), dhex) except TypeError: if not isinstance(residue, MonosaccharideResidue): return False else: raise
def from_monosaccharide(cls, monosaccharide, configuration=False, stem=True, ring=False): """Construct an instance of :class:`MonosaccharideResidue` from an instance of |Monosaccharide|. This function attempts to preserve derivatization if possible. This function will create a *deep copy* of `monosaccharide`. Parameters ---------- monosaccharide : Monosaccharide The monosaccharide to be converted configuration : bool, optional Whether or not to preserve |Configuration|. Defaults to |False| stem : bool, optional Whether or not to preserve |Stem|. Defaults to |True| ring : bool, optional Whether or not to preserve |RingType|. Defaults to |False| Returns ------- MonosaccharideResidue """ residue = monosaccharide.clone(monosaccharide_type=cls) premass = residue.mass() deriv = has_derivatization(monosaccharide) strip_derivatization(residue) if _resolve_special_base_type(monosaccharide) is None: if not configuration: residue.configuration = (Configuration.x,) if not stem: residue.stem = (Stem.x,) if not ring: residue.ring_start = residue.ring_end = None if deriv: derivatize(residue, deriv) if residue.mass() != premass and not deriv: residue.composition += water_composition return residue
def normalize_key(composition): key_obj = composition.clone() key_obj = composition_transform.strip_derivatization(key_obj) return str(key_obj)
def strip_derivatize_glycoct(record): s = record.structure.clone() composition_transform.strip_derivatization(s) return(str(s))