structs.jl 5.03 KB
Newer Older
1

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

anand jain's avatar
anand jain committed
6
    SBML.UnitPart("second",  # base SI unit, this says we are measuring time
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
7
8
9
10
11
12
             -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
anand jain's avatar
anand jain committed
13
[`SBML.Model`](@ref).
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
14
"""
15
16
17
18
19
20
21
22
struct UnitPart
    kind::String
    exponent::Int
    scale::Int
    multiplier::Float64
    UnitPart(k, e, s, m) = new(k, e, s, m)
end

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

"""
Abstract type for all kinds of gene product associations
"""
abstract type GeneProductAssociation end

"""
Gene product reference in the association expression
"""
struct GPARef <: GeneProductAssociation
    gene_product::String
end

"""
Boolean binary "and" in the association expression
"""
struct GPAAnd <: GeneProductAssociation
    terms::Vector{GeneProductAssociation}
end

"""
Boolean binary "or" in the association expression
"""
struct GPAOr <: GeneProductAssociation
    terms::Vector{GeneProductAssociation}
end

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
A simplified representation of MathML-specified math AST
"""
abstract type Math end

"""
A literal value (usually a numeric constant) in mathematical expression
"""
struct MathVal{T} <: Math where {T}
    val::T
end

"""
An identifier (usually a variable name) in mathematical expression
"""
struct MathIdent <: Math
    id::String
end

69
70
71
72
73
74
75
76
"""
A constant identified by name (usually something like `pi`, `e` or `true`) in
mathematical expression
"""
struct MathConst <: Math
    id::String
end

77
78
79
80
81
82
83
84
"""
A special value representing the current time of the simulation, with a special
name.
"""
struct MathTime <: Math
    id::String
end

85
86
87
88
89
90
91
"""
Function application ("call by name", no tricks allowed) in mathematical expression
"""
struct MathApply <: Math
    fn::String
    args::Vector{Math}
end
92

93
94
95
96
97
98
99
100
"""
Function definition (aka "lambda") in mathematical expression
"""
struct MathLambda <: Math
    args::Vector{String}
    body::Math
end

101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""
SBML Compartment with sizing information.
"""
struct Compartment
    name::Maybe{String}
    constant::Maybe{Bool}
    spatial_dimensions::Maybe{Int}
    size::Maybe{Float64}
    units::Maybe{String}
    notes::Maybe{String}
    annotation::Maybe{String}
    Compartment(na, c, sd, s, u, no = nothing, an = nothing) = new(na, c, sd, s, u, no, an)
end

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
115
116
"""
Reaction with stoichiometry that assigns reactants and products their relative
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
117
118
consumption/production rates (accessible in field `stoichiometry`), lower/upper
bounds (in tuples `lb` and `ub`, with unit names), and objective coefficient
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
119
(`oc`). Also may contains `notes` and `annotation`.
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
120
"""
121
122
123
124
125
struct Reaction
    stoichiometry::Dict{String,Float64}
    lb::Tuple{Float64,String}
    ub::Tuple{Float64,String}
    oc::Float64
126
    gene_product_association::Maybe{GeneProductAssociation}
127
    kinetic_math::Maybe{Math}
paulflang's avatar
paulflang committed
128
    reversible::Bool
129
    notes::Maybe{String}
130
    annotation::Maybe{String}
paulflang's avatar
paulflang committed
131
132
    Reaction(s, l, u, o, as, km, r, n = nothing, an = nothing) =
        new(s, l, u, o, as, km, r, n, an)
133
134
end

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
135
"""
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
136
137
Species metadata -- contains a human-readable `name`, a `compartment`
identifier, `formula`, `charge`, and additional `notes` and `annotation`.
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
138
"""
139
struct Species
140
    name::Maybe{String}
141
    compartment::String
142
    boundary_condition::Maybe{Bool}
143
    formula::Maybe{String}
144
    charge::Maybe{Int}
145
146
    initial_amount::Maybe{Tuple{Float64,Maybe{String}}}
    initial_concentration::Maybe{Tuple{Float64,Maybe{String}}}
147
    only_substance_units::Maybe{Bool}
148
    notes::Maybe{String}
149
    annotation::Maybe{String}
150
151
    Species(na, co, b, f, ch, ia, ic, osu, no = nothing, a = nothing) =
        new(na, co, b, f, ch, ia, ic, osu, no, a)
152
153
end

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
154
155
156
157
158
159
160
161
162
163
164
"""
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

165
166
167
168
169
170
171
172
173
174
175
"""
Custom function definition.
"""
struct FunctionDefinition
    name::Maybe{String}
    body::Maybe{Math}
    notes::Maybe{String}
    annotation::Maybe{String}
    FunctionDefinition(na, b, no = nothing, a = nothing) = new(na, b, no, a)
end

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
176
"""
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
177
178
179
180
181
Structure that collects the model-related data. Contains `parameters`, `units`,
`compartments`, `species` and `reactions` and `gene_products`, and additional
`notes` and `annotation` (also present internally in some of the data fields).
The contained dictionaries are indexed by identifiers of the corresponding
objects.
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
182
"""
183
struct Model
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
184
    parameters::Dict{String,Float64}
185
    units::Dict{String,Vector{UnitPart}}
186
    compartments::Dict{String,Compartment}
187
188
    species::Dict{String,Species}
    reactions::Dict{String,Reaction}
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
189
    gene_products::Dict{String,GeneProduct}
190
    function_definitions::Dict{String,FunctionDefinition}
191
    notes::Maybe{String}
192
    annotation::Maybe{String}
193
    Model(p, u, c, s, r, g, f, n = nothing, a = nothing) = new(p, u, c, s, r, g, f, n, a)
194
end