1 /** 2 * @file unsetNotes.java 3 * @brief Unsets notes for each element 4 * @author Akira Funahashi (translated from libSBML C++ examples (using other Java examples provided by Nicolas Rodriguez)) 5 * @author Akiya Jouraku 6 * 7 * <!-------------------------------------------------------------------------- 8 * This sample program is distributed under a different license than the rest 9 * of libSBML. This program uses the open-source MIT license, as follows: 10 * 11 * Copyright (c) 2013-2018 by the California Institute of Technology 12 * (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK) 13 * and the University of Heidelberg (Germany), with support from the National 14 * Institutes of Health (USA) under grant R01GM070923. All rights reserved. 15 * 16 * Permission is hereby granted, free of charge, to any person obtaining a 17 * copy of this software and associated documentation files (the "Software"), 18 * to deal in the Software without restriction, including without limitation 19 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 20 * and/or sell copies of the Software, and to permit persons to whom the 21 * Software is furnished to do so, subject to the following conditions: 22 * 23 * The above copyright notice and this permission notice shall be included in 24 * all copies or substantial portions of the Software. 25 * 26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 29 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 31 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 32 * DEALINGS IN THE SOFTWARE. 33 * 34 * Neither the name of the California Institute of Technology (Caltech), nor 35 * of the European Bioinformatics Institute (EMBL-EBI), nor of the University 36 * of Heidelberg, nor the names of any contributors, may be used to endorse 37 * or promote products derived from this software without specific prior 38 * written permission. 39 * ------------------------------------------------------------------------ --> 40 */ 41 42 43 import org.sbml.libsbml.Compartment; 44 import org.sbml.libsbml.Constraint; 45 import org.sbml.libsbml.Event; 46 import org.sbml.libsbml.InitialAssignment; 47 import org.sbml.libsbml.ModifierSpeciesReference; 48 import org.sbml.libsbml.Parameter; 49 import org.sbml.libsbml.SBMLWriter; 50 import org.sbml.libsbml.Species; 51 import org.sbml.libsbml.SpeciesReference; 52 import org.sbml.libsbml.SpeciesType; 53 import org.sbml.libsbml.EventAssignment; 54 import org.sbml.libsbml.FunctionDefinition; 55 import org.sbml.libsbml.KineticLaw; 56 import org.sbml.libsbml.Model; 57 import org.sbml.libsbml.Reaction; 58 import org.sbml.libsbml.Rule; 59 import org.sbml.libsbml.SBMLDocument; 60 import org.sbml.libsbml.SBMLReader; 61 import org.sbml.libsbml.UnitDefinition; 62 63 64 public class unsetNotes 65 { main(String[] args)66 public static void main (String[] args) 67 { 68 if (args.length != 2) 69 { 70 println("Usage: java unsetNotes <input-filename> <output-filename>"); 71 System.exit(1); 72 } 73 74 String filename = args[0]; 75 SBMLDocument document; 76 SBMLReader reader = new SBMLReader(); 77 SBMLWriter writer = new SBMLWriter(); 78 79 document = reader.readSBML(filename); 80 81 long errors = document.getNumErrors(); 82 83 if (errors > 0) 84 { 85 document.printErrors(); 86 System.exit((int)errors); 87 } 88 89 Model m = document.getModel(); 90 m.unsetNotes(); 91 92 for(int i=0; i < m.getNumReactions(); i++) 93 { 94 Reaction re = m.getReaction(i); 95 re.unsetNotes(); 96 97 for(int j=0; j < re.getNumReactants(); j++) 98 { 99 SpeciesReference rt = re.getReactant(j); 100 rt.unsetNotes(); 101 } 102 103 for(int j=0; j < re.getNumProducts(); j++) 104 { 105 SpeciesReference rt = re.getProduct(j); 106 rt.unsetNotes(); 107 } 108 109 for(int j=0; j < re.getNumModifiers(); j++) 110 { 111 ModifierSpeciesReference md = re.getModifier(j); 112 md.unsetNotes(); 113 } 114 115 if(re.isSetKineticLaw()) 116 { 117 KineticLaw kl = re.getKineticLaw(); 118 kl.unsetNotes(); 119 120 /* Parameter */ 121 for(int j=0; j < kl.getNumParameters(); j++) 122 { 123 Parameter pa = kl.getParameter(j); 124 pa.unsetNotes(); 125 } 126 } 127 } 128 129 for(int i=0; i < m.getNumSpecies(); i++) 130 { 131 Species sp = m.getSpecies(i); 132 sp.unsetNotes(); 133 } 134 135 for(int i=0; i < m.getNumCompartments(); i++) 136 { 137 Compartment sp = m.getCompartment(i); 138 sp.unsetNotes(); 139 } 140 141 for(int i=0; i < m.getNumFunctionDefinitions(); i++) 142 { 143 FunctionDefinition sp = m.getFunctionDefinition(i); 144 sp.unsetNotes(); 145 } 146 147 for(int i=0; i < m.getNumUnitDefinitions(); i++) 148 { 149 UnitDefinition sp = m.getUnitDefinition(i); 150 sp.unsetNotes(); 151 } 152 153 for(int i=0; i < m.getNumParameters(); i++) 154 { 155 Parameter sp = m.getParameter(i); 156 sp.unsetNotes(); 157 } 158 159 for(int i=0; i < m.getNumRules(); i++) 160 { 161 Rule sp = m.getRule(i); 162 sp.unsetNotes(); 163 } 164 165 for(int i=0; i < m.getNumInitialAssignments(); i++) 166 { 167 InitialAssignment sp = m.getInitialAssignment(i); 168 sp.unsetNotes(); 169 } 170 171 for(int i=0; i < m.getNumEvents(); i++) 172 { 173 Event sp = m.getEvent(i); 174 sp.unsetNotes(); 175 176 for(int j=0; j < sp.getNumEventAssignments(); j++) 177 { 178 EventAssignment ea = sp.getEventAssignment(j); 179 ea.unsetNotes(); 180 } 181 } 182 183 for(int i=0; i < m.getNumSpeciesTypes(); i++) 184 { 185 SpeciesType sp = m.getSpeciesType(i); 186 sp.unsetNotes(); 187 } 188 189 for(int i=0; i < m.getNumConstraints(); i++) 190 { 191 Constraint sp = m.getConstraint(i); 192 sp.unsetNotes(); 193 } 194 195 writer.writeSBML(document, args[1]); 196 System.exit((int)errors); 197 } 198 println(String msg)199 static void println (String msg) 200 { 201 System.out.println(msg); 202 } 203 204 205 /** 206 * Loads the SWIG-generated libSBML Java module when this class is 207 * loaded, or reports a sensible diagnostic message about why it failed. 208 */ 209 static 210 { 211 try 212 { 213 System.loadLibrary("sbmlj"); 214 // For extra safety, check that the jar file is in the classpath. 215 Class.forName("org.sbml.libsbml.libsbml"); 216 } 217 catch (UnsatisfiedLinkError e) 218 { 219 System.err.println("Error encountered while attempting to load libSBML:"); 220 System.err.println("Please check the value of your " 221 + (System.getProperty("os.name").startsWith("Mac OS") 222 ? "DYLD_LIBRARY_PATH" : "LD_LIBRARY_PATH") + 223 " environment variable and/or your" + 224 " 'java.library.path' system property (depending on" + 225 " which one you are using) to make sure it list the" + 226 " directories needed to find the " + 227 System.mapLibraryName("sbmlj") + " library file and" + 228 " libraries it depends upon (e.g., the XML parser)."); 229 System.exit(1); 230 } 231 catch (ClassNotFoundException e) 232 { 233 System.err.println("Error: unable to load the file 'libsbmlj.jar'." + 234 " It is likely that your -classpath command line " + 235 " setting or your CLASSPATH environment variable " + 236 " do not include the file 'libsbmlj.jar'."); 237 e.printStackTrace(); 238 239 System.exit(1); 240 } 241 catch (SecurityException e) 242 { 243 System.err.println("Error encountered while attempting to load libSBML:"); 244 e.printStackTrace(); 245 System.err.println("Could not load the libSBML library files due to a"+ 246 " security exception.\n"); 247 System.exit(1); 248 } 249 } 250 } 251 252