Reconstruction Methods

Corda Algorithm

class troppo.methods.reconstruction.corda.CORDA(S, lb, ub, properties)[source]

Bases: ContextSpecificModelReconstructionAlgorithm

CORDA algorithm

Parameters

Sarray

Stoichiometric matrix

lbarray

Lower bounds

ubarray

Upper bounds

propertiesCORDAProperties

Properties object

Attributes

corso_fbaCORSOModel

CORSO FBA model

block_reactions_from_idxs(rxcat: ndarray)[source]

Block reactions from a list of indices

Parameters

rxcat: np.ndarray

Array of reaction indices

check_if_blocked(rx: int) bool[source]

Check if a reaction is blocked

Parameters

rx: int

Reaction index

Returns

bool

True if the reaction is blocked, False otherwise

static costfx_factory(nl, om, costbase)[source]
do_function_for_reactions_on_both_models(reaction: int, mfunction, corsofunction)[source]

Perform a function on both models

Parameters

reaction: int

Reaction index

mfunction: function

Function to perform on the CBModel

corsofunction: function

Function to perform on the CORSOModel

find_dependent_reactions(rx: int, constraint: int, constrainby: str, costfx, costbase: ndarray, ntimes: int, eps: float) tuple[source]

Find dependent reactions for a given reaction

Parameters

rx: int

Reaction index

constraint: int

Value of the constraint

constrainby: str

either ‘val’ (constrain fluxes by value) or ‘perc’ (constraint by percentage)

costfx: function

Cost function

costbase: np.ndarray

Cost base

ntimes: int

Number of CORSO FBA simulations performed per dependency assessment

eps: float

Epsilon value

Returns

tuple

Dependent reactions and reactions to delete

find_reaction_limits(rx: int) tuple[source]

Find the minimum and maximum flux for a given reaction

Parameters

rx: int

Reaction index

Returns

tuple

Minimum and maximum flux

properties_class

alias of CORDAProperties

run() ndarray[source]

Set up of the variables to be used and calls the run_corda method.

Returns

array

Returns an Array of reaction categories

run_corda(rx_cat: ndarray, constraint: int, constrainby: str, nl: int, ntimes: int, om: float = 10000.0, pr_to_np: float = 2, threads: int = 1) ndarray[source]

Run the CORDA algorithm

Parameters

rx_cat: np.ndarray

Array of reaction categories

constraint: int

Value of the constraint

constrainby: str

either ‘val’ (constrain fluxes by value) or ‘perc’ (constraint by percentage)

nl: int

Number of loops to perform

ntimes: int

Number of CORSO FBA simulations performed per dependency assessment

om: float

Cost assigned to reactions when calculating dependencies

pr_to_np: float

Threshold to include NP reactions if PR reactions depend on them

threads: int

Number of threads to use

Returns

np.ndarray

Returns an Array of reaction categories

class troppo.methods.reconstruction.corda.CORDAProperties(high_conf_rx: list, medium_conf_rx: list, neg_conf_rx: list, pr_to_np: Optional[float] = None, constraint: Optional[int] = None, constrainby: Optional[str] = None, om: Optional[float] = None, ntimes: Optional[int] = None, nl: Optional[int] = None, solver: Optional[str] = None, threads: Optional[int] = None)[source]

Bases: PropertiesReconstruction

Properties reconstruction using CORDA

Parameters

high_conf_rxlist

High confidence reactions

medium_conf_rxlist

Medium confidence reactions

neg_conf_rxlist

Negative confidence reactions

pr_to_npfloat

Threshold to include NP reactions if PR reactions depend on them

constraintint

Value of the constraint

constrainbystr

either ‘val’ (constrain fluxes by value) or ‘perc’ (constraint by percentage)

omfloat

cost assigned to reactions when calculating dependencies

ntimesint

Number of CORSO FBA simulations performed per dependency assessment

nlint or float

Number of loops to perform

solverstr

Solver to use for optimization

threadsint

Number of threads to use

CONSTRAINBY_PERC = 'perc'
CONSTRAINBY_VAL = 'val'
static from_integrated_scores(scores: tuple, **kwargs) CORDAProperties[source]

Create a CORDAProperties object from integrated scores

Parameters

scores: tuple

Tuple of high, medium and negative confidence scores

kwargs: dict

Additional arguments to pass to the constructor

Returns

CORDAProperties

class troppo.methods.reconstruction.corda.CORSOModel(cbmodel, corso_element_names=('R_PSEUDO_CORSO', 'M_PSEUDO_CORSO'), solver=None)[source]

Bases: 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 troppo.methods.reconstruction.corda.CORSOSolution(sol_max, sol_min, f, index_map, var_names, eps=1e-08)[source]

Bases: Solution

A solution to a COBRA FBA problem.

FastCORE Algorithm

class troppo.methods.reconstruction.fastcore.FASTcore(S: ndarray, lb: ndarray, ub: ndarray, properties: FastcoreProperties)[source]

Bases: ContextSpecificModelReconstructionAlgorithm

FASTcore algorithm for context-specific model reconstruction.

Parameters

S: numpy.ndarray

Stoichiometric matrix

lb: numpy.ndarray

Lower bounds

ub: numpy.ndarray

Upper bounds

properties: FastcoreProperties

Properties for the algorithm

LP3(J: ndarray, basis=None) dict[source]

LP3 problem.

Parameters

J: numpy.ndarray

Indices of the reactions to be considered

basis: None

Not used

Returns

dict

Dictionary with the solution of the LP3 problem

LP7(J, basis=None)[source]

LP7 problem.

Parameters

J: numpy.ndarray

Indices of the reactions to be considered

basis: None

Not used

Returns

dict

Dictionary with the solution of the LP3 problem

LP9(K, P)[source]

LP9 problem.

Parameters

K: numpy.ndarray

Indices of the reactions to be considered

P: numpy.ndarray

Indices of the reactions to be considered

Returns

dict

Dictionary with the solution of the LP3 problem

fastcore() list[source]

Fastcore algorithm.

Returns

list

List with the reaction IDs of the reactions in the resulting model

findSparseMode(J: ndarray, P: ndarray, singleton: bool, basis=None) ndarray[source]

Find sparse mode.

Parameters

J: numpy.ndarray or tuple

Indices of the reactions to be considered

P: numpy.ndarray

Indices of the reactions to be considered

singleton: bool

If True, the algorithm will consider only one reaction at a time

basis

List of basis vectors

Returns

numpy.ndarray

generate_LP3_problem()[source]

Generates the LP3 problem.

preprocessing() -> (<class 'numpy.ndarray'>, <class 'numpy.ndarray'>, <class 'numpy.ndarray'>, <class 'numpy.ndarray'>)[source]

Preprocessing of the model.

Returns

np.ndarray, np.ndarray, np.ndarray, np.ndarray

properties_class

alias of FastcoreProperties

reverse_irreversible_reactions_in_reverse_direction(irrev_reverse_idx: ndarray)[source]

Identifies the irreversible reactions in the reverse direction and returns the S matrix with the signals for the metabolites reversed, a vector with the upper bounds as reversed form the lower bounds and a vector with the lower bounds as the reverse of the upper ones.

Parameters

irrev_reverse_idx: numpy.ndarray

Indices of the irreversible reactions in the reverse direction

Returns

S: numpy.ndarray

Modified stoichiometric matrix

ub: numpy.ndarray

Modified upper bounds

lb: numpy.ndarray

Modified lower bounds

run()[source]

Run Fastcore algorithm.

Returns

list

List with the reaction IDs of the reactions in the resulting model

class troppo.methods.reconstruction.fastcore.FastcoreProperties(core: list, flux_threshold: float = 0.0001, solver: Optional[str] = None)[source]

Bases: PropertiesReconstruction

Properties for FASTcore algorithm.

Parameters

core: list

List of reactions that are considered core, as determined by the integrated scores

flux_threshold: float

Flux threshold for the algorithm

solver: str

Solver to be used

static from_integrated_scores(scores: list, **kwargs) FastcoreProperties[source]

Creates a FastcoreProperties object from integrated scores.

Parameters

scores: list

Integrated scores

kwargs: dict

Additional arguments

Returns

FastcoreProperties

FastcoreProperties object

GIMME Algorithm

class troppo.methods.reconstruction.gimme.GIMME(S: list, lb: list, ub: list, properties: GIMMEProperties)[source]

Bases: ContextSpecificModelReconstructionAlgorithm

GIMME algorithm

Parameters

S: list or ndarray

Stoichiometric matrix

lb: list or ndarray

Lower bounds

ub: list or ndarray

Upper bounds

properties: GIMMEProperties

GIMME properties

Attributes

S: ndarray

Stoichiometric matrix

lb: ndarray

Lower bounds

ub: ndarray

Upper bounds

properties: GIMMEProperties

GIMME properties

sol: GIMMESolution

GIMME solution

gm: GIMMEModel

GIMME model

properties_class

alias of GIMMEProperties

run()[source]

Run GIMME algorithm

Returns

list: List with index of active reactions.

class troppo.methods.reconstruction.gimme.GIMMEModel(cbmodel: ConstraintBasedModel, solver: Optional[str] = None)[source]

Bases: ConstraintBasedModel

A GIMME model is a model that is used to reconstruct a context-specific model using the GIMME algorithm.

Parameters:

cbmodel: ConstraintBasedModel

The template model that is used to reconstruct the context-specific model.

solver: str or None

The solver that is used to solve the optimization problem.

Attributes:

cbmodel: ConstraintBasedModel

The template model that is used to reconstruct the context-specific model.

mapping: dict

A dictionary that maps the reactions of the template model to the reactions of the GIMME model.

optimize_gimme(exp_vector: list, objectives: list, obj_frac: list = 0.9, flux_thres: Optional[float] = None)[source]

Optimize the GIMME model.

Parameters

exp_vector: list

A list of expression values for each reaction in the GIMME model.

objectives: list or tuple

A list of dictionaries that define the objectives of the GIMME model.

obj_frac: list or tuple or float

A list of fractions that define the lower bounds of the objectives. If a float is given, the same fraction is used for all objectives.

flux_thres: float

A threshold that defines the minimum flux that is allowed for each reaction in the GIMME model.

Returns

GIMMESolution:

The solution of the GIMME model.

class troppo.methods.reconstruction.gimme.GIMMEProperties(exp_vector: list, objectives: list, obj_frac: list = 0.9, preprocess: bool = False, flux_threshold: Optional[float] = None, solver: Optional[str] = None, reaction_ids: Optional[list] = None, metabolite_ids: Optional[list] = None)[source]

Bases: PropertiesReconstruction

Properties for GIMME

Parameters:

exp_vector: list or ndarray

Expression vector

objectives: list or tuple

List of objective vectors

obj_frac: list or tuple or float

Fraction of the objective vector to be used

preprocess: bool

Preprocess the model

flux_threshold: float

Flux threshold

solver: str

Solver to be used

reaction_ids: list

List of reaction ids

metabolite_ids: list

List of metabolite ids

static from_integrated_scores(scores: list, **kwargs)[source]

Create GIMMEProperties from integrated scores

Parameters

scores: list or ndarray

Integrated scores

kwargs: dict

Additional arguments

Returns

GIMMEProperties

class troppo.methods.reconstruction.gimme.GIMMESolution(sol, exp_vector, var_names, mapping=None)[source]

Bases: Solution

A GIMME solution is a solution of a GIMME model.

Parameters:

sol: Solution

The solution of the GIMME model.

exp_vector: list or ndarray

Expression vector

var_names: list

List of variable names

mapping: dict

A dictionary that maps the reactions of the template model to the reactions of the GIMME model.

get_reaction_activity(flux_threshold: float)[source]

Get the reaction activity of the GIMME solution.

Parameters

flux_threshold: float

The flux threshold that is used to determine the reaction activity.

Returns

reaction_index: list

List of reaction indices from active reactions.

iMAT Algorithm

class troppo.methods.reconstruction.imat.IMAT(S: ndarray, lb: ndarray, ub: ndarray, properties: IMATProperties)[source]

Bases: ContextSpecificModelReconstructionAlgorithm

IMAT algorithm

Parameters

Sndarray

The stoichiometric matrix

lbndarray

The lower bounds

ubndarray

The upper bounds

propertiesIMATProperties

The IMAT properties

Attributes

solLinearSystemOptimizer

The solution

static empty_matrix(r, c)[source]
generate_imat_problem(S, lb, ub, high_idx, low_idx, epsilon)[source]

Generate the IMAT problem

Parameters

S: ndarray

The stoichiometric matrix

lb: ndarray

The lower bounds

ub: ndarray

The upper bounds

high_idx: ndarray

The high index

low_idx: ndarray

The low index

epsilon: float or int

The epsilon value

Returns

lso: LinearSystemOptimizer

The linear system optimizer

lsystem: GenericLinearSystem

The linear system

properties_class

alias of IMATProperties

run()[source]

Run the algorithm and return a list of reactions to keep in the final model.

Returns

list: The list of reactions to keep in the final model

run_imat()[source]

Run the IMAT algorithm

Returns

solution: Solution

Instance with the solution to the IMAT problem

class troppo.methods.reconstruction.imat.IMATProperties(exp_vector: ndarray, exp_thresholds: tuple, core: Optional[ndarray] = None, tolerance: float = 1e-08, epsilon: int = 1)[source]

Bases: PropertiesReconstruction

Properties for IMAT algorithm

Parameters

exp_vectornp.ndarray or list

The vector of expression values

exp_thresholdstuple

The thresholds for the expression values

corelist, optional

The core reactions, by default None

tolerancefloat, optional

The tolerance, by default 1e-8

epsilonfloat, optional

The epsilon, by default 1

static from_integrated_scores(scores: list, **kwargs) IMATProperties[source]

Create IMAT properties from integrated scores

Parameters

scores: list

The list of integrated scores

kwargs: dict

Additional arguments

Returns

IMATProperties: The IMAT properties

SwiftCore Algorithm

class troppo.methods.reconstruction.swiftcore.SWIFTCORE(S: ndarray, lb: ndarray, ub: ndarray, properties: SwiftcoreProperties)[source]

Bases: ContextSpecificModelReconstructionAlgorithm

SWIFTCORE algorithm

Parameters

S: np.ndarray

Stoichiometric matrix

lb: np.ndarray

Lower bounds

ub: np.ndarray

Upper bounds

properties: SwiftcoreProperties

The properties of the algorithm

properties_class

alias of SwiftcoreProperties

run()[source]

Run the algorithm

Returns

np.ndarray : The core of the model

class troppo.methods.reconstruction.swiftcore.SwiftcoreProperties(core: list, weights: list, flux_threshold: int = 0.0001, solver: Optional[str] = None)[source]

Bases: PropertiesReconstruction

static from_integrated_scores(scores, **kwargs)[source]
troppo.methods.reconstruction.swiftcore.find_core(S: ndarray, lb: ndarray, ub: ndarray, blocked: ndarray, weights: ndarray, solver: str) Solution[source]

Find the core of the given model

Parameters

S: np.ndarray

Stoichiometric matrix

lb: np.ndarray

Lower bounds

ub: np.ndarray

Upper bounds

blocked: np.ndarray

Blocked reactions

weights: np.ndarray

Weights

solver: str

The solver to use

Returns

Solution : The solution of the optimization problem

(t)INIT Algorithm

class troppo.methods.reconstruction.tINIT.tINIT(S: ndarray, lb: ndarray, ub: ndarray, properties: tINITProperties)[source]

Bases: ContextSpecificModelReconstructionAlgorithm

The tINIT algorithm.

Parameters

Snp.ndarray

The stoichiometric matrix.

lbnp.ndarray

The lower bounds for the reactions.

ubnp.ndarray

The upper bounds for the reactions.

propertiestINITProperties

The properties for the algorithm.

build_problem()[source]

Builds the problem to be optimized

Returns

preprocessing()[source]

Preprocessing of the algorithm.

Returns

properties_class

alias of tINITProperties

run() array[source]
run_tINIT() array[source]

Runs the tINIT algorithm

Returns

np.array

An array of the reactions that are used in the model

solve_problem()[source]

Solves the problem

Returns

class troppo.methods.reconstruction.tINIT.tINITProperties(reactions_scores: list, present_metabolites: Optional[list] = None, essential_reactions: Optional[list] = None, production_weight: float = 0.5, allow_excretion: bool = False, no_reverse_loops: bool = False, solver: Optional[str] = None)[source]

Bases: PropertiesReconstruction

Properties for the tINIT algorithm.

Parameters

reactions_scoreslist

The scores for each reaction.

present_metaboliteslist, default=[]

The metabolites that are present in the model.

essential_reactionslist, default=[]

The reactions that are essential in the model.

production_weightfloat, default=0.5

The weight of the production reactions.

allow_excretionbool, default=False

Whether to allow excretion.

no_reverse_loopsbool, default=False

Whether to allow reverse loops.

solverstr, default=None

The solver to be used.

static from_integrated_scores(scores: list, **kwargs: dict) tINITProperties[source]

Creates the properties object from integrated scores.

Parameters

scores: list

The integrated scores for each reaction.

kwargs: dict

The other properties.

Returns

tINITProperties

The properties object.