The utils package#
These are utility functions that are used for some glycan specific tasks.
The iupac module#
Functions to work with the IUPAC glycan nomenclature.
- class glycosylator.utils.iupac.IUPACParser[source]#
Bases:
objectA parser for condensed IUPAC glycan nomenclature strings. This class will generate a list of connecting glycan segments from a string from which a Molecule can be built.
- class glycosylator.utils.iupac.IUPACStringMaker[source]#
Bases:
objectThis class generates IUPAC/SNFG strings from a list of glycan molecule.
- beta_alpha_mismatch_pattern = 'b-(\\w+)\\((a)'#
- beta_alpha_mismatch_replacement = '\\1(b'#
- double_beta_pattern = '(b-(\\w+\\(b))'#
- double_beta_replacement = '\\2'#
- terminal_alpha_pattern = '([\\]\\)]\\w+)$'#
- terminal_alpha_replacement = '\\1(a1-'#
- terminal_beta_pattern = 'b-(\\w+)$'#
- terminal_beta_replacement = '\\1(b1-'#
- write_string(glycan: Glycan, add_terminal_conformation: bool = True) str[source]#
Write the IUPAC string for a glycan molecule.
- Parameters:
glycan (Glycan) – The glycan molecule to write the IUPAC string for.
add_terminal_conformation (bool) – If True, adds the terminal conformation as last(a1- or last(b1- to the string.
- Returns:
The IUPAC string for the glycan molecule.
- Return type:
str
- glycosylator.utils.iupac.make_iupac_string(glycan, add_terminal_conformation: bool = True)[source]#
Make an IUPAC/SNFG string from a glycan molecule.
- Parameters:
glycan (Glycan) – The glycan molecule to make the IUPAC string for.
add_terminal_conformation (bool) – If True, adds the terminal conformation as last(a1- or last(b1- to the end of the string.
- Returns:
The IUPAC string for the glycan molecule.
- Return type:
str
- glycosylator.utils.iupac.make_link_id(bond: Bond) str[source]#
Make a link id string in Glycosylator format from a Bond object.
- Parameters:
bond (Bond) – The bond from which to make an id string.
- Returns:
The linkage id string in Glycosylator format.
- Return type:
str
- glycosylator.utils.iupac.make_snfg_string(glycan, add_terminal_conformation: bool = True)#
Make an IUPAC/SNFG string from a glycan molecule.
- Parameters:
glycan (Glycan) – The glycan molecule to make the IUPAC string for.
add_terminal_conformation (bool) – If True, adds the terminal conformation as last(a1- or last(b1- to the end of the string.
- Returns:
The IUPAC string for the glycan molecule.
- Return type:
str
- glycosylator.utils.iupac.parse_iupac(string)[source]#
Parse a string of IUPAC/SNFG glycan nomenclature into a list of glycan segments.
- Parameters:
string (str) – The IUPAC glycan nomenclature string.
- Returns:
A list of tuples where each segment is a tuple of (residue1, residue2, linkage).
- Return type:
list
- glycosylator.utils.iupac.parse_snfg(string)#
Parse a string of IUPAC/SNFG glycan nomenclature into a list of glycan segments.
- Parameters:
string (str) – The IUPAC glycan nomenclature string.
- Returns:
A list of tuples where each segment is a tuple of (residue1, residue2, linkage).
- Return type:
list
The visual module#
Visualizations for glycosylator
- class glycosylator.utils.visual.Canvas[source]#
Bases:
objectA canvas of 2D slots for placing nodes.
- root_nodes#
The root nodes on the canvas.
- Type:
list
- all_nodes#
The nodes on the canvas (not regarding connectivity or hierarchy).
- Type:
list
- add(node: Node, x: int = None, y: int = None)[source]#
Add a node at a specific location on the canvas.
- Parameters:
node (Node) – The node to place.
x (int) – The x coordinate to place the node at.
y (int) – The y coordinate to place the node at.
- flip(horizontal: bool = False, vertical: bool = True)[source]#
Flip the canvas horizontally or vertically.
- Parameters:
horizontal (bool) – Whether to flip the canvas horizontally.
vertical (bool) – Whether to flip the canvas vertically.
- classmethod from_dict(_Canvas__dict)[source]#
Make a canvas from a dictionary.
- Parameters:
__dict (dict) – The dictionary to make the canvas from.
- Returns:
canvas – The canvas made from the dictionary.
- Return type:
- has_node(node_or_id)[source]#
Check if a node is on the canvas.
- Parameters:
node_or_id (Node or str) – The node or id to check for.
- is_free(x: int, y: int) bool[source]#
Check if a slot is free.
- Parameters:
x (int) – The x coordinate of the slot.
y (int) – The y coordinate of the slot.
- Returns:
is_free – Whether the slot is free.
- Return type:
bool
- property leaves: list#
The leaves of the canvas.
- remove(node: Node)[source]#
Remove a node from the canvas.
- Parameters:
node (Node) – The node to remove.
- render(ax, draw_edge_labels: bool = True, pretty_labels: bool = True, small_labels: bool = False, label_kws: dict = None, edge_kws: dict = None, adjust_axes: bool = True)[source]#
Render the canvas on a matplotlib axis. This requires that all nodes have a matplotlib patch associated with them.
- Parameters:
ax (matplotlib.axes.Axes) – The axis to render the canvas on.
draw_edge_labels (bool) – Whether to draw the id labels of the connecting edges.
pretty_labels (bool) – Whether to use the pretty format for the edge labels. Including greek letters and arrows.
small_labels (bool) – Whether to use the small format for the edge labels, without arrows.
label_kws (dict) – The keyword arguments to pass to the edge label drawing function.
edge_kws (dict) – The keyword arguments to pass to matplotlib.patches.ConnectionPatch.
- rotate90(clockwise: bool = True)[source]#
Rotate the canvas 90 degrees.
- Parameters:
clockwise (bool) – Whether to rotate the canvas clockwise.
- property xlim: tuple#
The x limits of the canvas.
- property ylim: tuple#
The y limits of the canvas.
- class glycosylator.utils.visual.GlycanViewer2D(glycan)[source]#
Bases:
objectA 2D scematic viewer for glycan structures
- class glycosylator.utils.visual.Node(id, icon=None)[source]#
Bases:
objectA node in a tree structure.
- Parameters:
id (str) – The id of the node.
icon (np.ndarray) – The icon to represent the node in SNFG format.
- id#
The id of the node.
- Type:
str
- icon#
The icon of the node.
- Type:
np.ndarray
- children#
The children of the node.
- Type:
list
- x#
The x coordinate of the node.
- Type:
int
- y#
The y coordinate of the node.
- Type:
int
- add_child(child: Node, x: int = None, y: int = None)[source]#
Add a child node to this node.
- Parameters:
child (Node) – The child node to add.
x (int) – The x coordinate of the child node.
y (int) – The y coordinate of the child node.
- property depth#
The depth of the node.
- has_valid_placement() bool[source]#
Check if a node has a valid placement on the canvas. Placements are valid if there is no other node at the same position.
- place(canvas: Canvas, x: int, y: int)[source]#
Place this node at (x, y) on the canvas.
- Parameters:
canvas (Canvas) – The canvas to place the node on.
x (int) – The x coordinate of the node.
y (int) – The y coordinate of the node.
- shift_up(dx, dy)[source]#
Shift this node and all parents by dx and dy. This will also affet all siblings and their children.
- property siblings: list#
Sibling nodes that share the same parent.
- class glycosylator.utils.visual.ScaffoldViewer2D(scaffold, bar_color: str = 'xkcd:sandy', bar_height: int = 6, height: float = 20, figsize: tuple = None)[source]#
Bases:
objectA 2D schematic for a protein scaffold
- Parameters:
scaffold (Scaffold) – The protein scaffold to visualize.
bar_color (str) – The color to use for the bar representing the protein sequence.
bar_height (int) – The height of the bar representing the protein sequence.
height (float) – The total height of each subplot (chain) in the figure.
- draw_glycans(scalar: float = 1)[source]#
Draw the glycans
- Parameters:
scalar (float) – A scalar to use for artificially upscaling the glycans.
- draw_glycosylation_sites(n_linked_color='xkcd:sky blue', o_linked_color='xkcd:medium pink', draw_legend: bool = True)[source]#
Highlight glycosylation sites
- Parameters:
n_linked_color (str) – The color to use for N-linked glycosylation sites.
o_linked_color (str) – The color to use for O-linked glycosylation sites.
draw_legend (bool) – Whether to draw a legend for the glycosylation sites.
- glycosylator.utils.visual.USE_GLYCOWORK = False#
Whether to use GlycoDraw from GlycoWork to draw glycan structures
- glycosylator.utils.visual.dont_use_glycowork()[source]#
Don’t use GlycoDraw from GlycoWork to draw glycan structures
- glycosylator.utils.visual.edge_label_defaults = {'alpha': 1.0, 'clip_on': False, 'font_color': 'k', 'font_size': 7, 'font_weight': 'normal', 'horizontalalignment': 'center', 'rotate': True}#
Default edge label drawing parameters