# -*- coding: utf-8 -*-
"""Test functionalities of FASTCC."""
from __future__ import absolute_import
import pytest
import cobra
from cobra.flux_analysis import fastcc, flux_variability_analysis
@pytest.fixture(scope="module")
@pytest.fixture(scope="module")
[docs]def opposing_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 = cobra.Model("opposing")
v1 = cobra.Reaction("v1")
v2 = cobra.Reaction("v2")
v3 = cobra.Reaction("v3")
v4 = cobra.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, benchmark, all_solvers):
"""Benchmark fastcc."""
model.solver = all_solvers
benchmark(fastcc, model)
[docs]def test_opposing(opposing_model, all_solvers):
"""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, all_solvers):
"""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())