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;
        }
        public void test_SBMLConvertStrict_convertNonStrictUnits()
        {
            SBMLDocument d = new  SBMLDocument(2, 4);
            Model        m = d.createModel();
            Compartment  c = m.createCompartment();

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

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

            ar.setVariable("c");
            ar.setMath(math);
            assertTrue(d.setLevelAndVersion(2, 1, 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, 3, true) == false);
            assertTrue(d.getLevel() == 2);
            assertTrue(d.getVersion() == 4);
            assertTrue(d.setLevelAndVersion(1, 2, true) == false);
            assertTrue(d.getLevel() == 2);
            assertTrue(d.getVersion() == 4);
            d = null;
        }
Exemple #3
0
        public void test_SBMLConvert_convertToL2_SBMLDocument()
        {
            SBMLDocument d = new  SBMLDocument(1, 2);

            assertTrue(d.setLevelAndVersion(2, 1, false) == true);
            assertTrue(d.getLevel() == 2);
            assertTrue(d.getVersion() == 1);
            assertTrue(d.setLevelAndVersion(2, 2, false) == true);
            assertTrue(d.getLevel() == 2);
            assertTrue(d.getVersion() == 2);
            assertTrue(d.setLevelAndVersion(2, 3, false) == true);
            assertTrue(d.getLevel() == 2);
            assertTrue(d.getVersion() == 3);
            d = null;
        }
        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;
        }
Exemple #5
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_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;
        }
Exemple #7
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;
        }
    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);
    }
Exemple #9
0
        /// <summary>
        ///    Converts a SBML document to the latest version (3.1) that is supported.
        /// </summary>
        private void convertSBML(SBMLDocument sbmlDoc)
        {
            var latestLevel   = SBMLDocument.getDefaultLevel();
            var latestVersion = SBMLDocument.getDefaultVersion();

            if (sbmlDoc.getLevel() == latestLevel || sbmlDoc.getVersion() == latestVersion)
            {
                return;
            }

            var success = sbmlDoc.setLevelAndVersion(latestLevel, latestVersion);

            if (!success)
            {
                throw new MoBiException(SBMLConstants.CouldNotConvertToActualLevel(latestLevel, latestVersion,
                                                                                   sbmlDoc.getLevel(), sbmlDoc.getVersion()));
            }
        }
        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;
        }
Exemple #11
0
        public void test_SBMLDocument_copyConstructor()
        {
            SBMLDocument o1 = new SBMLDocument();

            o1.setLevelAndVersion(2, 1, false);
            assertTrue(o1.getLevel() == 2);
            assertTrue(o1.getVersion() == 1);
            SBMLDocument o2 = new SBMLDocument(o1);

            assertTrue(o2.getLevel() == 2);
            assertTrue(o2.getVersion() == 1);
            o2 = null;
            o1 = null;
        }
Exemple #12
0
        public void Initialize(Model sbmlModel, SBMLDocument sbmlDoc)
        {
            Level   = (int)sbmlDoc.getLevel();
            Version = (int)sbmlDoc.getVersion();
            SaveSpeciesReferences(sbmlModel);

            if (sbmlModel.isSetConversionFactor())
            {
                ConversionFactor = sbmlModel.getConversionFactor();
            }
            if (sbmlModel.isSetSBOTerm())
            {
                SboTerm = sbmlModel.getSBOTerm();
            }
        }
Exemple #13
0
        public void test_SBMLDocument_assignmentOperator()
        {
            SBMLDocument o1 = new SBMLDocument();

            o1.setLevelAndVersion(2, 1, false);
            assertTrue(o1.getLevel() == 2);
            assertTrue(o1.getVersion() == 1);
            SBMLDocument o2 = new SBMLDocument();

            o2 = o1;
            assertTrue(o2.getLevel() == 2);
            assertTrue(o2.getVersion() == 1);
            o2 = null;
            o1 = null;
        }
Exemple #14
0
        public void test_SBMLConvert_addModifiersToReaction()
        {
            SBMLDocument d  = new  SBMLDocument(1, 2);
            Model        m  = d.createModel();
            Reaction     r  = m.createReaction();
            KineticLaw   kl = r.createKineticLaw();

            kl.setFormula("k1*S1*S2*S3*S4*S5");
            SimpleSpeciesReference ssr1;
            SimpleSpeciesReference ssr2;
            Species s1 = m.createSpecies();

            s1.setId("S1");
            Species s2 = m.createSpecies();

            s2.setId("S2");
            Species s3 = m.createSpecies();

            s3.setId("S3");
            Species s4 = m.createSpecies();

            s4.setId("S4");
            Species s5 = m.createSpecies();

            s5.setId("S5");
            SpeciesReference sr1 = r.createReactant();
            SpeciesReference sr2 = r.createReactant();
            SpeciesReference sr3 = r.createProduct();

            sr1.setSpecies("S1");
            sr2.setSpecies("S2");
            sr3.setSpecies("S5");
            assertTrue(r.getNumModifiers() == 0);
            assertTrue(d.setLevelAndVersion(2, 1, false) == true);
            assertTrue(d.getLevel() == 2);
            assertTrue(d.getVersion() == 1);
            assertTrue(m.getReaction(0).getNumModifiers() == 2);
            ssr1 = m.getReaction(0).getModifier(0);
            ssr2 = m.getReaction(0).getModifier(1);
            assertTrue(("S3" == ssr1.getSpecies()));
            assertTrue(("S4" == ssr2.getSpecies()));
            d = null;
        }
    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 != 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:  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);
    }