public static int Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: create_sedml output-filename."); return(2); } // create the document SedDocument doc = new SedDocument(); doc.setLevel(1); doc.setVersion(1); { // create a first model referencing an sbml file SedModel model = doc.createModel(); model.setId("model1"); model.setSource("file.xml"); model.setLanguage("urn:sedml:sbml"); // create a second model modifying a variable of that other sbml file model = doc.createModel(); model.setId("model2"); model.setSource("model1"); model.setLanguage("urn:sedml:sbml"); // change a paramerter 'k' to 0.1 SedChangeAttribute change = model.createChangeAttribute(); change.setTarget("/sbml:sbml/sbml:model/sbml:listOfParameters/sbml:parameter[@id='k']/@value"); change.setNewValue("0.1"); // remove species 's1' SedRemoveXML remove = model.createRemoveXML(); remove.setTarget("/sbml:sbml/sbml:model/sbml:listOfSpecies/sbml:species[@id='S1']"); // now for something tricky we want to update the initialConcentration of 'S2' to be // half what it was in the original model SedComputeChange compute = model.createComputeChange(); compute.setTarget("/sbml:sbml/sbml:model/sbml:listOfSpecies/sbml:species[@id="S2"]/@initialConcentration"); SedVariable variable = compute.createVariable(); variable.setId("S2"); variable.setModelReference("model1"); variable.setTarget("/sbml:sbml/sbml:model/sbml:listOfSpecies/sbml:species[@id='S2']"); compute.setMath(libsedml.parseFormula("S2 / 2")); } // create simulation SedUniformTimeCourse tc = doc.createUniformTimeCourse(); tc.setId("sim1"); tc.setInitialTime(0.0); tc.setOutputStartTime(0.0); tc.setOutputEndTime(10.0); tc.setNumberOfPoints(1000); // need to set the correct KISAO Term SedAlgorithm alg = tc.createAlgorithm(); alg.setKisaoID("KISAO:0000019"); // create a task that uses the simulation and the model above SedTask task = doc.createTask(); task.setId("task1"); task.setModelReference("model1"); task.setSimulationReference("sim1"); // add a DataGenerator to hold the output for time SedDataGenerator dg = doc.createDataGenerator(); dg.setId("time"); dg.setName("time"); SedVariable var = dg.createVariable(); var.setId("v0"); var.setName("time"); var.setTaskReference("task1"); var.setSymbol("urn:sedml:symbol:time"); dg.setMath(libsedml.parseFormula("v0")); // and one for S1 dg = doc.createDataGenerator(); dg.setId("S1"); dg.setName("S1"); var = dg.createVariable(); var.setId("v1"); var.setName("S1"); var.setTaskReference("task1"); var.setTarget("/sbml:sbml/sbml:model/sbml:listOfSpecies/sbml:species[@id='S1']"); dg.setMath(libsedml.parseFormula("v1")); // add a report SedReport report = doc.createReport(); report.setId("r1"); report.setName("report 1"); SedDataSet set = report.createDataSet(); set.setId("ds1"); set.setLabel("time"); set.setDataReference("time"); set = report.createDataSet(); set.setId("ds2"); set.setLabel("S1"); set.setDataReference("S1"); // add a 2d plot SedPlot2D plot = doc.createPlot2D(); plot.setId("p1"); plot.setName("S1 Timecourse"); SedCurve curve = plot.createCurve(); curve.setId("c1"); curve.setName("S1"); curve.setLogX(false); curve.setLogY(false); curve.setXDataReference("time"); curve.setYDataReference("S1"); // add a 3D Plot SedPlot3D plot2 = doc.createPlot3D(); plot2.setId("p2"); plot2.setName("dunno"); SedSurface surf = plot2.createSurface(); surf.setId("surf1"); surf.setName("S1"); surf.setLogX(false); surf.setLogY(false); surf.setLogZ(false); surf.setXDataReference("time"); surf.setYDataReference("S1"); surf.setZDataReference("S1"); // write the document libsedml.writeSedML(doc, args[0]); return(0); }
public static int Main(string[] args) { if (args.Length != 1) { Console.WriteLine("{0}Usage: print_sedml input-filename{0}{0}", Environment.NewLine); return(2); } SedDocument doc = libsedml.readSedML(args[0]); if (doc.getErrorLog().getNumFailsWithSeverity(libsedml.LIBSEDML_SEV_ERROR) > 0) { Console.WriteLine(doc.getErrorLog().toString()); return(2); } Console.WriteLine("The document has " + doc.getNumSimulations() + " simulation(s)." + Environment.NewLine); for (int i = 0; i < doc.getNumSimulations(); ++i) { SedSimulation current = doc.getSimulation(i); switch (current.getTypeCode()) { case libsedml.SEDML_SIMULATION_UNIFORMTIMECOURSE: { SedUniformTimeCourse tc = (SedUniformTimeCourse)(current); Console.WriteLine("\tTimecourse id=" + tc.getId() + " start=" + tc.getOutputStartTime() + " end=" + tc.getOutputEndTime() + " numPoints=" + tc.getNumberOfPoints() + " kisao=" + (tc.isSetAlgorithm() ? tc.getAlgorithm().getKisaoID() : "none") + Environment.NewLine); break; } default: Console.WriteLine("\tUncountered unknown simulation. " + current.getId() + Environment.NewLine); break; } } Console.WriteLine(Environment.NewLine); Console.WriteLine("The document has " + doc.getNumModels() + " model(s)." + Environment.NewLine); for (int i = 0; i < doc.getNumModels(); ++i) { SedModel current = doc.getModel(i); Console.WriteLine("\tModel id=" + current.getId() + " language=" + current.getLanguage() + " source=" + current.getSource() + " numChanges=" + current.getNumChanges() + Environment.NewLine); } Console.WriteLine(Environment.NewLine); Console.WriteLine("The document has " + doc.getNumTasks() + " task(s)." + Environment.NewLine); for (int i = 0; i < doc.getNumTasks(); ++i) { SedTask current = doc.getTask(i); Console.WriteLine("\tTask id=" + current.getId() + " model=" + current.getModelReference() + " sim=" + current.getSimulationReference() + Environment.NewLine); } Console.WriteLine(Environment.NewLine); Console.WriteLine("The document has " + doc.getNumDataGenerators() + " datagenerators(s)." + Environment.NewLine); for (int i = 0; i < doc.getNumDataGenerators(); ++i) { SedDataGenerator current = doc.getDataGenerator(i); Console.WriteLine("\tDG id=" + current.getId() + " math=" + libsedml.formulaToString(current.getMath()) + Environment.NewLine); } Console.WriteLine(Environment.NewLine); Console.WriteLine("The document has " + doc.getNumOutputs() + " output(s)." + Environment.NewLine); for (int i = 0; i < doc.getNumOutputs(); ++i) { SedOutput current = doc.getOutput(i); switch (current.getTypeCode()) { case libsedml.SEDML_OUTPUT_REPORT: { SedReport r = (SedReport)(current); Console.WriteLine("\tReport id=" + current.getId() + " numDataSets=" + r.getNumDataSets() + Environment.NewLine); break; } case libsedml.SEDML_OUTPUT_PLOT2D: { SedPlot2D p = (SedPlot2D)(current); Console.WriteLine("\tPlot2d id=" + current.getId() + " numCurves=" + p.getNumCurves() + Environment.NewLine); break; } case libsedml.SEDML_OUTPUT_PLOT3D: { SedPlot3D p = (SedPlot3D)(current); Console.WriteLine("\tPlot3d id=" + current.getId() + " numSurfaces=" + p.getNumSurfaces() + Environment.NewLine); break; } default: Console.WriteLine("\tEncountered unknown output " + current.getId() + Environment.NewLine); break; } } return(0); }