Skip to content
Snippets Groups Projects
Commit aed4aa08 authored by ardalan's avatar ardalan
Browse files

exportSBML is now writeSBML

parent 74c920ee
No related branches found
No related tags found
No related merge requests found
...@@ -49,7 +49,7 @@ getSBMLCompartList, ...@@ -49,7 +49,7 @@ getSBMLCompartList,
getSBMLSpeciesList, getSBMLSpeciesList,
getSBMLReactionsList, getSBMLReactionsList,
readSBMLmod, readSBMLmod,
exportSBML, writeSBML,
getSBMLFbcversion, getSBMLFbcversion,
getSBMLmodNotes, getSBMLmodNotes,
getSBMLmodAnnotation getSBMLmodAnnotation
......
...@@ -330,7 +330,7 @@ deformatGene<-function(idstr) { ...@@ -330,7 +330,7 @@ deformatGene<-function(idstr) {
return(idstr) return(idstr)
} }
exportSBML<- function(morg=NULL,level=2,version=4,FbcLevel=0,filename="export.xml",recoverExtMet=TRUE,printNotes=TRUE,printAnnos=TRUE,validation=FALSE ){ writeSBML<- function(morg=NULL,level=2,version=4,fbcLevel=0,filename="export.xml",recoverExtMet=FALSE,printNotes=TRUE,printAnnos=TRUE,validation=FALSE ){
if(class(morg)!="modelorg"){ if(class(morg)!="modelorg"){
stop("morg has to be of class modelorg\n") stop("morg has to be of class modelorg\n")
} }
...@@ -340,7 +340,7 @@ exportSBML<- function(morg=NULL,level=2,version=4,FbcLevel=0,filename="export.xm ...@@ -340,7 +340,7 @@ exportSBML<- function(morg=NULL,level=2,version=4,FbcLevel=0,filename="export.xm
{ {
# test if Matrix has no double values # test if Matrix has no double values
if( !all( S(morg) == floor(S(morg))) ) warning("Level 1 does not support double values") if( !all( S(morg) == floor(S(morg))) ) warning("Level 1 does not support double values")
FbcLevel=0 fbcLevel=0
if(version != 2) if(version != 2)
{ {
warning("just Level 1 Version 2 will be supported") warning("just Level 1 Version 2 will be supported")
...@@ -348,7 +348,7 @@ exportSBML<- function(morg=NULL,level=2,version=4,FbcLevel=0,filename="export.xm ...@@ -348,7 +348,7 @@ exportSBML<- function(morg=NULL,level=2,version=4,FbcLevel=0,filename="export.xm
} }
}else if (level==2) }else if (level==2)
{ {
FbcLevel=0 fbcLevel=0
if(version >5) if(version >5)
{ {
warning("Level 2 Version 5 will be supported") warning("Level 2 Version 5 will be supported")
...@@ -361,7 +361,7 @@ exportSBML<- function(morg=NULL,level=2,version=4,FbcLevel=0,filename="export.xm ...@@ -361,7 +361,7 @@ exportSBML<- function(morg=NULL,level=2,version=4,FbcLevel=0,filename="export.xm
} }
} }
else if (level==3) else if (level==3)
{ if(FbcLevel >2)FbcLevel=2 { if(fbcLevel >2)fbcLevel=2
if(version != 1) if(version != 1)
{ {
print("Level 3 Version 1 will be supported") print("Level 3 Version 1 will be supported")
...@@ -454,10 +454,10 @@ exportSBML<- function(morg=NULL,level=2,version=4,FbcLevel=0,filename="export.xm ...@@ -454,10 +454,10 @@ exportSBML<- function(morg=NULL,level=2,version=4,FbcLevel=0,filename="export.xm
#Have Gene if not ->no need to write in FBC2 #Have Gene if not ->no need to write in FBC2
if(haveform) if(haveform)
{ {
if(FbcLevel==0)met_notes[i]<-sub("FORMULA: [^<]+",paste("FORMULA: ",met_formula[i], sep = ""), met_notes[i], perl = TRUE) if(fbcLevel==0)met_notes[i]<-sub("FORMULA: [^<]+",paste("FORMULA: ",met_formula[i], sep = ""), met_notes[i], perl = TRUE)
else met_notes[i]<-sub(paste("<",tag,">","FORMULA: [^<]+","</",tag,">",sep = ""),"",met_notes[i], perl = TRUE) else met_notes[i]<-sub(paste("<",tag,">","FORMULA: [^<]+","</",tag,">",sep = ""),"",met_notes[i], perl = TRUE)
} }
else if(FbcLevel==0) met_notes[i]<-gsub("</notes>",paste("<",tag,">","FORMULA: ",met_formula[i],"</",tag,">","\n</notes>",sep = ""),met_notes[i]) else if(fbcLevel==0) met_notes[i]<-gsub("</notes>",paste("<",tag,">","FORMULA: ",met_formula[i],"</",tag,">","\n</notes>",sep = ""),met_notes[i])
} }
if (!is.null(met_charge)) if (!is.null(met_charge))
{ {
...@@ -465,13 +465,13 @@ exportSBML<- function(morg=NULL,level=2,version=4,FbcLevel=0,filename="export.xm ...@@ -465,13 +465,13 @@ exportSBML<- function(morg=NULL,level=2,version=4,FbcLevel=0,filename="export.xm
#Have Subsystem #Have Subsystem
if(havecharge) if(havecharge)
{ {
if(FbcLevel !=0 || (level==2 && version==1 )) if(fbcLevel !=0 || (level==2 && version==1 ))
met_notes[i]<-sub(paste("<",tag,">","CHARGE: [^<]+","</",tag,">",sep = ""),"",met_notes[i], perl = TRUE) met_notes[i]<-sub(paste("<",tag,">","CHARGE: [^<]+","</",tag,">",sep = ""),"",met_notes[i], perl = TRUE)
else met_notes[i]<-sub("CHARGE: [^<]+",paste("CHARGE: ",met_charge[i], sep = ""), met_notes[i], perl = TRUE) else met_notes[i]<-sub("CHARGE: [^<]+",paste("CHARGE: ",met_charge[i], sep = ""), met_notes[i], perl = TRUE)
} }
else if(FbcLevel==0) if(level!=2 && version!=1) met_notes[i]<-gsub("</notes>",paste("<",tag,">","CHARGE: ",met_charge[i],"</",tag,">","\n</notes>",sep = ""),met_notes[i]) else if(fbcLevel==0) if(level!=2 && version!=1) met_notes[i]<-gsub("</notes>",paste("<",tag,">","CHARGE: ",met_charge[i],"</",tag,">","\n</notes>",sep = ""),met_notes[i])
} }
} }
} }
...@@ -504,10 +504,10 @@ exportSBML<- function(morg=NULL,level=2,version=4,FbcLevel=0,filename="export.xm ...@@ -504,10 +504,10 @@ exportSBML<- function(morg=NULL,level=2,version=4,FbcLevel=0,filename="export.xm
#Have Gene if not ->no need to write in FBC2 #Have Gene if not ->no need to write in FBC2
if(havegene) if(havegene)
{ {
if(FbcLevel==2) react_notes[i]<-sub(paste("<",tag,">","GENE[_ ]?ASSOCIATION: [^<]+","</",tag,">",sep = ""),"",react_notes[i], perl = TRUE) if(fbcLevel==2) react_notes[i]<-sub(paste("<",tag,">","GENE[_ ]?ASSOCIATION: [^<]+","</",tag,">",sep = ""),"",react_notes[i], perl = TRUE)
else react_notes[i]<-sub("GENE[_ ]?ASSOCIATION: [^<]+",paste("GENE_ASSOCIATION: ",gpr(morg)[i], sep = ""), react_notes[i], perl = TRUE) else react_notes[i]<-sub("GENE[_ ]?ASSOCIATION: [^<]+",paste("GENE_ASSOCIATION: ",gpr(morg)[i], sep = ""), react_notes[i], perl = TRUE)
} }
else if(FbcLevel!=2)react_notes[i]<-gsub("</notes>",paste("<",tag,">","GENE_ASSOCIATION: ",gpr(morg)[i],"</",tag,">","\n</notes>",sep = ""),react_notes[i]) else if(fbcLevel!=2)react_notes[i]<-gsub("</notes>",paste("<",tag,">","GENE_ASSOCIATION: ",gpr(morg)[i],"</",tag,">","\n</notes>",sep = ""),react_notes[i])
#Have Subsystem #Have Subsystem
if(havesub)react_notes[i]<-sub("SUBSYSTEM: [^<]+",paste("SUBSYSTEM: ",newsubS[i], sep = ""), react_notes[i], perl = TRUE) if(havesub)react_notes[i]<-sub("SUBSYSTEM: [^<]+",paste("SUBSYSTEM: ",newsubS[i], sep = ""), react_notes[i], perl = TRUE)
...@@ -532,7 +532,7 @@ exportSBML<- function(morg=NULL,level=2,version=4,FbcLevel=0,filename="export.xm ...@@ -532,7 +532,7 @@ exportSBML<- function(morg=NULL,level=2,version=4,FbcLevel=0,filename="export.xm
success <-.Call("exportSBML", PACKAGE = "sybilSBML", success <-.Call("exportSBML", PACKAGE = "sybilSBML",
as.integer(version), as.integer(version),
as.integer(level), as.integer(level),
as.integer(FbcLevel), as.integer(fbcLevel),
as.character(filename), as.character(filename),
SYBIL_SETTINGS("MAXIMUM"), SYBIL_SETTINGS("MAXIMUM"),
as.character(mod_desc(morg)), as.character(mod_desc(morg)),
......
\name{exportSBML} \name{writeSBML}
\alias{exportSBML} \alias{writeSBML}
\encoding{utf8} \encoding{utf8}
\title{Exports a Metabolic Network in SBML Format} \title{Exports a Metabolic Network in SBML Format}
\description{ \description{
The function exports a metabolic network from S4 object of the class \code{\link{modelorg}} in SBML format. The function The function exports a metabolic network from S4 object of the class \code{\link{modelorg}} in SBML format. The function returns TRUE if the SBML file is successfully built.
returns a success message if exported to SBML file is successfully built.
} }
\usage{ \usage{
exportSBML(morg=NULL,level=2,version=4,FbcLevel=0, writeSBML(morg=NULL,level=2,version=4,fbcLevel=0,
filename="export.xml", filename="export.xml",
recoverExtMet=TRUE, recoverExtMet=FALSE,
printNotes=TRUE, printNotes=TRUE,
printAnnos=TRUE, printAnnos=TRUE,
validation=FALSE) validation=FALSE)
...@@ -32,7 +31,7 @@ ...@@ -32,7 +31,7 @@
A single integer value containing the SBML version for the exporting SBML file. \cr A single integer value containing the SBML version for the exporting SBML file. \cr
Default: \code{4}. Default: \code{4}.
} }
\item{FbcLevel}{ \item{fbcLevel}{
A single integer value containing the fbc package version for the exporting SBML file. \cr A single integer value containing the fbc package version for the exporting SBML file. \cr
Default: \code{2}. Default: \code{2}.
} }
...@@ -42,7 +41,7 @@ ...@@ -42,7 +41,7 @@
} }
\item{recoverExtMet}{ \item{recoverExtMet}{
Boolean: recover external metabolites and refer them to compartment \code{"BOUNDARY"}.\cr Boolean: recover external metabolites and refer them to compartment \code{"BOUNDARY"}.\cr
Default: \code{TRUE}. Default: \code{FALSE}.
} }
\item{printNotes}{ \item{printNotes}{
Boolean: print Notes from original SBML file .\cr Boolean: print Notes from original SBML file .\cr
...@@ -66,7 +65,7 @@ ...@@ -66,7 +65,7 @@
} }
\value{ \value{
A single character string for a success message. A single boolean value for a successful export .
} }
\references{ \references{
...@@ -100,7 +99,7 @@ ...@@ -100,7 +99,7 @@
\note{ \note{
The function \code{exportSBML} makes use of the library The function \code{writeSBML} makes use of the library
\code{libSBML} (\url{http://www.sbml.org}). \code{libSBML} (\url{http://www.sbml.org}).
} }
...@@ -112,7 +111,7 @@ ...@@ -112,7 +111,7 @@
dir <- system.file(package = "sybilSBML", "extdata") dir <- system.file(package = "sybilSBML", "extdata")
file <- file.path(dir, "ecoli_core_model.xml") file <- file.path(dir, "ecoli_core_model.xml")
mod <- readSBMLmod(file, bndCond = FALSE) mod <- readSBMLmod(file, bndCond = FALSE)
exportSBML(mod,level=3,version=1,FbcLevel=2) writeSBML(mod,level=3,version=1,fbcLevel=2)
} }
\keyword{ IO } \keyword{ IO }
......
...@@ -2291,11 +2291,16 @@ SEXP exportSBML (SEXP version, SEXP level,SEXP FbcLevel, SEXP filename,SEXP sybi ...@@ -2291,11 +2291,16 @@ SEXP exportSBML (SEXP version, SEXP level,SEXP FbcLevel, SEXP filename,SEXP sybi
// write SBML file // write SBML file
int result = writeSBML(sbmlDoc, fname); int result = writeSBML(sbmlDoc, fname);
SEXP out = R_NilValue; SEXP out = R_NilValue;
if (result) out = Rf_mkString(append_strings("Wrote file",fname," ")); if (result)
else out = Rf_mkString(append_strings("Failed to write",fname," ")); {
printf("Wrote file %s \n",fname);
out = Rf_ScalarLogical(1);
//UNPROTECT(1); }
else
{
printf("Cloud not write file %s \n",fname);
out = Rf_ScalarLogical(0);
}
return out; return out;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment