Glycan

Represent polysaccharide molecules and their associated functions

Represent a sugar graph with pseudo-directed edges.

glypy.structure.glycan.fragment_to_substructure(fragment, tree)[source]

Extract the substructure of tree which is contained in fragment

>>> from glypy import glycans as glycan_factory
>>> from glypy.structure import glycan
>>> n_linked_core = glycan_factory["N-Linked Core"]
>>> frag = n_linked_core.fragments().next()
>>> frag
<Fragment  mass=221.089937203 kind=Y included_nodes=set([1]) link_ids={1: ('', 'Y')} name=Y1 crossring_cleavages={} score=0.0 composition=Composition({'H': 15, 'C': 8, 'O': 6, 'N': 1})>
>>> glycan.fragment_to_substructure(frag, n_linked_core)
RES
1b:b-dglc-HEX-1:5
2s:n-acetyl
LIN
1:1d(2+1)2n

>>>
Parameters:

fragment: Fragment

The Fragment to extract substructure for.

tree: Glycan

The Glycan to extract substructure from.

Returns:

Glycan:

The Glycan substructure defined by the nodes contained in fragment as found in tree

class glypy.structure.glycan.Glycan(root=None, index_method='dfs')[source]

Bases: glypy.structure.base.SaccharideCollection

Represents a full graph of connected Monosaccharide objects and their connecting bonds.

Attributes

root: Monosaccharide The first monosaccharide unit of the glycan, and the reducing end if present.
index: list A list of the Monosaccharide instances in self in the order they are encountered by traversal by traversal_methods[index_method]
link_index: list A list of the Link connecting the Monosaccharide instances in self in the order they are encountered by traversal by traversal_methods[index_method]
reducing_end: ReducedEnd or None The reducing end on root.
branch_lengths: dict A dictionary mapping branch symbols to their lengths
__eq__(other)[source]

Two glycans are considered equal if they are identically ordered nodes.

Parameters:self, other: :class:`~glypy.structure.glycan.Glycan`
Returns:bool

See also

glypy.structure.Monosaccharide.exact_ordering_equality()

__getitem__(ix)[source]

Alias for index.__getitem__

__init__(root=None, index_method='dfs')[source]

Constructs a new Glycan from the collection of connected Monosaccharide objects rooted at root.

If index_method is not None, the graph is indexed by the default search method given by traversal_methods[index_method]

__len__()

The number of nodes in the graph. __len__() is an alias of this

Returns:int
breadth_first_traversal(from_node=None, apply_fn=<function identity at 0x00000000081CCE48>, visited=None)[source]

Make a breadth-first traversal of the glycan graph. Children are explored in descending bond-order.

bfs() is an alias of this method. Both names can be used to specify this strategy to _get_traversal_method().

Parameters:

from_node: None or Monosaccharide

If from_node is None, then traversal starts from the root node. Otherwise it begins from the given node.

apply_fn: function

A function applied to each node on arrival. If this function returns a non-None value, the result is yielded from the generator, otherwise it is ignored. Defaults to identity()

visited: set or None

A set of node ID values to ignore. If None, defaults to the empty set

Yields:

Return Value of apply_fn, by default Monosaccharide

Iteratively generate all subtrees from glycosidic bond cleavages, creating all \(2{L \choose n}\) subtrees.

Parameters:

n_links : int

Number of links to break simultaneously

Yields:

Subtree

clone(index_method='dfs', visited=None, cls=None)[source]

Create a copy of self, indexed using index_method, a traversal method or None.

Returns:Glycan
count_branches()[source]

Count the number of branches in the Glycan tree

Returns:int
crossring_subtrees(n_links)[source]

Generate all combinations of cross ring fragments and glycosidic cleavages, cleaving between 1 and n_links monosaccharides paired with n_links - 1 to 0 glycosidic cleavages.

Parameters:

n_links : int

Total number of breaks to create, between cross ring cleavages and complemenatary glycosidic cleavages.

Yields:

Subtree

deindex()[source]

When combining two Glycan structures, very often their component ids will overlap, making it impossible to differentiate between a cycle and the new graph. This function mangles all of the node and link ids so that they are distinct from the pre-existing nodes.

depth_first_traversal(from_node=None, apply_fn=<function identity at 0x00000000081CCE48>, visited=None)[source]

Make a depth-first traversal of the glycan graph. Children are explored in descending bond-order.

This is the default traversal method for all Glycan objects. dfs() is an alias of this method. Both names can be used to specify this strategy to _get_traversal_method().

Parameters:

from_node: None or Monosaccharide

If from_node is None, then traversal starts from the root node. Otherwise it begins from the given node.

apply_fn: function

A function applied to each node on arrival. If this function returns a non-None value, the result is yielded from the generator, otherwise it is ignored. Defaults to identity()

visited: set or None

A set of node ID values to ignore. If None, defaults to the empty set

Yields:

Return Value of apply_fn, by default Monosaccharide

exact_ordering_equality(other)

Two glycans are considered equal if they are identically ordered nodes.

Parameters:self, other: :class:`~glypy.structure.glycan.Glycan`
Returns:bool

See also

glypy.structure.Monosaccharide.exact_ordering_equality()

fragments(kind='BY', max_cleavages=1, average=False, charge=0, mass_data=None, traversal_method='dfs')[source]

Generate carbohydrate backbone fragments from this glycan by examining the disjoint subtrees created by removing one or more monosaccharide-monosaccharide bond.

Parameters:

kind: `sequence`

Any iterable or sequence of characters corresponding to A/B/C/X/Y/Z as published by Domon and Costello

max_cleavages: |int|

The maximum number of bonds to break per fragment

average: bool, optional, defaults to `False`

Whether or not to use the average isotopic composition when calculating masses. When average == False, masses are calculated using monoisotopic mass.

charge: int, optional, defaults to 0

If charge is non-zero, m/z is calculated, where m is the theoretical mass, and z is charge

mass_data: dict, optional, defaults to `None`

If mass_data is None, standard NIST mass and isotopic abundance data are used. Otherwise the contents of mass_data are assumed to contain elemental mass and isotopic abundance information.

Yields:

Fragment

Iterates over all Link objects in Glycan.

Parameters:

substituents: bool

If substituents is True, then include the Link objects in substituent_links on each Monosaccharide

method: str or function

The traversal method controlling the order of the nodes visited

visited: None or set

The collection of id values to ignore when traversing

Yields:

Link

iternodes(from_node=None, apply_fn=<function identity at 0x00000000081CCE48>, method='dfs', visited=None)[source]

Generic iterator over nodes. Glycan.__iter__() is an alias of this method

Parameters:

from_node: None or Monosaccharide

If from_node is None, then traversal starts from the root node. Otherwise it begins from the given node.

apply_fn: function

A function applied to each node on arrival. If this function returns a non-None value, the result is yielded from the generator, otherwise it is ignored. Defaults to identity()

method: str or `function`

Traversal method to use. See _get_traversal_method()

visited: set or None

A set of node ID values to ignore. If None, defaults to the empty set

Yields:

Return Value of apply_fn, by default Monosaccharide

See also

depth_first_traversal, breadth_first_traversal, _get_traversal_method

label_branches()[source]

Labels each branch point with an alphabetical symbol. Also computes and stores each branch’s length and stores it in branch_lengths. Sets branch_lengths of self and Link.label for each link attached to self.

leaves(bidirectional=False, method='dfs', visited=None)[source]

Iterates over all Monosaccharide objects in Glycan, yielding only those that have no child nodes.

Parameters:

bidirectional: bool

If bidirectional is True, then only Monosaccharide objects with only one entry in links.

method: str or function

The traversal method controlling the order of the nodes visited

visited: None or set

The collection of id values to ignore when traversing

Yields:

Monosaccharide

mass(average=False, charge=0, mass_data=None, method='dfs')[source]

Calculates the total mass of the intact graph by querying each node for its mass.

Parameters:

average: bool

Whether or not to use the average isotopic composition when calculating masses. When average == False, masses are calculated using monoisotopic mass.

charge: int

If charge is non-zero, m/z is calculated, where m is the theoretical mass, and z is charge

mass_data: dict

If mass_data is None, standard NIST mass and isotopic abundance data are used. Otherwise the contents of mass_data are assumed to contain elemental mass and isotopic abundance information.

Returns:

float

name_fragment(fragment)[source]

Attempt to assign a full name to a fragment based on the branch and position relative to the reducing end along side A/B/C/X/Y/Z, according to Domon and Costello

order()[source]

The number of nodes in the graph. __len__() is an alias of this

Returns:int
reducing_end

An alias for Monosaccharide.reducing_end for root

reindex(method='dfs')[source]

Traverse the graph using the function specified by method. The order of traversal defines the new id value for each Monosaccharide and Link.

The order of traversal also defines the ordering of the Monosaccharide in index and Link in link_index.

reroot(index_method='dfs')[source]

Set root to the node with the lowest id

set_reducing_end(value)[source]

Sets the reducing end type, and configures the root residue appropriately.

If the reducing_end is not None, then the following state changes are made to the root:

self.root.ring_start = 0
self.root.ring_end = 0
self.root.anomer = "uncyclized"

Else, the correct state is unknown:

self.root.ring_start = None
self.root.ring_end = None
self.root.anomer = None
substructures(max_cleavages=1, min_cleavages=1, inplace=False)[source]

Generate disjoint subtrees from this glycan by examining by removing one or more monosaccharide-monosaccharide bond.

Parameters:

max_cleavages: |int|

The maximum number of bonds to break per substructure

min_cleavages: |int|

The minimum number of bonds to break per substructure

min_size: |int|

The minimum number of monosaccharides per substructure

subtrees(max_cleavages=1, include_crossring=False)[source]

Generate subtrees from this tree by breaking max_cleavages bonds or rings.

Parameters:

max_cleavages: int

The maximum number of bonds to break per fragment

include_crossring: bool

Whether to include cross ring cleavages

Yields:

Subtree

topological_equality(other)[source]

Two glycans are considered equal if they are topologically equal.

Parameters:

self: :class:`Glycan`

other: :class:`Glycan`

Returns:

bool

See also

glypy.structure.Monosaccharide.topological_equality()

total_composition(method='dfs')[source]

Computes the sum of the composition of all Monosaccharide objects in self

Returns:Composition