Glycan Composition

GlycanComposition, MonosaccharideResidue, and SubstituentResidue are useful for working with bag-of-residues where topology and connections are not relevant, but the aggregate composition is known. These types work with a subset of the IUPAC three letter code for specifying compositions.

A Monosaccharide is meant to be able to precisely describe where all of the bonds from the carbon backbone are. A MonosaccharideResidue abstracts away the notion of position, and automatically deduct a water molecule from their composition to account for a single incoming and a single outgoing glycosidic bond. Because they do not try to completely describe the physical configuration of the molecule, MonosaccharideResidue removes information about ring type, anomericty, configuration, and optionally stem type. The level of detail discarded is customizable in the MonosaccharideResidue.from_monosaccahride() class method.

A GlycanComposition is just a bag of MonosaccharideResidue and SubstituentResidue, similar to Composition. Its keys may be either MonosaccharideResidue instances, SubstituentResidue instances or strings which can be parsed by from_iupac_lite(), and its values are integers. They may also be written to and from a string using GlycanComposition.serialize() and GlycanComposition.parse().

>>> g = GlycanComposition(Hex=3, HexNAc=2)
>>> g["Hex"]
3
>>> r = MonosaccharideResidue.from_iupac_lite("Hex")
>>> r
MonosaccharideResidue(Hex)
>>> g[r]
3
>>> import glypy
>>> abs(g.mass() - glypy.motifs["N-Glycan core basic 1"].mass()) < 1e-5
True
>>> g2 = GlycanComposition(Hex=5)
>>> g["@n-acetyl"] = -2 # Remove two n-acetyl groups from the composition
>>> abs(g.mass() - g2.mass()) < 1e-5
True
class glypy.composition.glycan_composition.GlycanComposition(*args, **kwargs)[source]

Bases: dict, glypy.structure.base.SaccharideCollection

Describe a glycan as a collection of MonosaccharideResidue counts without explicit linkage information relating how each monosaccharide is connected to its neighbors.

This class subclasses dict, and assumes that keys will either be MonosaccharideResidue instances, SubstituentResidue instances, or strings in iupac_lite format which will be parsed into one of these types. While other types may be used, this is not recommended. All standard dict methods are supported.

|GlycanComposition| objects may be derivatized just as Glycan objects are, with glypy.composition.composition_transform.derivatize() and glypy.composition.composition_transform.strip_derivatization().

GlycanComposition objects also support composition arithmetic, and can be added or subtracted from each other or multiplied by an integer.

As GlycanComposition is not a complete structure, they cannot be translated into text formats as full Glycan objects are. They may instead be converted to and from a short-form text notation using GlycanComposition.serialize() and reconstructed from this format using GlycanComposition.parse().

Attributes

reducing_end (|ReducingEnd|) Describe the reducing end of the aggregate without binding it to a specific monosaccharide. This will contribute to composition and mass calculations.
_composition_offset: Composition Account for the one water molecule’s worth of composition left over from applying the “residue” transformation to each monosaccharide in the aggregate.
__getitem__(key)[source]

Get the quantity of key

If key is a string, it will be passed through from_iupac_lite()

If key has a reducing end value, that reducing end will be set on self

Parameters:

key : str, MonosaccharideResidue, SubstituentResidue, or MolecularComposition

The entity to store

Returns:

int

__setitem__(key, value)[source]

Set the quantity of key to value

If key is a string, it will be passed through from_iupac_lite()

If key has a reducing end value, that reducing end will be set on self

Parameters:

key : str, MonosaccharideResidue, SubstituentResidue, or MolecularComposition

The entity to store

value : int

The value to store

collapse()[source]

Merge redundant keys.

After performing a structure-detail removing operation like drop_positions(), drop_configurations(), or drop_stems(), monosaccharide keys may be redundant.

collapse will merge keys which refer to the same type of molecule.

classmethod from_glycan(glycan)[source]

Convert a Glycan into a |GlycanComposition|.

Parameters:

glycan : Glycan

The instance to be converted

Returns:

GlycanComposition

class glypy.composition.glycan_composition.MonosaccharideResidue(*args, **kwargs)[source]

Bases: glypy.structure.monosaccharide.Monosaccharide

__eq__(other)[source]

Test for equality between MonosaccharideResidue instances by comparing the result of MonosaccharideResidue.name() calls between self and other.

MonosaccharideResidue.name() is an alias of to_iupac_lite() called on self

__hash__()[source]

Obtain a hash value from self based on MonosaccharideResidue.name().

Returns:int
classmethod from_monosaccharide(monosaccharide, configuration=False, stem=True, ring=False)[source]

Construct an instance of 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

class glypy.composition.glycan_composition.SubstituentResidue(name, composition=None, id=None, links=None, can_nh_derivatize=None, is_nh_derivatizable=None, derivatize=False, attachment_composition=None)[source]

Bases: glypy.structure.substituent.Substituent

Represent substituent molecules unassociated with a specific monosaccharide residue.

Note

SubstituentResidue‘s composition value includes the losses for forming a bond between a monosaccharide residue and the substituent.

Attributes

name: str As in Substituent, but with SubstituentResidue.sigil prepended.
composition: Composition  
links: OrderedMultiMap  
_order: int  
__hash__()[source]

Obtain a hash value from self based on name.

Returns:int
sigil = '@'

All substituent string identifiers are prefixed with this character for the from_iupac_lite() parser

glypy.composition.glycan_composition.to_iupac_lite()
glypy.composition.glycan_composition.from_iupac_lite()
glypy.composition.glycan_composition.from_glycan(cls, glycan)

Convert a Glycan into a |GlycanComposition|.

Parameters:

glycan : Glycan

The instance to be converted

Returns:

GlycanComposition

glypy.composition.glycan_composition.parse(cls, string)