loadmodels.jl 5.73 KB
Newer Older
1
2
3

sbmlfiles = [
    # a test model from BIGG
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
4
    (
5
        joinpath(@__DIR__, "data", "e_coli_core.xml"),
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
6
7
8
9
10
        "http://bigg.ucsd.edu/static/models/e_coli_core.xml",
        "b4db506aeed0e434c1f5f1fdd35feda0dfe5d82badcfda0e9d1342335ab31116",
        72,
        95,
    ),
11
    # a relatively new non-curated model from biomodels
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
12
    (
13
        joinpath(@__DIR__, "data", "T1M1133.xml"),
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
14
15
16
17
18
        "https://www.ebi.ac.uk/biomodels/model/download/MODEL1909260004.4?filename=T1M1133.xml",
        "2b1e615558b6190c649d71052ac9e0dc1635e3ad281e541bc7d4fdf2892a5967",
        2517,
        3956,
    ),
19
    # a curated model from biomodels
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
20
    (
21
        joinpath(@__DIR__, "data", "Dasgupta2020.xml"),
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
22
23
24
25
26
        "https://www.ebi.ac.uk/biomodels/model/download/BIOMD0000000973.3?filename=Dasgupta2020.xml",
        "958b131d4df2f215dae68255433542f228601db0326d26a54efd08ddcf823489",
        2,
        6,
    ),
27
28
    # a cool model with `time` from SBML testsuite
    (
29
        joinpath(@__DIR__, "data", "sbml00852.xml"),
30
31
32
33
34
        "https://raw.githubusercontent.com/sbmlteam/sbml-test-suite/master/cases/semantic/00852/00852-sbml-l3v2.xml",
        "d013765aa358d265941420c2e3d81fcbc24b0aa4e9f39a8dc8852debd1addb60",
        4,
        3,
    ),
35
    # another model from SBML suite, with initial concentrations
paulflang's avatar
paulflang committed
36
37
38
39
40
41
42
    (
        joinpath(@__DIR__, "data", "sbml00374.xml"),
        "https://raw.githubusercontent.com/sbmlteam/sbml-test-suite/master/cases/semantic/00374/00374-sbml-l3v2.xml",
        "424683eea6bbb577aad855d95f2de5183a36e296b06ba18b338572cd7dba6183",
        4,
        2,
    ),
43
44
45
46
47
48
49
50
    # this contains some special math
    (
        joinpath(@__DIR__, "data", "sbml01565.xml"),
        "https://raw.githubusercontent.com/sbmlteam/sbml-test-suite/master/cases/semantic/01565/01565-sbml-l3v1.xml",
        "14a80fbce316eea2adb566f67b4668ad151db8954e487309852ece7f730c8c99",
        104,
        52,
    ),
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
51
52
53
54
55
56
57
58
    # this contains l3v1-incompatible contents
    (
        joinpath(@__DIR__, "data", "sbml01289.xml"),
        "https://raw.githubusercontent.com/sbmlteam/sbml-test-suite/master/cases/semantic/01289/01289-sbml-l3v2.xml",
        "35ffa072052970b92fa358ee0f5750394ad74958e889cb85c98ed238642de4d0",
        0,
        0,
    ),
59
60
61
62
63
]

@testset "Loading of models from various sources" begin
    for (sbmlfile, url, hash, expected_mets, expected_rxns) in sbmlfiles
        if !isfile(sbmlfile)
64
            Downloads.download(url, sbmlfile)
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
        end

        cksum = bytes2hex(sha256(open(sbmlfile)))
        if cksum != hash
            @warn "The downloaded model `$sbmlfile' seems to be different from the expected one. Tests will likely fail." cksum
        end

        @testset "Loading of $sbmlfile" begin
            mdl = readSBML(sbmlfile)

            @test typeof(mdl) == Model

            mets, rxns, _ = getS(mdl)

            @test length(mets) == expected_mets
            @test length(rxns) == expected_rxns
        end
    end
end
84
85
86
87
88
89
90
91

@testset "Time variables in math" begin
    # this test is here mainly for keeping a magical constant that we need for
    # parsing time synced with libsbml source
    contains_time(x::SBML.MathTime) = true
    contains_time(x::SBML.MathApply) = any(contains_time.(x.args))
    contains_time(_) = false

92
    m = readSBML(joinpath(@__DIR__, "data", "sbml00852.xml"))
93
94
    @test all(contains_time.(r.kinetic_math for (_, r) in m.reactions))
end
95

96
97
98
99
100
@testset "Units" begin
    m = readSBML(joinpath(@__DIR__, "data", "sbml00852.xml"))
    @test m.units["volume"] == 1 * u"L"
    @test m.units["time"] == 1 * u"s"
    @test m.units["substance"] == 1 * u"mol"
Mosè Giordano's avatar
Mosè Giordano committed
101
102
103
104

    m = readSBML(joinpath(@__DIR__, "data", "units.xml"))
    @test m.units["non_existent"] == 0.00314
    @test m.units["no_dimensions"] == 20.0
105
106
end

107
108
109
@testset "Initial amounts and concentrations" begin
    m = readSBML(joinpath(@__DIR__, "data", "sbml00852.xml"))

110
    @test all(isnothing(ic) for (k, ic) in SBML.initial_concentrations(m))
111
    @test length(SBML.initial_amounts(m)) == 4
112
113
114
115
116
117
    @test isapprox(sum(ia for (sp, ia) in SBML.initial_amounts(m)), 0.001)
    @test isapprox(
        sum(ic for (sp, ic) in SBML.initial_concentrations(m, convert_amounts = true)),
        0.001,
    )

paulflang's avatar
paulflang committed
118
119
120
121
    m = readSBML(joinpath(@__DIR__, "data", "sbml00374.xml"))

    @test all(isnothing(ic) for (k, ic) in SBML.initial_amounts(m))
    @test length(SBML.initial_concentrations(m)) == 4
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
    @test isapprox(sum(ic for (sp, ic) in SBML.initial_concentrations(m)), 0.00208)
    @test isapprox(
        sum(ia for (sp, ia) in SBML.initial_amounts(m, convert_concentrations = true)),
        0.25 * 0.00208,
    )
end

@testset "Extensive kinetic math" begin
    m = readSBML(joinpath(@__DIR__, "data", "sbml00852.xml"))

    subterm =
        SBML.extensive_kinetic_math(m, m.reactions["reaction1"].kinetic_math).args[1].args[2]
    @test subterm.fn == "/"
    @test subterm.args[1] == SBML.MathIdent("S1")
    @test isapprox(subterm.args[2].val, 1.0)
137
end
138
139
140
141
142
143
144
145
146

@testset "logBase and root math functions" begin
    m = readSBML(joinpath(@__DIR__, "data", "sbml01565.xml"))

    @test convert(Num, m.reactions["J23"].kinetic_math) == 0.0

    @variables S29 S29b
    @test isequal(convert(Num, m.reactions["J29"].kinetic_math), 2.0 * S29 * S29b)
end
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
147

148
@testset "converters work and fail gracefully" begin
149
    @test_logs (:error, r"^SBML reported error:") (:error, r"^SBML reported error:") @test_throws ErrorException readSBML(
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
150
151
152
153
154
155
        joinpath(@__DIR__, "data", "sbml01289.xml"),
        doc -> begin
            set_level_and_version(3, 1)(doc)
            convert_simplify_math(doc)
        end,
    )
156
157
158
159
160
161
162
163
164

    test_math =
        readSBML(
            joinpath(@__DIR__, "data", "sbml01565.xml"),
            libsbml_convert("expandInitialAssignments"),
        ).reactions["J31"].kinetic_math

    @test test_math.args[2].fn == "sin"
    @test test_math.args[2].args[1].val == 2.1
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
165
end