cobamp.core package

Submodules

cobamp.core.linear_systems module

class cobamp.core.linear_systems.BendersMasterSystem(F, c, g, lb, ub, solver)[source]

Bases: cobamp.core.linear_systems.GenericLinearSystem

add_combinatorial_benders_cut(x_sol)[source]
Args:
x_sol:
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 ——-

remove_cuts()[source]
class cobamp.core.linear_systems.BendersSlaveSystem(A, M, D, b, e, lb_y, ub_y, solver=None)[source]

Bases: cobamp.core.linear_systems.GenericLinearSystem

parametrize(x_sol)[source]
Args:
x_sol:
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.

generate_dual_problem(S, irrev, T, b)[source]
Args:
S: irrev: T: b:
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.

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 ——-

class cobamp.core.linear_systems.IrreversibleLinearPatternSystem(S, lb, ub, subset, **kwargs)[source]

Bases: cobamp.core.linear_systems.IrreversibleLinearSystem

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 ——-

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

add_c_variable()[source]
c = None
dvar_mapping = None
dvars = None
get_c_variable()[source]
get_dvar_mapping()[source]
get_dvars()[source]
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:
add_variables_to_model(var_names, lb, ub, var_types)[source]
Args:
var_names: lb: ub: var_types:
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 ——-

dummy_variable()[source]
empty_constraint(b_lb, b_ub, **kwargs)[source]
Args:
b_lb: b_ub: **kwargs:
get_configuration()[source]
get_constraint_bounds(constraints=None)[source]
Args:
constraints:
get_constraint_matrices(constraints=None, vars=None)[source]
Args:
constraints: vars:
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.

get_stuff(what, index)[source]
Args:
what: index:
get_system_matrix(constraints=None, vars=None)[source]
Args:
constraints: vars:
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:

remove_from_model(index, what)[source]
Args:
index: what:
select_solver(solver=None)[source]

Args: solver:

set_constraint_bounds(constraints, lb, ub)[source]
Args:
constraints: lb: ub:
set_default_configuration()[source]
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:
set_objective(coefficients, minimize, vars=None)[source]
Args:
coefficients: minimize: vars:
set_variable_bounds(vars, lb, ub)[source]
Args:
vars: lb: ub:
set_variable_types(vars, types)[source]
Args:
vars: types:
set_working_memory_limit(workmem)[source]

Defines the amount of memory available for the solver to use. Use this at your own peril! :param n_threads: Memory in MegaBytes available to the solver :return:

Args:
workmem:
was_built()[source]
write_to_lp(filename)[source]
Args:
filename:
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.linear_systems.bak_irrev(lb, ub)[source]
Args:
lb: ub:
cobamp.core.linear_systems.fix_backwards_irreversible_reactions(S, lb, ub)[source]
Args:
S: lb: ub:
cobamp.core.linear_systems.fwd_irrev(lb, ub)[source]
Args:
lb: ub:
cobamp.core.linear_systems.get_default_solver()[source]
cobamp.core.linear_systems.get_solver_interfaces()[source]
cobamp.core.linear_systems.make_irreversible_model(S, lb, ub)[source]
Args:
S: lb: ub:
cobamp.core.linear_systems.prepare_irreversible_system(self, S, lb, ub, non_consumed, consumed, produced, solver, force_bounds)[source]
Args:
self: S: lb: ub: non_consumed: consumed: produced: solver: force_bounds:

cobamp.core.models module

class cobamp.core.models.CORSOModel(cbmodel, corso_element_names=('R_PSEUDO_CORSO', 'M_PSEUDO_CORSO'), solver=None)[source]

Bases: cobamp.core.models.ConstraintBasedModel

optimize_corso(cost, of_dict, minimize=False, constraint=1, constraintby='val', eps=1e-06, flux1=None)[source]
set_corso_objective()[source]
set_costs(cost)[source]
solve_original_model(of_dict, minimize=False)[source]
class cobamp.core.models.ConstraintBasedModel(S, thermodynamic_constraints, reaction_names=None, metabolite_names=None, optimizer=True, solver=None)[source]

Bases: object

add_metabolite(arg, name=None)[source]
add_reaction(arg, bounds, name=None)[source]
decode_index(index, labels)[source]
flux_limits(reaction)[source]
get_bounds_as_list()[source]
get_reaction_bounds(index)[source]
get_stoichiometric_matrix(rows=None, columns=None)[source]
initialize_optimizer()[source]
is_reversible_reaction(index)[source]
make_irreversible()[source]
optimize(coef_dict=None, minimize=False)[source]
remove_metabolite(index)[source]
remove_reaction(index)[source]
revert_to_original_bounds()[source]
set_objective(coef_dict, minimize=False)[source]
set_reaction_bounds(index, **kwargs)[source]
set_stoichiometric_matrix(values, rows=None, columns=None)[source]
class cobamp.core.models.GIMMEModel(cbmodel, solver=None)[source]

Bases: cobamp.core.models.ConstraintBasedModel

optimize_gimme(exp_vector, objectives, obj_frac, flux_thres)[source]
cobamp.core.models.make_irreversible_model_raven(S, lb, ub, inverse_reverse_reactions=False)[source]

cobamp.core.optimization module

class cobamp.core.optimization.BatchOptimizer(linear_system: cobamp.core.linear_systems.LinearSystem, threads=4)[source]

Bases: object

batch_optimize(bounds, objective_coefs, objective_senses)[source]
class cobamp.core.optimization.BendersDecompositionOptimizer(master_system, slave_system, hard_fail=False, build=True)[source]

Bases: object

optimize(max_iterations=10000, slave_pool=20)[source]
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]

Bases: cobamp.core.optimization.Solution

class cobamp.core.optimization.GIMMESolution(sol, exp_vector, var_names, mapping=None)[source]

Bases: cobamp.core.optimization.Solution

get_reaction_activity(flux_threshold)[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'
get_active_indicator_varids()[source]

Returns the indices of active indicator variables (maps with variables on the original stoichiometric matrix)

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

populate(limit=None)[source]
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_names()[source]

Returns all keys present in the attribute dictionary.

attribute_value(attribute_name)[source]

Parameters

attribute_name: A dictionary key (preferrably str)
objective_value()[source]

Returns the objective value for this solution

set_attribute(key, value)[source]

Sets the value of a given <key> as <value>.

Parameters

key - A string

value - Any object to be associated with the supplied key

status()[source]
to_series()[source]
var_values()[source]
x()[source]

Returns a ndarray with the solution values in order (from the variables)

cobamp.core.optimization.optimization_pool(lsystem, bound_change_list, objective_coef_list, objective_sense_list, threads=4)[source]
cobamp.core.optimization.random_string_generator(N)[source]

Parameters

N : an integer

cobamp.core.transformer module

class cobamp.core.transformer.ModelTransformer[source]

Bases: object

transform(args, properties)[source]
transform_array(S, lb, ub, properties)[source]
class cobamp.core.transformer.ReactionIndexMapping(otn, nto)[source]

Bases: object

from_new(idx)[source]
from_original(idx)[source]
multiply(new_ids)[source]

Module contents