structs.jl 3.31 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

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

"""
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


Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
59
60
"""
Reaction with stoichiometry that assigns reactants and products their relative
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
61
62
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
63
(`oc`). Also may contains `notes` and `annotation`.
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
64
"""
65
66
67
68
69
struct Reaction
    stoichiometry::Dict{String,Float64}
    lb::Tuple{Float64,String}
    ub::Tuple{Float64,String}
    oc::Float64
70
    gene_product_association::Maybe{GeneProductAssociation}
71
    notes::Maybe{String}
72
    annotation::Maybe{String}
73
    Reaction(s, l, u, o, as, n = nothing, an = nothing) = new(s, l, u, o, as, n, an)
74
75
end

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
76
"""
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
77
78
Species metadata -- contains a human-readable `name`, a `compartment`
identifier, `formula`, `charge`, and additional `notes` and `annotation`.
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
79
"""
80
81
82
struct Species
    name::String
    compartment::String
83
    formula::Maybe{String}
84
85
    charge::Maybe{Int}
    notes::Maybe{String}
86
87
    annotation::Maybe{String}
    Species(na, co, f, ch, no = nothing, a = nothing) = new(na, co, f, ch, no, a)
88
89
end

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
90
91
92
93
94
95
96
97
98
99
100
"""
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
101
"""
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
102
103
104
105
106
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
107
"""
108
struct Model
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
109
    parameters::Dict{String,Float64}
110
111
112
113
    units::Dict{String,Vector{UnitPart}}
    compartments::Vector{String}
    species::Dict{String,Species}
    reactions::Dict{String,Reaction}
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
114
    gene_products::Dict{String,GeneProduct}
115
    notes::Maybe{String}
116
    annotation::Maybe{String}
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
117
    Model(p, u, c, s, r, g, n = nothing, a = nothing) = new(p, u, c, s, r, g, n, a)
118
end