micom.util#

Holds utility functions for other modules.

Module Contents#

Functions#

is_active_demand(r)

Check if a reaction is a demand reaction.

fix_demands(model)

Check for forced sinks and demands and deactivates them.

download_model(url, folder='.')

Download a model.

_read_model(file)

Read a model from a local file.

load_model(filepath)

Load a cobra model from several file types.

load_pickle(filename)

Load a community model from a pickled version.

serialize_models(files, dir='.')

Convert several models to Python pickles.

chr_or_input(m)

Return ascii character for the ordinal or the original string.

clean_ids(id)

Clean ids up a bit.

compartment_id(micom_obj)

Get the compartment id for a cobra object and prune the prefix if needed.

join_models(model_files, id=None)

Join several models into one.

fluxes_from_primals(model, info)

Extract a list of fluxes from the model primals.

add_var_from_expression(model, name, expr, lb=None, ub=None)

Add a variable to a model equaling an expression.

check_modification(community)

Check whether a community already carries a modification.

_format_min_growth(min_growth, taxa)

Format min_growth into a pandas series.

_apply_min_growth(community, min_growth, atol=1e-06, rtol=1e-06)

Set minimum growth constraints on a model.

adjust_solver_config(solver)

Adjust the optlang solver configuration for larger problems.

reset_min_community_growth(com)

Reset the lower bound for the community growth.

Attributes#

_read_funcs

COMPARTMENT_RE

micom.util._read_funcs[source]#
micom.util.COMPARTMENT_RE = (_{}$)|([^a-zA-Z0-9 :]{}[^a-zA-Z0-9 :]$)[source]#
micom.util.is_active_demand(r)[source]#

Check if a reaction is a demand reaction.

micom.util.fix_demands(model)[source]#

Check for forced sinks and demands and deactivates them.

micom.util.download_model(url, folder='.')[source]#

Download a model.

micom.util._read_model(file)[source]#

Read a model from a local file.

micom.util.load_model(filepath)[source]#

Load a cobra model from several file types.

micom.util.load_pickle(filename)[source]#

Load a community model from a pickled version.

Parameters

filename (str) – The file the community is stored in.

Returns

The loaded community model.

Return type

micom.Community

micom.util.serialize_models(files, dir='.')[source]#

Convert several models to Python pickles.

micom.util.chr_or_input(m)[source]#

Return ascii character for the ordinal or the original string.

micom.util.clean_ids(id)[source]#

Clean ids up a bit.

micom.util.compartment_id(micom_obj)[source]#

Get the compartment id for a cobra object and prune the prefix if needed.

micom.util.join_models(model_files, id=None)[source]#

Join several models into one.

This requires all the models to use the same ID system.

Parameters
  • model_files (list of strings) – The files to be joined.

  • id (str) – The new ID for the model. Will be the ID of the first model if None.

Returns

The joined cobra Model.

Return type

cobra.Model

micom.util.fluxes_from_primals(model, info)[source]#

Extract a list of fluxes from the model primals.

micom.util.add_var_from_expression(model, name, expr, lb=None, ub=None)[source]#

Add a variable to a model equaling an expression.

micom.util.check_modification(community)[source]#

Check whether a community already carries a modification.

Parameters

community (micom.Community) – The community class to check.

Raises

ValueError – If the community already carries a modification and adding another would not be safe.

micom.util._format_min_growth(min_growth, taxa)[source]#

Format min_growth into a pandas series.

Parameters
  • min_growth (positive float or array-like object.) – The minimum growth rate for each individual in the community. Either a single value applied to all individuals or one value for each.

  • taxa (array-like) – The ID for each individual model in the community.

Returns

A pandas Series mapping each individual to its minimum growth rate.

Return type

pandas.Series

micom.util._apply_min_growth(community, min_growth, atol=1e-06, rtol=1e-06)[source]#

Set minimum growth constraints on a model.

Will integrate with the context.

micom.util.adjust_solver_config(solver)[source]#

Adjust the optlang solver configuration for larger problems.

micom.util.reset_min_community_growth(com)[source]#

Reset the lower bound for the community growth.