Ejemplo n.º 1
0
    def test_link_site_no_overlap(self):

        ambig = '''
                RES
                1b:x-dglc-HEX-x:x
                2s:n-acetyl
                3b:b-dglc-HEX-1:5
                4s:n-acetyl
                5b:b-dman-HEX-1:5
                6b:a-dman-HEX-1:5
                7b:b-dglc-HEX-1:5
                8s:n-acetyl
                9b:b-dgal-HEX-1:5
                10b:a-dman-HEX-1:5
                11b:a-dman-HEX-1:5
                LIN
                1:1d(2+1)2n
                2:1o(4+1)3d
                3:3d(2+1)4n
                4:3o(4+1)5d
                5:5o(3|6+1)6d
                6:6o(2+1)7d
                7:7d(2+1)8n
                8:7o(4+1)9d
                9:5o(3|6+1)10d
                10:10o(3|6+1)11d
                '''
        exact = '''
                RES
                1b:x-dglc-HEX-1:5
                2s:n-acetyl
                3b:b-dglc-HEX-1:5
                4s:n-acetyl
                5b:b-dman-HEX-1:5
                6b:a-dman-HEX-1:5
                7b:b-dglc-HEX-1:5
                8s:n-acetyl
                9b:a-dman-HEX-1:5
                10b:a-dman-HEX-1:5
                11b:a-dman-HEX-1:5
                LIN
                1:1d(2+1)2n
                2:1o(4+1)3d
                3:3d(2+1)4n
                4:3o(4+1)5d
                5:5o(3+1)6d
                6:6o(2+1)7d
                7:7d(2+1)8n
                8:5o(6+1)9d
                9:9o(3+1)10d
                10:9o(6+1)11d
                '''
        ambig = glycoct.loads(ambig)
        exact = glycoct.loads(exact)
        ambig.set_reducing_end(True)
        exact.set_reducing_end(True)
        self.assertEqual(ambig.total_composition(), exact.total_composition())
        self.assertEqual(ambig, ambig.clone())
        self.assertEqual(derivatize(ambig.clone(), 'methyl').total_composition(),
                         derivatize(exact.clone(), 'methyl').total_composition())
Ejemplo n.º 2
0
 def apply_derivatization(self, residue, deriv):
     if deriv.startswith("^"):
         deriv = deriv[1:]
         deriv = self.substituent_parser.symbol_to_name(deriv)
         derivatize(residue, deriv)
     else:
         raise IUPACError("Derivatization Extension Must Start with '^'")
Ejemplo n.º 3
0
 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 test_parse_derivatized(self):
     glyc = glycans["N-Linked Core"]
     composition_transform.derivatize(glyc, "methyl")
     comp = GlycanComposition.from_glycan(glycans["N-Linked Core"])
     composition_transform.derivatize(comp, "methyl")
     self.assertAlmostEqual(glyc.mass(), comp.mass(), 3)
     frozen_comp = self.GlycanCompositionType.parse(comp)
     self.assertAlmostEqual(glyc.mass(), frozen_comp.mass(), 3)
Ejemplo n.º 5
0
    def test_derivatize(self):
        glyc = glycans["N-Linked Core"]
        composition_transform.derivatize(glyc, "methyl")
        comp = GlycanComposition.from_glycan(glyc)
        self.assertAlmostEqual(glyc.mass(), comp.mass(), 3)

        comp = GlycanComposition.from_glycan(glycans["N-Linked Core"])
        composition_transform.derivatize(comp, "methyl")
        self.assertAlmostEqual(glyc.mass(), comp.mass(), 3)
    def test_derivatize(self):
        glyc = glycans["N-Linked Core"]
        with self.assertRaises(glycan_composition.FrozenError):
            composition_transform.derivatize(glyc, "methyl")
            comp = self.GlycanCompositionType.from_glycan(glyc)
            self.assertAlmostEqual(glyc.mass(), comp.mass(), 3)

            comp = self.GlycanCompositionType.from_glycan(glycans["N-Linked Core"])
            composition_transform.derivatize(comp, "methyl")
            self.assertAlmostEqual(glyc.mass(), comp.mass(), 3)
            self.assertAlmostEqual(self.GlycanCompositionType.parse(comp).mass(), comp.mass(), 3)
Ejemplo n.º 7
0
 def test_validate_reducing_end(self):
     structure = named_structures.monosaccharides['Hex']
     composition = structure.total_composition()
     structure.reducing_end = ReducedEnd()
     self.assertEqual(structure.total_composition(), composition + Composition("H2"))
     structure.reducing_end = True
     self.assertEqual(structure.total_composition(), composition + Composition("H2"))
     self.assertEqual(structure.total_composition(), structure.clone().total_composition())
     self.assertEqual(structure.total_composition(), pickle.loads(pickle.dumps(structure)).total_composition())
     structure.reducing_end = None
     self.assertEqual(structure.total_composition(), composition)
     structure.reducing_end = True
     composition_transform.derivatize(structure, "methyl")
     self.assertEqual(structure.mass(), structure.clone().mass())
Ejemplo n.º 8
0
 def _process_composition(self):
     gc, structure_classes = next(self.glycan_source)
     if self.reduction is not None and gc.reducing_end is None:
         gc.reducing_end = self.reduction.clone()
     if self.derivatization is not None:
         gc = composition_transform.derivatize(gc, self.derivatization)
     return gc, structure_classes
Ejemplo n.º 9
0
 def _process_composition(self):
     gc, structure_classes = next(self.glycan_source)
     if self.reduction is not None and gc.reducing_end is None:
         gc.reducing_end = self.reduction.clone()
     if self.derivatization is not None:
         gc = composition_transform.derivatize(gc, self.derivatization)
     return gc, structure_classes
Ejemplo n.º 10
0
 def test_derivatized_glycan_parse(self):
     ref = composition_transform.derivatize(
         glypy.motifs["N-Glycan complex 1"], "methyl")
     serializer = iupac.GlycanSerializer(iupac.DerivatizationAwareMonosaccharideSerializer())
     text = serializer(ref)
     deserializer = iupac.GlycanDeserializer(iupac.DerivatizationAwareMonosaccharideDeserializer())
     obj = deserializer(text)
     self.assertEqual(obj, ref)
    def test_normalize_glycan_composition(self):
        base = glycan_composition.GlycanComposition.parse("{Hex:6; HexNAc:5; Neu5Ac:3}")
        deriv = composition_transform.derivatize(
            glycan_composition.GlycanComposition.parse(
                "{Hex:6; HexNAc:5; Neu5Ac:3}"), "methyl")

        normd_symbol = symbolic_expression.GlycanSymbolContext(deriv)
        normd_composition = glycan_composition.GlycanComposition.parse(normd_symbol.serialize())

        self.assertEqual(base, normd_composition)
Ejemplo n.º 12
0
    def test_normalize_glycan_composition(self):
        base = glycan_composition.GlycanComposition.parse(
            "{Hex:6; HexNAc:5; Neu5Ac:3}")
        deriv = composition_transform.derivatize(
            glycan_composition.GlycanComposition.parse(
                "{Hex:6; HexNAc:5; Neu5Ac:3}"), "methyl")

        normd_symbol = symbolic_expression.GlycanSymbolContext(deriv)
        normd_composition = glycan_composition.GlycanComposition.parse(
            normd_symbol.serialize())

        self.assertEqual(base, normd_composition)
Ejemplo n.º 13
0
    def test_derivatize(self):
        reference = {"GlcNAc": 245.1263, "Fuc": 174.0892, "NeuAc": 361.1737}
        for name in ["GlcNAc", "NeuAc", "Fuc"]:
            base = monosaccharides[name]
            residue = glycan_composition.MonosaccharideResidue.from_monosaccharide(base)
            composition_transform.derivatize(base, "methyl")
            composition_transform.derivatize(residue, "methyl")
            self.assertAlmostEqual(
                base.mass() - (water_mass + 2 * (Substituent("methyl").mass() - glypy.Composition("H").mass * 2)),
                residue.mass(),
                3,
            )
            self.assertAlmostEqual(reference[name], residue.mass(), 3)

            base = monosaccharides[name]
            composition_transform.derivatize(base, "methyl")
            residue = glycan_composition.MonosaccharideResidue.from_monosaccharide(base)

            self.assertAlmostEqual(
                base.mass() - (water_mass + 2 * (Substituent("methyl").mass() - glypy.Composition("H").mass * 2)),
                residue.mass(),
                3,
            )

            self.assertAlmostEqual(reference[name], residue.mass(), 3)
    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
Ejemplo n.º 15
0
 def test_monosacchide_crossring(self):
     test_cases = [
         'Glc',
         "GlcNAc",
         "Xyl",
         'GalA',
         'Fuc',
         'IdoA',
         "KDN"
     ]
     store = self.load_all()
     for case in test_cases:
         test = store[case]
         target = monosaccharides[case]
         for k, v in test.items():
             target_d = {t.kind: t for t in crossring_fragments.crossring_fragments(target, k[0], k[1])}
             target_d_permethylated = {t.kind: t for t in crossring_fragments.crossring_fragments(
                 composition_transform.derivatize(target.clone(), "methyl"), k[0], k[1])}
             for kind in {"A", "X"}:
                 self.assertAlmostEqual(v[kind].mass, target_d[kind].mass(), 3)
                 self.assertAlmostEqual(v[kind].permethylated_mass, target_d_permethylated[kind].mass(), 3)
 def test_is_derivatized(self):
     broad = load("broad_n_glycan")
     self.assertFalse(similarity.is_derivatized(broad.root))
     composition_transform.derivatize(broad, 'methyl')
     self.assertTrue(similarity.is_derivatized(broad.root))
Ejemplo n.º 17
0
 def test_monosaccharide_serialize(self):
     obj = composition_transform.derivatize(glypy.monosaccharides.HexNAc, 'methyl')
     ref = '?-?-Hexp2NAc^Me'
     serializer = iupac.DerivatizationAwareMonosaccharideSerializer()
     text = serializer(obj)
     self.assertEqual(text, ref)
Ejemplo n.º 18
0
def derivatized_mass(row, derivative):
    return composition_transform.derivatize(row.structure, derivative).mass()
Ejemplo n.º 19
0
 def test_derivatize_bare(self):
     permethylated_reduced_mass = 1716.9033
     glycan = load("common_glycan")
     glycan.reducing_end = ReducedEnd()
     composition_transform.derivatize(glycan, 'methyl')
     self.assertAlmostEqual(glycan.mass(), permethylated_reduced_mass, 3)
Ejemplo n.º 20
0
 def test_monosaccharide_parse(self):
     text = '?-?-Hexp2NAc^Me'
     parser = iupac.DerivatizationAwareMonosaccharideDeserializer()
     obj, _ = parser(text)
     ref = composition_transform.derivatize(glypy.monosaccharides.HexNAc, 'methyl')
     self.assertEqual(obj, ref)
def derivatize(glycan_obj, derivatization_kind):
    if derivatization_kind is not None:
        composition_transform.derivatize(glycan_obj, derivatization_type[derivatization_kind])