cobamp.core package¶
Submodules¶
cobamp.core.linear_systems module¶
-
class
cobamp.core.linear_systems.
BendersMasterSystem
(F, c, g, lb, ub, solver)[source]¶
-
class
cobamp.core.linear_systems.
BendersSlaveSystem
(A, M, D, b, e, lb_y, ub_y, solver=None)[source]¶
-
class
cobamp.core.linear_systems.
DualLinearSystem
(S, lb, ub, T, b, solver=None)[source]¶ Bases:
cobamp.core.linear_systems.KShortestCompatibleLinearSystem
,cobamp.core.linear_systems.GenericLinearSystem
Class representing a dual system based on a steady-state metabolic network whose elementary flux modes are minimal cut sets for use with the KShortest algorithms. Based on previous work by Ballerstein et al. and Von Kamp et al.
[1] von Kamp, A., & Klamt, S. (2014). Enumeration of smallest intervention strategies in genome-scale metabolic networks. PLoS computational biology, 10(1), e1003378. [2] Ballerstein, K., von Kamp, A., Klamt, S., & Haus, U. U. (2011). Minimal cut sets in a metabolic network are elementary modes in a dual network. Bioinformatics, 28(3), 381-387.
-
class
cobamp.core.linear_systems.
GenericLinearSystem
(S, var_types, lb, ub, b_lb, b_ub, var_names, solver=None)[source]¶ Bases:
cobamp.core.linear_systems.LinearSystem
Class representing a generic system of linear (in)equations Used as arguments for various algorithms implemented in the package.
-
class
cobamp.core.linear_systems.
IrreversibleLinearPatternSystem
(S, lb, ub, subset, **kwargs)[source]¶
-
class
cobamp.core.linear_systems.
IrreversibleLinearSystem
(S, lb, ub, non_consumed=(), consumed=(), produced=(), solver=None, force_bounds={})[source]¶ Bases:
cobamp.core.linear_systems.KShortestCompatibleLinearSystem
,cobamp.core.linear_systems.GenericLinearSystem
Class representing a steady-state biological system of metabolites and reactions without dynamic parameters. All irreversible reactions are split into their forward and backward components so every lower bound is 0. Used as arguments for various algorithms implemented in the package.
-
class
cobamp.core.linear_systems.
KShortestCompatibleLinearSystem
[source]¶ Bases:
cobamp.core.linear_systems.LinearSystem
Abstract class representing a linear system that can be passed as an argument for the KShortestAlgorithm class. Subclasses must instantiate the following variables:
__dvar_mapping: A dictionary mapping reaction indexes with variable names
__dvars: A list of variable names (str) or Tuple[str] if two linear system variables represent a single flux. Should be kept as type list to maintain order.
__c: str representing the variable to be used as constant for indicator constraints
-
c
= None¶
-
dvar_mapping
= None¶
-
dvars
= None¶
-
-
class
cobamp.core.linear_systems.
LinearSystem
[source]¶ Bases:
object
An abstract class defining the template for subclasses implementing linear systems that can be used with optimizers such as CPLEX and passed onto other algorithms supplied with the package.
Must instantiate the following variables:
S: System of linear equations represented as a n-by-m ndarray, preferrably with dtype as float or int
__model: Linear model as an instance of the solver.
-
add_columns_to_model
(S_new, var_names, lb, ub, var_types)[source]¶ - Args:
- S_new: var_names: lb: ub: var_types:
-
add_rows_to_model
(S_new, b_lb, b_ub, only_nonzero=False, indicator_rows=None, vars=None, names=None)[source]¶ - Args:
- S_new: b_lb: b_ub: only_nonzero: indicator_rows: vars: names:
-
build_problem
()[source]¶ Builds a CPLEX model with the constraints specified in the constructor arguments. This method must be implemented by any <LinearSystem>. Refer to the constructor ——-
-
get_model
()[source]¶ Returns the model instance. Must call <self.build_problem()> to return a CPLEX model.
-
get_stoich_matrix_shape
()[source]¶ Returns a tuple with the shape (rows, columns) of the supplied stoichiometric matrix.
-
model
= None¶
-
populate_constraints_from_matrix
(S, constraints, vars, only_nonzero=False)[source]¶ - Args:
- S: Two-dimensional np.ndarray instance constraints (side of all): vars: list of variable instances only_nonzero:
-
populate_model_from_matrix
(S, var_types, lb, ub, b_lb, b_ub, var_names, only_nonzero=False, indicator_rows=None)[source]¶ - Args:
S: Two-dimensional np.ndarray instance var_types: list or tuple with length equal to the amount of columns of S
containing variable types (e.g.- lb: list or tuple with length equal to the amount of columns of S
- containing the lower bounds for all variables
- ub: list or tuple with length equal to the amount of columns of S
- containing the upper bounds for all variables
- b_lb: list or tuple with length equal to the amount of rows of S
- containing the lower bound for the right hand
- b_ub: list or tuple with length equal to the amount of rows of S
- containing the upper bound for the right hand
var_names: string identifiers for the variables only_nonzero: indicator_rows:
-
set_number_of_threads
(n_threads=0)[source]¶ Defines the amount of threads available for the solver to use. :param n_threads: Number of threads available to the solver. Set to 0 if default parameters are needed :return:
- Args:
- n_threads:
-
-
class
cobamp.core.linear_systems.
SteadyStateLinearSystem
(S, lb, ub, var_names, solver=None)[source]¶ Bases:
cobamp.core.linear_systems.GenericLinearSystem
Class representing a steady-state biological system of metabolites and reactions without dynamic parameters Used as arguments for various algorithms implemented in the package.
cobamp.core.models module¶
-
class
cobamp.core.models.
CORSOModel
(cbmodel, corso_element_names=('R_PSEUDO_CORSO', 'M_PSEUDO_CORSO'), solver=None)[source]¶
-
class
cobamp.core.models.
ConstraintBasedModel
(S, thermodynamic_constraints, reaction_names=None, metabolite_names=None, optimizer=True, solver=None)[source]¶ Bases:
object
cobamp.core.optimization module¶
-
class
cobamp.core.optimization.
BatchOptimizer
(linear_system: cobamp.core.linear_systems.LinearSystem, threads=4)[source]¶ Bases:
object
-
class
cobamp.core.optimization.
BendersDecompositionOptimizer
(master_system, slave_system, hard_fail=False, build=True)[source]¶ Bases:
object
-
class
cobamp.core.optimization.
BendersSlaveOptimizer
(slave_system, hard_fail, build)[source]¶ Bases:
cobamp.core.optimization.LinearSystemOptimizer
-
optimize
()[source]¶ Internal function to instantiate the solver and return a solution to the optimization problem
Parameters
objective: A List[Tuple[coef,name]], where coef is an objective coefficient and name is the name of the variable to be optimized.
minimize: A boolean that, when True, defines the problem as a minimization
-
-
class
cobamp.core.optimization.
CORSOSolution
(sol_max, sol_min, f, index_map, var_names, eps=1e-08)[source]¶
-
class
cobamp.core.optimization.
KShortestSolution
(value_map, status, indicator_map, dvar_mapping, dvars, **kwargs)[source]¶ Bases:
cobamp.core.optimization.Solution
A Solution subclass that also contains attributes suitable for elementary flux modes such as non-cancellation sums of split reactions and reaction activity.
-
SIGNED_INDICATOR_SUM
= 'signed_indicator_map'¶
-
SIGNED_VALUE_MAP
= 'signed_value_map'¶
-
-
class
cobamp.core.optimization.
LinearSystemOptimizer
(linear_system, hard_fail=False, build=True)[source]¶ Bases:
object
Class with methods to solve a <LinearSystem> as a linear optimization problem.
-
optimize
()[source]¶ Internal function to instantiate the solver and return a solution to the optimization problem
Parameters
objective: A List[Tuple[coef,name]], where coef is an objective coefficient and name is the name of the variable to be optimized.
minimize: A boolean that, when True, defines the problem as a minimization
-
-
class
cobamp.core.optimization.
Solution
(value_map, status, **kwargs)[source]¶ Bases:
object
Class representing a solution to a given linear optimization problem. Includes an internal dictionary for additional information to be included.
-
attribute_value
(attribute_name)[source]¶ Parameters
attribute_name: A dictionary key (preferrably str)
-