15.1.1.1.1.1. cobra.core.dictlist
¶
15.1.1.1.1.1.1. Module Contents¶
-
class
cobra.core.dictlist.
DictList
(*args)[source]¶ A combined dict and list
This object behaves like a list, but has the O(1) speed benefits of a dict when looking up elements by their id.
-
__init__
(*args)[source]¶ Instantiate a combined dict and list.
Parameters: args (iterable) – iterable as single argument to create new DictList from
-
_check
(id)[source]¶ make sure duplicate id’s are not added. This function is called before adding in elements.
-
get_by_any
(iterable)[source]¶ Get a list of members using several different ways of indexing
Parameters: iterable (list (if not, turned into single element list)) – list where each element is either int (referring to an index in in this DictList), string (a id of a member in this DictList) or member of this DictList for pass-through Returns: a list of members Return type: list
-
query
(search_function, attribute=None)[source]¶ Query the list
Parameters: - search_function (a string, regular expression or function) – Used to find the matching elements in the list. - a regular expression (possibly compiled), in which case the given attribute of the object should match the regular expression. - a function which takes one argument and returns True for desired values
- attribute (string or None) – the name attribute of the object to passed as argument to the search_function. If this is None, the object itself is used.
Returns: a new list of objects which match the query
Return type: Examples
>>> import cobra.test >>> model = cobra.test.create_test_model('textbook') >>> model.reactions.query(lambda x: x.boundary) >>> import re >>> regex = re.compile('^g', flags=re.IGNORECASE) >>> model.metabolites.query(regex, attribute='name')
-
_extend_nocheck
(iterable)[source]¶ extends without checking for uniqueness
This function should only be used internally by DictList when it can guarantee elements are already unique (as in when coming from self or other DictList). It will be faster because it skips these checks.
-
__sub__
(other)[source]¶ x.__sub__(y) <==> x - y
Parameters: other (iterable) – other must contain only unique id’s present in the list
-
__isub__
(other)[source]¶ x.__sub__(y) <==> x -= y
Parameters: other (iterable) – other must contain only unique id’s present in the list
-
__add__
(other)[source]¶ x.__add__(y) <==> x + y
Parameters: other (iterable) – other must contain only unique id’s which do not intersect with self
-
__iadd__
(other)[source]¶ x.__iadd__(y) <==> x += y
Parameters: other (iterable) – other must contain only unique id’s whcih do not intersect with self
-
__getstate__
()[source]¶ gets internal state
This is only provided for backwards compatibility so older versions of cobrapy can load pickles generated with cobrapy. In reality, the “_dict” state is ignored when loading a pickle
-
__setstate__
(state)[source]¶ sets internal state
Ignore the passed in state and recalculate it. This is only for compatibility with older pickles which did not correctly specify the initialization class
-