structs.jl 2.48 KB
Newer Older
1

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
2
3
4
5
6
7
"""
    Maybe{X}

Type shortcut for "`X` or nothing" or "nullable `X`" in javaspeak. Name
got inspired by our functional friends.
"""
8
9
const Maybe{X} = Union{Nothing,X}

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
10
"""
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
11
Part of a measurement unit definition that corresponds to the SBML definition
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
12
of `Unit`. For example, the unit "per square megahour", Mh^(-2), is written as:
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
13

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
14
15
16
17
18
19
20
21
    UnitPart("second",  # base SI unit, this says we are measuring time
             -2,        # exponent, says "per square"
             6,         # log-10 scale of the unit, says "mega"
             1/3600)    # second-to-hour multiplier

Compound units (such as "volt-amperes" and "dozens of yards per ounce") are
built from multiple `UnitPart`s; see the definition of field `units` in
[`Model`](@ref).
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
22
"""
23
24
25
26
27
28
29
30
struct UnitPart
    kind::String
    exponent::Int
    scale::Int
    multiplier::Float64
    UnitPart(k, e, s, m) = new(k, e, s, m)
end

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
31
32
"""
Reaction with stoichiometry that assigns reactants and products their relative
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
33
34
35
consumption/production rates (accessible in field `stoichiometry`), lower/upper
bounds (in tuples `lb` and `ub`, with unit names), and objective coefficient
(`oc`).
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
36
"""
37
38
39
40
41
struct Reaction
    stoichiometry::Dict{String,Float64}
    lb::Tuple{Float64,String}
    ub::Tuple{Float64,String}
    oc::Float64
42
    notes::Maybe{String}
43
44
    annotation::Maybe{String}
    Reaction(s, l, u, o, n = nothing, a = nothing) = new(s, l, u, o, n, a)
45
46
end

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
47
"""
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
48
49
Species metadata -- contains a human-readable `name`, and a `compartment`
identifier
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
50
"""
51
52
53
struct Species
    name::String
    compartment::String
54
    formula::String
55
56
    charge::Maybe{Int}
    notes::Maybe{String}
57
58
    annotation::Maybe{String}
    Species(na, co, f, ch, no = nothing, a = nothing) = new(na, co, f, ch, no, a)
59
60
end

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
61
62
63
64
65
66
67
68
69
70
71
"""
Gene product metadata.
"""
struct GeneProduct
    name::Maybe{String}
    label::Maybe{String}
    notes::Maybe{String}
    annotation::Maybe{String}
    GeneProduct(na, l, no = nothing, a = nothing) = new(na, l, no, a)
end

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
72
"""
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
73
74
75
Structure that collects the model-related data. Contains `units`,
`compartments`, `species` and `reactions`. The contained dictionaries are
indexed by identifiers of the corresponding objects.
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
76
"""
77
struct Model
St. Elmo's avatar
St. Elmo committed
78
    params::Dict{String,Float64}
79
80
81
82
    units::Dict{String,Vector{UnitPart}}
    compartments::Vector{String}
    species::Dict{String,Species}
    reactions::Dict{String,Reaction}
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
83
    gene_products::Dict{String,GeneProduct}
84
    notes::Maybe{String}
85
    annotation::Maybe{String}
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
86
    Model(p, u, c, s, r, g, n = nothing, a = nothing) = new(p, u, c, s, r, g, n, a)
87
end