LCSB-BioCore / COBREXA.jl

Constraint-Based Reconstruction and EXascale Analysis
https://lcsb-biocore.github.io/COBREXA.jl/
Apache License 2.0
42 stars 8 forks source link

JSON model format incompatible with escher #758

Closed HettieC closed 1 year ago

HettieC commented 1 year ago

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": [.

exaexa commented 1 year ago

hi! this is in the released version, or develop/next branches? also, which model? (or all of them fail?)

stelmo commented 1 year ago

This is a home built model. Not sure about the other branches, but definitely on next.

exaexa commented 1 year ago

I just tested with SBML->JSON and matlab->JSON on current next and can't reproduce; any repro script welcome

HettieC commented 1 year ago

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?

exaexa commented 1 year ago

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)
HettieC commented 1 year ago

OK great, thanks!

exaexa commented 1 year ago

Did that fix it? (I'd close the issue)

HettieC commented 1 year ago

Yeah it does :)