cobra.io.dict
¶
Provide functions for cobrapy objects to generic Python objects and vice-versa.
Module Contents¶
Functions¶
|
Convert possible types to correct Python types. |
|
Update new_dict with optional attributes from cobra_object. |
|
Convert a cobra Metabolite object to dictionary. |
|
Convert a dictionary to cobra Metabolite object. |
|
Convert a cobra Gene object to dictionary. |
|
Convert a dictionary to cobra Gene object. |
|
Convert a cobra Reaction object to a dictionary. |
|
Convert a dictionary to a cobra Reaction object. |
|
Convert a cobra Model to a dictionary. |
|
Build a cobra Model from a dictionary. |
Attributes¶
- cobra.io.dict._REQUIRED_REACTION_ATTRIBUTES = ['id', 'name', 'metabolites', 'lower_bound', 'upper_bound', 'gene_reaction_rule'][source]¶
- cobra.io.dict._ORDERED_OPTIONAL_REACTION_KEYS = ['objective_coefficient', 'subsystem', 'notes', 'annotation'][source]¶
- cobra.io.dict._ORDERED_OPTIONAL_METABOLITE_KEYS = ['charge', 'formula', '_bound', 'notes', 'annotation'][source]¶
- cobra.io.dict._ORDERED_OPTIONAL_MODEL_KEYS = ['name', 'compartments', 'notes', 'annotation'][source]¶
- cobra.io.dict._fix_type(value: Union[str, float, bool, Set, Dict]) Union[str, float, bool, List, collections.OrderedDict] [source]¶
Convert possible types to correct Python types.
- cobra.io.dict._update_optional(cobra_object: cobra.Object, new_dict: Dict, optional_attribute_dict: Dict, ordered_keys: Sequence) None [source]¶
Update new_dict with optional attributes from cobra_object.
- Parameters
cobra_object (cobra.Object) – The cobra Object to update optional attributes from.
new_dict (dict) – The dictionary to update optional attributes for.
optional_attribute_dict (dict) – The dictionary to use as default value lookup store.
- Raises
IndexError – If key in ordered_keys is not found in optional_attribute_dict.
AttributeError – If key in ordered_keys is not found in cobra_object.
- cobra.io.dict._metabolite_to_dict(metabolite: cobra.core.Metabolite) collections.OrderedDict [source]¶
Convert a cobra Metabolite object to dictionary.
- Parameters
metabolite (cobra.Metabolite) – The cobra.Metabolite to convert to dictionary.
- Returns
The converted dictionary object.
- Return type
See also
_metabolite_from_dict
Convert a dictionary to cobra Metabolite object.
- cobra.io.dict._metabolite_from_dict(metabolite: Dict) cobra.core.Metabolite [source]¶
Convert a dictionary to cobra Metabolite object.
- Parameters
metabolite (dict) – The dictionary to convert to cobra.Metabolite .
- Return type
See also
_metabolite_to_dict
Convert a cobra Metabolite object to dictionary.
- cobra.io.dict._gene_to_dict(gene: cobra.core.Gene) collections.OrderedDict [source]¶
Convert a cobra Gene object to dictionary.
- Parameters
gene (cobra.Gene) – The cobra.Gene to convert to dictionary.
- Returns
The converted dictionary object.
- Return type
See also
_gene_from_dict
Convert a dictionary to cobra Gene object.
- cobra.io.dict.gene_from_dict(gene: Dict) cobra.core.Gene [source]¶
Convert a dictionary to cobra Gene object.
- Parameters
gene (dict) – The dictionary to convert to cobra.Gene .
- Returns
The converted cobra.Gene object.
- Return type
See also
_gene_to_dict
Convert a cobra Gene object to a dictionary.
- cobra.io.dict._reaction_to_dict(reaction: cobra.core.Reaction) collections.OrderedDict [source]¶
Convert a cobra Reaction object to a dictionary.
- Parameters
reaction (cobra.Reaction) – The cobra.Reaction to convert to dictionary.
- Returns
The converted dictionary object.
- Return type
See also
_reaction_from_dict
Convert a dictionary to a cobra Reaction object.
- cobra.io.dict._reaction_from_dict(reaction: Dict, model: cobra.core.Model) cobra.core.Reaction [source]¶
Convert a dictionary to a cobra Reaction object.
- Parameters
reaction (dict) – The dictionary to convert to cobra.Reaction .
model (cobra.Model) – The model to which the reaction should associate with.
- Returns
The converted cobra.Reaction object.
- Return type
See also
_reaction_to_dict
Convert a cobra Reaction object to a dictionary.
- cobra.io.dict.model_to_dict(model: cobra.core.Model, sort: bool = False) collections.OrderedDict [source]¶
Convert a cobra Model to a dictionary.
- Parameters
model (cobra.Model) – The model to reformulate as a dict.
sort (bool, optional) – Whether to sort the metabolites, reactions, and genes or maintain the order defined in the model (default False).
- Returns
A dictionary with keys: ‘genes’, ‘compartments’, ‘id’, ‘metabolites’, ‘notes’ and ‘reactions’; where ‘metabolites’, ‘genes’ and ‘metabolites’ are in turn lists of dictionaries holding all attributes to form the corresponding object.
- Return type
OrderedDict
See also
model_from_dict
Convert a dictionary to a cobra Model.
- cobra.io.dict.model_from_dict(obj: Dict) cobra.core.Model [source]¶
Build a cobra Model from a dictionary.
Models stored in JSON are first formulated as a dictionary that can be read to a cobra Model using this function.
- Parameters
obj (dict) – A dictionary with keys: ‘genes’, ‘compartments’, ‘id’, ‘metabolites’, ‘notes’ and ‘reactions’; where ‘metabolites’, ‘genes’ and ‘metabolites’ are in turn lists of dictionaries holding all attributes to form the corresponding object.
- Returns
The generated model.
- Return type
- Raises
ValueError – If obj has no ‘reactions’ attribute.
See also
model_to_dict
Convert a cobra Model to a dictionary.