micom package

Submodules

micom.algorithms module

Implements additional analysis algorithms for communities.

micom.algorithms.euclidean(inclusion)

Calculate euclidean distances for a community.

micom.algorithms.jaccard(inclusion)

Calculate jaccard distances for a community.

micom.algorithms.metabolic_dist(reactions, metric=<function jaccard>)

Calculate the metabolic distances between all members.

micom.algorithms.reaction_matrix(files)

Create a matrix of reactions x models.

micom.community module

A class representing a microbial or tissue community.

class micom.community.Community(taxonomy, id=None, name=None, rel_threshold=1e-06, solver=None, progress=True, max_exchange=100, mass=1)

Bases: cobra.core.model.Model

A community of models.

This class represents a community of individual models. It was designed for microbial communities but may also be used for multi-tissue or tissue-cell mixture models as long as all individuals exist within a single enclosing compartment.

abundances

pandas.Series – The normalized abundances.

Setting this attribute will also trigger the appropriate updates in the exchange fluxes and the community objective.

cooperative_tradeoff(min_growth=0.0, fraction=1.0, fluxes=False, pfba=True)

Find the best tradeoff between community and individual growth.

Finds the set of growth rates which maintian a particular community growth and spread up growth across all species as much as possible. This is done by minimizing the L2 norm of the growth rates with a minimal community growth.

Parameters:
  • min_growth (float or array-like, optional) – The minimal growth rate required for each individual. May be a single value or an array-like object with the same length as there are individuals.
  • fraction (float or list of floats in [0, 1]) – The minum percentage of the community growth rate that has to be maintained. For instance 0.9 means maintain 90% of the maximal community growth rate. Defaults to 100%.
  • fluxes (boolean, optional) – Whether to return the fluxes as well.
  • pfba (boolean, optional) – Whether to obtain fluxes by parsimonious FBA rather than “classical” FBA. This is highly recommended.
Returns:

The solution of the optimization. If fluxes==False will only contain the objective value, community growth rate and individual growth rates. If more than one fraction value is given will return a pandas Series of solutions with the fractions as indices.

Return type:

micom.CommunitySolution or pd.Series of solutions

exchanges

list – Returns all exchange reactions in the model.

Uses several heuristics based on the reaction name and compartments to exclude reactions that are not exchange reactions.

knockout_species(species=None, fraction=1.0, method='change', progress=True, diag=True)

Sequentially knowckout a list of species in the model.

This uses cooperative tradeoff as optimization criterion in order to get unqiue solutions for individual growth rates. Requires a QP solver to work.

Parameters:
  • species (str or list of strs) – Names of species to be knocked out.
  • fraction (float in [0, 1], optional) – Percentage of the maximum community growth rate that has to be maintained. Defaults to 100%.
  • method (str, optional) – One of “raw”, “change” or “relative change” that dictates whether to return the new growth rate (raw), the change in growth rate new - old or the relative change ([new - old] / old).
  • progress (bool, optional) – Whether to show a progress bar. On by default.
  • diag (bool, optional) – Whether the diagonal should contain values as well. If False will be filled with NaNs.
Returns:

A data frame with one row for each knockout and growth rates in the columns. Here the row name indicates which species has been knocked out and the columns contain the growth changes for all species in that knockout.

Return type:

pandas.DataFrame

modification

str – Denotes modifications to the model currently applied.

Will be None if the community is unmodified.

optcom(strategy='lagrangian', min_growth=0.0, fluxes=False, pfba=True)

Run OptCom for the community.

OptCom methods are a group of optimization procedures to find community solutions that provide a tradeoff between the cooperative community growth and the egoistic growth of each individual [#c1]_. micom provides several strategies that can be used to find optimal solutions:

  • “moma”: Minimization of metabolic adjustment. Simultaneously optimizes the community objective (maximize) and the cooperativity cost (minimize). This method finds an exact maximum but doubles the number of required variables, thus being slow.
  • “lmoma”: The same as “moma” only with a linear representation of the cooperativity cost (absolute value).
  • “original”: Solves the multi-objective problem described in [#c1]_. Here, the community growth rate is maximized simultanously with all individual growth rates. Note that there are usually many Pareto-optimal solutions to this problem and the method will only give one solution. This is also the slowest method.
Parameters:
  • community (micom.Community) – The community to optimize.
  • strategy (str) – The strategy used to solve the OptCom formulation. Defaults to “lagrangian” which gives a decent tradeoff between speed and correctness.
  • min_growth (float or array-like) – The minimal growth rate required for each individual. May be a single value or an array-like object with the same length as there are individuals.
  • fluxes (boolean) – Whether to return the fluxes as well.
  • pfba (boolean) – Whether to obtain fluxes by parsimonious FBA rather than “classical” FBA.
Returns:

The solution of the optimization. If fluxes==False will only contain the objective value, community growth rate and individual growth rates.

Return type:

micom.CommunitySolution

References

[1]OptCom: a multi-level optimization framework for the metabolic modeling and analysis of microbial communities. Zomorrodi AR, Maranas CD. PLoS Comput Biol. 2012 Feb;8(2):e1002363. doi: 10.1371/journal.pcbi.1002363, PMID: 22319433
optimize(fluxes=False, pfba=True, raise_error=False)

Optimize the model using flux balance analysis.

Parameters:
  • slim (boolean, optional) – Whether to return a slim solution which does not contain fluxes, just growth rates.
  • raise_error (boolean, optional) – Should an error be raised if the solution is not optimal. Defaults to False which will either return a solution with a non-optimal status or None if optimization fails.
Returns:

The solution after optimization or None if there is no optimum.

Return type:

micom.CommunitySolution

optimize_all(fluxes=False, progress=False)

Return solutions for individually optimizing each model.

Notes

This might well mean that growth rates for all other individuals are low since the individual may use up all available resources. As a consequence the reported growth rates may usually never be obtained all at once.

Parameters:
  • fluxes (boolean, optional) – Whether to return all fluxes. Defaults to just returning the maximal growth rate.
  • progress (boolean, optional) – Whether to show a progress bar.
Returns:

The maximal growth rate for each species.

Return type:

pandas.Series

optimize_single(id)

Optimize growth rate for one individual.

optimize_single will calculate the maximal growth rate for one individual member of the community.

Notes

This might well mean that growth rates for all other individuals are low since the individual may use up all available resources.

Parameters:
  • id (str) – The ID of the individual to be optimized.
  • fluxes (boolean, optional) – Whether to return all fluxes. Defaults to just returning the maximal growth rate.
Returns:

The maximal growth rate for the given species.

Return type:

float

set_abundance(value, normalize=True)

Change abundances for one or more taxa.

Parameters:
  • value (array-like object) – The new abundances. Must contain one value for each taxon. Can be a named object like a pandas Series.
  • normalize (boolean, optional) – Whether to normalize the abundances to a total of 1.0. Many things in micom asssume that this is always the case. Only change this if you know what you are doing :O
taxonomy

pandas.DataFrame – The taxonomy used within the model.

This attribute only returns a copy.

to_pickle(filename)

Save a community in serialized form.

Parameters:filename (str) – Where to save the pickled community.
Returns:
Return type:Nothing
micom.community.load_pickle(filename)

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.duality module

Implements a fast dual formulation.

micom.duality.fast_dual(model, prefix='dual_')

Add dual formulation to the problem.

A mathematical optimization problem can be viewed as a primal and a dual problem. If the primal problem is a minimization problem the dual is a maximization problem, and the optimal value of the dual is a lower bound of the optimal value of the primal. For linear problems, strong duality holds, which means that the optimal values of the primal and dual are equal (duality gap = 0). This functions takes an optlang Model representing a primal linear problem and returns a new Model representing the dual optimization problem. The provided model must have a linear objective, linear constraints and only continuous variables. Furthermore, the problem must be in standard form, i.e. all variables should be non-negative. Both minimization and maximization problems are allowed.

micom.duality.model

cobra.Model – The model to be dualized.

micom.duality.prefix

str – The string that will be prepended to all variable and constraint names in the returned dual problem.

Returns:The coefficients for the new dual objective.
Return type:dict

micom.elasticity module

Calculate elasticity coefficients.

Functions to calculate elasticity coefficients for various community quantities.

micom.elasticity.elasticities_by_abundance(com, reactions, fraction, growth_rate, progress)

Get the elasticity coefficients for a set of variables.

Parameters:
  • com (micom.Community) – The community for wrhich to calculate elasticities.
  • variables (list of optlang.Variable) – The variables for which to calculate the elasticities. All of these must have non-zero primal vaues in the previous solution.
Returns:

The long/tidy version of the elasticities. Contains columns variable, effector, and elasticity.

Return type:

pandas.Dataframe

micom.elasticity.elasticities_by_medium(com, reactions, fraction, growth_rate, progress)

Get the elasticity coefficients for a set of variables.

Parameters:
  • com (micom.Community) – The community for wrhich to calculate elasticities.
  • variables (list of optlang.Variable) – The variables for which to calculate the elasticities. All of these must have non-zero primal vaues in the previous solution.
Returns:

The long/tidy version of the elasticities. Contains columns variable, effector, and elasticity.

Return type:

pandas.Dataframe

micom.elasticity.exchange_elasticities(com, fraction=1.0, progress=True)

Calculate elasticities for exchange reactions.

Calculates elasticity coefficients using the exchange reactions as response and exchange bounds (diet) and taxa abundances as effectors/parameters. Will use an arbitrary flux distribution as base.

Parameters:
  • com (micom.Community) – The community for wrhich to calculate elasticities.
  • fraction (double) – The tradeoff to use for the cooperative tradeoff method. Fraction of maximal community growth to enforce.
  • progress (boolean) – Whether to shwo progress bars. Will show two, one for the diet optimizations and another one for the taxa abundances.
Returns:

A data frame with the following columns: “reaction” - the exchange reaction (response), “effector” - the parameter that was changed, “direction” - whether the flux runs in the forward od reverse direction, “elasticity” - the elasticity coefficient, “type” - the type of effector either “exchange” for diet or “abundance” for taxa abundances.

Return type:

pandas.DataFrame

micom.logger module

configures the logger for mico.

micom.logger.file_logger(filepath)

Log micom messages to file.

micom.media module

Manages functions for growth media analysis and manipulation.

micom.media.add_linear_obj(community)

Add a linear version of a minimal medium to the community.

Changes the optimization objective to finding the growth medium requiring the smallest total import flux:

minimize sum |r_i| for r_i in import_reactions
Parameters:community (micom.Community) – The community to modify.
micom.media.add_mip_obj(community)

Add a mixed-integer version of a minimal medium to the community.

Changes the optimization objective to finding the medium with the least components:

minimize size(R) where R part of import_reactions
Parameters:community (micom.Community) – The community to modify.
micom.media.default_excludes = ['biosynthesis', 'transcription', 'replication', 'sink', 'demand', 'DM_', 'SN_', 'SK_']

A list of sub-strings in reaction IDs that usually indicate that the reaction is not an exchange reaction.

micom.media.minimal_medium(community, community_growth, min_growth=0.0, exports=False, minimize_components=False, open_exchanges=False, solution=False)

Find the minimal growth medium for the community.

Finds the minimal growth medium for the community which allows for community 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).

Parameters:
  • community (micom.Community) – The community to modify.
  • community_growth (positive float) – The minimum community-wide growth rate.
  • 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.
  • exports (boolean) – Whether to include export fluxes in the returned medium. Defaults to False which will only return import fluxes.
  • minimize_components (boolean) – 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.
  • 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.
  • solution (boolean) – Whether to also return the entire solution and all fluxes for the minimal medium.
Returns:

A series {rid: flux} giving the import flux for each required import reaction. If solution is True retuns a dictionary {“medium”: panas.Series, “solution”: micom.CommunitySolution}.

Return type:

pandas.Series or dict

micom.optcom module

Implements optimization and model problems.

micom.optcom.add_dualized_optcom(community, min_growth)

Add dual Optcom variables and constraints to a community.

Uses the original formulation of OptCom and solves the following multi-objective problem:

maximize community_growth
s.t. maximize growth_rate_i for all i
     s.t. Sv_i = 0
          lb_i >= v_i >= ub_i

Notes

This method will only find one arbitrary solution from the Pareto front. There may exist several other optimal solutions.

Parameters:
  • community (micom.Community) – The community to modify.
  • 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.
micom.optcom.add_moma_optcom(community, min_growth, linear=False)

Add a dualized MOMA version of OptCom.

Solves a MOMA (minimization of metabolic adjustment) formulation of OptCom given by:

minimize cooperativity_cost
s.t. maximize community_objective
     s.t. Sv = 0
          lb >= v >= ub
where community_cost = sum (growth_rate - max_growth)**2
      if linear=False or
      community_cost = sum |growth_rate - max_growth|
      if linear=True
Parameters:
  • community (micom.Community) – The community to modify.
  • 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.
  • linear (boolean) – Whether to use a non-linear (sum of squares) or linear version of the cooperativity cost. If set to False requires a QP-capable solver.
micom.optcom.optcom(community, strategy, min_growth, fluxes, pfba)

Run OptCom for the community.

OptCom methods are a group of optimization procedures to find community solutions that provide a tradeoff between the cooperative community growth and the egoistic growth of each individual [2]. micom provides several strategies that can be used to find optimal solutions:

  • “moma”: Minimization of metabolic adjustment. Simultaneously optimizes the community objective (maximize) and the cooperativity cost (minimize). This method finds an exact maximum but doubles the number of required variables, thus being slow.
  • “lmoma”: The same as “moma” only with a linear representation of the cooperativity cost (absolute value).
  • “original”: Solves the multi-objective problem described in [2]. Here, the community growth rate is maximized simultanously with all individual growth rates. Note that there are usually many Pareto-optimal solutions to this problem and the method will only give one solution. This is also the slowest method.
Parameters:
  • community (micom.Community) – The community to optimize.
  • strategy (str) – The strategy used to solve the OptCom formulation. Defaults to “lagrangian” which gives a decent tradeoff between speed and correctness.
  • min_growth (float or array-like) – The minimal growth rate required for each individual. May be a single value or an array-like object with the same length as there are individuals.
  • fluxes (boolean) – Whether to return the fluxes as well.
  • pfba (boolean) – Whether to obtain fluxes by parsimonious FBA rather than “classical” FBA.
Returns:

The solution of the optimization. If fluxes==False will only contain the objective value, community growth rate and individual growth rates.

Return type:

micom.CommunitySolution

References

[2](1, 2) OptCom: a multi-level optimization framework for the metabolic modeling and analysis of microbial communities. Zomorrodi AR, Maranas CD. PLoS Comput Biol. 2012 Feb;8(2):e1002363. doi: 10.1371/journal.pcbi.1002363, PMID: 22319433

micom.problems module

Implements tradeoff optimization between community and egoistic growth.

micom.problems.cooperative_tradeoff(community, min_growth, fraction, fluxes, pfba)

Find the best tradeoff between community and individual growth.

micom.problems.knockout_species(community, species, fraction, method, progress, diag=True)

Knockout a species from the community.

micom.problems.regularize_l2_norm(community, min_growth)

Add an objective to find the most “egoistic” solution.

This adds an optimization objective finding a solution that maintains a (sub-)optimal community growth rate but is the closest solution to the community members individual maximal growth rates. So it basically finds the best possible tradeoff between maximizing community growth and individual (egoistic) growth. Here the objective is given as the sum of squared differences between the individuals current and maximal growth rate. In the linear case squares are substituted by absolute values (Manhattan distance).

Parameters:
  • community (micom.Community) – The community to modify.
  • min_growth (positive float) – The minimal community growth rate that has to be mantained.
  • linear (boolean) – Whether to use a non-linear (sum of squares) or linear version of the cooperativity cost. If set to False requires a QP-capable solver.
  • max_gcs (None or dict) – The precomputed maximum individual growth rates.

micom.solution module

A community solution object.

class micom.solution.CommunitySolution(community, slim=False, reactions=None, metabolites=None)

Bases: cobra.core.solution.Solution

An FBA solution for an entire community.

objective_value

float – The (optimal) value for the objective function.

members

pandas.Series – Contains basic info about the individual compartments/members of the community such as id, abundance and growth rates. Will also include one row for the external medium (without abundance and growth rate).

growth_rate

float – The overall growth rate for the community normalized to 1 gDW.

status

str – The solver status related to the solution.

strategy

str – The optimization strategy used to obtain the solution (may be empty).

fluxes

pandas.DataFrame – Contains the reaction fluxes (primal values of variables) stratified by compartment. Columns denote individual fluxes and rows denote compartments: one for every species plus one for the external medium. Fluxes will be NA if the reaction does not exist in the organism.

reduced_costs

pandas.Series – Contains reaction reduced costs (dual values of variables) stratified by species. Columns denote individual fluxes and rows denote species. Reduced costs will be NA if the reaction does not exist in the organism.

shadow_prices

pandas.Series – Contains metabolite shadow prices (dual values of constraints) stratified by species. Columns denote individual metabolites and rows denote species. Shadow prices will be NA if the metabolite does not exist in the organism.

micom.solution.add_pfba_objective(community)

Add pFBA objective.

Add objective to minimize the summed flux of all reactions to the current objective. This one will work with any objective (even non-linear ones).

See also

pfba()

Parameters:community (micom.Community) – The community to add the objective to.
micom.solution.crossover(community, sol, fluxes=False, pfba=False)

Get the crossover solution.

micom.solution.good = ['optimal', 'numeric', 'feasible', 'suboptimal', 'iteration_limit']

Solver states that permit returning the solution.

micom.solution.optimize_with_fraction(com, fraction, growth_rate=None, fluxes=False, pfba=False)

Optimize with a constrained community growth rate.

micom.solution.optimize_with_retry(com, message='could not get optimum.')

Try to reset the solver.

micom.solution.reset_solver(community)

Reset the solver.

micom.solution.solve(community, fluxes=True, pfba=True, raise_error=False)

Get all fluxes stratified by species.

micom.util module

Holds utility functions for other modules.

micom.util.add_var_from_expression(model, name, expr, lb=None, ub=None)

Add a variable to a model equaling an expression.

micom.util.adjust_solver_config(solver)

Adjust the optlang solver configuration for larger problems.

micom.util.check_modification(community)

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.download_model(url, folder='.')

Download a model.

micom.util.fluxes_from_primals(model, info)

Extract a list of fluxes from the model primals.

micom.util.join_models(model_files, id=None)

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.load_model(filepath)

Load a cobra model from several file types.

micom.util.reset_min_community_growth(com)

Reset the lower bound for the community growth.

micom.util.serialize_models(files, dir='.')

Convert several models to Python pickles.

micom.workflows module

Makes it easier to run analyses on several samples in parallel.

micom.workflows.workflow(func, args, n_jobs=4, unit='sample(s)')

Run analyses for several samples in parallel.

This will analyze several samples in parallel. Includes a workaround for optlang memory leak.

Parameters:
  • func (function) – A function that takes a single argument (can be any object) and that performs your analysis for a single sample.
  • args (array-like object) – An array-like object (list, tuple, numpy array, pandas Series, etc.) that contains the arguments for each sample.
  • n_jobs (positive int) – How many samples to analyze in parallel at once.
  • unit (str) – The unit used for the progress bar.

Module contents

Simple init file for mico.

class micom.Community(taxonomy, id=None, name=None, rel_threshold=1e-06, solver=None, progress=True, max_exchange=100, mass=1)

Bases: cobra.core.model.Model

A community of models.

This class represents a community of individual models. It was designed for microbial communities but may also be used for multi-tissue or tissue-cell mixture models as long as all individuals exist within a single enclosing compartment.

abundances

pandas.Series – The normalized abundances.

Setting this attribute will also trigger the appropriate updates in the exchange fluxes and the community objective.

cooperative_tradeoff(min_growth=0.0, fraction=1.0, fluxes=False, pfba=True)

Find the best tradeoff between community and individual growth.

Finds the set of growth rates which maintian a particular community growth and spread up growth across all species as much as possible. This is done by minimizing the L2 norm of the growth rates with a minimal community growth.

Parameters:
  • min_growth (float or array-like, optional) – The minimal growth rate required for each individual. May be a single value or an array-like object with the same length as there are individuals.
  • fraction (float or list of floats in [0, 1]) – The minum percentage of the community growth rate that has to be maintained. For instance 0.9 means maintain 90% of the maximal community growth rate. Defaults to 100%.
  • fluxes (boolean, optional) – Whether to return the fluxes as well.
  • pfba (boolean, optional) – Whether to obtain fluxes by parsimonious FBA rather than “classical” FBA. This is highly recommended.
Returns:

The solution of the optimization. If fluxes==False will only contain the objective value, community growth rate and individual growth rates. If more than one fraction value is given will return a pandas Series of solutions with the fractions as indices.

Return type:

micom.CommunitySolution or pd.Series of solutions

exchanges

list – Returns all exchange reactions in the model.

Uses several heuristics based on the reaction name and compartments to exclude reactions that are not exchange reactions.

knockout_species(species=None, fraction=1.0, method='change', progress=True, diag=True)

Sequentially knowckout a list of species in the model.

This uses cooperative tradeoff as optimization criterion in order to get unqiue solutions for individual growth rates. Requires a QP solver to work.

Parameters:
  • species (str or list of strs) – Names of species to be knocked out.
  • fraction (float in [0, 1], optional) – Percentage of the maximum community growth rate that has to be maintained. Defaults to 100%.
  • method (str, optional) – One of “raw”, “change” or “relative change” that dictates whether to return the new growth rate (raw), the change in growth rate new - old or the relative change ([new - old] / old).
  • progress (bool, optional) – Whether to show a progress bar. On by default.
  • diag (bool, optional) – Whether the diagonal should contain values as well. If False will be filled with NaNs.
Returns:

A data frame with one row for each knockout and growth rates in the columns. Here the row name indicates which species has been knocked out and the columns contain the growth changes for all species in that knockout.

Return type:

pandas.DataFrame

modification

str – Denotes modifications to the model currently applied.

Will be None if the community is unmodified.

optcom(strategy='lagrangian', min_growth=0.0, fluxes=False, pfba=True)

Run OptCom for the community.

OptCom methods are a group of optimization procedures to find community solutions that provide a tradeoff between the cooperative community growth and the egoistic growth of each individual [#c1]_. micom provides several strategies that can be used to find optimal solutions:

  • “moma”: Minimization of metabolic adjustment. Simultaneously optimizes the community objective (maximize) and the cooperativity cost (minimize). This method finds an exact maximum but doubles the number of required variables, thus being slow.
  • “lmoma”: The same as “moma” only with a linear representation of the cooperativity cost (absolute value).
  • “original”: Solves the multi-objective problem described in [#c1]_. Here, the community growth rate is maximized simultanously with all individual growth rates. Note that there are usually many Pareto-optimal solutions to this problem and the method will only give one solution. This is also the slowest method.
Parameters:
  • community (micom.Community) – The community to optimize.
  • strategy (str) – The strategy used to solve the OptCom formulation. Defaults to “lagrangian” which gives a decent tradeoff between speed and correctness.
  • min_growth (float or array-like) – The minimal growth rate required for each individual. May be a single value or an array-like object with the same length as there are individuals.
  • fluxes (boolean) – Whether to return the fluxes as well.
  • pfba (boolean) – Whether to obtain fluxes by parsimonious FBA rather than “classical” FBA.
Returns:

The solution of the optimization. If fluxes==False will only contain the objective value, community growth rate and individual growth rates.

Return type:

micom.CommunitySolution

References

[3]OptCom: a multi-level optimization framework for the metabolic modeling and analysis of microbial communities. Zomorrodi AR, Maranas CD. PLoS Comput Biol. 2012 Feb;8(2):e1002363. doi: 10.1371/journal.pcbi.1002363, PMID: 22319433
optimize(fluxes=False, pfba=True, raise_error=False)

Optimize the model using flux balance analysis.

Parameters:
  • slim (boolean, optional) – Whether to return a slim solution which does not contain fluxes, just growth rates.
  • raise_error (boolean, optional) – Should an error be raised if the solution is not optimal. Defaults to False which will either return a solution with a non-optimal status or None if optimization fails.
Returns:

The solution after optimization or None if there is no optimum.

Return type:

micom.CommunitySolution

optimize_all(fluxes=False, progress=False)

Return solutions for individually optimizing each model.

Notes

This might well mean that growth rates for all other individuals are low since the individual may use up all available resources. As a consequence the reported growth rates may usually never be obtained all at once.

Parameters:
  • fluxes (boolean, optional) – Whether to return all fluxes. Defaults to just returning the maximal growth rate.
  • progress (boolean, optional) – Whether to show a progress bar.
Returns:

The maximal growth rate for each species.

Return type:

pandas.Series

optimize_single(id)

Optimize growth rate for one individual.

optimize_single will calculate the maximal growth rate for one individual member of the community.

Notes

This might well mean that growth rates for all other individuals are low since the individual may use up all available resources.

Parameters:
  • id (str) – The ID of the individual to be optimized.
  • fluxes (boolean, optional) – Whether to return all fluxes. Defaults to just returning the maximal growth rate.
Returns:

The maximal growth rate for the given species.

Return type:

float

set_abundance(value, normalize=True)

Change abundances for one or more taxa.

Parameters:
  • value (array-like object) – The new abundances. Must contain one value for each taxon. Can be a named object like a pandas Series.
  • normalize (boolean, optional) – Whether to normalize the abundances to a total of 1.0. Many things in micom asssume that this is always the case. Only change this if you know what you are doing :O
taxonomy

pandas.DataFrame – The taxonomy used within the model.

This attribute only returns a copy.

to_pickle(filename)

Save a community in serialized form.

Parameters:filename (str) – Where to save the pickled community.
Returns:
Return type:Nothing
micom.load_pickle(filename)

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