Skip to content
Snippets Groups Projects
Commit ec9b7e1b authored by Miroslav Kratochvil's avatar Miroslav Kratochvil :bicyclist:
Browse files

unsupport `name` field in models

It looks great but we aren't going to support it in core MetabolicModel
interface. Moreover, it's only a prettification, which the users may manage
externally.

Closes #392 (name support will be implemented elsewhere)
parent 1b2fa49e
No related branches found
No related tags found
No related merge requests found
...@@ -4,17 +4,15 @@ Gene struct. ...@@ -4,17 +4,15 @@ Gene struct.
# Fields # Fields
```` ````
id :: String id :: String
name :: Union{String, Nothing}
notes :: Dict{String, Vector{String}} notes :: Dict{String, Vector{String}}
annotation :: Dict{String, Union{Vector{String}, String}} annotation :: Dict{String, Union{Vector{String}, String}}
```` ````
""" """
mutable struct Gene mutable struct Gene
id::String id::String
name::Maybe{String}
notes::Notes notes::Notes
annotations::Annotations annotations::Annotations
Gene(id::String = ""; name = nothing, notes = Notes(), annotations = Annotations()) = Gene(id::String = ""; notes = Notes(), annotations = Annotations()) =
new(id, name, notes, annotations) new(id, notes, annotations)
end end
...@@ -4,7 +4,6 @@ Metabolite structure. ...@@ -4,7 +4,6 @@ Metabolite structure.
# Fields # Fields
```` ````
id :: String id :: String
name :: String
formula :: String formula :: String
charge :: Int charge :: Int
compartment :: String compartment :: String
...@@ -14,7 +13,6 @@ annotation :: Dict{String, Union{Vector{String}, String}} ...@@ -14,7 +13,6 @@ annotation :: Dict{String, Union{Vector{String}, String}}
""" """
mutable struct Metabolite mutable struct Metabolite
id::String id::String
name::Maybe{String}
formula::Maybe{String} formula::Maybe{String}
charge::Maybe{Int} charge::Maybe{Int}
compartment::Maybe{String} compartment::Maybe{String}
...@@ -23,11 +21,10 @@ mutable struct Metabolite ...@@ -23,11 +21,10 @@ mutable struct Metabolite
Metabolite( Metabolite(
id = ""; id = "";
name = nothing,
formula = nothing, formula = nothing,
charge = nothing, charge = nothing,
compartment = nothing, compartment = nothing,
notes = Notes(), notes = Notes(),
annotations = Annotations(), annotations = Annotations(),
) = new(id, name, formula, charge, compartment, notes, annotations) ) = new(id, formula, charge, compartment, notes, annotations)
end end
""" """
mutable struct Reaction mutable struct Reaction
id::String id::String
name::Maybe{String}
metabolites::Dict{String,Float64} metabolites::Dict{String,Float64}
lb::Float64 lb::Float64
ub::Float64 ub::Float64
...@@ -16,7 +15,6 @@ A structure for representing a single reaction in a [`StandardModel`](@ref). ...@@ -16,7 +15,6 @@ A structure for representing a single reaction in a [`StandardModel`](@ref).
""" """
mutable struct Reaction mutable struct Reaction
id::String id::String
name::Maybe{String}
metabolites::Dict{String,Float64} metabolites::Dict{String,Float64}
lb::Float64 lb::Float64
ub::Float64 ub::Float64
...@@ -30,7 +28,6 @@ end ...@@ -30,7 +28,6 @@ end
""" """
Reaction( Reaction(
id = ""; id = "";
name = nothing,
metabolites = Dict{String,Float64}(), metabolites = Dict{String,Float64}(),
lb = -_constants.default_reaction_bound, lb = -_constants.default_reaction_bound,
ub = _constants.default_reaction_bound, ub = _constants.default_reaction_bound,
...@@ -47,7 +44,6 @@ explicitely assigned. ...@@ -47,7 +44,6 @@ explicitely assigned.
""" """
function Reaction( function Reaction(
id = ""; id = "";
name = nothing,
metabolites = Dict{String,Float64}(), metabolites = Dict{String,Float64}(),
lb = -_constants.default_reaction_bound, lb = -_constants.default_reaction_bound,
ub = _constants.default_reaction_bound, ub = _constants.default_reaction_bound,
...@@ -60,7 +56,6 @@ function Reaction( ...@@ -60,7 +56,6 @@ function Reaction(
mets = Dict(k => float(v) for (k, v) in metabolites) mets = Dict(k => float(v) for (k, v) in metabolites)
return Reaction( return Reaction(
id, id,
name,
mets, mets,
lb, lb,
ub, ub,
......
...@@ -301,7 +301,7 @@ function Base.convert(::Type{StandardModel}, model::MetabolicModel) ...@@ -301,7 +301,7 @@ function Base.convert(::Type{StandardModel}, model::MetabolicModel)
gid; gid;
notes = gene_notes(model, gid), notes = gene_notes(model, gid),
annotations = gene_annotations(model, gid), annotations = gene_annotations(model, gid),
) # TODO: add name accessor )
end end
for mid in metids for mid in metids
...@@ -333,7 +333,7 @@ function Base.convert(::Type{StandardModel}, model::MetabolicModel) ...@@ -333,7 +333,7 @@ function Base.convert(::Type{StandardModel}, model::MetabolicModel)
notes = reaction_notes(model, rid), notes = reaction_notes(model, rid),
annotations = reaction_annotations(model, rid), annotations = reaction_annotations(model, rid),
subsystem = reaction_subsystem(model, rid), subsystem = reaction_subsystem(model, rid),
) # TODO: add name accessor )
end end
return StandardModel( return StandardModel(
......
...@@ -18,7 +18,6 @@ Shallow copy of a [`Reaction`](@ref) ...@@ -18,7 +18,6 @@ Shallow copy of a [`Reaction`](@ref)
""" """
Base.copy(r::Reaction) = Reaction( Base.copy(r::Reaction) = Reaction(
r.id; r.id;
name = r.name,
metabolites = r.metabolites, metabolites = r.metabolites,
lb = r.lb, lb = r.lb,
ub = r.ub, ub = r.ub,
...@@ -36,7 +35,6 @@ Shallow copy of a [`Metabolite`](@ref) ...@@ -36,7 +35,6 @@ Shallow copy of a [`Metabolite`](@ref)
""" """
Base.copy(m::Metabolite) = Metabolite( Base.copy(m::Metabolite) = Metabolite(
m.id; m.id;
name = m.name,
formula = m.formula, formula = m.formula,
charge = m.charge, charge = m.charge,
compartment = m.compartment, compartment = m.compartment,
...@@ -49,7 +47,7 @@ Base.copy(m::Metabolite) = Metabolite( ...@@ -49,7 +47,7 @@ Base.copy(m::Metabolite) = Metabolite(
Shallow copy of a [`Gene`](@ref) Shallow copy of a [`Gene`](@ref)
""" """
Base.copy(g::Gene) = Gene(g.id; name = g.name, notes = g.notes, annotations = g.annotations) Base.copy(g::Gene) = Gene(g.id; notes = g.notes, annotations = g.annotations)
""" """
atom_exchange(model::StandardModel, rxn_id::String) atom_exchange(model::StandardModel, rxn_id::String)
......
...@@ -202,8 +202,7 @@ end ...@@ -202,8 +202,7 @@ end
""" """
function remove_reactions(m::CoreModelCoupled, rxns::Vector{String}) function remove_reactions(m::CoreModelCoupled, rxns::Vector{String})
rxn_indices = rxn_indices = [findfirst(isequal(rid), m.lm.rxns) for rid in intersect(rxns, m.lm.rxns)]
[findfirst(isequal(name), m.lm.rxns) for name in intersect(rxns, m.lm.rxns)]
if isempty(rxn_indices) if isempty(rxn_indices)
return m return m
else else
......
...@@ -2,23 +2,16 @@ ...@@ -2,23 +2,16 @@
g = Gene() g = Gene()
# test defaults # test defaults
@test isnothing(g.name)
@test isempty(g.notes) @test isempty(g.notes)
@test isempty(g.annotations) @test isempty(g.annotations)
# Now assign # Now assign
g.id = "gene1" g.id = "gene1"
g.name = "gene_name"
g.notes = Dict("notes" => ["blah", "blah"]) g.notes = Dict("notes" => ["blah", "blah"])
g.annotations = Dict("sboterm" => ["sbo"], "ncbigene" => ["ads", "asds"]) g.annotations = Dict("sboterm" => ["sbo"], "ncbigene" => ["ads", "asds"])
# Test pretty printing # Test pretty printing
@test all( @test all(contains.(sprint(show, MIME("text/plain"), g), ["gene1", "blah", "asds"]))
contains.(
sprint(show, MIME("text/plain"), g),
["gene1", "gene_name", "blah", "asds"],
),
)
# Test duplicate annotation finder # Test duplicate annotation finder
g2 = Gene("gene2") g2 = Gene("gene2")
......
@testset "Metabolite" begin @testset "Metabolite" begin
m1 = Metabolite() m1 = Metabolite()
m1.id = "met1" m1.id = "met1"
m1.name = "metabolite 1"
m1.formula = "C6H12O6N" m1.formula = "C6H12O6N"
m1.charge = 1 m1.charge = 1
m1.compartment = "c" m1.compartment = "c"
...@@ -11,7 +10,7 @@ ...@@ -11,7 +10,7 @@
@test all( @test all(
contains.( contains.(
sprint(show, MIME("text/plain"), m1), sprint(show, MIME("text/plain"), m1),
["met1", "metabolite 1", "C6H12O6N", "blah", "asds"], ["met1", "C6H12O6N", "blah", "asds"],
), ),
) )
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
r1 = Reaction() r1 = Reaction()
r1.id = "r1" r1.id = "r1"
r1.name = "reaction 1"
r1.metabolites = Dict(m1.id => -1.0, m2.id => 1.0) r1.metabolites = Dict(m1.id => -1.0, m2.id => 1.0)
r1.lb = -100.0 r1.lb = -100.0
r1.ub = 100.0 r1.ub = 100.0
...@@ -33,7 +32,7 @@ ...@@ -33,7 +32,7 @@
@test all( @test all(
contains.( contains.(
sprint(show, MIME("text/plain"), r1), sprint(show, MIME("text/plain"), r1),
["r1", "reaction 1", "100.0", "g1 and g2", "glycolysis", "blah", "biocyc"], ["r1", "100.0", "g1 and g2", "glycolysis", "blah", "biocyc"],
), ),
) )
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
r1 = Reaction() r1 = Reaction()
r1.id = "r1" r1.id = "r1"
r1.name = "reaction 1"
r1.metabolites = Dict(m1.id => -1.0, m2.id => 1.0) r1.metabolites = Dict(m1.id => -1.0, m2.id => 1.0)
r1.lb = -100.0 r1.lb = -100.0
r1.ub = 100.0 r1.ub = 100.0
...@@ -35,7 +34,7 @@ ...@@ -35,7 +34,7 @@
r4.annotations = Dict("sboterm" => ["sbo"], "biocyc" => ["ads", "asds"]) r4.annotations = Dict("sboterm" => ["sbo"], "biocyc" => ["ads", "asds"])
mets = [m1, m2, m3, m4] mets = [m1, m2, m3, m4]
gs = [g1, g2, g3] # DO NOT name variables the names of accessor functions! gs = [g1, g2, g3]
rxns = [r1, r2, r3, r4] rxns = [r1, r2, r3, r4]
model = StandardModel() model = StandardModel()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment