17.1.1.5. cobra.medium¶

Imports for the media module.

17.1.1.5.2. Package Contents¶

17.1.1.5.2.1. Functions¶

 find_boundary_types(model, boundary_type, external_compartment=None) Find specific boundary reactions. Find the external compartment in the model. is_boundary_type(reaction, boundary_type, external_compartment) Check whether a reaction is an exchange reaction. minimal_medium(model, min_objective_value=0.1, exports=False, minimize_components=False, open_exchanges=False) Find the minimal growth medium for the model.
cobra.medium.find_boundary_types(model, boundary_type, external_compartment=None)[source]

Find specific boundary reactions.

Parameters
• model (cobra.Model) – A cobra model.

• boundary_type (str) – What boundary type to check for. Must be one of “exchange”, “demand”, or “sink”.

• external_compartment (str or None) – The id for the external compartment. If None it will be detected automatically.

Returns

A list of likely boundary reactions of a user defined type.

Return type

list of cobra.reaction

cobra.medium.find_external_compartment(model)[source]

Find the external compartment in the model.

Uses a simple heuristic where the external compartment should be the one with the most exchange reactions.

Parameters

model (cobra.Model) – A cobra model.

Returns

The putative external compartment.

Return type

str

cobra.medium.is_boundary_type(reaction, boundary_type, external_compartment)[source]

Check whether a reaction is an exchange reaction.

Parameters
• reaction (cobra.Reaction) – The reaction to check.

• boundary_type (str) – What boundary type to check for. Must be one of “exchange”, “demand”, or “sink”.

• external_compartment (str) – The id for the external compartment.

Returns

Whether the reaction looks like the requested type. Might be based on a heuristic.

Return type

boolean

cobra.medium.sbo_terms

SBO term identifiers for various boundary types.

cobra.medium.minimal_medium(model, min_objective_value=0.1, exports=False, minimize_components=False, open_exchanges=False)[source]

Find the minimal growth medium for the model.

Finds the minimal growth medium for the model which allows for model as well as individual growth. Here, a minimal medium can either be the medium requiring the smallest total import flux or the medium requiring the least components (ergo ingredients), which will be much slower due to being a mixed integer problem (MIP).

Parameters
• model (cobra.model) – The model to modify.

• min_objective_value (positive float or array-like object) – The minimum growth rate (objective) that has to be achieved.

• exports (boolean) – Whether to include export fluxes in the returned medium. Defaults to False which will only return import fluxes.

• minimize_components (boolean or positive int) – Whether to minimize the number of components instead of the total import flux. Might be more intuitive if set to True but may also be slow to calculate for large communities. If set to a number n will return up to n alternative solutions all with the same number of components.

• open_exchanges (boolean or number) – Whether to ignore currently set bounds and make all exchange reactions in the model possible. If set to a number all exchange reactions will be opened with (-number, number) as bounds.

Returns

A series giving the import flux for each required import reaction and (optionally) the associated export fluxes. All exchange fluxes are oriented into the import reaction e.g. positive fluxes denote imports and negative fluxes exports. If minimize_components is a number larger 1 may return a DataFrame where each column is a minimal medium. Returns None if the minimization is infeasible (for instance if min_growth > maximum growth rate).

Return type

pandas.Series, pandas.DataFrame or None

Notes

Due to numerical issues the minimize_components option will usually only minimize the number of “large” import fluxes. Specifically, the detection limit is given by integrality_tolerance * max_bound where max_bound is the largest bound on an import reaction. Thus, if you are interested in small import fluxes as well you may have to adjust the solver tolerance at first with model.tolerance = 1e-7 for instance. However, this will be very slow for large models especially with GLPK.