Commit 04a398bb authored by Claus Jonathan Fritzemeier's avatar Claus Jonathan Fritzemeier
Browse files

merged master with writeSBML branch

parents 4f3015c4 3b8f5e09
Package: sybilSBML
Type: Package
Title: SBML Integration in Package 'Sybil'
Version: 2.0.11
Date: 2016-06-06
Version: 3.0.1
Date: 2016-12-16
Authors@R: c(person(c("C.", "Jonathan"), "Fritzemeier", role = c("cre", "ctb"), email = "clausjonathan.fritzemeier@uni-duesseldorf.de"),
person("Gabriel", "Gelius-Dietrich", role = c("aut", "ctb")),
person("Deya", "Alzoubi", role = "ctb"))
person("Deya", "Alzoubi", role = "ctb"),
person("Ardalan", "Habil", role = "ctb"))
Maintainer: C. Jonathan Fritzemeier <clausjonathan.fritzemeier@uni-duesseldorf.de>
Depends: R (>= 2.14.2), Matrix, sybil (>= 2.0.0)
Imports: methods
Description: 'SBML' (Systems Biology Markup Language) integration in 'sybil'. Many constraint based metabolic models are published in 'SBML' format ('*.xml'). Herewith is the ability to read and check 'SBML' files in 'sybil' provided.
Description: 'SBML' (Systems Biology Markup Language) with FBC (Flux Balance Constraints) integration in 'sybil'. Many constraint based metabolic models are published in 'SBML' format ('*.xml'). Herewith is the ability to read, write, and check 'SBML' files in 'sybil' provided.
License: GPL-3 | file LICENSE
LazyLoad: yes
Collate: generics.R sbmlPtrClass.R sbmlErrorClass.R sybilSBML.R
uglyHack.R readSBMLmod.R zzz.R
Packaged: 2015-06-06 07:11:55 UTC; jonathan
Packaged: 2016-12-16 07:11:55 UTC; jonathan
Author: C. Jonathan Fritzemeier [cre, ctb],
Gabriel Gelius-Dietrich [aut, ctb],
Deya Alzoubi [ctb]
Deya Alzoubi [ctb],
Ardalan Habil [ctb]
NeedsCompilation: yes
Repository: CRAN
......@@ -48,5 +48,9 @@ getSBMLunitDefinitionsList,
getSBMLCompartList,
getSBMLSpeciesList,
getSBMLReactionsList,
readSBMLmod
readSBMLmod,
writeSBML,
getSBMLFbcversion,
getSBMLmodNotes,
getSBMLmodAnnotation
)
......@@ -247,7 +247,13 @@ parseNotesReact <- function(notes) {
gpr <- sub("GENE[_ ]?ASSOCIATION: *", "", fields_str[j])
gene_rule <- sybil:::.parseBoolean(gpr)
#print(gene_rule)
}
}#Ardalan Habil
else if (grepl("GPR[_ ]?ASSOCIATION", fields_str[j])) {
gpr <- sub("GPR[_ ]?ASSOCIATION: *", "", fields_str[j])
gene_rule <- sybil:::.parseBoolean(gpr)
}
if (charmatch("SUBSYSTEM", fields_str[j], nomatch = -1) != -1) {
subSyst <- sub("SUBSYSTEM: *", "", fields_str[j])
subSyst <- sub("^S_", "", subSyst, perl = TRUE)
......@@ -283,6 +289,14 @@ sbmldoc <- openSBMLfile(filename)
message("OK")
# warning if new Version/Level/
SBMLlevel<- getSBMLlevel(sbmldoc)
SBMLversion<- getSBMLversion(sbmldoc)
FBCversion<-getSBMLFbcversion(sbmldoc)
if(SBMLlevel == 3 && SBMLversion > 1)
warning(paste("No support for Level 3 Version ",SBMLversion))
if (FBCversion > 2)
warning(paste("No support for Fbc Version ",FBCversion))
#------------------------------------------------------------------------------#
# check the model #
......@@ -380,6 +394,7 @@ if (mdesc == filename) {
sybil::mod_desc(mod) <- mdesc
#------------------------------------------------------------------------------#
# units #
#------------------------------------------------------------------------------#
......@@ -398,7 +413,7 @@ if (is.null(compartmentsList)) {
}
missingId(compartmentsList)
sybil::mod_compart(mod) <- compartmentsList[["id"]]
comp_tmp_id <- compartmentsList[["id"]]
#------------------------------------------------------------------------------#
......@@ -430,6 +445,7 @@ missingId(metabolitesList)
metSpIds <- metabolitesList[["id"]]
#nummet <- getSBMLnumSpecies(sbmlmod)
if (isTRUE(bndCond)) {
metSpBnd <- metabolitesList[["boundaryCondition"]]
met_id_pos <- !metSpBnd
......@@ -485,12 +501,20 @@ gpr <- character(numreact)
hasNotes <- FALSE
hasAnnot <- FALSE
#FBC contraints @Ardalan Habil
fbclowbnd<-reactionsList[["fbc_lowbnd"]]
fbcuppbnd<-reactionsList[["fbc_uppbnd"]]
fbcgprRules<-reactionsList[["fbc_gprRules"]]
fbcObjectives<-reactionsList[["fbc_Objectives"]]
for (i in 1 : numreact) {
# the notes/annotations field
notes <- reactionsList[["notes"]][i]
annot <- reactionsList[["annotation"]][i]
# Notes und Annotation can be null ( @Ardalan Habil)
if(!is.null( reactionsList[["notes"]]))
if (nchar(notes) > 0) {
hasNotes <- TRUE
......@@ -504,7 +528,7 @@ for (i in 1 : numreact) {
}
else {
if(!is.null( reactionsList[["annotation"]]))
if (nchar(annot) > 0) {
hasAnnot <- TRUE
pn <- regexpr("Pathway Name: [^<]+", annot, perl = TRUE)
......@@ -512,7 +536,18 @@ for (i in 1 : numreact) {
}
}
fbcgene_rule <- NA
if ( !is.null(fbcgprRules))
{
fbcgene_rule<- sybil:::.parseBoolean(fbcgprRules[i])
genes[[i]] <- fbcgene_rule$gene # list of genes
rules[i] <- fbcgene_rule$rule # rules
gpr[i] <- fbcgprRules[i]
}
# Check here if reactants and products lists exist, same for the stoichiometry slot
......@@ -565,6 +600,16 @@ for (i in 1 : numreact) {
# }
# the constraints
#FBC contraints @Ardalan Habil
if ( !is.null(fbclowbnd) && !is.null(fbcuppbnd))
{
lbnd[i] <- checkupplowbnd(fbclowbnd[i])
ubnd[i] <- checkupplowbnd(fbcuppbnd[i])
}
#read from kinetic_law if fbc is empty
else
{
parm <- reactionsList[["kinetic_law"]][[i]]
if (is.null(parm)) {
ubnd[i] <- def_bnd
......@@ -591,10 +636,16 @@ for (i in 1 : numreact) {
# reduced cost? (sbml file)
}
}
}
#FBC Objective @Ardalan Habil
if(!is.null(fbcObjectives))
{
ocof[i]<-as.numeric(fbcObjectives[i])
}
}
# ---------------------------------------------------------------------------- #
# search for unused metabolites and unused reactions
......@@ -877,7 +928,7 @@ else {
rules <- rules[SKIP_REACTION]
gpr <- gpr[SKIP_REACTION]
if (isTRUE(hasNotes)) {
if (isTRUE(hasNotes) || !is.null(fbcgprRules) ) {
message("GPR mapping ... ", appendLF = FALSE)
#allGenes <- unique(allGenes)
......@@ -897,14 +948,13 @@ else {
if ( (length(genes[[i]] == 1)) && (genes[[i]] != "") ) {
geneInd <- match(genes[[i]], allGenes)
rxnGeneMat[i, geneInd] <- TRUE
# no use because new gprRule format
# for (j in 1 : length(geneInd)) {
# pat <- paste("x(", j, ")", sep = "")
# repl <- paste("x[", geneInd[j], "]", sep = "")
#
# rules[i] <- gsub(pat, repl, rules[i], fixed = TRUE)
# }
for (j in 1 : length(geneInd)) {
pat <- paste("x(", j, ")", sep = "")
repl <- paste("x[", geneInd[j], "]", sep = "")
rules[i] <- gsub(pat, repl, rules[i], fixed = TRUE)
}
}
}
......@@ -970,6 +1020,63 @@ react_name_tmp <- sub( "\\s+$", "", react_name_tmp, perl = TRUE)
sybil::react_name(mod) <- react_name_tmp
#------------------------------------------------------------------------------#
# Reaction Attr @Ardalan #
#------------------------------------------------------------------------------#
# Test for new Slots
if( .hasSlot(mod,"mod_attr") && .hasSlot(mod,"comp_attr") && .hasSlot(mod,"met_attr") && .hasSlot(mod,"react_attr") )
newSybil<-TRUE
else newSybil<-FALSE
numreact<-nummet <- sum(SKIP_REACTION)
reactannotation <- reactionsList[["annotation"]][SKIP_REACTION]
reactnotes <- reactionsList[["notes"]][SKIP_REACTION]
if(newSybil)
{
sybil::react_attr(mod) <-data.frame(row.names=1:numreact)
#Speed optimierung durch notes NULL falls nichts drin steht
if( !is.null(reactannotation) && length(reactannotation)==numreact )sybil::react_attr(mod)[['annotation']]<-reactannotation
if( !is.null(reactnotes) && length(reactnotes)==numreact )sybil::react_attr(mod)[['notes']]<-reactnotes
}
#------------------------------------------------------------------------------#
# Model Attr @Ardalan #
#------------------------------------------------------------------------------#
modanno<-getSBMLmodAnnotation(sbmlmod)
modnotes<-getSBMLmodNotes(sbmlmod)
if(newSybil)
{
sybil::mod_attr(mod) <-data.frame(row.names=1)
if(nchar(modanno)>1)sybil::mod_attr(mod)[['annotation']]<-modanno
if(nchar(modnotes)>1)sybil::mod_attr(mod)[['notes']]<-modnotes
}
#------------------------------------------------------------------------------#
# compartments Attr @Ardalan #
#------------------------------------------------------------------------------#
# Define SKIP_COMPARTMENT FALSE= HAS NO REFERENCE
met_comp_tmp <- metabolitesList[["compartment"]][met_id_pos][SKIP_METABOLITE]
SKIP_COMPARTMENT<- comp_tmp_id %in% unique(met_comp_tmp)
sybil::mod_compart(mod) <- comp_tmp_id[SKIP_COMPARTMENT]
numcom<-length(mod_compart(mod))
comannotation <- compartmentsList[["annotation"]][SKIP_COMPARTMENT]
comnotes <- compartmentsList[["notes"]][SKIP_COMPARTMENT]
if(newSybil)
{
sybil::comp_attr(mod) <-data.frame(row.names=1:numcom)
if( !is.null(comannotation) && length(comannotation)==numcom )sybil::comp_attr(mod)[['annotation']]<-comannotation
if( !is.null(comnotes) && length(comnotes)==numcom )sybil::comp_attr(mod)[['notes']]<-comnotes
}
#------------------------------------------------------------------------------#
# metabolite id's #
#------------------------------------------------------------------------------#
......@@ -985,7 +1092,7 @@ sybil::met_id(mod) <- gsub("-", "_", met_id_tmp, fixed = TRUE)
# metabolite compartments #
#------------------------------------------------------------------------------#
met_comp_tmp <- metabolitesList[["compartment"]][met_id_pos][SKIP_METABOLITE]
#met_comp_tmp <- metabolitesList[["compartment"]][met_id_pos][SKIP_METABOLITE]
sybil::met_comp(mod) <- match(met_comp_tmp, sybil::mod_compart(mod))
......@@ -1002,6 +1109,69 @@ met_name_tmp <- sub( "\\s+$", "", met_name_tmp, perl = TRUE)
sybil::met_name(mod) <- met_name_tmp
#------------------------------------------------------------------------------#
# metabolite attr @Ardalan Habil #
#------------------------------------------------------------------------------#
#ChemicalFormula Charge Notes Annotation MetaID @Ardalan Habil
metformula <- metabolitesList[["chemicalFormula"]][met_id_pos][SKIP_METABOLITE]
metcharge <- metabolitesList[["charge"]][met_id_pos][SKIP_METABOLITE]
metnotes <- metabolitesList[["notes"]][met_id_pos][SKIP_METABOLITE]
metannotation <- metabolitesList[["annotation"]][met_id_pos][SKIP_METABOLITE]
metchargenote<-NULL
metformulanote<-NULL
# check metnotes for Formula and Charge
if( !is.null(metnotes) && length(metnotes==nummet))
{
pn <- regexpr("FORMULA: [^<]+", metnotes, perl = TRUE)
metformulanote <- substr(metnotes, (pn+9), pn + ((attr(pn, "match.length"))-1))
pn <- regexpr("CHARGE: [^<]+", metnotes, perl = TRUE)
metchargenote <- substr(metnotes, (pn+8), pn + ((attr(pn, "match.length"))-1))
metchargenote <- as.integer(metchargenote)
metchargenote[is.na(metchargenote)] <- 0
}
nummet <- sum(SKIP_METABOLITE)
if(newSybil)
{
# save attributes to met_attr slot
sybil::met_attr(mod) <-data.frame(row.names=1:nummet)
if( !is.null(metformula) && length(metformula)==nummet)
{sybil::met_attr(mod)[['chemicalFormula']]<-metformula}
else{
if(length(metformulanote)==nummet)
{ if(max(nchar(metformulanote)) >0)
sybil::met_attr(mod)[['chemicalFormula']]<-metformulanote
}
}
if( !is.null(metcharge) && length(metcharge)==nummet && sum(metcharge)!=0)
{sybil::met_attr(mod)[['charge']]<-metcharge}
else{
if( length(metchargenote)==nummet)
{ if(max(nchar(metchargenote)) >0)
sybil::met_attr(mod)[['charge']]<-metchargenote
}
}
if( !is.null(metnotes) && length(metnotes)==nummet)sybil::met_attr(mod)[['notes']]<-metnotes
if( !is.null(metannotation) && length(metannotation)==nummet)sybil::met_attr(mod)[['annotation']]<-metannotation
# Save boundaryCondition when bndCond=FALSE
if (!isTRUE(bndCond)) {
metBnd <- metabolitesList[["boundaryCondition"]][met_id_pos][SKIP_METABOLITE]
# When all metBnd = False -> metabolite removed by extMetFlag
if( !is.null(metBnd) && length(metBnd)==nummet && !all(metBnd == FALSE) )sybil::met_attr(mod)[['boundaryCondition']]<-metBnd
}
}
#------------------------------------------------------------------------------#
# check reversibilities #
#------------------------------------------------------------------------------#
......
#------------------------------------------------------------------------------#
# Link to libSBML for sybil #
#------------------------------------------------------------------------------#
# sybilSBML.R
# Link to libSBML for sybil.
#
# Copyright (C) 2010-2013 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics,
# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany.
# All right reserved.
# Email: geliudie@uni-duesseldorf.de
#
# This file is part of sybilSBML.
#
# SybilSBML is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SybilSBML is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SybilSBML. If not, see <http://www.gnu.org/licenses/>.
#------------------------------------------------------------------------------#
versionLibSBML <- function() {
version <- .Call("getLibSBMLversion", PACKAGE = "sybilSBML")
return(version)
}
#------------------------------------------------------------------------------#
openSBMLfile <- function(fname, ptrtype = "sbml_doc") {
if ( file.exists(fname) == FALSE ) {
stop("file not found: ", sQuote(fname))
}
sbmlf <- .Call("readSBMLfile", PACKAGE = "sybilSBML",
as.character(normalizePath(fname)[1]),
as.character(ptrtype)
)
sbmlfP <- sbmlDocPointer(sbmlf)
return(sbmlfP)
}
#------------------------------------------------------------------------------#
closeSBMLfile <- function(sbmlf) {
invisible(
.Call("delDocument", PACKAGE = "sybilSBML",
sbmlPointer(sbmlf)
)
)
}
#------------------------------------------------------------------------------#
getSBMLmodel <- function(sbmlf, ptrtype = "sbml_mod") {
sbmlm <- .Call("getSBMLmodel", PACKAGE = "sybilSBML",
sbmlPointer(sbmlf),
as.character(ptrtype)
)
sbmlmP <- sbmlModPointer(sbmlm, sbmlf)
if (isTRUE(isNULLpointerSBML(sbmlmP))) {
sbmlmP <- NULL
}
return(sbmlmP)
}
#------------------------------------------------------------------------------#
delSBMLmodel <- function(sbmlm) {
invisible(
.Call("delModel", PACKAGE = "sybilSBML",
sbmlPointer(sbmlm)
)
)
}
#------------------------------------------------------------------------------#
getSBMLlevel <- function(sbmlf) {
level <- .Call("getSBMLlevel", PACKAGE = "sybilSBML",
sbmlPointer(sbmlf)
)
return(level)
}
#------------------------------------------------------------------------------#
getSBMLversion <- function(sbmlf) {
version <- .Call("getSBMLversion", PACKAGE = "sybilSBML",
sbmlPointer(sbmlf)
)
return(version)
}
#------------------------------------------------------------------------------#
validateSBMLdocument <- function(sbmlf) {
if (is(sbmlf, "character")) {
sbmlff <- openSBMLfile(fname = sbmlf)
}
else {
sbmlff <- sbmlf
}
val <- .Call("validateDocument", PACKAGE = "sybilSBML",
sbmlPointer(sbmlff)
)
if (is(sbmlf, "character")) {
val <- getSBMLerrors(sbmlff)
closeSBMLfile(sbmlff)
}
return(val)
}
#------------------------------------------------------------------------------#
getSBMLerrors <- function(sbmlf) {
err <- .Call("getSBMLerrors", PACKAGE = "sybilSBML",
sbmlPointer(sbmlf)
)
err <- sbmlError(err, sbmlf)
return(err)
}
#------------------------------------------------------------------------------#
getSBMLmodId <- function(sbmlm) {
modid <- .Call("getSBMLmodId", PACKAGE = "sybilSBML",
sbmlPointer(sbmlm)
)
return(modid)
}
#------------------------------------------------------------------------------#
getSBMLmodName <- function(sbmlm) {
modn <- .Call("getSBMLmodName", PACKAGE = "sybilSBML",
sbmlPointer(sbmlm)
)
return(modn)
}
#------------------------------------------------------------------------------#
getSBMLnumCompart <- function(sbmlm) {
num <- .Call("getSBMLnumCompart", PACKAGE = "sybilSBML",
sbmlPointer(sbmlm)
)
return(num)
}
#------------------------------------------------------------------------------#
getSBMLnumSpecies <- function(sbmlm) {
num <- .Call("getSBMLnumSpecies", PACKAGE = "sybilSBML",
sbmlPointer(sbmlm)
)
return(num)
}
#------------------------------------------------------------------------------#
getSBMLnumReactions <- function(sbmlm) {
num <- .Call("getSBMLnumReactions", PACKAGE = "sybilSBML",
sbmlPointer(sbmlm)
)
return(num)
}
#------------------------------------------------------------------------------#
getSBMLunitDefinitionsList <- function(sbmlm) {
units <- .Call("getSBMLunitDefinitionsList", PACKAGE = "sybilSBML",
sbmlPointer(sbmlm)
)
return(units)
}
#------------------------------------------------------------------------------#
getSBMLCompartList <- function(sbmlm) {
comp <- .Call("getSBMLCompartList", PACKAGE = "sybilSBML",
sbmlPointer(sbmlm)
)
return(comp)
}
#------------------------------------------------------------------------------#
getSBMLSpeciesList <- function(sbmlm) {
spec <- .Call("getSBMLSpeciesList", PACKAGE = "sybilSBML",
sbmlPointer(sbmlm)
)
return(spec)
}
#------------------------------------------------------------------------------#
getSBMLReactionsList <- function(sbmlm) {
react <- .Call("getSBMLReactionsList", PACKAGE = "sybilSBML",
sbmlPointer(sbmlm)
)