"""Test functionalities of FASTCC."""
from typing import Callable, List
import pytest
from cobra import Model, Reaction
from cobra.flux_analysis import fastcc, flux_variability_analysis
@pytest.fixture(scope="module")
@pytest.fixture(scope="module")
[docs]def opposing_model() -> Model:
"""Generate a toy model with opposing reversible reactions.
This toy model ensures that two opposing reversible reactions do not
appear as blocked.
"""
test_model = Model("opposing")
v1 = Reaction("v1")
v2 = Reaction("v2")
v3 = Reaction("v3")
v4 = Reaction("v4")
test_model.add_reactions([v1, v2, v3, v4])
v1.reaction = "-> 2 A"
v2.reaction = "A -> C" # Later made reversible via bounds.
v3.reaction = "D -> C" # Later made reversible via bounds.
v4.reaction = "D ->"
v1.bounds = 0.0, 3.0
v2.bounds = -3.0, 3.0
v3.bounds = -3.0, 3.0
v4.bounds = 0.0, 3.0
test_model.objective = v4
return test_model
[docs]def test_fastcc_benchmark(
model: Model, benchmark: Callable, all_solvers: List[str]
) -> None:
"""Benchmark fastcc."""
model.solver = all_solvers
benchmark(fastcc, model)
[docs]def test_opposing(opposing_model: Model, all_solvers: List[str]) -> None:
"""Test FASTCC."""
opposing_model.solver = all_solvers
consistent_model = fastcc(opposing_model)
expected_reactions = {"v1", "v2", "v3", "v4"}
assert expected_reactions == {rxn.id for rxn in consistent_model.reactions}
[docs]def test_fastcc_against_fva_nonblocked_rxns(
model: Model, all_solvers: List[str]
) -> None:
"""Test non-blocked reactions obtained by FASTCC against FVA."""
model.solver = all_solvers
fastcc_consistent_model = fastcc(model)
fva = flux_variability_analysis(model, fraction_of_optimum=0.0)
nonblocked_rxns_fva = fva.index[
(fva.minimum.abs() > model.tolerance) | (fva.maximum.abs() > model.tolerance)
]
assert all(fastcc_consistent_model.reactions) == all(nonblocked_rxns_fva.tolist())