17.1.1.3.2.1. cobra.io.dict
¶
Provide functions for cobrapy objects to generic Python objects and vice-versa.
17.1.1.3.2.1.1. Module Contents¶
17.1.1.3.2.1.1.1. 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. |
-
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, np.float, np.bool, Set, Dict]) → Union[str, float, bool, List, OrderedDict][source]¶ Convert possible types to correct Python types.
-
cobra.io.dict.
_update_optional
(cobra_object: 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: Metabolite) → 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) → Metabolite[source]¶ Convert a dictionary to cobra Metabolite object.
- Parameters
metabolite (dict) – The dictionary to convert to cobra.Metabolite .
- Returns
- Return type
See also
_metabolite_to_dict()
Convert a cobra Metabolite object to dictionary.
-
cobra.io.dict.
_gene_to_dict
(gene: Gene) → 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) → 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: Reaction) → 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: Model) → 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: Model, sort: bool = False) → 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) → 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.