Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
exaexa committed Oct 23, 2024
2 parents cf5ba8a + 0f10c31 commit 8542c3b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "COBREXA"
uuid = "babc4406-5200-4a30-9033-bf5ae714c842"
authors = ["The developers of COBREXA.jl"]
version = "1.5.1"
version = "1.5.2"

[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand Down Expand Up @@ -31,17 +31,17 @@ DistributedData = "0.1.4, 0.2"
DocStringExtensions = "0.8, 0.9"
Downloads = "1"
GLPK = "1"
HDF5 = "0.16"
HDF5 = "0.16, 0.17"
JSON = "0.21"
JuMP = "1"
LinearAlgebra = "1"
MAT = "0.10"
MacroTools = "0.5.6"
OrderedCollections = "1.4"
PikaParser = "0.5"
PikaParser = "0.5, 0.6"
Pkg = "1"
Random = "1"
SBML = "~1.3, ~1.4"
SBML = "~1.3, ~1.4, ~1.5"
SHA = "0.7, 1"
Serialization = "1"
SparseArrays = "1"
Expand Down
36 changes: 27 additions & 9 deletions src/base/types/JSONModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ JSONModel(json::Dict{String,Any}) = begin
end

function _parse_annotations(x)::Annotations
Annotations([k => if typeof(v) == String
Annotations([k => if v isa String
[v]
elseif v isa AbstractDict
string.(collect(v))
else
convert(Vector{String}, v)
end for (k, v) in x])
Expand Down Expand Up @@ -161,6 +163,7 @@ Parses the `.gene_reaction_rule` from reactions.
reaction_gene_association(model::JSONModel, rid::String) = _maybemap(
_parse_grr,
get(model.rxns[model.rxn_index[rid]], "gene_reaction_rule", nothing),
nothing,
)

"""
Expand All @@ -176,8 +179,11 @@ $(TYPEDSIGNATURES)
Parse and return the metabolite `.formula`
"""
metabolite_formula(model::JSONModel, mid::String) =
_maybemap(_parse_formula, get(model.mets[model.met_index[mid]], "formula", nothing))
metabolite_formula(model::JSONModel, mid::String) = _maybemap(
_parse_formula,
get(model.mets[model.met_index[mid]], "formula", nothing),
nothing,
)

"""
$(TYPEDSIGNATURES)
Expand All @@ -203,15 +209,19 @@ Gene annotations from the [`JSONModel`](@ref).
gene_annotations(model::JSONModel, gid::String)::Annotations = _maybemap(
_parse_annotations,
get(model.genes[model.gene_index[gid]], "annotation", nothing),
Annotations(),
)

"""
$(TYPEDSIGNATURES)
Gene notes from the [`JSONModel`](@ref).
"""
gene_notes(model::JSONModel, gid::String)::Notes =
_maybemap(_parse_notes, get(model.genes[model.gene_index[gid]], "notes", nothing))
gene_notes(model::JSONModel, gid::String)::Notes = _maybemap(
_parse_notes,
get(model.genes[model.gene_index[gid]], "notes", nothing),
Notes(),
)

"""
$(TYPEDSIGNATURES)
Expand All @@ -221,15 +231,19 @@ Reaction annotations from the [`JSONModel`](@ref).
reaction_annotations(model::JSONModel, rid::String)::Annotations = _maybemap(
_parse_annotations,
get(model.rxns[model.rxn_index[rid]], "annotation", nothing),
Annotations(),
)

"""
$(TYPEDSIGNATURES)
Reaction notes from the [`JSONModel`](@ref).
"""
reaction_notes(model::JSONModel, rid::String)::Notes =
_maybemap(_parse_notes, get(model.rxns[model.rxn_index[rid]], "notes", nothing))
reaction_notes(model::JSONModel, rid::String)::Notes = _maybemap(
_parse_notes,
get(model.rxns[model.rxn_index[rid]], "notes", nothing),
Notes(),
)

"""
$(TYPEDSIGNATURES)
Expand All @@ -239,15 +253,19 @@ Metabolite annotations from the [`JSONModel`](@ref).
metabolite_annotations(model::JSONModel, mid::String)::Annotations = _maybemap(
_parse_annotations,
get(model.mets[model.met_index[mid]], "annotation", nothing),
Annotations(),
)

"""
$(TYPEDSIGNATURES)
Metabolite notes from the [`JSONModel`](@ref).
"""
metabolite_notes(model::JSONModel, mid::String)::Notes =
_maybemap(_parse_notes, get(model.mets[model.met_index[mid]], "notes", nothing))
metabolite_notes(model::JSONModel, mid::String)::Notes = _maybemap(
_parse_notes,
get(model.mets[model.met_index[mid]], "notes", nothing),
Notes(),
)

"""
$(TYPEDSIGNATURES)
Expand Down
7 changes: 4 additions & 3 deletions src/base/types/abstract/Maybe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ end
"""
$(TYPEDSIGNATURES)
Apply a function to `x` only if it is not `nothing`.
Apply a function to `x` only if it is not `nothing`. Returns `f(x)` when
applied, otherwise returns `default`.
"""
function _maybemap(f, x::Maybe)::Maybe
isnothing(x) ? nothing : f(x)
function _maybemap(f, x::Maybe, default = nothing)::Maybe
isnothing(x) ? default : f(x)
end
2 changes: 2 additions & 0 deletions src/base/utils/gene_associations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ const _grr_grammar = begin
x == '-' ||
x == ':' ||
x == '.' ||
x == '@' ||
x == '#' ||
x == '\'' ||
x == '[' ||
x == ']' ||
Expand Down

0 comments on commit 8542c3b

Please sign in to comment.