1#!/usr/bin/env perl 2# -*-Perl-*- 3## 4## @file unsetAnnotation.pl 5## @brief unset annotation for each element 6## @author Akiya Jouraku 7## 8## <!-------------------------------------------------------------------------- 9## This sample program is distributed under a different license than the rest 10## of libSBML. This program uses the open-source MIT license, as follows: 11## 12## Copyright (c) 2013-2018 by the California Institute of Technology 13## (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK) 14## and the University of Heidelberg (Germany), with support from the National 15## Institutes of Health (USA) under grant R01GM070923. All rights reserved. 16## 17## Permission is hereby granted, free of charge, to any person obtaining a 18## copy of this software and associated documentation files (the "Software"), 19## to deal in the Software without restriction, including without limitation 20## the rights to use, copy, modify, merge, publish, distribute, sublicense, 21## and/or sell copies of the Software, and to permit persons to whom the 22## Software is furnished to do so, subject to the following conditions: 23## 24## The above copyright notice and this permission notice shall be included in 25## all copies or substantial portions of the Software. 26## 27## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 30## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 32## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 33## DEALINGS IN THE SOFTWARE. 34## 35## Neither the name of the California Institute of Technology (Caltech), nor 36## of the European Bioinformatics Institute (EMBL-EBI), nor of the University 37## of Heidelberg, nor the names of any contributors, may be used to endorse 38## or promote products derived from this software without specific prior 39## written permission. 40## ------------------------------------------------------------------------ --> 41## 42 43use LibSBML; 44no strict; 45 46if ($#ARGV != 1 ) { 47 print "Usage: unsetAnnotation <input-filename> <output-filename>\n"; 48 exit 1; 49} 50 51$filename = $ARGV[0]; 52 53$document = LibSBML::readSBML($filename); 54 55 56$errors = $document->getNumErrors(); 57 58if ($errors > 0) { 59 $document->printErrors(); 60 exit $errors; 61} 62 63$m = $document->getModel(); 64$m->unsetAnnotation(); 65 66for ($i = 0; $i < $m->getNumReactions(); $i++) { 67 $re = $m->getReaction($i); 68 $re->unsetAnnotation(); 69 70 for ($j = 0; $j < $re->getNumReactants(); $j++) { 71 $rt = $re->getReactant($j); 72 $rt->unsetAnnotation(); 73 } 74 for ($j = 0; $j < $re->getNumProducts(); $j++) { 75 $rt = $re->getProduct($j); 76 $rt->unsetAnnotation(); 77 } 78 for ($j =0; $j < $re->getNumModifiers(); $j++) { 79 $md = $re->getModifier($j); 80 $md->unsetAnnotation(); 81 } 82 if ($re->isSetKineticLaw()) { 83 $kl = $re->getKineticLaw(); 84 $kl->unsetAnnotation(); 85 86 for ($j =0; $j < $kl->getNumParameters(); $j++) { 87 $pa = $kl->getParameter(j); 88 $pa->unsetAnnotation(); 89 } 90 } 91} 92for ($i = 0; $i < $m->getNumSpecies(); $i++) { 93 $sp = $m->getSpecies($i); 94 $sp->unsetAnnotation(); 95} 96for ($i = 0; $i <$m->getNumCompartments(); $i++) { 97 $sp = $m->getCompartment($i); 98 $sp->unsetAnnotation(); 99} 100for ($i = 0; $i <$m->getNumFunctionDefinitions(); $i++) { 101 $sp = $m->getFunctionDefinition($i); 102 $sp->unsetAnnotation(); 103} 104for ($i = 0; $i <$m->getNumUnitDefinitions(); $i++) { 105 $sp = $m->getUnitDefinition($i); 106 $sp->unsetAnnotation(); 107} 108for ($i = 0; $i <$m->getNumParameters(); $i++) { 109 $sp = $m->getParameter($i); 110 $sp->unsetAnnotation(); 111} 112for ($i = 0; $i <$m->getNumRules(); $i++) { 113 $sp = $m->getRule($i); 114 $sp->unsetAnnotation(); 115} 116for ($i = 0; $i <$m->getNumInitialAssignments(); $i++) { 117 $sp = $m->getInitialAssignment($i); 118 $sp->unsetAnnotation(); 119} 120for ($i = 0; $i <$m->getNumEvents(); $i++) { 121 $sp = $m->getEvent($i); 122 $sp->unsetAnnotation(); 123 124 for ($j =0; $j <$sp->getNumEventAssignments(); $j++) { 125 $ea = $sp->getEventAssignment($j); 126 $ea->unsetAnnotation(); 127 } 128} 129for ($i = 0; $i <$m->getNumSpeciesTypes(); $i++) { 130 $sp = $m->getSpeciesType($i); 131 $sp->unsetAnnotation(); 132} 133for ($i = 0; $i <$m->getNumConstraints(); $i++) { 134 $sp = $m->getConstraint($i); 135 $sp->unsetAnnotation(); 136} 137LibSBML::writeSBML($document, $ARGV[1]); 138 139exit $errors; 140 141