7.1.2.5. cobramod.utils

CobraMod’s helpful function

This module is intended to stored multiple functions, which cannot be grouped to any module. In other words, these functions are general functions. An .. rubric:: Example

  • check_imbalance: Check for unbalanced reactions.

7.1.2.5.1. Attributes

7.1.2.5.2. Functions

build_metabolite(identifier, formula, name, charge, ...)

Returns a basic cobra.Metabolite. Creation of the metabolite

fix_name(name)

Returns new string, where hyphens are replaced to underscores

check_imbalance(reaction, stop_imbalance, show_imbalance)

Verifies if given reaction is unbalanced in given model.

get_key_dict(dictionary, pattern)

From given pattern, return the first key of the dictionary that matches it

read_lines(f)

Reads Text I/O and returns iterator of line that are not comments nor

create_replacement(filename)

Creates a dictionary build from given file. Key are the first word until

compare_type(first, second)

Returns True is both objects are the same type, else raise TypeError.

compare_DictList(first, second)

Yields item identifiers from the first DictList that are not in the second

write_to_file(sequences, filename)

Writes to given file all items from the iterable in separate lines.

find_intersection(dictlist, query, revert)

Return the first item from the intersection of a DictList and the values of

is_compound(string)

get_arrow_position(reaction_str)

is_transport(reaction_str)

Check if given reaction includes same participant in both sides,

convert_to_transport(reaction_str, compartment)

Modifies the reaction string such that the left side of the equation

confirm_metabolite(model, metabolites)

Checks if given metabolites are already in the model. If not, they will be

confirm_sink(model, identifier)

Creates sink reactions for the metabolites that participate in given

add_reactions_to_model(model, reactions)

Check function that adds Reactions to given model if it does not

reaction_is_minimize(model, identifier)

Return whether given reaction should be minimized when optimizing

inform_new_sinks(model, previous_sinks)

Warns the user if sinks were created during the extension of the Model.

get_credentials(file)

kegg_info_to_version(info)

7.1.2.5.3. Module Contents

cobramod.utils.debug_log
cobramod.utils.ARROWS: dict[str, tuple[int, int]]
cobramod.utils.build_metabolite(identifier, formula, name, charge, compartment)

Returns a basic cobra.Metabolite. Creation of the metabolite writes in the log a with a DEBUG level. level.

Parameters:
  • identifier (str) – Short name for Metabolite.

  • formula (str) – Chemical formula

  • name (name) – Long name for Metabolite

  • charge (float) – Charge of the metabolite

  • compartment (str) – Location

Returns:

new created metabolite

Return type:

Metabolite

cobramod.utils.fix_name(name)

Returns new string, where hyphens are replaced to underscores

Parameters:

name (str)

Return type:

str

cobramod.utils.check_imbalance(reaction, stop_imbalance, show_imbalance)

Verifies if given reaction is unbalanced in given model.

Parameters:
  • reaction (Reaction) – Reaction object to examine.

  • stop_imbalance (bool) – If imbalance is found, stop process.

  • show_imbalance (bool) – If imbalance is found, show output.

Raises:

UnbalancedReaction – if given reaction is unbalanced.

cobramod.utils.get_key_dict(dictionary, pattern)

From given pattern, return the first key of the dictionary that matches it or is a sub-string of it. It will raise a Warning if nothing found.

Parameters:
Return type:

str

cobramod.utils.read_lines(f)

Reads Text I/O and returns iterator of line that are not comments nor blanks spaces

Parameters:

f (TextIO)

Return type:

Iterator

cobramod.utils.create_replacement(filename)

Creates a dictionary build from given file. Key are the first word until a colon ‘:’ is found. The rest represents the value

Parameters:

filename (pathlib.Path)

Return type:

dict

cobramod.utils.compare_type(first, second)

Returns True is both objects are the same type, else raise TypeError.

Parameters:
  • first (Any)

  • second (Any)

cobramod.utils.compare_DictList(first, second)

Yields item identifiers from the first DictList that are not in the second DictList

Parameters:
Return type:

Generator

cobramod.utils.write_to_file(sequences, filename)

Writes to given file all items from the iterable in separate lines.

Parameters:
cobramod.utils.find_intersection(dictlist, query, revert)

Return the first item from the intersection of a DictList and the values of a dictionary. The identifiers from the DictList can be reverted to their original. Returns None if no intersection is found

Parameters:
Return type:

Optional[str]

cobramod.utils.is_compound(string)
Parameters:

string (str)

Return type:

bool

cobramod.utils.get_arrow_position(reaction_str)
Parameters:

reaction_str (str)

Return type:

int

cobramod.utils.is_transport(reaction_str)

Check if given reaction includes same participant in both sides, meaning that there is a tranport reaction. Prefix is not taken into consideration.

Parameters:

reaction_str (str)

Return type:

bool

cobramod.utils.convert_to_transport(reaction_str, compartment)

Modifies the reaction string such that the left side of the equation comes from the extracelullar compartment

Parameters:
  • reaction_str (str)

  • compartment (str)

Return type:

str

cobramod.utils.confirm_metabolite(model, metabolites)

Checks if given metabolites are already in the model. If not, they will be added into the model.

Parameters:
  • model (Model) – Model to extend.

  • metabolites (List[Metabolites]) – List with Metabolites.

cobramod.utils.confirm_sink(model, identifier)

Creates sink reactions for the metabolites that participate in given reaction. They can only be created if the corresponding metabolite only participates in one reaction. Otherwise, the metabolite can be somehow turnover

Parameters:
cobramod.utils.add_reactions_to_model(model, reactions)

Check function that adds Reactions to given model if it does not contain the reaction. It logs the skipped reactions.

Parameters:
cobramod.utils.reaction_is_minimize(model, identifier)

Return whether given reaction should be minimized when optimizing

Parameters:
Return type:

bool

cobramod.utils.inform_new_sinks(model, previous_sinks)

Warns the user if sinks were created during the extension of the Model. i.e. Function compares a set with sink identifiers with the actual sinks in a model.

Parameters:
cobramod.utils.get_credentials(file)
Parameters:

file (pathlib.Path)

Return type:

tuple[str, str]

cobramod.utils.kegg_info_to_version(info)
Parameters:

info (str)

Return type:

str