Closed HettieC closed 1 year ago
hi! this is in the released version, or develop/next branches? also, which model? (or all of them fail?)
This is a home built model. Not sure about the other branches, but definitely on next
.
I just tested with SBML->JSON and matlab->JSON on current next
and can't reproduce; any repro script welcome
Hi! Sorry for slow response! This is in the next
branch, and this is the script to reproduce:
using COBREXA.Everything, JSON
model = ObjectModel(id = "example")
mets = [Metabolite(string("m",num)) for num = 1:2]
add_metabolites!(model,mets)
rxn = Reaction("r1", Dict("m1" => -1, "m2"=>1))
add_reaction!(model,rxn)
open("example_model.json","w") do io
JSON.print(io,convert(JSONModel, model))
end
and it produces the file example_model.json
which starts with { "json": { "metabolites": [ {
and does not show up as a model when used in escher. Possibly it's a problem with the JSON
package and not with cobrexa.
Is there a built in function to save models that I'm missing?
ah yes, you're serializing the whole JSON model structure even with the COBREXA wrapper, which produces the "json" part. JSON package is too smart here and actually handles this without an error, despite it technically should be one.
You should be able to use
save_model(model, "example_model.json")
...to do this directly.
Alternatively, you can fix your example by extracting the JSON part of the model as follows:
JSON.print(io,convert(JSONModel, model).json)
OK great, thanks!
Did that fix it? (I'd close the issue)
Yeah it does :)
In the #next branch: Using
convert(JSONModel, model)
produces a json file with the first line{ "json": { "metabolites": [
, but escher doesn't recognise this format, it works if you get ride of the{"json":
, so that the first line is instead{ "metabolites": [
.