1#!/usr/bin/env perl 2# -*-Perl-*- 3## 4## @file promoteParameters.pl 5## @brief promotes all local to global paramters 6## @author Frank T. Bergmann 7## 8## 9## <!-------------------------------------------------------------------------- 10## This sample program is distributed under a different license than the rest 11## of libSBML. This program uses the open-source MIT license, as follows: 12## 13## Copyright (c) 2013-2018 by the California Institute of Technology 14## (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK) 15## and the University of Heidelberg (Germany), with support from the National 16## Institutes of Health (USA) under grant R01GM070923. All rights reserved. 17## 18## Permission is hereby granted, free of charge, to any person obtaining a 19## copy of this software and associated documentation files (the "Software"), 20## to deal in the Software without restriction, including without limitation 21## the rights to use, copy, modify, merge, publish, distribute, sublicense, 22## and/or sell copies of the Software, and to permit persons to whom the 23## Software is furnished to do so, subject to the following conditions: 24## 25## The above copyright notice and this permission notice shall be included in 26## all copies or substantial portions of the Software. 27## 28## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 29## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 31## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 32## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 33## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 34## DEALINGS IN THE SOFTWARE. 35## 36## Neither the name of the California Institute of Technology (Caltech), nor 37## of the European Bioinformatics Institute (EMBL-EBI), nor of the University 38## of Heidelberg, nor the names of any contributors, may be used to endorse 39## or promote products derived from this software without specific prior 40## written permission. 41## ------------------------------------------------------------------------ --> 42 43use File::Basename; 44use LibSBML; 45no strict; 46 47if ($#ARGV != 1) { 48 print "usage: promoteParameters.pl input-filename output-filename\n"; 49 exit 1; 50} 51 52$infile = $ARGV[0]; 53$outfile = $ARGV[1]; 54 55unless (-e $infile) { 56 print("[Error] ", $infile, ": No such file.", "\n"); 57 exit 1; 58} 59$reader = new LibSBML::SBMLReader(); 60$writer = new LibSBML::SBMLWriter(); 61$sbmldoc = $reader->readSBML($infile); 62 63if ($sbmldoc->getNumErrors() > 0) { 64 if ($sbmldoc->getError(0)->getErrorId() == $LibSBML::XMLFileUnreadable) { 65 # Handle case of unreadable file here. 66 $sbmldoc->printErrors(); 67 } 68 elsif ($sbmldoc->getError(0)->getErrorId() == $LibSBML::XMLFileOperationError) { 69 # Handle case of other file error here. 70 $sbmldoc->printErrors(); 71 } 72 else { 73 # Handle other error cases here. 74 $sbmldoc->printErrors(); 75 } 76 exit 1; 77} 78$props = new LibSBML::ConversionProperties(); 79$props->addOption("promoteLocalParameters", true, "Promotes all Local Parameters to Global ones"); 80if ($sbmldoc->convert($props) != $LibSBML::LIBSBML_OPERATION_SUCCESS) 81{ 82 print("[Error] Conversion failed.", "\n"); 83 exit 3; 84} 85$writer->writeSBML($sbmldoc, $outfile); 86print("[OK] done, wrote ", $outfile, "\n"); 87 88