Beispiel #1
0
 def from_glycan(cls, glycan):
     inst = cls()
     glycan = tree(glycan)
     inst.extend(glycan)
     inst.reducing_end = glycan.reducing_end
     deriv = has_derivatization(glycan.root)
     if deriv:
         inst._composition_offset += (
             deriv.total_composition() - deriv.attachment_composition_loss()) * 2
     return inst
 def _handle_reduction_and_derivatization(self, reduced):
     if reduced:
         reduced = ReducedEnd(Composition(reduced))
         self.reducing_end = reduced
     deriv = None
     for key in self:
         deriv = has_derivatization(key)
         if deriv:
             break
     if deriv:
         # strip_derivatization(self)
         # derivatize(self, deriv)
         self._derivatized(deriv.clone(), make_counter(uid()), include_reducing_end=False)
 def _format_map(mapping):
     store = dict()
     for key, value in dict(mapping).items():
         if isinstance(key, SymbolNode):
             key = key.symbol
         elif isinstance(key, (str, _MR)):
             text_key = str(key)
             key = _FMR.from_iupac_lite(text_key)
             is_derivatized = composition_transform.has_derivatization(key)
             if is_derivatized:
                 key = str(glycan_composition.from_iupac_lite.strip_derivatization(text_key))
             else:
                 key = text_key
         store[key] = value
     return store
 def _format_map(mapping):
     store = dict()
     for key, value in dict(mapping).items():
         if isinstance(key, SymbolNode):
             key = key.symbol
         elif isinstance(key, (str, _MR)):
             text_key = str(key)
             key = _FMR.from_iupac_lite(text_key)
             is_derivatized = composition_transform.has_derivatization(key)
             if is_derivatized:
                 key = str(
                     glycan_composition.from_iupac_lite.
                     strip_derivatization(text_key))
             else:
                 key = text_key
         store[key] = value
     return store
    def monosaccharide_to_iupac(self, residue):
        """
        Encode a subset of traits of a :class:`Monosaccharide`-like object
        using a limited subset of the IUPAC three letter code. The information
        present is sufficient to reconstruct a :class:`MonosaccharideResidue` instance
        reflecting the base type and its native substituents and modificats.
        .. note::
            This function is not suitable for use on whole |Glycan| objects. Instead,
            see :meth:`GlycanComposition.from_glycan` and :meth:`GlycanComposition.serialize`

        Parameters
        ----------
        residue: Monosaccharide
            The object to be encoded

        Returns
        -------
        str

        See Also
        --------
        :func:`from_iupac_lite`
        """
        template = "{modification}{base_type}{substituent}"
        modification = ""
        base_type = self.resolve_special_base_type(residue)
        if base_type is None:
            if len(residue.stem) == 1 and residue.stem[0] is not Stem.Unknown:
                base_type = residue.stem[0].name.title()
            else:
                base_type = residue.superclass.name.title()
        modification = self.modification_extractor(residue.modifications, base_type)
        substituent = self.substituent_resolver(residue)
        string = template.format(
            modification=modification,
            base_type=base_type,
            substituent=substituent
        )

        deriv = has_derivatization(residue)
        if deriv:
            string = "%s^%s" % (string, self.substituent_resolver.serialize_substituent(deriv))
        return string
    def from_glycan(cls, glycan):
        """
        Convert a |Glycan| into a |GlycanComposition|.

        Parameters
        ----------
        glycan : Glycan
            The instance to be converted

        Returns
        -------
        GlycanComposition
        """
        inst = cls()
        glycan = tree(glycan)
        inst.extend(glycan)
        inst.reducing_end = glycan.reducing_end
        deriv = has_derivatization(glycan.root)
        if deriv:
            inst._composition_offset += (
                deriv.total_composition() - deriv.attachment_composition_loss()) * 2
        return inst
    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
Beispiel #8
0
 def monosaccharide_to_iupac(self, residue):
     string = super(DerivatizationAwareMonosaccharideSerializer, self).monosaccharide_to_iupac(residue)
     deriv = has_derivatization(residue)
     if deriv:
         string = "%s^%s" % (string, self.substituent_resolver.serialize_substituent(deriv))
     return string