gapseq icon indicating copy to clipboard operation
gapseq copied to clipboard

loss of model attributes when converting SBML to RDS causing error in gapfilling

Open estebano11 opened this issue 1 year ago • 6 comments

for bug reports and errors please report the output of: ./gapseq test Hi, Thank you for the software, I am finding it very useful. I added reactions in different compartments (extracellular, periplasm, etc) in the sbml file (xml) because I find it easier working on python instead of R. But I wanted to know if I can convert this file into RDS to make use of the gapfilling process. Do you think this is feasible?

Thank you!

Esteban.

estebano11 avatar Aug 11 '22 16:08 estebano11

hi, yes you can load xml files in R using the package sybilSBML

library(sybilSBML)
mod <- readSBMLmod("my.xml")
saveRDS(mod, "my.RDS")

jotech avatar Aug 15 '22 08:08 jotech

Hi, thanks for the reply.

Sorry in my first comment didn't specify with details. I have done this but I have an error when I want to use the RDS file with gapseq. Doing with ecoli in toys:

gapseq fill -m ecoli-draft.RDS -n ecoli-medium.csv -g ecoli-rxnXgenes.RDS -c ecoli-rxnWeights.RDS
...
Final growth rate:     1.941537 

Uptake at limit:
Maltose:2.5, NH3:10, N-Acetyl-D-glucosamine:5, Neu5Ac:5, Melitose:1.67, Sucrose:2.5, O2:12.5 

Top 10 produced metabolites:
H+:50.658, Acetate:49.47, H2O:34.554, CO2:20.421, H2:2.635, EX cpd11416 c0:1.942, Galactose:1.67, 5-Methylthio-D-ribose:0.007 
Warning message:
Model file already exists and will be overwritten! 
Wrote file ecoli.xml
Patching file ecoli.xml ... done

Then I use ecoli.xml to read it and export in RDS (I am aware that gapseq generate the RDS, but just to demostrate in the case when I want to modify the xml and then use it to gapfill)

library(sybilSBML)
mod <- readSBMLmod("ecoli.xml")
> mod <- readSBMLmod("ecoli.xml")
reading SBML file ... OK
getting the model ... OK
creating S and parsing constraints ... OK
GPR mapping ... OK
cleaning up ... OK
validating object ... OK
> mod
model name:              
number of compartments  3 
                        c0 
                        e0 
                        p0 
number of reactions:    3035 
number of metabolites:  2451 
number of unique genes: 1252 
objective function:     +1 EX_cpd11416_c0 

saveRDS(mod, "ecoli2.RDS")

When I want to use ecoli2.RDS in gapseq I have the following error:

gapseq fill -m ecoli2.RDS -n ecoli-medium.csv -g ecoli-rxnXgenes.RDS -c ecoli-rxnWeights.RDS
Loading model files ecoli2.RDS 
Error in `[.data.frame`(mod.orig@mod_attr, , "annotation") : 
  selezionate colonne non definite
Calls: grepl -> [ -> [.data.frame
Esecuzione interrotta

gapseq version: 1.2 315f35d

I attach the files generated just in case. Do you know if I can solve this issue?

Thanks ecoli.zip !

estebano11 avatar Aug 15 '22 10:08 estebano11

Hi, I see; thanks for the clarification! The problem is some data loss from importing and exporting the model again. I just committed a quick fix for this, but we should also take care of the data loss in general.

jotech avatar Aug 19 '22 14:08 jotech

Reproducible example for the divergence in model attributes that could cause errors when a sbml is imported in R and used as input for gapfilling:

library(sybilSBML)
library(sybil)

mod.rds <- readRDS("toy/ecoli.RDS")
mod.sbml <- readSBMLmod("toy/ecoli.xml.gz")

mod.sbml@mod_attr
                                                                                                                notes
1 <notes>\n  <html xmlns="http://www.w3.org/1999/xhtml">\n    <p>gapseq version: 1.1 4a17997</p>\n  </html>\n</notes>

mod.rds@mod_attr
           annotation
1 tax_domain:Bacteria

dim(mod.rds@react_attr)
[1] 3029   26
dim(mod.sbml@react_attr)
[1] 3029    1


dim(mod.sbml@met_attr)
[1] 2451    3
dim(mod.rds@met_attr)
[1] 2451   29

jotech avatar Aug 19 '22 14:08 jotech

I adapted the issue name to make it clearer

jotech avatar Aug 19 '22 14:08 jotech

Hi jotech, Thank you for the reply. Now is clear why I can't do this. I modified my script to use it in R, so I add the reactions to the draft RDS file instead of the xml using addReact(). In this way now I can work, if you can find the solution to export RDS from xml would be useful also.

Thanks!

Esteban.

estebano11 avatar Aug 22 '22 12:08 estebano11

Hi,

I'm afraid, that we can't get the additional columns exported to sbml.

SBML has only limited and pre-defined columns of model, reaction and metabolite attributes that are exported. In the RDS file, we keep some additional information that is helpful for debugging and further analysis – information that gets lost when exporting to SBML.

Waschina avatar Sep 05 '22 15:09 Waschina

Hi Silvio, Thank you for the reply and take care about this. I will work directly on the RDS files through the sybil package then. I will close this thread but the help was useful to know this issue I was having.

Thanks.

estebano11 avatar Sep 05 '22 15:09 estebano11