int main (int argc, char *argv[]) { SBMLDocument_t *doc; if (argc != 4) { printf("Usage: stripPackage input-filename package-to-strip output-filename\n"); return 2; } doc = readSBML(argv[1]); if (SBMLDocument_getNumErrorsWithSeverity(doc, LIBSBML_SEV_ERROR) > 0) { SBMLDocument_printErrors(doc, stderr); } else { /* need new variables ... */ ConversionProperties_t* props; ConversionOption_t* option1; ConversionOption_t* option2; /* create a new conversion properties structure */ props = ConversionProperties_create(); /* add an option that we want to strip a given package */ option1 = ConversionOption_create("stripPackage"); ConversionOption_setType(option1, CNV_TYPE_BOOL); ConversionOption_setValue(option1, "true"); ConversionOption_setDescription(option1, "Strip SBML Level 3 package constructs from the model"); ConversionProperties_addOption(props, option1); /* add an option with the package we want to remove */ option2 = ConversionOption_create("package"); ConversionOption_setType(option2, CNV_TYPE_STRING); ConversionOption_setValue(option2, argv[2]); ConversionOption_setDescription(option2, "Name of the SBML Level 3 package to be stripped"); ConversionProperties_addOption(props, option2); /* perform the conversion */ if (SBMLDocument_convert(doc, props) != LIBSBML_OPERATION_SUCCESS) { printf ("conversion failed ... "); return 3; } /* successfully completed, write the resulting file */ writeSBML(doc, argv[3]); } return 0; }
int main (int argc, char *argv[]) { SBMLDocument_t *doc; if (argc != 3) { printf("Usage: echoSBML input-filename output-filename\n"); return 2; } doc = readSBML(argv[1]); if (SBMLDocument_getNumErrors(doc) > 0) { SBMLDocument_printErrors(doc, stderr); } else { writeSBML(doc, argv[2]); } return 0; }
LIBSBML_CPP_NAMESPACE_USE int main(int argc,char** argv) { if (argc != 2) { std::cout << "Usage: example1\n"; return 1; } // // Creates an SBMLNamespaces object with the given SBML level, version // package name, package version. // // (NOTE) By defualt, the name of package (i.e. "qual") will be used // if the arugment for the prefix is missing or empty. Thus the argument // for the prefix can be added as follows: // // SBMLNamespaces sbmlns(3,1,"qual",1,"QUAL"); // SBMLNamespaces sbmlns(3,1,"qual",1); // // (NOTES) The above code creating an SBMLNamespaces object can be replaced // with one of the following other styles. // // (1) Creates an SBMLNamespace object with a SBML core namespace and then // adds a qual package namespace to the object. // // SBMLNamespaces sbmlns(3,1); // sbmlns.addPkgNamespace("qual",1); // // OR // // SBMLNamespaces sbmlns(3,1); // sbmlns.addNamespace(QualExtension::XmlnsL3V1V1,"qual"); // // (2) Creates a QualPkgNamespaces object (SBMLNamespace derived class for // qual package. The class is basically used for createing an SBase // derived objects defined in the qual package) with the given SBML // level, version, and package version // // QualPkgNamespaces sbmlns(3,1,1); // // create the document SBMLDocument *document = new SBMLDocument(&sbmlns); // mark qual as required document->setPackageRequired("qual", true); // create the Model Model* model=document->createModel(); // create the Compartment Compartment* compartment = model->createCompartment(); compartment->setId("c"); compartment->setConstant(true); // // Get a QualModelPlugin object plugged in the model object. // // The type of the returned value of SBase::getPlugin() function is // SBasePlugin*, and thus the value needs to be casted for the // corresponding derived class. // QualModelPlugin* mplugin = static_cast<QualModelPlugin*>(model->getPlugin("qual")); // create the QualitativeSpecies QualitativeSpecies* qs = mplugin->createQualitativeSpecies(); qs->setId("s1"); qs->setCompartment("c"); qs->setConstant(false); qs->setInitialLevel(1); qs->setMaxLevel(4); qs->setName("sss"); // create the Transition Transition* t = mplugin->createTransition(); t->setId("d"); t->setSBOTerm(1); Input* i = t->createInput(); i->setId("RD"); i->setQualitativeSpecies("s1"); i->setTransitionEffect(INPUT_TRANSITION_EFFECT_NONE); i->setSign(INPUT_SIGN_NEGATIVE); i->setThresholdLevel(2); i->setName("aa"); Output* o = t->createOutput(); o->setId("wd"); o->setQualitativeSpecies("s1"); o->setTransitionEffect(OUTPUT_TRANSITION_EFFECT_PRODUCTION); o->setOutputLevel(2); o->setName("aa"); DefaultTerm* dt = t->createDefaultTerm(); dt->setResultLevel(2) ; FunctionTerm* ft = t->createFunctionTerm(); ASTNode* math = SBML_parseL3Formula("geq(s1, 2)"); ft->setResultLevel(1); ft->setMath(math); writeSBML(document,"qual_example1.xml"); delete document; return 0; }
int main (int argc, char *argv[]) { SBMLDocument_t* d; Model_t* m; unsigned int errors; if (argc != 3) { printf("\n" " usage: appendAnnotation <input-filename> <output-filename>\n" "\n"); return 2; } d = readSBML(argv[1]); errors = SBMLDocument_getNumErrors(d); if (errors > 0) { printf("Read Error(s):\n"); SBMLDocument_printErrors(d, stdout); printf("Correct the above and re-run.\n"); } else { int n; Species_t* s; char* model_history_annotation = "<annotation>\n" " <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:vCard=\"http://www.w3.org/2001/vcard-rdf/3.0#\" xmlns:bqbiol=\"http://biomodels.net/biology-qualifiers/\" xmlns:bqmodel=\"http://biomodels.net/model-qualifiers/\">\n" " <rdf:Description rdf:about=\"#\">\n" " <dc:creator rdf:parseType=\"Resource\">\n" " <rdf:Bag>\n" " <rdf:li rdf:parseType=\"Resource\">\n" " <vCard:N rdf:parseType=\"Resource\">\n" " <vCard:Family>Keating</vCard:Family>\n" " <vCard:Given>Sarah</vCard:Given>\n" " </vCard:N>\n" " <vCard:EMAIL>[email protected]</vCard:EMAIL>\n" " <vCard:ORG>\n" " <vCard:Orgname>University of Hertfordshire</vCard:Orgname>\n" " </vCard:ORG>\n" " </rdf:li>\n" " </rdf:Bag>\n" " </dc:creator>\n" " <dcterms:created rdf:parseType=\"Resource\">\n" " <dcterms:W3CDTF>1999-11-13T06:54:32Z</dcterms:W3CDTF>\n" " </dcterms:created>\n" " <dcterms:modified rdf:parseType=\"Resource\">\n" " <dcterms:W3CDTF>2007-11-31T06:54:00-02:00</dcterms:W3CDTF>\n" " </dcterms:modified>\n" " </rdf:Description>\n" " </rdf:RDF>\n" "</annotation>\n"; m = SBMLDocument_getModel(d); SBase_appendAnnotationString((SBase_t*)m, model_history_annotation); /* * The above code can be replaced by the following code. * ModelHistory * h = new ModelHistory(); ModelCreator *c = new ModelCreator(); c->setFamilyName("Keating"); c->setGivenName("Sarah"); c->setEmail("*****@*****.**"); c->setOrganisation("University of Hertfordshire"); h->addCreator(c); Date * date = new Date("1999-11-13T06:54:32"); Date * date2 = new Date("2007-11-31T06:54:00-02:00"); h->setCreatedDate(date); h->setModifiedDate(date2); d->getModel()->setModelHistory(h); * */ n = Model_getNumSpecies(m); if (n > 0) { char* cvterms_annotation = "<annotation>\n" " <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:vCard=\"http://www.w3.org/2001/vcard-rdf/3.0#\" xmlns:bqbiol=\"http://biomodels.net/biology-qualifiers/\" xmlns:bqmodel=\"http://biomodels.net/model-qualifiers/\">\n" " <rdf:Description rdf:about=\"#\">\n" " <bqbiol:isVersionOf>\n" " <rdf:Bag>\n" " <rdf:li rdf:resource=\"http://www.geneontology.org/#GO:0005892\"/>\n" " <rdf:li rdf:resource=\"http://www.ebi.ac.uk/interpro/#IPR002394\"/>\n" " </rdf:Bag>\n" " </bqbiol:isVersionOf>\n" " <bqbiol:is>\n" " <rdf:Bag>\n" " <rdf:li rdf:resource=\"http://www.geneontology.org/#GO:0005895\"/>\n" " </rdf:Bag>\n" " </bqbiol:is>\n" " </rdf:Description>\n" " </rdf:RDF>\n" "</annotation>\n"; s = Model_getSpecies(m, 0); SBase_appendAnnotationString((SBase_t*)s, cvterms_annotation); /* * The above code can be replaced by the following code. * CVTerm *cv = new CVTerm(); cv->setQualifierType(BIOLOGICAL_QUALIFIER); cv->setBiologicalQualifierType(BQB_IS_VERSION_OF); cv->addResource("http://www.geneontology.org/#GO:0005892"); CVTerm *cv2 = new CVTerm(); cv2->setQualifierType(BIOLOGICAL_QUALIFIER); cv2->setBiologicalQualifierType(BQB_IS); cv2->addResource("http://www.geneontology.org/#GO:0005895"); CVTerm *cv1 = new CVTerm(); cv1->setQualifierType(BIOLOGICAL_QUALIFIER); cv1->setBiologicalQualifierType(BQB_IS_VERSION_OF); cv1->addResource("http://www.ebi.ac.uk/interpro/#IPR002394"); s->addCVTerm(cv); s->addCVTerm(cv2); s->addCVTerm(cv1); * */ } writeSBML(d, argv[2]); } SBMLDocument_free(d); return errors; }
int main (int argc, char *argv[]) { unsigned int latestLevel = SBMLDocument_getDefaultLevel(); unsigned int latestVersion = SBMLDocument_getDefaultVersion(); unsigned int errors; SBMLDocument_t *d; if (argc != 3) { printf("Usage: convertSBML input-filename output-filename\n"); printf("This program will attempt to convert a model either to\n"); printf("SBML Level %d Version %d (if the model is not already) or, if", latestLevel, latestVersion); printf("the model is already expressed in Level %d Version %d, this\n", latestLevel, latestVersion); printf("program will attempt to convert the model to Level 1 Version 2.\n"); return 1; } d = readSBML(argv[1]); errors = SBMLDocument_getNumErrors(d); if (errors > 0) { printf("Encountered the following SBML error(s):\n"); SBMLDocument_printErrors(d, stdout); printf("Conversion skipped. Please correct the problems above first.\n"); return errors; } else { unsigned int olevel = SBMLDocument_getLevel(d); unsigned int oversion = SBMLDocument_getVersion(d); int success; if (olevel < latestLevel || oversion < latestVersion) { printf("Attempting to convert model to SBML Level %d Version %d.\n", latestLevel, latestVersion); success = SBMLDocument_setLevelAndVersion(d, latestLevel, latestVersion); } else { printf("Attempting to convert model to SBML Level 1 Version 2.\n"); success = SBMLDocument_setLevelAndVersion(d, 1, 2); } errors = SBMLDocument_getNumErrors(d); if (!success) { printf("Unable to perform conversion due to the following:\n"); SBMLDocument_printErrors(d, stdout); printf("Conversion skipped. Either libSBML does not (yet) have\n"); printf("ability to convert this model, or (automatic) conversion\n"); printf("is not possible in this case.\n"); } else if (errors > 0) { printf("Information may have been lost in conversion; but a valid model "); printf("was produced by the conversion.\nThe following information "); printf("was provided:\n"); SBMLDocument_printErrors(d, stdout); writeSBML(d, argv[2]); } else { printf("Conversion completed.\n"); writeSBML(d, argv[2]); } } SBMLDocument_free(d); return errors; }
LIBSBML_CPP_NAMESPACE_USE int main(int argc,char** argv) { SBMLNamespaces sbmlns(3,1,"fbc",1); // create the document SBMLDocument *document = new SBMLDocument(&sbmlns); document->setPackageRequired("fbc", false); // create the Model Model* model=document->createModel(); // create the Compartment Compartment* compartment = model->createCompartment(); compartment->setId("compartment"); compartment->setConstant(true); compartment->setSize(1); // create the Species Species* species = model->createSpecies(); species->setId("Node1"); species->setCompartment("compartment"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node2"); species->setCompartment("compartment"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node3"); species->setCompartment("compartment"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node4"); species->setCompartment("compartment"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node5"); species->setCompartment("compartment"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node6"); species->setCompartment("compartment"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node7"); species->setCompartment("compartment"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node8"); species->setCompartment("compartment"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node0"); species->setCompartment("compartment"); species->setBoundaryCondition(true); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node9"); species->setCompartment("compartment"); species->setBoundaryCondition(true); species->setConstant(false); species->setHasOnlySubstanceUnits(false); Reaction* reaction = model->createReaction(); reaction->setId("J0"); reaction->setReversible(false); reaction->setFast(false); SpeciesReference* reactant = reaction->createReactant(); reactant->setSpecies("Node0"); reactant->setStoichiometry(1); reactant->setConstant(true); SpeciesReference* product = reaction->createProduct(); product->setSpecies("Node1"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J1"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node1"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node2"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J2"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node2"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node3"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J3"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node1"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node4"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J4"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node4"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node3"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J5"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node3"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node5"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J6"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node5"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node6"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J7"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node6"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node7"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J8"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node5"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node8"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J9"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node8"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node7"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J10"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node7"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node9"); product->setStoichiometry(1); product->setConstant(true); // // Get a FbcModelPlugin object plugged in the model object. // // The type of the returned value of SBase::getPlugin() function is // SBasePlugin*, and thus the value needs to be casted for the // corresponding derived class. // FbcModelPlugin* mplugin = static_cast<FbcModelPlugin*>(model->getPlugin("fbc")); FluxBound* bound= mplugin->createFluxBound(); bound->setId("bound1"); bound->setReaction("J0"); bound->setOperation("equal"); bound->setValue(10); Objective* objective = mplugin->createObjective(); objective->setId("obj1"); objective->setType("maximize"); // mark obj1 as active objective mplugin->setActiveObjectiveId("obj1"); FluxObjective* fluxObjective = objective->createFluxObjective(); fluxObjective->setReaction("J8"); fluxObjective->setCoefficient(1); writeSBML(document,"fbc_example1.xml"); delete document; }
int main (int argc, char *argv[]) { SBMLDocument_t* d; Model_t* m; unsigned int errors; if (argc != 3) { printf("\n" " usage: addModelHistory <input-filename> <output-filename>\n" "\n"); return 2; } d = readSBML(argv[1]); errors = SBMLDocument_getNumErrors(d); if (errors > 0) { printf("Read Error(s):\n"); SBMLDocument_printErrors(d, stdout); printf("Correct the above and re-run.\n"); } else { int status; Date_t* date, *date2; ModelHistory_t* h = ModelHistory_create(); ModelCreator_t* c = ModelCreator_create(); ModelCreator_setFamilyName(c, "Keating"); ModelCreator_setGivenName(c, "Sarah"); ModelCreator_setEmail(c, "*****@*****.**"); ModelCreator_setOrganisation(c, "University of Hertfordshire"); status = ModelHistory_addCreator(h, c); printStatus("Status for addCreator: ", status); date = Date_createFromString("1999-11-13T06:54:32"); date2 = Date_createFromString("2007-11-30T06:54:00-02:00"); status = ModelHistory_setCreatedDate(h, date); printStatus("Set created date: ", status); status = ModelHistory_setModifiedDate(h, date2); printStatus("Set modified date: ", status); m = SBMLDocument_getModel(d); status = Model_setModelHistory(m, h); printStatus("Set model history: ", status); writeSBML(d, argv[2]); } SBMLDocument_free(d); return errors; }
LIBSBML_CPP_NAMESPACE_USE int main(int argc,char** argv) { DynPkgNamespaces sbmlns; // create the document SBMLDocument *document = new SBMLDocument(&sbmlns); document->setPackageRequired("dyn", true); // create the Model Model* model=document->createModel(); model->setId("singleCell"); // create the Compartment Compartment* compartment = model->createCompartment(); compartment->setId("Extracellular"); compartment->setConstant(true); compartment->setSize(8000000); compartment->setSpatialDimensions(3.0); compartment = model->createCompartment(); compartment->setId("PlasmaMembrane"); compartment->setConstant(true); compartment->setSize(314); compartment->setSpatialDimensions(2.0); compartment = model->createCompartment(); compartment->setId("Cytosol"); compartment->setConstant(true); compartment->setSize(523); compartment->setSpatialDimensions(3.0); // create the Species Species* species = model->createSpecies(); species->setId("C_EC"); species->setCompartment("Extracellular"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("RTR_M"); species->setCompartment("PlasmaMembrane"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("RCC_M"); species->setCompartment("PlasmaMembrane"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("A_C"); species->setCompartment("Cytosol"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("AA_C"); species->setCompartment("Cytosol"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("T"); species->setCompartment("Cytosol"); species->setBoundaryCondition(false); species->setConstant(false); species->setInitialConcentration(10); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("S"); species->setCompartment("Cytosol"); species->setBoundaryCondition(false); species->setConstant(false); species->setInitialConcentration(5); species->setHasOnlySubstanceUnits(false); // create the Reactions Reaction* reaction = model->createReaction(); reaction->setId("r1"); reaction->setReversible(true); reaction->setFast(false); reaction->setCompartment("Extracellular"); SpeciesReference* reactant = reaction->createReactant(); reactant->setSpecies("RTR_M"); reactant->setStoichiometry(1); reactant->setConstant(true); reactant = reaction->createReactant(); reactant->setSpecies("C_EC"); reactant->setStoichiometry(1); reactant->setConstant(true); SpeciesReference* product = reaction->createProduct(); product->setSpecies("RCC_M"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("r2"); reaction->setReversible(true); reaction->setFast(false); reaction->setCompartment("Cytosol"); reactant = reaction->createReactant(); reactant->setSpecies("A_C"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("AA_C"); product->setStoichiometry(1); product->setConstant(true); SimpleSpeciesReference* modifier = reaction->createModifier(); modifier->setSpecies("RCC_M"); // Create Event Event* event = model->createEvent(); event->setUseValuesFromTriggerTime(true); Trigger* trigger = event->createTrigger(); trigger->setInitialValue(false); trigger->setPersistent(true); trigger->setMath(SBML_parseFormula("lt(AA_C, T)")); // // Get a DynEventPlugin object plugged in the event object. // // The type of the returned value of SBase::getPlugin() function is // SBasePlugin*, and thus the value needs to be casted for the // corresponding derived class. // DynEventPlugin* eplugin = static_cast<DynEventPlugin*>(event->getPlugin("dyn")); eplugin->setApplyToAll(true); eplugin->setCboTerm("http://cbo.biocomplexity.indiana.edu/svn/cbo/trunk/CBO_1_0.owl#CellDeath"); event = model->createEvent(); event->setUseValuesFromTriggerTime(true); trigger = event->createTrigger(); trigger->setInitialValue(false); trigger->setPersistent(true); trigger->setMath(SBML_parseFormula("lt(AA_C, S)")); eplugin = static_cast<DynEventPlugin*>(event->getPlugin("dyn")); eplugin->setApplyToAll(true); eplugin->setCboTerm("http://cbo.biocomplexity.indiana.edu/svn/cbo/trunk/CBO_1_0.owl#CellDevision"); document->checkConsistency(); if (document->getNumErrors(LIBSBML_SEV_ERROR) > 0) document->printErrors(); writeSBML(document,"dyn_example1.xml"); delete document; }
LIBSBML_CPP_NAMESPACE_USE int main(int argc, char** argv) { // // Creates an SBMLNamespaces object with the given SBML level, version // package name. // SBMLNamespaces sbmlns(2, 3); sbmlns.addNamespace(LayoutExtension::getXmlnsL2(), "layout"); // (NOTES) The above code creating an SBMLNamespaces object can be replaced // with the following other style. // // (2) Creates a LayoutPkgNamespaces object (SBMLNamespace derived class // for layout package. The class is basically used for createing an // SBase derived objects belonging to the layout package) with the // given SBML level, version. (Package version is not required by // Layout extension of SBML Level 2) // // LayoutPkgNamespaces sbmlns(2, 3); // // create the document SBMLDocument *document = new SBMLDocument(&sbmlns); // create the Model Model* model = document->createModel(); model->setId("TestModel_with_modifiers"); document->setModel(model); // create the Layout LayoutPkgNamespaces layoutns(2, 3); LayoutModelPlugin* mplugin = static_cast<LayoutModelPlugin*>(model->getPlugin("layout")); Layout* layout = mplugin->createLayout(); layout->setId("Layout_1"); Dimensions dim(&layoutns, 400.0, 230.0); layout->setDimensions(&dim); // create the Compartment Compartment* compartment = model->createCompartment(); compartment->setId("Yeast"); // create the CompartmentGlyph CompartmentGlyph* compartmentGlyph = layout->createCompartmentGlyph(); compartmentGlyph->setId("CompartmentGlyph_1"); compartmentGlyph->setCompartmentId(compartment->getId()); BoundingBox bb(&layoutns, "bb1", 5, 5, 390, 220); compartmentGlyph->setBoundingBox(&bb); // create the Species, SpeciesGlyphs and associated TextGlyphs // Glucose Species* species_Gluc = model->createSpecies(); species_Gluc->setId("Glucose"); species_Gluc->setCompartment(compartment->getId()); SpeciesGlyph* glyph_Gluc = layout->createSpeciesGlyph(); glyph_Gluc->setId("SpeciesGlyph_Glucose"); glyph_Gluc->setSpeciesId(species_Gluc->getId()); bb = BoundingBox(&layoutns, "bb2", 105, 20, 130, 20); glyph_Gluc->setBoundingBox(&bb); TextGlyph* tGlyph = layout->createTextGlyph(); tGlyph->setId("TextGlyph_Glucose"); bb = BoundingBox(&layoutns, "bbA", 115, 20, 110, 20); tGlyph->setBoundingBox(&bb); tGlyph->setOriginOfTextId(species_Gluc->getId()); tGlyph->setGraphicalObjectId(glyph_Gluc->getId()); // Glucose-6-phosphate Species* species_G6P = model->createSpecies(); species_G6P->setId("Glucose_hyphen_6_hyphen_phosphate"); species_G6P->setCompartment(compartment->getId()); SpeciesGlyph* glyph_G6P = layout->createSpeciesGlyph(); glyph_G6P->setId("SpeciesGlyph_G6P"); glyph_G6P->setSpeciesId(species_G6P->getId()); bb = BoundingBox(&layoutns, "bb5", 50, 190, 270, 20); glyph_G6P->setBoundingBox(&bb); tGlyph = layout->createTextGlyph(); tGlyph->setId("TextGlyph_G6P"); bb = BoundingBox(&layoutns, "bbD", 60, 190, 250, 20); tGlyph->setBoundingBox(&bb); tGlyph->setOriginOfTextId(species_G6P->getId()); tGlyph->setGraphicalObjectId(glyph_G6P->getId()); // ATP Species* species_ATP = model->createSpecies(); species_ATP->setId("ATP"); species_ATP->setCompartment(compartment->getId()); SpeciesGlyph* glyph_ATP = layout->createSpeciesGlyph(); glyph_ATP->setId("SpeciesGlyph_ATP"); glyph_ATP->setSpeciesId(species_ATP->getId()); bb = BoundingBox(&layoutns, "bb3", 270, 70, 80, 20); glyph_ATP->setBoundingBox(&bb); tGlyph = layout->createTextGlyph(); tGlyph->setId("TextGlyph_ATP"); bb = BoundingBox(&layoutns, "bbB", 280, 70, 60, 20); tGlyph->setBoundingBox(&bb); tGlyph->setOriginOfTextId(species_ATP->getId()); tGlyph->setGraphicalObjectId(glyph_ATP->getId()); // ADP Species* species_ADP = model->createSpecies(); species_ADP->setId("ADP"); species_ADP->setCompartment(compartment->getId()); SpeciesGlyph* glyph_ADP = layout->createSpeciesGlyph(); glyph_ADP->setId("glyph_ADP"); glyph_ADP->setSpeciesId(species_ADP->getId()); bb = BoundingBox(&layoutns, "bb4", 270, 140, 80, 20); glyph_ADP->setBoundingBox(&bb); tGlyph = layout->createTextGlyph(); tGlyph->setId("TextGlyph_ADP"); bb = BoundingBox(&layoutns, "bbC", 280, 140, 60, 20); tGlyph->setBoundingBox(&bb); tGlyph->setOriginOfTextId(species_ADP->getId()); tGlyph->setGraphicalObjectId(glyph_ADP->getId()); // Phosphate Species* species_Pi = model->createSpecies(); species_Pi->setId("Pi"); species_Pi->setCompartment(compartment->getId()); SpeciesGlyph* glyph_Pi = layout->createSpeciesGlyph(); glyph_Pi->setId("SpeciesGlyph_Pi"); glyph_Pi->setSpeciesId(species_Pi->getId()); bb = BoundingBox(&layoutns, "bb6", 50, 100, 60, 20); glyph_Pi->setBoundingBox(&bb); tGlyph = layout->createTextGlyph(); tGlyph->setId("TextGlyph_PI"); bb = BoundingBox(&layoutns, "bbE", 60, 100, 40, 20); tGlyph->setBoundingBox(&bb); tGlyph->setOriginOfTextId(species_Pi->getId()); tGlyph->setGraphicalObjectId(glyph_Pi->getId()); // create the Reaction Reaction* reaction_Hexokinase = model->createReaction(); reaction_Hexokinase->setId("Hexokinase"); reaction_Hexokinase->setReversible(false); ReactionGlyph* glyph_Hexokinase = layout->createReactionGlyph(); glyph_Hexokinase->setId("glyph_Hexokinase"); glyph_Hexokinase->setReactionId(reaction_Hexokinase->getId()); Curve* curve_Hexokinase = glyph_Hexokinase->getCurve(); LineSegment* ls = curve_Hexokinase->createLineSegment(); Point p(&layoutns, 170, 100); ls->setStart(&p); p = Point(&layoutns, 170, 130); ls->setEnd(&p); // create the species reference for glucose SpeciesReference* reference_Gluc = reaction_Hexokinase->createReactant(); reference_Gluc->setSpecies(species_Gluc->getId()); reference_Gluc->setId("SpeciesReference_Glucose"); // create species reference glyph for glucose SpeciesReferenceGlyph* speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph(); speciesReferenceGlyph->setId("SpeciesReferenceGlyph_Glucose"); speciesReferenceGlyph->setSpeciesGlyphId(glyph_Gluc->getId()); speciesReferenceGlyph->setSpeciesReferenceId(reference_Gluc->getId()); speciesReferenceGlyph->setRole(SPECIES_ROLE_SUBSTRATE); ls = speciesReferenceGlyph->createLineSegment(); p = Point(&layoutns, 170, 100); ls->setStart(&p); p = Point(&layoutns, 170, 50); ls->setEnd(&p); // create species reference for ATP SpeciesReference* reference_ATP = reaction_Hexokinase->createReactant(); reference_ATP->setSpecies(species_ATP->getId()); reference_ATP->setId("SpeciesReference_ATP"); // create the species reference glyph for ATP speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph(); speciesReferenceGlyph->setId("SpeciesReferenceGlyph_ATP"); speciesReferenceGlyph->setSpeciesGlyphId(glyph_ATP->getId()); speciesReferenceGlyph->setSpeciesReferenceId(reference_ATP->getId()); speciesReferenceGlyph->setRole(SPECIES_ROLE_SIDESUBSTRATE); CubicBezier* cb = speciesReferenceGlyph->createCubicBezier(); p = Point(&layoutns, 170, 100); cb->setStart(&p); p = Point(&layoutns, 170, 80); cb->setBasePoint1(&p); p = Point(&layoutns, 170, 80); cb->setBasePoint2(&p); p = Point(&layoutns, 260, 80); cb->setEnd(&p); // create species reference for G6P SpeciesReference* reference_G6P = reaction_Hexokinase->createProduct(); reference_G6P->setSpecies(species_G6P->getId()); reference_G6P->setId("SpeciesReference_G6P"); // create species reference for G6P as product speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph(); speciesReferenceGlyph->setId("SpeciesReferenceGlyph_G6P_1"); speciesReferenceGlyph->setSpeciesGlyphId(glyph_G6P->getId()); speciesReferenceGlyph->setSpeciesReferenceId(reference_G6P->getId()); speciesReferenceGlyph->setRole(SPECIES_ROLE_PRODUCT); ls = speciesReferenceGlyph->createLineSegment(); p = Point(&layoutns, 170, 130); ls->setStart(&p); p = Point(&layoutns, 170, 180); ls->setEnd(&p); // create species reference for ADP SpeciesReference* reference_ADP = reaction_Hexokinase->createProduct(); reference_ADP->setSpecies(species_ADP->getId()); reference_ADP->setId("SpeciesReference_ADP"); // create the species reference glyph for ADP speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph(); speciesReferenceGlyph->setId("SpeciesReferenceGlyph_ADP"); speciesReferenceGlyph->setSpeciesGlyphId(glyph_ADP->getId()); speciesReferenceGlyph->setSpeciesReferenceId(reference_ADP->getId()); speciesReferenceGlyph->setRole(SPECIES_ROLE_SIDEPRODUCT); cb = speciesReferenceGlyph->createCubicBezier(); p = Point(&layoutns, 170, 130); cb->setStart(&p); p = Point(&layoutns, 170, 150); cb->setBasePoint1(&p); p = Point(&layoutns, 170, 150); cb->setBasePoint2(&p); p = Point(&layoutns, 260, 150); cb->setEnd(&p); // create modifier species reference for glucose-6-phosphate ModifierSpeciesReference* reference_G6P_2 = reaction_Hexokinase->createModifier(); reference_G6P_2->setSpecies(species_G6P->getId()); reference_G6P_2->setId("ModifierSpeciesReference_G6P"); reaction_Hexokinase->addModifier(reference_G6P_2); // create species reference glyph for G6P as a modifier speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph(); speciesReferenceGlyph->setId("SpeciesReferenceGlyph_G6P_2"); speciesReferenceGlyph->setSpeciesReferenceId(reference_G6P_2->getId()); speciesReferenceGlyph->setSpeciesGlyphId(glyph_G6P->getId()); speciesReferenceGlyph->setRole(SPECIES_ROLE_INHIBITOR); cb = speciesReferenceGlyph->createCubicBezier(); p = Point(&layoutns, 45, 200); cb->setStart(&p); p = Point(&layoutns, 0, 200); cb->setBasePoint1(&p); p = Point(&layoutns, 0, 120); cb->setBasePoint2(&p); p = Point(&layoutns, 165, 120); cb->setEnd(&p); // create modifier species reference for phosphate ModifierSpeciesReference* reference_Pi = reaction_Hexokinase->createModifier(); reference_Pi->setSpecies(species_Pi->getId()); reference_Pi->setId("ModifierSpeciesReference_Pi"); reaction_Hexokinase->addModifier(reference_Pi); // create the species reference glyph for Phosphate speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph(); speciesReferenceGlyph->setId("SpeciesReferenceGlyph_PI"); speciesReferenceGlyph->setSpeciesReferenceId(reference_Pi->getId()); speciesReferenceGlyph->setSpeciesGlyphId(glyph_Pi->getId()); speciesReferenceGlyph->setRole(SPECIES_ROLE_ACTIVATOR); cb = speciesReferenceGlyph->createCubicBezier(); p = Point(&layoutns, 115, 110); cb->setStart(&p); p = Point(&layoutns, 140, 110); cb->setBasePoint1(&p); p = Point(&layoutns, 140, 110); cb->setBasePoint2(&p); p = Point(&layoutns, 165, 110); cb->setEnd(&p); // write model to file writeSBML(document, "layout_example3_L2.xml"); delete document; }
int main (int argc, char* argv[]) { unsigned int i,j,errors; const char* filename = argv[1]; SBMLDocument_t* document; Model_t* m; if (argc != 3) { printf("\nUsage: unsetNotes <input-filename> <output-filename>\n"); return 1; } filename = argv[1]; document = readSBML(filename); errors = SBMLDocument_getNumErrors(document); if(errors > 0) { SBMLDocument_printErrors(document, stderr); SBMLDocument_free(document); return errors; } m = SBMLDocument_getModel( document ); SBase_unsetNotes((SBase_t*)m); for(i=0; i < Model_getNumReactions(m); i++) { Reaction_t* re = Model_getReaction(m, i); SBase_unsetNotes((SBase_t*)re); for(j=0; j < Reaction_getNumReactants(re); j++) { SpeciesReference_t* rt = Reaction_getReactant(re,j); SBase_unsetNotes((SBase_t*)rt); } for(j=0; j < Reaction_getNumProducts(re); j++) { SpeciesReference_t* rt = Reaction_getProduct(re,j); SBase_unsetNotes((SBase_t*)rt); } for(j=0; j < Reaction_getNumModifiers(re); j++) { SpeciesReference_t* md = Reaction_getModifier(re,j); SBase_unsetNotes((SBase_t*)md); } if(Reaction_isSetKineticLaw(re)) { KineticLaw_t* kl = Reaction_getKineticLaw(re); SBase_unsetNotes((SBase_t*)kl); for(j=0; j < KineticLaw_getNumParameters(kl); j++) { Parameter_t* pa = KineticLaw_getParameter(kl, j); SBase_unsetNotes((SBase_t*)pa); } } } for(i=0; i < Model_getNumSpecies(m); i++) { Species_t* sp = Model_getSpecies(m, i); SBase_unsetNotes((SBase_t*)sp); } for(i=0; i < Model_getNumCompartments(m); i++) { Compartment_t* sp = Model_getCompartment(m,i); SBase_unsetNotes((SBase_t*)sp); } for(i=0; i < Model_getNumFunctionDefinitions(m); i++) { FunctionDefinition_t* sp = Model_getFunctionDefinition(m,i); SBase_unsetNotes((SBase_t*)sp); } for(i=0; i < Model_getNumUnitDefinitions(m); i++) { UnitDefinition_t* sp = Model_getUnitDefinition(m, i); SBase_unsetNotes((SBase_t*)sp); } for(i=0; i < Model_getNumParameters(m); i++) { Parameter_t* sp = Model_getParameter(m, i); SBase_unsetNotes((SBase_t*)sp); } for(i=0; i < Model_getNumRules(m); i++) { Rule_t* sp = Model_getRule(m, i); SBase_unsetNotes((SBase_t*)sp); } for(i=0; i < Model_getNumInitialAssignments(m); i++) { InitialAssignment_t* sp = Model_getInitialAssignment(m, i); SBase_unsetNotes((SBase_t*)sp); } for(i=0; i < Model_getNumEvents(m); i++) { Event_t* sp = Model_getEvent(m, i); SBase_unsetNotes((SBase_t*)sp); for(j=0; j < Event_getNumEventAssignments(sp); j++) { EventAssignment_t* ea = Event_getEventAssignment(sp, j); SBase_unsetNotes((SBase_t*)ea); } } for(i=0; i < Model_getNumSpeciesTypes(m); i++) { SpeciesType_t* sp = Model_getSpeciesType(m, i); SBase_unsetNotes((SBase_t*)sp); } for(i=0; i < Model_getNumConstraints(m); i++) { Constraint_t* sp = Model_getConstraint(m, i); SBase_unsetNotes((SBase_t*)sp); } writeSBML(document, argv[2]); SBMLDocument_free(document); return errors; }
LIBSBML_CPP_NAMESPACE_USE int main(int argc,char** argv) { DynPkgNamespaces sbmlns; sbmlns.addPackageNamespace("comp", 1, "comp"); // create the document SBMLDocument *document = new SBMLDocument(&sbmlns); document->setPackageRequired("dyn", true); document->setPackageRequired("comp", true); // create the Model Model* model=document->createModel(); model->setId("grid2x2"); // create the Compartment Compartment* compartment = model->createCompartment(); compartment->setId("Loc1"); compartment->setConstant(false); compartment->setSize(1); compartment->setSpatialDimensions(2.0); DynCompartmentPlugin* cplugin = static_cast<DynCompartmentPlugin*>(compartment->getPlugin("dyn")); SpatialComponent* component = cplugin->createSpatialComponent(); component->setSpatialIndex(DYN_SPATIALKIND_CARTESIANX); component->setVariable("q1_X"); component = cplugin->createSpatialComponent(); component->setSpatialIndex(DYN_SPATIALKIND_CARTESIANY); component->setVariable("q1_Y"); CompSBasePlugin* compPlugin = static_cast<CompSBasePlugin*>(compartment->getPlugin("comp")); ReplacedElement* relement = compPlugin->createReplacedElement(); relement->setIdRef("C"); relement->setSubmodelRef("GRID_1_1_cell"); compartment = model->createCompartment(); compartment->setId("Loc2"); compartment->setConstant(false); compartment->setSize(1); compartment->setSpatialDimensions(2.0); cplugin = static_cast<DynCompartmentPlugin*>(compartment->getPlugin("dyn")); component = cplugin->createSpatialComponent(); component->setSpatialIndex(DYN_SPATIALKIND_CARTESIANX); component->setVariable("q2_X"); component = cplugin->createSpatialComponent(); component->setSpatialIndex(DYN_SPATIALKIND_CARTESIANY); component->setVariable("q2_Y"); compPlugin = static_cast<CompSBasePlugin*>(compartment->getPlugin("comp")); relement = compPlugin->createReplacedElement(); relement->setIdRef("C"); relement->setSubmodelRef("GRID_1_2_cell"); compartment = model->createCompartment(); compartment->setId("Loc3"); compartment->setConstant(false); compartment->setSize(1); compartment->setSpatialDimensions(2.0); cplugin = static_cast<DynCompartmentPlugin*>(compartment->getPlugin("dyn")); component = cplugin->createSpatialComponent(); component->setSpatialIndex(DYN_SPATIALKIND_CARTESIANX); component->setVariable("q3_X"); component = cplugin->createSpatialComponent(); component->setSpatialIndex(DYN_SPATIALKIND_CARTESIANY); component->setVariable("q3_Y"); compPlugin = static_cast<CompSBasePlugin*>(compartment->getPlugin("comp")); relement = compPlugin->createReplacedElement(); relement->setIdRef("C"); relement->setSubmodelRef("GRID_2_1_cell"); compartment = model->createCompartment(); compartment->setId("Loc4"); compartment->setConstant(false); compartment->setSize(1); compartment->setSpatialDimensions(2.0); cplugin = static_cast<DynCompartmentPlugin*>(compartment->getPlugin("dyn")); component = cplugin->createSpatialComponent(); component->setSpatialIndex(DYN_SPATIALKIND_CARTESIANX); component->setVariable("q4_X"); component = cplugin->createSpatialComponent(); component->setSpatialIndex(DYN_SPATIALKIND_CARTESIANY); component->setVariable("q4_Y"); compPlugin = static_cast<CompSBasePlugin*>(compartment->getPlugin("comp")); relement = compPlugin->createReplacedElement(); relement->setIdRef("C"); relement->setSubmodelRef("GRID_2_2_cell"); // create Parameters Parameter* param = model->createParameter(); param->initDefaults(); param->setId("q1_X"); param->setValue(1); param = model->createParameter(); param->initDefaults(); param->setId("q1_Y"); param->setValue(1); param = model->createParameter(); param->initDefaults(); param->setId("q2_X"); param->setValue(2); param = model->createParameter(); param->initDefaults(); param->setId("q2_Y"); param->setValue(1); param = model->createParameter(); param->initDefaults(); param->setId("q3_X"); param->setValue(1); param = model->createParameter(); param->initDefaults(); param->setId("q3_Y"); param->setValue(2); param = model->createParameter(); param->initDefaults(); param->setId("q4_X"); param->setValue(2); param = model->createParameter(); param->initDefaults(); param->setId("q4_Y"); param->setValue(2); // create SubModels CompModelPlugin* mplugin = static_cast<CompModelPlugin*>(model->getPlugin("comp")); Submodel* submodel = mplugin->createSubmodel(); submodel->setId("GRID_1_1_cell"); submodel->setModelRef("Cell"); submodel = mplugin->createSubmodel(); submodel->setId("GRID_1_2_cell"); submodel->setModelRef("Cell"); submodel = mplugin->createSubmodel(); submodel->setId("GRID_2_1_cell"); submodel->setModelRef("Cell"); submodel = mplugin->createSubmodel(); submodel->setId("GRID_2_2_cell"); submodel->setModelRef("Cell"); // create the ModelDefinition CompSBMLDocumentPlugin* dplugin = static_cast<CompSBMLDocumentPlugin*>(document->getPlugin("comp")); ModelDefinition* mdef = dplugin->createModelDefinition(); mdef->setId("Cell"); compartment = mdef->createCompartment(); compartment->initDefaults(); compartment->setId("C"); compartment->setSpatialDimensions(2.0); compartment->setSize(1.0); Species* species = mdef->createSpecies(); species->setId("R"); species->setCompartment("C"); species->setHasOnlySubstanceUnits(false); species->setBoundaryCondition(false); species->setConstant(false); species = mdef->createSpecies(); species->setId("S"); species->setCompartment("C"); species->setHasOnlySubstanceUnits(false); species->setBoundaryCondition(false); species->setConstant(false); Reaction* reaction = mdef->createReaction(); reaction->setId("Degradation_R"); reaction->setReversible(false); reaction->setFast(false); reaction->setCompartment("C"); SpeciesReference* reactant = reaction->createReactant(); reactant->setSpecies("R"); reactant->setStoichiometry(1); reactant->setConstant(true); reaction = mdef->createReaction(); reaction->setId("Degradation_S"); reaction->setReversible(false); reaction->setFast(false); reaction->setCompartment("C"); reactant = reaction->createReactant(); reactant->setSpecies("S"); reactant->setStoichiometry(1); reactant->setConstant(true); document->checkConsistency(); Event* event = mdef->createEvent(); event->setId("event0"); event->setUseValuesFromTriggerTime(false); DynEventPlugin* eplugin = static_cast<DynEventPlugin*>(event->getPlugin("dyn")); eplugin->setApplyToAll(true); eplugin->setCboTerm("http://cbo.biocomplexity.indiana.edu/svn/cbo/trunk/CBO_1_0.owl#CellDivision"); Trigger* trigger = event->createTrigger(); trigger->setInitialValue(false); trigger->setPersistent(false); trigger->setMath(SBML_parseFormula("true")); if (document->getNumErrors(LIBSBML_SEV_ERROR) > 0) document->printErrors(); writeSBML(document,"dyn_example2.xml"); delete document; }
LIBSBML_CPP_NAMESPACE_USE int main(int argc,char** argv){ // // Creates an SBMLNamespaces object with the given SBML level, version // package name, package version. // // (NOTE) By defualt, the name of package (i.e. "groups") will be used // if the arugment for the prefix is missing or empty. Thus the argument // for the prefix can be added as follows: // // SBMLNamespaces sbmlns(3,1,"groups",1,"GROUP"); // SBMLNamespaces sbmlns(3,1,"groups",1); // // (NOTES) The above code creating an SBMLNamespaces object can be replaced // with one of the following other styles. // // (1) Creates an SBMLNamespace object with a SBML core namespace and then // adds a groups package namespace to the object. // // SBMLNamespaces sbmlns(3,1); // sbmlns.addPkgNamespace("groups",1); // // OR // // SBMLNamespaces sbmlns(3,1); // sbmlns.addNamespace(GroupsExtension::XmlnsL3V1V1,"groups"); // // (2) Creates a GroupsPkgNamespaces object (SBMLNamespace derived class for // groups package. The class is basically used for createing an SBase derived // objects defined in the groups package) with the given SBML level, version, // and package version // // GroupsPkgNamespaces sbmlns(3,1,1); // // create the document SBMLDocument *document = new SBMLDocument(&sbmlns); // create the Model Model* model=document->createModel(); // create the Compartment Compartment* compartment = model->createCompartment(); compartment->setId("cytosol"); compartment->setConstant(true); compartment=model->createCompartment(); compartment->setId("mitochon"); compartment->setConstant(true); // create the Species Species* species = model->createSpecies(); species->setId("ATPc"); species->setCompartment("cytosol"); species->setInitialConcentration(1); species->setHasOnlySubstanceUnits(false); species->setBoundaryCondition(false); species->setConstant(false); species = model->createSpecies(); species->setId("ATPm"); species->setCompartment("mitochon"); species->setInitialConcentration(2); species->setHasOnlySubstanceUnits(false); species->setBoundaryCondition(false); species->setConstant(false); // create the Groups // // Get a GroupsModelPlugin object plugged in the model object. // // The type of the returned value of SBase::getPlugin() function is SBasePlugin*, and // thus the value needs to be casted for the corresponding derived class. // GroupsModelPlugin* mplugin = static_cast<GroupsModelPlugin*>(model->getPlugin("groups")); // // Creates a Group object via GroupsModelPlugin object. // Group* group = mplugin->createGroup(); group->setId("ATP"); group->setKind(GROUP_KIND_CLASSIFICATION); group->setSBOTerm("SBO:0000252"); Member* member = group->createMember(); member->setIdRef("ATPc"); member = group->createMember(); member->setIdRef("ATPm"); writeSBML(document,"groups_example1.xml"); delete document; }
int main (int argc, char *argv[]) { SBMLDocument_t* d; Model_t* m; unsigned int errors, n; Reaction_t *r; if (argc != 3) { printf("\n" " usage: addingEvidenceCodes_1 <input-filename> <output-filename>\n" " Adds controlled vocabulary term to a reaction\n" "\n"); return 2; } d = readSBML(argv[1]); errors = SBMLDocument_getNumErrors(d); if (errors > 0) { printf("Read Error(s):\n"); SBMLDocument_printErrors(d, stdout); printf("Correct the above and re-run.\n"); } else { m = SBMLDocument_getModel(d); n = Model_getNumReactions(m); if (n <= 0) { printf( "Model has no reactions.\n Cannot add CV terms\n"); } else { CVTerm_t *cv1, *cv2; r = Model_getReaction(m, 0); /* check that the reaction has a metaid * no CVTerms will be added if there is no metaid to reference */ if (SBase_isSetMetaId((SBase_t*)r)) SBase_setMetaId((SBase_t*)r, "metaid_0000052"); cv1 = CVTerm_createWithQualifierType(BIOLOGICAL_QUALIFIER); CVTerm_setBiologicalQualifierType(cv1, BQB_IS_DESCRIBED_BY); CVTerm_addResource(cv1, "urn:miriam:obo.eco:ECO%3A0000183"); SBase_addCVTerm((SBase_t*)r, cv1); cv2 = CVTerm_createWithQualifierType(BIOLOGICAL_QUALIFIER); CVTerm_setBiologicalQualifierType(cv2, BQB_IS); CVTerm_addResource(cv2, "urn:miriam:kegg.reaction:R00756"); CVTerm_addResource(cv2, "urn:miriam:reactome:REACT_736"); SBase_addCVTerm((SBase_t*)r, cv2); writeSBML(d, argv[2]); } } SBMLDocument_free(d); return errors; }