1# 2# \file addingEvidenceCodes_1.R 3# \brief adds controlled vocabulary terms to a reaction in a model 4# \author Frank Bergmann 5# 6# <!-------------------------------------------------------------------------- 7# This sample program is distributed under a different license than the rest 8# of libSBML. This program uses the open-source MIT license, as follows: 9# 10# Copyright (c) 2013-2018 by the California Institute of Technology 11# (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK) 12# and the University of Heidelberg (Germany), with support from the National 13# Institutes of Health (USA) under grant R01GM070923. All rights reserved. 14# 15# Permission is hereby granted, free of charge, to any person obtaining a 16# copy of this software and associated documentation files (the "Software"), 17# to deal in the Software without restriction, including without limitation 18# the rights to use, copy, modify, merge, publish, distribute, sublicense, 19# and/or sell copies of the Software, and to permit persons to whom the 20# Software is furnished to do so, subject to the following conditions: 21# 22# The above copyright notice and this permission notice shall be included in 23# all copies or substantial portions of the Software. 24# 25# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 28# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 30# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 31# DEALINGS IN THE SOFTWARE. 32# 33# Neither the name of the California Institute of Technology (Caltech), nor 34# of the European Bioinformatics Institute (EMBL-EBI), nor of the University 35# of Heidelberg, nor the names of any contributors, may be used to endorse 36# or promote products derived from this software without specific prior 37# written permission. 38# ------------------------------------------------------------------------ --> 39# 40# 41# 42# Usage: R --slave -f addingEvidenceCodes_1.R --args <input-filename> <output-filename> 43# 44# 45 46library(libSBML) 47 48args <- commandArgs(trailingOnly = TRUE) 49 50if (length(args) != 2) { 51 stop( 52 " usage: addingEvidenceCodes_1 <input-filename> <output-filename>\n Adds controlled vocabulary term to a reaction\n" 53 ); 54} 55 56d = readSBML(args[1]); 57errors = SBMLDocument_getNumErrors(d); 58 59if (errors > 0) { 60 cat("Read Error(s):\n"); 61 SBMLDocument_printErrors(d); 62 cat("Correct the above and re-run.\n"); 63} else { 64 65 m = SBMLDocument_getModel(d); 66 n = Model_getNumReactions(m); 67 68 if (n <= 0) { 69 cat( "Model has no reactions.\n Cannot add CV terms\n"); 70 } else { 71 r = Model_getReaction(m, 0); 72 73 # check that the reaction has a metaid 74 # no CVTerms will be added if there is no metaid to reference 75 # 76 if (SBase_isSetMetaId(r) == FALSE) 77 SBase_setMetaId(r, "metaid_0000052"); 78 79 cv1 = CVTerm("BIOLOGICAL_QUALIFIER"); 80 CVTerm_setBiologicalQualifierType(cv1, "BQB_IS_DESCRIBED_BY"); 81 CVTerm_addResource(cv1, "urn:miriam:obo.eco:ECO%3A0000183"); 82 83 SBase_addCVTerm(r, cv1); 84 85 cv2 = CVTerm("BIOLOGICAL_QUALIFIER"); 86 CVTerm_setBiologicalQualifierType(cv2, "BQB_IS"); 87 CVTerm_addResource(cv2, "urn:miriam:kegg.reaction:R00756"); 88 CVTerm_addResource(cv2, "urn:miriam:reactome:REACT_736"); 89 90 SBase_addCVTerm(r, cv2); 91 92 writeSBML(d, args[2]); 93 } 94} 95 96q(status=errors); 97