Utilities and commonly reused generics¶
Many helper functions used throughout the rest of the library.
-
class
glypy.utils.base.ClassPropertyDescriptor(fget, fset=None)[source]¶ Bases:
objectStandard Class Property Descriptor Implementation
-
glypy.utils.base.classproperty(func)[source]¶ Applies ClassPropertyDescriptor as you would a normal @property descriptor
-
glypy.utils.base.cyclewarning()[source]¶ Used to warn users about the presence of cylcical glycans, which are harder to reason about for crossring_cleavages.
-
glypy.utils.base.make_counter(start=1)[source]¶ Create a functor whose only internal piece of data is a mutable container with a reference to an integer,
start. When the functor is called, it returns currentintvalue ofstartand increments the mutable value by one.Parameters: start: int, optional
The number to start counting from. Defaults to
1.Returns: int:
The next number in the count progression.
-
glypy.utils.base.make_struct(name, fields, debug=False)[source]¶ A convenience function for defining plain-old-data (POD) objects that are optimized for named accessor lookup, unlike
namedtuple. If the named container does not require any special logic and won’t be extended, the resulting structure is best for storing and accessing the data.Parameters: name: str
The name of the new class structure
fields: iterable of str
-
glypy.utils.base.opener(obj, mode='r')[source]¶ Try to use
objto access a file-object. Ifobjis a string, assume it denotes a path to a file, and open that file in the specified mode. Ifobjhas an attributeread, assume it itself is a file-like object and return it.Parameters: obj: basestring or file-like object
If
objis a base string it is treated like a file path, else if it supports the file-like operationread, return the object unchanged.mode: str, optional
The mode, if any, to open
objwith if it is a file path. Defaults to ‘r’,read
-
glypy.utils.base.root(structure)[source]¶ The
rootprotocol function.Creates a generic method for obtaining the root of a structure representing or containing a glycan graph with a single distinct root.
Parameters: structure : any
An object that implements the
rootprotocol, containing a tree structure somewhere inside it.Returns: Monosaccharide : The root of the
Glycantree
-
glypy.utils.base.tree(structure)[source]¶ The
treeprotocol function.Creates a generic method for obtaining the
Glycanof a structure representing or containing a glycan graph.Parameters: structure : any
An object that implements the
rootprotocol, containing a tree structure somewhere inside it.Returns: Glycan
-
class
glypy.utils.enum.Enum[source]¶ Bases:
objectA simple class implementing
EnumMeta. Useful base type for other enumerated types.
-
class
glypy.utils.enum.EnumMeta[source]¶ Bases:
typeA metaclass for types hosting enumerated members. Class attributes are automatically translated into
EnumValueobjects with the specified value and a name string matching the specified attribute name. Newly assigned attributes are wrapped dynamically.The class itself can be treated like a dictionary for looking up these attributes by name or value, and these values can be iterated over.
- ..note::
Why is this necessary? It’s probably not. I chose to write it initially for compatibility with a previous iteration of the library, but later decided it was worth keeping for two reasons:
- Avoids
stringly-typingthe library. Comparison of strings is a slippery slope to raw magic strings littering the codebase. - Richer comparison behavior allows these same names to be used in different modes with the same symbol.
- Namespacing of EnumValue objects makes it easier to avoid accidental name collisions when comparing EnumValues instead of magic strings.
- Avoids
-
__call__(k)¶ Attempt to translate the input object
kinto a data member of the Enum.First try to find an element of
selfby hashing it against member names.Then try to find an element of
selfby searching for a member in self that is value-equal tokOtherwise throw a
KeyErrorParameters: k: object
The value to be translated.
Returns:
-
__setattr__(k, v)[source]¶ Intercept attribute assignment, wrapping values in
EnumValueParameters: k : str
Name to be set
v : object
The value to assign. If it is not of type
EnumValueit will be wrapped likeEnumValue(self, name=k, value=v)
-
translate(k)[source]¶ Attempt to translate the input object
kinto a data member of the Enum.First try to find an element of
selfby hashing it against member names.Then try to find an element of
selfby searching for a member in self that is value-equal tokOtherwise throw a
KeyErrorParameters: k: object
The value to be translated.
Returns:
-
class
glypy.utils.enum.EnumValue(group, name, value, other_names=None)[source]¶ Bases:
objectRepresents a wrapper around an value with a name to identify it and more rich comparison logic. A value of an enumerated type
-
class
glypy.utils.multimap.MultiMap(**kwargs)[source]¶ Bases:
objectImplements a simple MultiMap data structure on top of a dictionary of lists
-
items()[source]¶ Returns an iterator over the items of
contents. Each item takes the form of(key, value).
-
-
class
glypy.utils.multimap.OrderedMultiMap(**kwargs)[source]¶ Bases:
glypy.utils.multimap.MultiMapImplements a simple MultiMap data structure on top of a dictionary of lists that remembers the order keys were first inserted in.
-
keys()¶ Alias of
__iter__()
-