ecoli_flux.jl 2.21 KB
Newer Older
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
1

2
sbmlfile = joinpath(@__DIR__, "data", "Ec_core_flux1.xml")
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
3
4

if !isfile(sbmlfile)
5
    Downloads.download(
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
6
7
8
        "http://systemsbiology.ucsd.edu/sites/systemsbiology.ucsd.edu/files/Attachments/Images/InSilicoOrganisms/Ecoli/Ecoli_SBML/Ec_core_flux1.xml",
        sbmlfile,
    )
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
9
10
end

11
12
13
cksum = bytes2hex(sha256(open(sbmlfile)))
if cksum != "01a883b364fa60582101ca1e270515e7fcb3fb2f60084d92e5ee45f9f72bbe50"
    @warn "The downloaded E Coli core flux model seems to be different from the expected one. Tests will likely fail." cksum
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
14
15
end

16
@testset "SBML flux model loading" begin
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
17
    mdl = readSBML(sbmlfile)
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
18
19

    @test typeof(mdl) == Model
Laurent Heirendt's avatar
Laurent Heirendt committed
20

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
21
22
23
    @test_logs (:error, "SBML reported error: File unreadable.") @test_throws AssertionError readSBML(
        sbmlfile * ".does.not.really.exist",
    )
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
24

Mosè Giordano's avatar
Mosè Giordano committed
25
    @test mdl.units["mmol_per_gDW_per_hr"]  3.6001008028224795 * u"mol * g^-1 * s^-1"
26

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
27
    @test length(mdl.compartments) == 2
Laurent Heirendt's avatar
Laurent Heirendt committed
28

29
    mets, rxns, S = stoichiometry_matrix(mdl)
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
30

31
    @test typeof(S) <: AbstractMatrix{Float64}
32
33
    @test typeof(stoichiometry_matrix(mdl; zeros = spzeros)[3]) <: SparseMatrixCSC{Float64}
    @test typeof(stoichiometry_matrix(mdl; zeros = zeros)[3]) == Matrix{Float64}
34

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
35
36
    @test length(mets) == 77
    @test length(rxns) == 77
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
37
    @test size(S) == (length(mets), length(rxns))
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
38
39
40
41
42
43

    # totally arbitrary value tests
    @test isapprox(sum(S), 42.1479)
    @test mets[10:12] == ["M_akg_e", "M_fum_c", "M_pyr_c"]
    @test rxns[10:12] == ["R_H2Ot", "R_PGL", "R_EX_glc_e_"]

44
45
    lbs, ubs = flux_bounds(mdl)
    ocs = flux_objective(mdl)
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
46
47
48
49
50
51

    @test length(ocs) == length(mets)
    @test ocs[40] == 1.0
    deleteat!(ocs, 40)
    @test all(ocs .== 0.0)

52
53
    @test length(flux_bounds(mdl)[1]) == length(rxns)
    @test length(flux_bounds(mdl)[2]) == length(rxns)
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
54

55
    getunit((val, unit)) = unit
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
56
57
    @test all([broadcast(getunit, lbs) broadcast(getunit, ubs)] .== "mmol_per_gDW_per_hr")

58
    getval((val, unit)) = val
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
59
60
61
62
63
64
65
66
67
    lvals = broadcast(getval, lbs)
    uvals = broadcast(getval, ubs)
    @test isapprox(lvals[27], uvals[27])
    @test isapprox(lvals[27], 7.6)
    @test isapprox(lvals[12], -10)

    @test count(isapprox.(lvals, -999999)) == 40
    @test count(isapprox.(lvals, 0)) == 35
    @test count(isapprox.(uvals, 999999)) == 76
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
68
end