Gapfilling Methods

Combinatorial Gapfilling Algorithm

class troppo.methods.gapfill.consensus.CombinatorialGapfill(template_model, tasks, min_acceptable_tasks=0.5)[source]

Bases: object

This Class uses a combinatorial gap-filling algorithm to remove reactions to the final model

Parameters

template_modeldict

A dictionary containing the template model. Must contain {S, lb, ub} and possibly rx_names/met_names.

task_dictdict

A dictionary containing the tasks that need to be completed by the final model.

min_acceptable_tasksint or float (default: 0.5)

The minimum number of tasks that need to be completed by the final model. If an integer is provided, this is the minimum number of tasks that need to be completed. If a float is provided, this is the minimum percentage of tasks.

build_final_model(partials: dict, start_from: int, lost_metabolic_tasks: dict, lost_reaction_sets: dict, validators: dict) set[source]

This method builds the final model by adding reactions to the partial model that completes the most tasks.

Parameters

partials: dict

A dictionary containing the partial models.

start_from: int

The index of the partial model to start from.

lost_metabolic_tasks: dict

A dictionary containing the tasks that were lost when a reaction was removed from the model.

lost_reaction_sets: dict

A dictionary containing the reactions that were removed from the model.

validators: dict

A dictionary containing the TaskValidator instances.

Returns

final_model: set

A set containing the indices of the reactions that are present in the final model.

gapfill(rx_presences: list) Iterable[source]

This method performs gap-filling to build the final model.

Parameters

rx_presences: list

A list containing the indices of the reactions that are present in the model.

Returns

final_model: list

A list containing the indices of the reactions that are present in the final model.

static generate_partial_models(rx_presences: list) dict[source]

Generates partial models from the presence/absence of reactions in the template model.

Parameters

rx_presences: list

A list containing the indices of the reactions that are present in the model.

Returns

partial_models: dict

A dictionary containing the partial models.

is_valid_model(tasks: set, ko: int, validator: TaskEvaluator) bool[source]

This method checks if a model is valid by testing the presence of the tasks after removing a reaction.

Parameters

tasks: set

A set containing the indices of the tasks to be tested.

ko: int

The index of the reaction to be knocked out.

validator: TaskEvaluator

A TaskEvaluator instance.

Returns

valid: bool

A boolean indicating if the model is valid.

Elementary Flux Mode Gapfilling Algorithm

class troppo.methods.gapfill.efm.EFMGapfill(S: ndarray, lb: ndarray, ub: ndarray, properties: EFMGapfillProperties)[source]

Bases: GapfillAlgorithm

Gap-filling algorithm based on the KShortestEFMAlgorithm.

Parameters:

S: ndarray

Stoichiometric matrix.

lb: ndarray

Lower bounds.

ub: ndarray

Upper bounds.

properties: EFMGapfillProperties

Properties for the algorithm.

gapfill(avbl_fluxes: list, lsystem_args: dict, solver: str) Iterable[source]

Gap-filling algorithm based on the KShortestEFMAlgorithm.

Parameters

avbl_fluxes: list

Available fluxes.

lsystem_args: dict

Dictionary of arguments to be passed to the IrreversibleLinearPatternSystem.

solver: str

Solver to be used by the IrreversibleLinearPatternSystem.

Returns

enumerator: Iterable

Enumerator for the EFM Gap-filling algorithm.

get_enumerator(S: ndarray, lb: ndarray, ub: ndarray, avbl_fluxes: list, solver: str, lsystem_args: dict) Iterable[source]

Get the enumerator for the EFM Gap-filling algorithm.

Parameters

S: ndarray

Stoichiometric matrix.

lb: ndarray

Lower bounds.

ub: ndarray

Upper bounds.

avbl_fluxes: list

Available fluxes.

solver: str

Solver to be used by the IrreversibleLinearPatternSystem.

lsystem_args: dict

Dictionary of arguments to be passed to the IrreversibleLinearPatternSystem.

Returns

enumerator: Iterable

Enumerator for the EFM Gap-filling algorithm.

properties_class

alias of EFMGapfillProperties

run() list[source]

Run the EFM Gap-filling algorithm.

Returns

result: list

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

class troppo.methods.gapfill.efm.EFMGapfillProperties(avbl_fluxes: list, lsystem_args: dict, solver: str = 'GLPK', kshproperties: ~cobamp.algorithms.kshortest.KShortestProperties = N_THREADS = 0 FORCE_NON_CANCEL = True BIGMVALUE = 1000000.0 BIGM_CONSTS = True MAXSOLUTIONS = 1 TIMELIMIT = 0 METHOD = ITERATE)[source]

Bases: GapfillProperties

Properties for the EFM Gap-filling algorithm.

Parameters:

avbl_fluxes: list

List of available fluxes.

lsystem_args: dict

Dictionary of arguments to be passed to the IrreversibleLinearPatternSystem.

solver: str

Solver to be used by the IrreversibleLinearPatternSystem.

kshproperties: KShortestProperties

Properties for the KShortestEFMAlgorithm.

FastCC Gapfilling Algorithm

class troppo.methods.gapfill.fastcc.FastCC(S: ndarray, lb: ndarray, ub: ndarray, properties: dict)[source]

Bases: FASTcore

FASTCC gap-filling method for the reconstruction of metabolic models using the FASTcore algorithm.

Parameters

Snumpy.ndarray

The stoichiometric matrix of the model.

lbnumpy.ndarray

The lower bounds of the model.

ubnumpy.ndarray

The upper bounds of the model.

propertiesdict

The properties of the model.

fastcc()[source]

FASTCC algorithm.

Returns

self.Anumpy.ndarray

The set of reactions that are flux consistent.

self.Vnumpy.ndarray

The flux vectors of the flux consistent reactions.

self.incInumpy.ndarray

The set of irreversible reactions that are flux inconsistent.

self.irrev_reversenumpy.ndarray

The set of irreversible reactions that are in reverse direction.

prepocessing()[source]

Preprocessing of the model.

run()[source]

Run Fastcore algorithm.

Returns

list

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

class troppo.methods.gapfill.fastcc.FastCCProperties(flux_threshold: float, method: str, solver: str)[source]

Bases: PropertiesReconstruction, ABC

Properties for FastCC

Parameters

flux_thresholdfloat

Flux threshold

methodstr

‘original’ or ‘nonconvex’

solverstr

Solver to use

Pathway Analysis Gapfilling Algorithm

class troppo.methods.gapfill.pathway_analysis.CombinatorialEFMGapfill(template_model, media)[source]

Bases: object

combinatorial_gapfill(sample_models, model_approval_fx)[source]
gapfill_partial_pair(m0, m1, model_approval_fx)[source]
generate_partial_models(sample_models)[source]
prune_model(to_keep)[source]
class troppo.methods.gapfill.pathway_analysis.SubEFMGapfill(template_model: dict, task_reactions, subset_forced_reactions, iterative=True, max_time: int = 0, max_threads: int = 0, big_m: bool = False, big_m_value: int = 1000, solver: Optional[str] = None, at_most_n_sols: int = 1, populate_max_size: Optional[int] = None)[source]

Bases: object

Solve the gap-filling problem using an Elementary Flux Mode enumeration algorithm.

Parameters

template_model: dict

The template model for the gap-filling problem. Must contain {S, lb, ub} and possibly rx_names/met_names.

task_reactions

Contains the task reactions.

subset_forced_reactions

Contains the indexes of the forced reactions’ subset.

iterative: bool

Flag to determine whether the k-shortest algorithm behaviour.

max_time: int

Maximum time for the algorithm to run.

max_threads: int

Maximum number of threads to be used.

big_m: bool

Flag to determine whether to use big-M constraints.

big_m_value: int

Value of the big-M constraints.

solver: str

Solver to be used by the IrreversibleLinearPatternSystem.

at_most_n_sols: int

Maximum number of solutions to be returned.

populate_max_size: int

Maximum size of the population.

gapfill(missing_set, forced=(), non_forced=())[source]

Gapfill the model using the task reactions and the subset of forced reactions.

Parameters

missing_set

Dictionary containing the indexes of the missing reactions.

forced:

Dictionary containing the indexes of the forced reactions.

non_forced:

Dictionary containing the indexes of the non-forced reactions.

Returns

List of solutions.

troppo.methods.gapfill.pathway_analysis.simulate_context(model, context, objective, sense, sol_approval_fx)[source]