corneto.methods.MultiSampleFBA#

class corneto.methods.MultiSampleFBA(lambda_reg=0.0, beta_reg=0.0, flux_indicator_name='edge_has_flux', disable_structured_sparsity=False, default_flow_upper_bound=None, default_flow_lower_bound=None, backend=None)#

Bases: FlowMethod

Flux Balance Analysis (FBA) method for multiple samples.

This class implements Flux Balance Analysis for metabolic networks across multiple samples. It supports sparsity regularization and reaction objectives.

Note

The graph is expected to be a genome scale metabolic network. It can also be imported in SBML format (XML) using the corneto.io.import_cobra_model function (requires cobrapy).

Flux Balance Analysis calculates metabolic fluxes by optimizing an objective such as biomass production subject to stoichiometric constraints.

MultiSampleFBA extends traditional FBA to analyze multiple samples or conditions simultaneously.

Parameters:
  • flux_indicator_name (str)

  • disable_structured_sparsity (bool)

  • default_flow_upper_bound (float | None)

  • default_flow_lower_bound (float | None)

  • backend (Backend | None)

lambda_reg#

Regularization parameter to minimize the number of active reactions across samples (only when samples > 1).

Type:

float

beta_reg#

Additional regularization parameter for controlling sparsity individually for each sample.

Type:

float

flux_indicator_name#

Name of the variable used to indicate active fluxes.

Type:

str

disable_structured_sparsity#

Whether to disable structured sparsity optimization.

Type:

bool

backend#

The optimization backend to use.

Type:

Backend

Examples

Basic usage with a single condition:

>>> from corneto.io import import_miom_model
>>> from corneto.methods.fba import MultiSampleFBA
>>> model = import_miom_model("path/to/metabolic_model.miom")
>>> P = MultiSampleFBA().build(
...     model,
...     objectives={"EX_biomass_e": -1},
... )
>>> P.solve()

Multi-condition analysis with a reaction knockout:

>>> P = MultiSampleFBA().build_many(
...     model,
...     objectives={
...         "control": {"EX_biomass_e": -1},
...         "knockout": {"EX_biomass_e": -1},
...     },
...     reaction_bounds={
...         "control": {},
...         "knockout": {"MDHm": (0, 0)},
...     },
... )
__init__(lambda_reg=0.0, beta_reg=0.0, flux_indicator_name='edge_has_flux', disable_structured_sparsity=False, default_flow_upper_bound=None, default_flow_lower_bound=None, backend=None)#

Initialize a MultiSampleFBA instance.

Parameters:
  • lambda_reg (float, optional) – Primary sparsity regularization. Higher values encourage fewer active reactions. Defaults to 0.0.

  • beta_reg (float, optional) – Secondary regularization parameter for sparsity. Used when both types of regularization are needed. Defaults to 0.0.

  • flux_indicator_name (str, optional) – Name for the flux indicator variables. These track whether a reaction is active. Defaults to “edge_has_flux”.

  • disable_structured_sparsity (bool, optional) – Disable structured sparsity optimization. Defaults to False.

  • default_flow_lower_bound (float, optional) – Default reaction lower bound when the graph does not provide one.

  • default_flow_upper_bound (float, optional) – Default reaction upper bound when the graph does not provide one.

  • backend (Optional[Backend], optional) – The optimization backend to use. If None, the default backend is used. Defaults to None.

Methods

__init__([lambda_reg, beta_reg, ...])

Initialize a MultiSampleFBA instance.

build(model[, data, objectives, reaction_bounds])

Build a single-condition FBA problem from explicit inputs.

build_from_data(graph[, data])

Build the complete optimization problem.

build_many(model, *[, objectives, ...])

Build a multi-condition FBA problem from named condition mappings.

create_flow_based_problem(flow_problem, ...)

Create the flow-based optimization problem.

create_problem(graph, data)

Create the optimization problem using a flow-based formulation.

description()

Returns a description of the method.

get_flow_bounds(graph, data)

Return sample-specific flux bounds for the flow formulation.

name()

Returns the name of the method.

preprocess(graph, data)

Preprocess the graph and data before solving.

references()

Return citation keys for the method.

show_bibtex()

Display raw BibTeX entries in a formatted block for easy copying.

show_references()

Display formatted citations in a Jupyter notebook.

Attributes

backend

Return the optimization backend being used.

build(model, data=None, *, objectives=None, reaction_bounds=None)#

Build a single-condition FBA problem from explicit inputs.

Parameters:
build_many(model, *, objectives=None, reaction_bounds=None)#

Build a multi-condition FBA problem from named condition mappings.

Parameters:

model (BaseGraph)

preprocess(graph, data)#

Preprocess the graph and data before solving.

This can be extended with flux-consistent preprocessing such as removing blocked reactions or dead-end metabolites.

Parameters:
  • graph (BaseGraph) – The metabolic network graph to be analyzed.

  • data (Data) – The experimental data containing sample information.

Returns:

The preprocessed graph and data.

Return type:

Tuple[BaseGraph, Data]

get_flow_bounds(graph, data)#

Return sample-specific flux bounds for the flow formulation.

Parameters:
Return type:

Dict[str, Any]

create_flow_based_problem(flow_problem, graph, data)#

Create the flow-based optimization problem.

Parameters:
  • flow_problem – The optimization problem object.

  • graph (BaseGraph) – The metabolic network graph.

  • data (Data) – The experimental data containing sample information.

Returns:

The configured optimization problem ready to be solved.

static references()#

Return citation keys for the method.