GlycoCT

A GlycoCT (Condensed) parser. Supports RES, LIN, and un-nested REP sections.

>>>from glypy.io import glycoct
>>>glycoct.loads("""RES
1b:o-dman-HEX-0:0|1:aldi
2b:a-lido-HEX-1:5|6:a
3s:sulfate
LIN
1:1o(3+1)2d
2:2o(2+1)3n
3:2o(4+1)4d
""")
>>>
glypy.io.glycoct.GlycoCT

alias of GlycoCTReader

class glypy.io.glycoct.GlycoCTReader(stream, structure_class=<class 'glypy.structure.glycan.Glycan'>, allow_repeats=True)[source]

Bases: object

Simple State-Machine parser for condensed GlycoCT representations. Yields Glycan instances.

__init__(stream, structure_class=<class 'glypy.structure.glycan.Glycan'>, allow_repeats=True)[source]

Creates a parser of condensed GlycoCT.

Parameters:

stream: basestring or file-like

A path to a file or a file-like object to be processed

__iter__()[source]

Calls parse() and stores it for reuse with __next__()

__next__()

Alias for next. Supports Py3 Iterator interface

handle_linkage(line)[source]

Handle a linkage line, creates an instance of Link and attaches it to the two referenced nodes in graph. The parent node is always an instance of Monosaccharide, and the child node may either be an instance of Monosaccharide or Substituent or Monosaccharide.

Called by parse()

See also Link for more information on the impact of instantiating a Link object.

handle_residue_line(line)[source]

Handle a base line, creates an instance of Monosaccharide and adds it to graph at the given index.

Called by parse()

handle_residue_substituent(line)[source]

Handle a substituent line, creates an instance of Substituent and adds it to graph at the given index. The Substituent object is not yet linked to a Monosaccharide instance.

Called by parse()

classmethod loads(glycoct_str, structure_class=<class 'glypy.structure.glycan.Glycan'>, allow_repeats=True)[source]

Parse results from str

next()[source]

Calls parse() if the internal iterator has not been instantiated

parse()[source]

Returns an iterator that yields each complete Glycan instance from the underlying text stream.

postprocess()[source]

Handle all deferred operations such as binding together and expanding repeating units. Removes any distinguishing markers on node ids, and constructs a new instance of structure_class from the accumulated graph

Returns:Glycan
class glypy.io.glycoct.StructurePrecisionEnum[source]

Bases: glypy.utils.enum.Enum

EnumType

glypy.io.glycoct.conf_stem_pattern = <_sre.SRE_Pattern object at 0x00000000082D37B0>

Pattern for parsing the potentially repeated Configuration and Stem regions of the lines of the RES section.

glypy.io.glycoct.decorate_tree(tree, decorate_value)[source]

Transform each node in the tree’s id value into a tuple of (decorate_value, node.id) to use common ids across identical graphs but discriminable between attached copies.

Parameters:

tree: Glycan

decorate_value: int

Returns:

Glycan

glypy.io.glycoct.decorated_value(tree)[source]

Get the decorating value from a tree’s root node.id.

Returns None if the tree is undecorated

Parameters:tree: Glycan
Returns:int or None
glypy.io.glycoct.dump(structure, buffer=None)[source]

Serialize the Glycan graph object into condensed GlycoCT, using buffer to store the result. If buffer is None, then the function will operate on a newly created StringIO object.

Parameters:

structure: |Glycan|

The structure to serialize

buffer: file-like or None

The stream to write the serialized structure to. If None, uses an instance of StringIO

Returns:

file-like or str if buffer is None

glypy.io.glycoct.get_decorated(tree, id)[source]

As Glycan.get(), but with awareness of decorated node.id attributes. Will fall back to the normal get method if the tree is undecorated.

Parameters:

tree: Glycan

id: int

Returns:

Monosaccharide

Special truncation of the link_pattern which is used on REP header sections

Pattern for parsing Link lines found in the LIN section

glypy.io.glycoct.loads(glycoct_str, structure_class=<class 'glypy.structure.glycan.Glycan'>, allow_repeats=True)[source]

A convenience wrapper for GlycoCTReader.loads()

As additional convenience, this function does not return an iterator over glycans, and returns a single instance if only one is present, or a list of instances otherwise.

glypy.io.glycoct.modification_pattern = <_sre.SRE_Pattern object at 0x000000000829BE10>

Pattern for parsing modifications found on monosaccharide residue lines in the RES section

glypy.io.glycoct.read(stream, structure_class=<class 'glypy.structure.glycan.Glycan'>, allow_repeats=True)[source]

A convenience wrapper for GlycoCTReader

glypy.io.glycoct.rep_header_pattern = <_sre.SRE_Pattern object>

Pattern for interpreting the REP# instance header section

glypy.io.glycoct.res_pattern = <_sre.SRE_Pattern object at 0x000000000613F470>

Pattern for parsing the lines of the RES section corresponding to individual Monosaccharide residues

glypy.io.glycoct.undecorate_tree(tree)[source]

Remove decoration from a tree and reindex its nodes.

Depends upon Glycan.index to find nodes

Parameters:tree: Glycan
Returns:Glycan