flux_variability_analysis.jl 2.47 KB
Newer Older
Sylvain Arreckx's avatar
Sylvain Arreckx committed
1
2
@testset "Flux variability analysis" begin
    cp = test_simpleLP()
3
    optimizer = Tulip.Optimizer
4
    fluxes = flux_variability_analysis(cp, optimizer)
Sylvain Arreckx's avatar
Sylvain Arreckx committed
5
6

    @test size(fluxes) == (2, 2)
7
8
9
10
    @test fluxes  [
        1.0 1.0
        2.0 2.0
    ]
Sylvain Arreckx's avatar
Sylvain Arreckx committed
11

12
    fluxes = flux_variability_analysis(cp, [2], optimizer)
Sylvain Arreckx's avatar
Sylvain Arreckx committed
13
14

    @test size(fluxes) == (1, 2)
cylon-x's avatar
cylon-x committed
15
    @test isapprox(fluxes, [2 2], atol = TEST_TOLERANCE)
Taneli Pusa's avatar
Taneli Pusa committed
16

17
    # a special testcase for slightly sub-optimal FVA (gamma<1)
18
    cp = CoreModel(
19
20
21
22
        [-1.0 -1.0 -1.0],
        [0.0],
        [1.0, 0.0, 0.0],
        [0.0, 0.0, -1.0],
Taneli Pusa's avatar
Taneli Pusa committed
23
24
25
26
        1.0 * ones(3),
        ["r$x" for x = 1:3],
        ["m1"],
    )
27
    fluxes = flux_variability_analysis(cp, optimizer)
cylon-x's avatar
cylon-x committed
28
29
30
31
32
33
34
35
36
    @test isapprox(
        fluxes,
        [
            1.0 1.0
            0.0 0.0
            -1.0 -1.0
        ],
        atol = TEST_TOLERANCE,
    )
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
37
    fluxes = flux_variability_analysis(cp, optimizer; bounds = gamma_bounds(0.5))
cylon-x's avatar
cylon-x committed
38
39
40
41
42
43
44
45
46
    @test isapprox(
        fluxes,
        [
            0.5 1.0
            0.0 0.5
            -1.0 -0.5
        ],
        atol = TEST_TOLERANCE,
    )
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
47
    fluxes = flux_variability_analysis(cp, optimizer; bounds = _ -> (0, Inf))
cylon-x's avatar
cylon-x committed
48
49
50
51
52
53
54
55
56
    @test isapprox(
        fluxes,
        [
            0.0 1.0
            0.0 1.0
            -1.0 0.0
        ],
        atol = TEST_TOLERANCE,
    )
57

58
59
60
    @test isempty(flux_variability_analysis(cp, Vector{Int}(), Tulip.Optimizer))
    @test_throws DomainError flux_variability_analysis(cp, [-1], Tulip.Optimizer)
    @test_throws DomainError flux_variability_analysis(cp, [99999999], Tulip.Optimizer)
Sylvain Arreckx's avatar
Sylvain Arreckx committed
61
end
Taneli Pusa's avatar
Taneli Pusa committed
62
63
64

@testset "Parallel FVA" begin
    cp = test_simpleLP()
65
66

    fluxes = flux_variability_analysis(cp, [1, 2], Tulip.Optimizer; workers = W)
cylon-x's avatar
cylon-x committed
67
68
69
70
71
72
73
74
    @test isapprox(
        fluxes,
        [
            1.0 1.0
            2.0 2.0
        ],
        atol = TEST_TOLERANCE,
    )
Taneli Pusa's avatar
Taneli Pusa committed
75
end
St. Elmo's avatar
St. Elmo committed
76

St. Elmo's avatar
St. Elmo committed
77
@testset "Flux variability analysis with StandardModel" begin
78
    model = load_model(StandardModel, model_paths["e_coli_core.json"])
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
79
    mins, maxs = flux_variability_analysis_dict(
St. Elmo's avatar
St. Elmo committed
80
81
        model,
        Tulip.Optimizer;
cylon-x's avatar
cylon-x committed
82
        bounds = objective_bounds(0.99),
St. Elmo's avatar
St. Elmo committed
83
        modifications = [
84
            change_optimizer_attribute("IPM_IterationsLimit", 500),
85
86
            change_constraint("EX_glc__D_e"; lb = -10, ub = -10),
            change_constraint("EX_o2_e"; lb = 0.0, ub = 0.0),
St. Elmo's avatar
St. Elmo committed
87
88
        ],
    )
St. Elmo's avatar
St. Elmo committed
89

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
90
91
    @test isapprox(maxs["EX_ac_e"]["EX_ac_e"], 8.5185494, atol = TEST_TOLERANCE)
    @test isapprox(mins["EX_ac_e"]["EX_ac_e"], 7.4483887, atol = TEST_TOLERANCE)
St. Elmo's avatar
St. Elmo committed
92
end