static SBMLDocument testReadSBMLFromString(string file) { if (!File.Exists(file)) { ERR("[ReadSBMLFromString] Error: (" + file + ") : No such file or directory."); return(null); } StreamReader oReader = new StreamReader(file); string sSBML = oReader.ReadToEnd(); SBMLDocument d = libsbml.readSBMLFromString(sSBML); if (d == null) { ERR("[ReadSBMLFromString] Error: (" + file + ") SBMLDocument is null."); return(null); } if (d.getModel() == null) { for (int i = 0; i < d.getNumErrors(); i++) { ERR("[ReadSBMLFromString] Error: (" + file + ") : " + d.getError(i).getMessage()); } return(null); } else if (d.getNumErrors() > 0) { bool iserror = false; for (int i = 0; i < d.getNumErrors(); i++) { long severity = d.getError(i).getSeverity(); if ((severity == libsbml.LIBSBML_SEV_ERROR) || (severity == libsbml.LIBSBML_SEV_FATAL) ) { iserror = true; ERR("[ReadSBMLFromString] Error: (" + file + ") : " + d.getError(i).getMessage()); } } if (iserror) { return(null); } } OK(); return(d); }
public static int Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Usage: inlineInitialAssignments filename outFile"); return(1); } string filename = args[0]; string outFile = args[1]; long current = DateTime.Now.Ticks; SBMLDocument document = libsbml.readSBML(filename); if (document.getNumErrors(libsbml.LIBSBML_SEV_ERROR) > 0) { Console.WriteLine("The models contains errors, please correct them before continuing."); document.printErrors(); return(1); } var model = document.getModel(); SBMLTransforms.expandInitialAssignments(model); libsbml.writeSBML(document, outFile); return(0); }
public static int Main(string[] args) { if (args.Length != 1) { Console.Write(Environment.NewLine + "Usage: printMath filename" + Environment.NewLine + Environment.NewLine); return(1); } string filename = args[0]; SBMLDocument document = libsbml.readSBML(filename); if (document.getNumErrors() > 0) { Console.Error.Write("Encountered the following SBML errors:" + Environment.NewLine); document.printErrors(new OStream(OStream.CERR)); return(1); } Model model = document.getModel(); if (model == null) { Console.Write("No model present." + Environment.NewLine); return(1); } printMath(model); Console.WriteLine(); return(0); }
public static void Main(string[] args) { if (args.Length != 2) { string myname = Path.GetFileName(Environment.GetCommandLineArgs()[0]); Console.WriteLine("Usage: {0} input-filename output-filename", myname); Environment.Exit(1); } string inputFile = args[0]; string outputFile = args[1]; if (!File.Exists(inputFile)) { Console.WriteLine("[Error] {0} : No such file.", inputFile); Environment.Exit(1); } SBMLReader reader = new SBMLReader(); SBMLWriter writer = new SBMLWriter(); SBMLDocument sbmlDoc = reader.readSBML(inputFile); if (sbmlDoc.getNumErrors() > 0) { sbmlDoc.printErrors(); Console.WriteLine("[Error] Cannot read {0}", inputFile); Environment.Exit(1); } writer.writeSBML(sbmlDoc, outputFile); Console.WriteLine("[OK] Echoed {0} to {1}", inputFile, outputFile); }
public static int Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: readSBML filename"); return(1); } string filename = args[0]; long current = DateTime.Now.Ticks; SBMLDocument document = libsbml.readSBML(filename); int errors = (int)document.getNumErrors(); Console.WriteLine(); Console.WriteLine(" filename: " + filename); Console.WriteLine(" file size: " + new FileInfo(filename).Length); Console.WriteLine(" read time (ms): " + (DateTime.Now.Ticks - current)); Console.WriteLine(" validation error(s): " + errors); Console.WriteLine(); document.printErrors(); return(errors); }
public static int Main(string[] args) { if (args.Length != 4) { Console.WriteLine("Usage: replaceOneFD filename functionDefinitionId reactionId outfile"); return(1); } string filename = args[0]; string outFile = args[3]; string functionDefinitionId = args[1]; string reactionId = args[2]; long current = DateTime.Now.Ticks; SBMLDocument document = libsbml.readSBML(filename); if (document.getNumErrors(libsbml.LIBSBML_SEV_ERROR) > 0) { Console.WriteLine("The models contains errors, please correct them before continuing."); document.printErrors(); return(1); } var model = document.getModel(); var functionDefinition = model.getFunctionDefinition(functionDefinitionId); if (functionDefinition == null) { Console.WriteLine(); Console.WriteLine("No functiondefinition with the given id can be found."); return(1); } var reaction = model.getReaction(reactionId); if (reaction == null) { Console.WriteLine(); Console.WriteLine("No reaction with the given id can be found."); return(1); } if (!reaction.isSetKineticLaw() || !reaction.getKineticLaw().isSetMath()) { Console.WriteLine(); Console.WriteLine("The reaction has no math set. "); return(1); } // Until here it was all setup, all we needed was an ASTNode, in which we wanted to // replace calls to a function definition, with the function definitions content. // SBMLTransforms.replaceFD(reaction.getKineticLaw().getMath(), functionDefinition); // finally write to file libsbml.writeSBML(document, outFile); return(0); }
public static int Main(string[] args) { if (args.Length != 1) { Console.Write(Environment.NewLine + "Usage: printSBML filename" + Environment.NewLine + Environment.NewLine); return(1); } string filename = args[0]; SBMLDocument document = libsbml.readSBML(filename); if (document.getNumErrors() > 0) { Console.WriteLine("Encountered the following SBML errors:" + Environment.NewLine); document.printErrors(); return(1); } int level = (int)document.getLevel(); int version = (int)document.getVersion(); Console.Write(Environment.NewLine + "File: " + filename + " (Level " + level + ", version " + version + ")" + Environment.NewLine); Model model = document.getModel(); if (model == null) { Console.Write("No model present." + Environment.NewLine); return(1); } Console.Write(" " + (level == 1 ? "name: " : " id: ") + (model.isSetId() ? model.getId() : "(empty)") + Environment.NewLine); if (model.isSetSBOTerm()) { Console.Write(" model sboTerm: " + model.getSBOTerm() + Environment.NewLine); } Console.Write("functionDefinitions: " + model.getNumFunctionDefinitions() + Environment.NewLine); Console.Write(" unitDefinitions: " + model.getNumUnitDefinitions() + Environment.NewLine); Console.Write(" compartmentTypes: " + model.getNumCompartmentTypes() + Environment.NewLine); Console.Write(" specieTypes: " + model.getNumSpeciesTypes() + Environment.NewLine); Console.Write(" compartments: " + model.getNumCompartments() + Environment.NewLine); Console.Write(" species: " + model.getNumSpecies() + Environment.NewLine); Console.Write(" parameters: " + model.getNumParameters() + Environment.NewLine); Console.Write(" initialAssignments: " + model.getNumInitialAssignments() + Environment.NewLine); Console.Write(" rules: " + model.getNumRules() + Environment.NewLine); Console.Write(" constraints: " + model.getNumConstraints() + Environment.NewLine); Console.Write(" reactions: " + model.getNumReactions() + Environment.NewLine); Console.Write(" events: " + model.getNumEvents() + Environment.NewLine); Console.Write(Environment.NewLine); return(0); }
/// <summary> /// The program is to be invoked with two arguments, the input and output file. /// </summary> /// <param name="args">command line arguments</param> /// <returns>0 in case of no errors</returns> public static int Main(string[] args) { if (args.Length != 2) { Console.WriteLine("{0}Usage: setIdFromNames filename output{0}{0}", Environment.NewLine); return(1); } string filename = args[0]; string output = args[1]; // read the document long start = DateTime.Now.Ticks; SBMLDocument document = libsbml.readSBMLFromFile(filename); long stop = DateTime.Now.Ticks; Console.WriteLine(); Console.WriteLine(" filename: {0}", filename); Console.WriteLine(" read time (ms): {0}", TimeSpan.FromTicks(stop - start).TotalMilliseconds); // stop in case of serious errors long errors = document.getNumErrors(libsbml.LIBSBML_SEV_ERROR); if (errors > 0) { Console.WriteLine(" error(s): {0}", errors); document.printErrors(); return((int)errors); } // get a list of all elements, as we will need to know all identifiers // so that we don't create duplicates. SBaseList allElements = document.getListOfAllElements(); // get a list of all ids var allIds = getAllIds(allElements); // create the transformer with the ids var trans = new SetIdFromNames(allIds); // rename the identifiers (using the elements we already gathered before) start = DateTime.Now.Ticks; document.getModel().renameIDs(allElements, trans); stop = DateTime.Now.Ticks; Console.WriteLine(" rename time (ms): {0}", TimeSpan.FromTicks(stop - start).TotalMilliseconds); // write to file start = DateTime.Now.Ticks; libsbml.writeSBMLToFile(document, output); stop = DateTime.Now.Ticks; Console.WriteLine(" write time (ms): {0}", TimeSpan.FromTicks(stop - start).TotalMilliseconds); Console.WriteLine(); // if we got here all went well ... return(0); }
public void test_WriteL3SBML_error() { SBMLDocument d = new SBMLDocument(); SBMLWriter w = new SBMLWriter(); assertEquals(false, w.writeSBML(d, "/tmp/impossible/path/should/fail")); assertTrue(d.getNumErrors() == 1); assertTrue(d.getError(0).getErrorId() == libsbml.XMLFileUnwritable); d = null; w = null; }
public void test_SBMLDocument_createWith() { SBMLDocument d = new SBMLDocument(1, 2); assertTrue(d.getTypeCode() == libsbml.SBML_DOCUMENT); assertTrue(d.getNotes() == null); assertTrue(d.getAnnotation() == null); assertTrue(d.getLevel() == 1); assertTrue(d.getVersion() == 2); assertTrue(d.getNumErrors() == 0); d = null; }
/// <summary> /// The program is to be invoked with one argument, the input file. /// </summary> /// <param name="args">command line arguments</param> /// <returns>0 in case of no errors</returns> public static int Main(string[] args) { if (args.Length != 1) { Console.WriteLine("{0}Usage: getAllElementsWithNotes filename{0}{0}", Environment.NewLine); return(1); } string filename = args[0]; // read the document long start = DateTime.Now.Ticks; SBMLDocument document = libsbml.readSBMLFromFile(filename); long stop = DateTime.Now.Ticks; Console.WriteLine(); Console.WriteLine(" filename: {0}", filename); Console.WriteLine(" read time (ms): {0}", TimeSpan.FromTicks(stop - start).TotalMilliseconds); // stop in case of serious errors long errors = document.getNumErrors(libsbml.LIBSBML_SEV_ERROR); if (errors > 0) { Console.WriteLine(" error(s): {0}", errors); document.printErrors(); return((int)errors); } // create the filter we want to use var filter = new NotesFilter(); // get a list of all elements with notes start = DateTime.Now.Ticks; Console.WriteLine(" searching ......:"); SBaseList allElements = document.getListOfAllElements(filter); stop = DateTime.Now.Ticks; Console.WriteLine(" search time (ms): {0}", TimeSpan.FromTicks(stop - start).TotalMilliseconds); Console.WriteLine(); Console.WriteLine(" elements with notes: {0}", allElements.getSize()); Console.WriteLine(); // if we got here all went well ... return(0); }
public static int Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Usage: evaluateCustomMath formula [model containing values]"); return(1); } string formula = args[0]; string filename = args.Length == 2 ? args[1] : null; var math = libsbml.parseFormula(formula); if (math == null) { Console.WriteLine("Invalid formula, aborting."); return(1); } SBMLDocument doc = null; if (filename != null) { doc = libsbml.readSBML(filename); if (doc.getNumErrors(libsbml.LIBSBML_SEV_ERROR) > 0) { Console.WriteLine("The models contains errors, please correct them before continuing."); doc.printErrors(); return(1); } // the following maps a list of ids to their corresponding model values // this makes it possible to evaluate expressions involving SIds. SBMLTransforms.mapComponentValues(doc.getModel()); } else { // create dummy document doc = new SBMLDocument(3, 1); } var result = SBMLTransforms.evaluateASTNode(math, doc.getModel()); Console.WriteLine("{0} = {1}", formula, result); return(0); }
static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("usage: printMulti sbml-file"); return; } SBMLDocument document = libsbml.readSBMLFromFile(args[0]); if (document.getNumErrors(libsbml.LIBSBML_SEV_ERROR) > 0) { document.printErrors(); return; } Model model = document.getModel(); // print multi model information printModelInfo(model); // print multi compartment information for (int i = 0; i < model.getNumCompartments(); ++i) { printCompartmentInfo(model.getCompartment(i)); } // print multi species information for (int i = 0; i < model.getNumSpecies(); ++i) { printSpeciesInfo(model.getSpecies(i)); } // print multi reaction information for (int i = 0; i < model.getNumReactions(); ++i) { printReactionInfo(model.getReaction(i)); } }
public static int Main(string[] args) { if (args.Length != 1) { Console.WriteLine(" Usage: printRenderInformation <input file> \n" + " prints a summary of the render information object."); return(1); } string inputFile = args[0]; SBMLDocument doc = libsbml.readSBMLFromFile(inputFile); Console.WriteLine("Using libSBML: {0} supporting packages for:", libsbml.getLibSBMLDottedVersion()); for (int i = 0; i < SBMLExtensionRegistry.getNumRegisteredPackages(); ++i) { Console.WriteLine("\t {0}", SBMLExtensionRegistry.getRegisteredPackageName(i)); } Console.WriteLine("\nThe document is: level {0}, version {1}", doc.getLevel(), doc.getVersion()); for (int i = 0; i < doc.getNumPlugins(); ++i) { Console.WriteLine(" doc uses package: {0}", doc.getPlugin(i).getElementNamespace()); } Console.WriteLine("\n"); long numErrors = doc.getNumErrors(libsbml.LIBSBML_SEV_ERROR); if (numErrors > 0) { Console.WriteLine("Encountered errors while reading the file. "); Console.WriteLine("Please correct the following errors and try again."); doc.printErrors(); return(2); } Model model = doc.getModel(); LayoutModelPlugin plugin = (LayoutModelPlugin)model.getPlugin("layout"); if (plugin == null || plugin.getNumLayouts() == 0) { Console.WriteLine("The loaded model contains no layout information, please add these first."); return(3); } RenderListOfLayoutsPlugin lolPlugin = (RenderListOfLayoutsPlugin)plugin.getListOfLayouts().getPlugin("render"); if (lolPlugin != null && lolPlugin.getNumGlobalRenderInformationObjects() > 0) { Console.WriteLine("The loaded model contains global Render information: "); for (int i = 0; i < lolPlugin.getNumGlobalRenderInformationObjects(); ++i) { GlobalRenderInformation info = lolPlugin.getRenderInformation(i); print_render_info(info); } } Layout layout = plugin.getLayout(0); RenderLayoutPlugin rPlugin = (RenderLayoutPlugin)layout.getPlugin("render"); if (rPlugin != null && rPlugin.getNumLocalRenderInformationObjects() > 0) { Console.WriteLine("The loaded model contains local Render information. "); // here we would do the same as above for the local render information ... for (int i = 0; i < rPlugin.getNumLocalRenderInformationObjects(); ++i) { LocalRenderInformation info = rPlugin.getRenderInformation(i); print_render_info(info); } } return(0); }
public static int Main(string[] args) { if (args.Length != 2) { Console.WriteLine(" usage: addingEvidenceCodes_2 <input-filename> <output-filename>"); Console.WriteLine(" Adds controlled vocabulary term to a species"); Console.WriteLine(); return(2); } SBMLDocument d = libsbml.readSBML(args[0]); long errors = d.getNumErrors(); if (errors > 0) { Console.WriteLine("Read Error(s):"); d.printErrors(); Console.WriteLine("Correct the above and re-run."); } else { long n = d.getModel().getNumSpecies(); if (n <= 0) { Console.WriteLine("Model has no species.\n Cannot add CV terms\n"); } else { Species s = d.getModel().getSpecies(0); /* check that the species has a metaid * no CVTerms will be added if there is no metaid to reference */ if (!s.isSetMetaId()) { s.setMetaId("metaid_0000052"); } CVTerm cv1 = new CVTerm(libsbml.BIOLOGICAL_QUALIFIER); cv1.setBiologicalQualifierType(libsbml.BQB_OCCURS_IN); cv1.addResource("urn:miriam:obo.go:GO%3A0005764"); s.addCVTerm(cv1); // now create the additional annotation //<rdf:Statement> // <rdf:subject rdf:resource="#metaid_0000052"/> // <rdf:predicate rdf:resource="http://biomodels.net/biology-qualifiers/occursIn"/> // <rdf:object rdf:resource="urn:miriam:obo.go:GO%3A0005764"/> // <bqbiol:isDescribedBy> // <rdf:Bag> // <rdf:li rdf:resource="urn:miriam:obo.eco:ECO%3A0000004"/> // <rdf:li rdf:resource="urn:miriam:pubmed:7017716"/> // </rdf:Bag> // </bqbiol:isDescribedBy> //</rdf:Statement> /* attributes */ XMLAttributes blank_att = new XMLAttributes(); XMLAttributes resource_att = new XMLAttributes(); /* create the outer statement node */ XMLTriple statement_triple = new XMLTriple("Statement", "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf"); XMLToken statement_token = new XMLToken(statement_triple, blank_att); XMLNode statement = new XMLNode(statement_token); /*create the subject node */ XMLTriple subject_triple = new XMLTriple("subject", "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf"); resource_att.clear(); resource_att.add("rdf:resource", "#" + s.getMetaId()); XMLToken subject_token = new XMLToken(subject_triple, resource_att); XMLNode subject = new XMLNode(subject_token); /*create the predicate node */ XMLTriple predicate_triple = new XMLTriple("predicate", "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf"); resource_att.clear(); resource_att.add("rdf:resource", "http://biomodels.net/biology-qualifiers/occursIn"); XMLToken predicate_token = new XMLToken(predicate_triple, resource_att); XMLNode predicate = new XMLNode(predicate_token); /*create the object node */ XMLTriple object_triple = new XMLTriple("object", "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf"); resource_att.clear(); resource_att.add("rdf:resource", "urn:miriam:obo.go:GO%3A0005764"); XMLToken object_token = new XMLToken(object_triple, resource_att); XMLNode object_ = new XMLNode(object_token); /* create the bqbiol node */ XMLTriple bqbiol_triple = new XMLTriple("isDescribedBy", "http://biomodels.net/biology-qualifiers/", "bqbiol"); XMLToken bqbiol_token = new XMLToken(bqbiol_triple, blank_att); XMLNode bqbiol = new XMLNode(bqbiol_token); /* create the bag node */ XMLTriple bag_triple = new XMLTriple("Bag", "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf"); XMLToken bag_token = new XMLToken(bag_triple, blank_att); XMLNode bag = new XMLNode(bag_token); /* create each li node and add to the bag */ XMLTriple li_triple = new XMLTriple("li", "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf"); resource_att.clear(); resource_att.add("rdf:resource", "urn:miriam:obo.eco:ECO%3A0000004"); XMLToken li_token = new XMLToken(li_triple, resource_att); li_token.setEnd(); XMLNode li = new XMLNode(li_token); bag.addChild(li); resource_att.clear(); resource_att.add("rdf:resource", "urn:miriam:pubmed:7017716"); li_token = new XMLToken(li_triple, resource_att); li_token.setEnd(); li = new XMLNode(li_token); bag.addChild(li); /* add the bag to bqbiol */ bqbiol.addChild(bag); /* add subject, predicate, object and bqbiol to statement */ statement.addChild(subject); statement.addChild(predicate); statement.addChild(object_); statement.addChild(bqbiol); /* create a top-level RDF element * this will ensure correct merging */ XMLNamespaces xmlns = new XMLNamespaces(); xmlns.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf"); xmlns.add("http://purl.org/dc/elements/1.1/", "dc"); xmlns.add("http://purl.org/dc/terms/", "dcterms"); xmlns.add("http://www.w3.org/2001/vcard-rdf/3.0#", "vCard"); xmlns.add("http://biomodels.net/biology-qualifiers/", "bqbiol"); xmlns.add("http://biomodels.net/model-qualifiers/", "bqmodel"); XMLTriple RDF_triple = new XMLTriple("RDF", "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf"); XMLToken RDF_token = new XMLToken(RDF_triple, blank_att, xmlns); XMLNode annotation = new XMLNode(RDF_token); /* add the staement node to the RDF node */ annotation.addChild(statement); s.appendAnnotation(annotation); libsbml.writeSBML(d, args[1]); } } return((int)errors); }
public static int Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: printUnits filename"); return(1); } string filename = args[0]; SBMLDocument document = libsbml.readSBML(filename); if (document.getNumErrors() > 0) { Console.Error.WriteLine("Encountered the following SBML errors:"); document.printErrors(); return(1); } Model model = document.getModel(); if (model == null) { Console.WriteLine("No model present."); return(1); } int i, j; for (i = 0; i < model.getNumSpecies(); i++) { Species s = model.getSpecies(i); Console.WriteLine("Species " + i + ": " + UnitDefinition.printUnits(s.getDerivedUnitDefinition())); } for (i = 0; i < model.getNumCompartments(); i++) { Compartment c = model.getCompartment(i); Console.WriteLine("Compartment " + i + ": " + UnitDefinition.printUnits(c.getDerivedUnitDefinition())) ; } for (i = 0; i < model.getNumParameters(); i++) { Parameter p = model.getParameter(i); Console.WriteLine("Parameter " + i + ": " + UnitDefinition.printUnits(p.getDerivedUnitDefinition())) ; } for (i = 0; i < model.getNumInitialAssignments(); i++) { InitialAssignment ia = model.getInitialAssignment(i); Console.WriteLine("InitialAssignment " + i + ": " + UnitDefinition.printUnits(ia.getDerivedUnitDefinition())); Console.WriteLine(" undeclared units: "); Console.WriteLine((ia.containsUndeclaredUnits() ? "yes\n" : "no\n")); } for (i = 0; i < model.getNumEvents(); i++) { Event e = model.getEvent(i); Console.WriteLine("Event " + i + ": "); if (e.isSetDelay()) { Console.WriteLine("Delay: " + UnitDefinition.printUnits(e.getDelay().getDerivedUnitDefinition())); Console.WriteLine(" undeclared units: "); Console.WriteLine((e.getDelay().containsUndeclaredUnits() ? "yes\n" : "no\n")); } for (j = 0; j < e.getNumEventAssignments(); j++) { EventAssignment ea = e.getEventAssignment(j); Console.WriteLine("EventAssignment " + j + ": " + UnitDefinition.printUnits(ea.getDerivedUnitDefinition())); Console.WriteLine(" undeclared units: "); Console.WriteLine((ea.containsUndeclaredUnits() ? "yes\n" : "no\n")); } } for (i = 0; i < model.getNumReactions(); i++) { Reaction r = model.getReaction(i); Console.WriteLine("Reaction " + i + ": "); if (r.isSetKineticLaw()) { Console.WriteLine("Kinetic Law: " + UnitDefinition.printUnits(r.getKineticLaw().getDerivedUnitDefinition())); Console.WriteLine(" undeclared units: "); Console.WriteLine((r.getKineticLaw().containsUndeclaredUnits() ? "yes\n" : "no\n")); } for (j = 0; j < r.getNumReactants(); j++) { SpeciesReference sr = r.getReactant(j); if (sr.isSetStoichiometryMath()) { Console.WriteLine("Reactant stoichiometryMath" + j + ": " + UnitDefinition.printUnits(sr.getStoichiometryMath().getDerivedUnitDefinition())); Console.WriteLine(" undeclared units: "); Console.WriteLine((sr.getStoichiometryMath().containsUndeclaredUnits() ? "yes\n" : "no\n")); } } for (j = 0; j < r.getNumProducts(); j++) { SpeciesReference sr = r.getProduct(j); if (sr.isSetStoichiometryMath()) { Console.WriteLine("Product stoichiometryMath" + j + ": " + UnitDefinition.printUnits(sr.getStoichiometryMath().getDerivedUnitDefinition())); Console.WriteLine(" undeclared units: "); Console.WriteLine((sr.getStoichiometryMath().containsUndeclaredUnits() ? "yes\n" : "no\n")); } } } for (i = 0; i < model.getNumRules(); i++) { Rule r = model.getRule(i); Console.WriteLine("Rule " + i + ": " + UnitDefinition.printUnits(r.getDerivedUnitDefinition())); Console.WriteLine(" undeclared units: "); Console.WriteLine((r.containsUndeclaredUnits() ? "yes\n" : "no\n")); } return(0); }
public static int Main(string[] args) { int latestLevel = (int)SBMLDocument.getDefaultLevel(); int latestVersion = (int)SBMLDocument.getDefaultVersion(); if (args.Length != 2) { Console.Write("Usage: convertSBML input-filename output-filename" + Environment.NewLine + "This program will attempt to convert a model either to" + Environment.NewLine + "SBML Level " + latestLevel + " Version " + latestVersion + " (if the model is not already) or, if " + Environment.NewLine + "the model is already expressed in Level " + latestLevel + " Version " + latestVersion + ", this" + Environment.NewLine + "program will attempt to convert the model to Level 1 Version 2." + Environment.NewLine); return(1); } string inputFile = args[0]; string outputFile = args[1]; SBMLDocument document = libsbml.readSBML(inputFile); long errors = document.getNumErrors(); if (errors > 0) { Console.Error.Write("Encountered the following SBML errors:" + Environment.NewLine); document.printErrors(); Console.Error.Write("Conversion skipped. Please correct the problems above first." + Environment.NewLine); return((int)errors); } /** * If the given model is not already L2v4, assume that the user wants to * convert it to the latest release of SBML (which is L2v4 currently). * If the model is already L2v4, assume that the user wants to attempt to * convert it down to Level 1 (specifically L1v2). */ int olevel = (int)document.getLevel(); int oversion = (int)document.getVersion(); bool success; if (olevel < latestLevel || oversion < latestVersion) { Console.Write("Attempting to convert Level " + olevel + " Version " + oversion + " model to Level " + latestLevel + " Version " + latestVersion + "." + Environment.NewLine); success = document.setLevelAndVersion(latestLevel, latestVersion); } else { Console.Write("Attempting to convert Level " + olevel + " Version " + oversion + " model to Level 1 Version 2." + Environment.NewLine); success = document.setLevelAndVersion(1, 2); } errors = document.getNumErrors(); if (!success) { Console.Error.Write("Unable to perform conversion due to the following:" + Environment.NewLine); document.printErrors(); Console.Write(Environment.NewLine); Console.Write("Conversion skipped. Either libSBML does not (yet)" + Environment.NewLine + "have the ability to convert this model or (automatic)" + Environment.NewLine + "conversion is not possible in this case." + Environment.NewLine); return((int)errors); } else if (errors > 0) { Console.Write("Information may have been lost in conversion; but a valid model "); Console.Write("was produced by the conversion.\nThe following information "); Console.Write("was provided:\n"); document.printErrors(); libsbml.writeSBML(document, outputFile); } else { Console.Write("Conversion completed." + Environment.NewLine); libsbml.writeSBML(document, outputFile); } return(0); }
public static int Main(string[] args) { if (args.Length != 2) { Console.WriteLine(" Usage: addRenderInformation <input file> <output file> \n" + " Adds a render information object to the input file"); return(1); } string inputFile = args[0]; string outputFile = args[1]; SBMLDocument doc = libsbml.readSBMLFromFile(inputFile); long numErrors = doc.getNumErrors(libsbml.LIBSBML_SEV_ERROR); if (numErrors > 0) { Console.WriteLine("Encountered errors while reading the file. "); Console.WriteLine("Please correct the following errors and try again."); doc.printErrors(); return(2); } Model model = doc.getModel(); LayoutModelPlugin plugin = (LayoutModelPlugin)model.getPlugin("layout"); if (plugin == null || plugin.getNumLayouts() == 0) { Console.WriteLine("The loaded model contains no layout information, please add these first."); return(3); } RenderListOfLayoutsPlugin lolPlugin = (RenderListOfLayoutsPlugin)plugin.getListOfLayouts().getPlugin("render"); if (lolPlugin != null && lolPlugin.getNumGlobalRenderInformationObjects() > 0) { Console.WriteLine("The loaded model contains global Render information. "); } // add render information to the first layout Layout layout = plugin.getLayout(0); RenderLayoutPlugin rPlugin = (RenderLayoutPlugin)layout.getPlugin("render"); if (rPlugin != null && rPlugin.getNumLocalRenderInformationObjects() > 0) { Console.WriteLine("The loaded model contains local Render information. "); } else { string uri = doc.getLevel() == 2 ? RenderExtension.getXmlnsL2() : RenderExtension.getXmlnsL3V1V1(); // enable render package doc.enablePackage(uri, "render", true); doc.setPackageRequired("render", false); rPlugin = (RenderLayoutPlugin)layout.getPlugin("render"); addRenderInformation(rPlugin); libsbml.writeSBMLToFile(doc, outputFile); } return(0); }