Пример #1
0
        public void test_SBMLDocument_clone()
        {
            SBMLDocument o1 = new SBMLDocument();

            o1.setLevelAndVersion(1, 1, false);
            Model m = new Model(1, 1);

            m.createCompartment();
            m.createSpecies();
            m.createReaction();
            m.setId("foo");
            o1.setModel(m);
            assertTrue(o1.getLevel() == 1);
            assertTrue(o1.getVersion() == 1);
            assertTrue(o1.getModel().getId() == "foo");
            assertTrue(o1.getModel().getLevel() == 1);
            assertTrue(o1.getModel().getVersion() == 1);
            assertTrue(o1.getModel().getSBMLDocument() == o1);
            SBMLDocument o2 = o1.clone();

            assertTrue(o2.getLevel() == 1);
            assertTrue(o2.getVersion() == 1);
            assertTrue(o2.getModel().getId() == "foo");
            assertTrue(o2.getModel().getLevel() == 1);
            assertTrue(o2.getModel().getVersion() == 1);
            assertTrue(o2.getModel().getSBMLDocument() == o2);
            o2 = null;
            o1 = null;
        }
        public void test_SBMLDocument_setModel()
        {
            SBMLDocument d  = new  SBMLDocument(2, 4);
            Model        m1 = new  Model(2, 4);
            Model        m2 = new  Model(2, 4);
            Model        mout;

            assertTrue(d.getModel() == null);
            int i = d.setModel(m1);

            assertTrue(i == libsbml.LIBSBML_OPERATION_SUCCESS);
            mout = d.getModel();
            assertTrue(mout != null);
            assertTrue(mout != m1);
            i = d.setModel(d.getModel());
            assertTrue(i == libsbml.LIBSBML_OPERATION_SUCCESS);
            mout = d.getModel();
            assertTrue(mout != null);
            assertTrue(mout != m1);
            i = d.setModel(m2);
            assertTrue(i == libsbml.LIBSBML_OPERATION_SUCCESS);
            mout = d.getModel();
            assertTrue(mout != null);
            assertTrue(mout != m2);
            d = null;
        }
        public void test_SBMLConvertStrict_convertNonStrictSBO()
        {
            SBMLDocument d = new  SBMLDocument(2, 4);
            Model        m = d.createModel();
            Compartment  c = m.createCompartment();

            c.setId("c");
            c.setConstant(false);
            (c).setSBOTerm(64);
            assertTrue(d.setLevelAndVersion(2, 3, true) == false);
            assertTrue(d.getLevel() == 2);
            assertTrue(d.getVersion() == 4);
            assertTrue(d.setLevelAndVersion(2, 2, true) == false);
            assertTrue(d.getLevel() == 2);
            assertTrue(d.getVersion() == 4);
            assertTrue(d.setLevelAndVersion(2, 1, true) == true);
            assertTrue(d.getLevel() == 2);
            assertTrue(d.getVersion() == 1);
            Compartment c1 = d.getModel().getCompartment(0);

            assertTrue((c1).getSBOTerm() == -1);
            assertTrue(d.setLevelAndVersion(1, 2, true) == true);
            assertTrue(d.getLevel() == 1);
            assertTrue(d.getVersion() == 2);
            Compartment c2 = d.getModel().getCompartment(0);

            assertTrue((c2).getSBOTerm() == -1);
            d = null;
        }
Пример #4
0
    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 void test_SBMLConvertStrict_convertL1ParamRule()
        {
            SBMLDocument d = new  SBMLDocument(1, 2);
            Model        m = d.createModel();
            Compartment  c = m.createCompartment();

            c.setId("c");
            Parameter p = m.createParameter();

            p.setId("p");
            Parameter p1 = m.createParameter();

            p1.setId("p1");
            ASTNode math = libsbml.parseFormula("p");
            Rule    ar   = m.createAssignmentRule();

            ar.setVariable("p1");
            ar.setMath(math);
            ar.setUnits("mole");
            assertTrue(d.setLevelAndVersion(2, 1, true) == true);
            assertTrue(d.getLevel() == 2);
            assertTrue(d.getVersion() == 1);
            Rule r1 = d.getModel().getRule(0);

            assertTrue(r1.getUnits() == "");
            d = null;
        }
Пример #6
0
        public void test_SBMLConvert_convertToL3_stoichiometryMath()
        {
            SBMLDocument d = new  SBMLDocument(2, 1);
            Model        m = d.createModel();
            Compartment  c = m.createCompartment();

            c.setId("c");
            Species s = m.createSpecies();

            s.setId("s");
            s.setCompartment("c");
            Reaction         r  = m.createReaction();
            SpeciesReference sr = r.createReactant();

            sr.setSpecies("s");
            StoichiometryMath sm  = sr.createStoichiometryMath();
            ASTNode           ast = libsbml.parseFormula("c*2");

            sm.setMath(ast);
            assertTrue(m.getNumRules() == 0);
            assertTrue(sr.isSetId() == false);
            assertTrue(d.setLevelAndVersion(3, 1, false) == true);
            m  = d.getModel();
            r  = m.getReaction(0);
            sr = r.getReactant(0);
            assertTrue(m.getNumRules() == 1);
            assertTrue(sr.isSetId() == true);
            Rule rule = m.getRule(0);

            assertTrue((rule.getVariable() == sr.getId()));
            d = null;
        }
Пример #7
0
        public void test_SBMLConvert_convertToL3_localParameters()
        {
            SBMLDocument d = new  SBMLDocument(1, 2);
            Model        m = d.createModel();
            Compartment  c = m.createCompartment();

            c.setId("c");
            Species s = m.createSpecies();

            s.setId("s");
            s.setCompartment("c");
            Reaction         r  = m.createReaction();
            SpeciesReference sr = r.createReactant();

            sr.setSpecies("s");
            KineticLaw kl = r.createKineticLaw();

            kl.setFormula("s*k");
            Parameter p = kl.createParameter();

            p.setId("k");
            assertTrue(kl.getNumLocalParameters() == 0);
            assertTrue(d.setLevelAndVersion(3, 1, false) == true);
            m  = d.getModel();
            r  = m.getReaction(0);
            kl = r.getKineticLaw();
            assertTrue(kl.getNumLocalParameters() == 1);
            LocalParameter lp = kl.getLocalParameter(0);

            d = null;
        }
        public void setUp()
        {
            string filename = "../../sbml/annotation/test/test-data/annotation.xml";

            d = libsbml.readSBML(filename);
            m = d.getModel();
        }
Пример #9
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 void test_SBMLConvertStrict_convertToL1()
        {
            SBMLDocument d = new  SBMLDocument(2, 4);
            Model        m = d.createModel();

            (m).setMetaId("_m");
            Compartment c = m.createCompartment();

            c.setId("c");
            (c).setSBOTerm(240);
            Species s = m.createSpecies();

            s.setId("s");
            s.setCompartment("c");
            assertTrue(d.setLevelAndVersion(1, 2, true) == true);
            assertTrue(d.getLevel() == 1);
            assertTrue(d.getVersion() == 2);
            Model m1 = d.getModel();

            assertTrue((m1).getMetaId() == "");
            Compartment c1 = m1.getCompartment(0);

            assertTrue((c1).getSBOTerm() == -1);
            Species s1 = m1.getSpecies(0);

            assertTrue(s1.getHasOnlySubstanceUnits() == false);
            d = null;
        }
    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);
    }
Пример #12
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);
    }
Пример #13
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_Model_parent_add()
        {
            SBMLDocument d = new SBMLDocument(2, 4);
            Model        m = new Model(2, 4);

            d.setModel(m);
            assertTrue(d == d.getModel().getParentSBMLObject());
            d = null;
        }
Пример #15
0
        public void test_Model_ancestor_add()
        {
            SBMLDocument d = new SBMLDocument(2, 4);
            Model        m = new Model(2, 4);

            d.setModel(m);
            assertTrue(d == d.getModel().getAncestorOfType(libsbml.SBML_DOCUMENT));
            d = null;
        }
        public void test_SBMLDocument_setModel3()
        {
            SBMLDocument d  = new  SBMLDocument(2, 2);
            Model        m1 = new  Model(2, 2);
            int          i  = d.setModel(m1);

            assertTrue(i == libsbml.LIBSBML_OPERATION_SUCCESS);
            assertTrue(d.getModel() != null);
            d = null;
        }
        public void test_SBMLDocument_setModel1()
        {
            SBMLDocument d  = new  SBMLDocument(2, 2);
            Model        m1 = new  Model(2, 1);
            int          i  = d.setModel(m1);

            assertTrue(i == libsbml.LIBSBML_VERSION_MISMATCH);
            assertTrue(d.getModel() == null);
            d = null;
        }
Пример #18
0
        public void test_Model_ancestor_create()
        {
            SBMLDocument d = new SBMLDocument();
            Model        m = d.createModel();

            assertTrue(m.getAncestorOfType(libsbml.SBML_DOCUMENT) == d);
            Model obj = d.getModel();

            assertTrue(obj.getAncestorOfType(libsbml.SBML_DOCUMENT) == d);
            d = null;
        }
        public void test_SBMLDocument_setModel2()
        {
            SBMLDocument d  = new  SBMLDocument(2, 2);
            Model        m1 = new  Model(1, 2);

            m1.createCompartment();
            int i = d.setModel(m1);

            assertTrue(i == libsbml.LIBSBML_LEVEL_MISMATCH);
            assertTrue(d.getModel() == null);
            d = null;
        }
Пример #20
0
        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);
        }
Пример #21
0
        public void test_SBMLConvert_convertFromL3_modelUnits()
        {
            UnitDefinition ud;
            SBMLDocument   d = new  SBMLDocument(3, 1);
            Model          m = d.createModel();

            m.setVolumeUnits("litre");
            assertTrue(m.getNumUnitDefinitions() == 0);
            assertTrue(d.setLevelAndVersion(2, 4, false) == true);
            m = d.getModel();
            assertTrue(m.getNumUnitDefinitions() == 1);
            ud = m.getUnitDefinition(0);
            assertTrue(("volume" == ud.getId()));
            assertTrue(ud.getNumUnits() == 1);
            assertTrue(ud.getUnit(0).getKind() == libsbml.UNIT_KIND_LITRE);
        }
Пример #22
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);
    }
Пример #23
0
        public void test_SBMLConvert_convertToL2v4_DuplicateAnnotations_model()
        {
            SBMLDocument d          = new  SBMLDocument(2, 1);
            Model        m          = d.createModel();
            string       annotation = "<rdf/>\n<rdf/>";
            int          i          = (m).setAnnotation(annotation);

            assertTrue(d.getLevel() == 2);
            assertTrue(d.getVersion() == 1);
            assertTrue((m).getAnnotation().getNumChildren() == 2);
            assertTrue(d.setLevelAndVersion(2, 4, true) == true);
            assertTrue(d.getLevel() == 2);
            assertTrue(d.getVersion() == 4);
            m = d.getModel();
            assertTrue((m).getAnnotation().getNumChildren() == 1);
            d = null;
        }
Пример #24
0
        public void test_WriteL3SBML_Reaction_full()
        {
            string expected = "<reaction id=\"v1\" reversible=\"true\" fast=\"false\">\n" +
                              "  <listOfReactants>\n" +
                              "    <speciesReference species=\"x0\"/>\n" +
                              "  </listOfReactants>\n" +
                              "  <listOfProducts>\n" +
                              "    <speciesReference species=\"s1\"/>\n" +
                              "  </listOfProducts>\n" +
                              "  <listOfModifiers>\n" +
                              "    <modifierSpeciesReference species=\"m1\"/>\n" +
                              "  </listOfModifiers>\n" +
                              "  <kineticLaw>\n" +
                              "    <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n" +
                              "      <apply>\n" +
                              "        <divide/>\n" +
                              "        <apply>\n" +
                              "          <times/>\n" +
                              "          <ci> vm </ci>\n" +
                              "          <ci> s1 </ci>\n" +
                              "        </apply>\n" +
                              "        <apply>\n" +
                              "          <plus/>\n" +
                              "          <ci> km </ci>\n" +
                              "          <ci> s1 </ci>\n" +
                              "        </apply>\n" +
                              "      </apply>\n" +
                              "    </math>\n" +
                              "  </kineticLaw>\n" +
                              "</reaction>";

            D.createModel();
            Reaction r = D.getModel().createReaction();

            r.setId("v1");
            r.setReversible(true);
            r.setFast(false);
            r.createReactant().setSpecies("x0");
            r.createProduct().setSpecies("s1");
            r.createModifier().setSpecies("m1");
            r.createKineticLaw().setFormula("(vm * s1)/(km + s1)");
            assertEquals(true, equals(expected, r.toSBML()));
        }
Пример #25
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));
        }
    }
Пример #26
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:  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 != 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)
    {
        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);
    }