本文整理汇总了C++中SBMLDocument类的典型用法代码示例。如果您正苦于以下问题:C++ SBMLDocument类的具体用法?C++ SBMLDocument怎么用?C++ SBMLDocument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SBMLDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SBMLDocument
static SBMLDocument *createEmptyDocument()
{
SBMLDocument *doc = new SBMLDocument();
doc->createModel("");
return doc;
}
示例2: main
int main(int argc,char** argv)
{
int retval = 0;
SBMLNamespaces sbmlns(3,1,"comp",1);
// create the document
SBMLDocument *document = new SBMLDocument(&sbmlns);
//Create our submodel
CompSBMLDocumentPlugin* compdoc
= static_cast<CompSBMLDocumentPlugin*>(document->getPlugin("comp"));
compdoc->setRequired(true);
ModelDefinition* mod1 = compdoc->createModelDefinition();
mod1->setId("enzyme");
mod1->setName("enzyme");
Compartment* comp=mod1->createCompartment();
comp->setSpatialDimensions((unsigned int)3);
comp->setConstant(true);
comp->setId("comp");
comp->setSize(1L);
Species spec(&sbmlns);
spec.setCompartment("comp");
spec.setHasOnlySubstanceUnits(false);
spec.setConstant(false);
spec.setBoundaryCondition(false);
spec.setId("S");
mod1->addSpecies(&spec);
spec.setId("E");
mod1->addSpecies(&spec);
spec.setId("D");
mod1->addSpecies(&spec);
spec.setId("ES");
mod1->addSpecies(&spec);
Reaction rxn(&sbmlns);
rxn.setReversible(true);
rxn.setFast(false);
Reaction rxn2(rxn);
rxn.setId("J0");
rxn2.setId("J1");
SpeciesReference sr(&sbmlns);
sr.setConstant(true);
sr.setStoichiometry(1);
sr.setSpecies("S");
rxn.addReactant(&sr);
sr.setSpecies("E");
rxn.addReactant(&sr);
rxn2.addProduct(&sr);
sr.setSpecies("ES");
rxn.addProduct(&sr);
rxn2.addReactant(&sr);
sr.setSpecies("D");
rxn2.addProduct(&sr);
mod1->addReaction(&rxn);
mod1->addReaction(&rxn2);
// create the Model
Model* model=document->createModel();
model->setId("aggregate");
// Create a submodel
CompModelPlugin* mplugin = static_cast<CompModelPlugin*>(model->getPlugin("comp"));
Submodel* submod1 = mplugin->createSubmodel();
submod1->setId("submod1");
submod1->setModelRef("enzyme");
Submodel submod2;
submod2.setId("submod2");
submod2.setModelRef("enzyme");
mplugin->addSubmodel(&submod2);
writeSBMLToFile(document,"eg-simple-aggregate.xml");
writeSBMLToFile(document,"enzyme_model.xml");
delete document;
document = readSBMLFromFile("enzyme_model.xml");
if (document == NULL)
{
cout << "Error reading back in file." << endl;
retval = -1;
}
else
{
document->setConsistencyChecks(LIBSBML_CAT_UNITS_CONSISTENCY, false);
document->checkConsistency();
if (document->getErrorLog()->getNumFailsWithSeverity(2) > 0
|| document->getErrorLog()->getNumFailsWithSeverity(3) > 0)
{
stringstream errorstream;
document->printErrors(errorstream);
cout << "Errors encoutered when round-tripping SBML file: \n"
<< errorstream.str() << endl;
retval = -1;
}
writeSBMLToFile(document, "enzyme_model_rt.xml");
delete document;
}
#ifdef WIN32
if (retval != 0)
{
cout << "(Press any key to exit.)" << endl;
//.........这里部分代码省略.........
示例3: main
int
main (int argc, char* argv[])
{
if (argc != 2)
{
cout << endl << "Usage: printNotes filename" << endl << endl;
return 1;
}
unsigned int i,j;
const char* filename = argv[1];
SBMLDocument* document;
SBMLReader reader;
document = reader.readSBML(filename);
unsigned int errors = document->getNumErrors();
cout << endl;
cout << "filename: " << filename << endl;
cout << endl;
if(errors > 0)
{
document->printErrors(cerr);
delete document;
return errors;
}
/* Model */
Model* m = document->getModel();
printNotes(m);
for(i=0; i < m->getNumReactions(); i++)
{
Reaction* re = m->getReaction(i);
printNotes(re);
/* SpeciesReference (Reacatant) */
for(j=0; j < re->getNumReactants(); j++)
{
SpeciesReference* rt = re->getReactant(j);
if (rt->isSetNotes()) cout << " ";
printNotes(rt, (rt->isSetSpecies() ? rt->getSpecies() : std::string("")) );
}
/* SpeciesReference (Product) */
for(j=0; j < re->getNumProducts(); j++)
{
SpeciesReference* rt = re->getProduct(j);
if (rt->isSetNotes()) cout << " ";
printNotes(rt, (rt->isSetSpecies() ? rt->getSpecies() : std::string("")) );
}
/* ModifierSpeciesReference (Modifier) */
for(j=0; j < re->getNumModifiers(); j++)
{
ModifierSpeciesReference* md = re->getModifier(j);
if (md->isSetNotes()) cout << " ";
printNotes(md, (md->isSetSpecies() ? md->getSpecies() : std::string("")) );
}
/* Kineticlaw */
if(re->isSetKineticLaw())
{
KineticLaw* kl = re->getKineticLaw();
if (kl->isSetNotes()) cout << " ";
printNotes(kl);
/* Parameter */
for(j=0; j < kl->getNumParameters(); j++)
{
Parameter* pa = kl->getParameter(j);
if (pa->isSetNotes()) cout << " ";
printNotes(pa);
}
}
}
/* Species */
for(i=0; i < m->getNumSpecies(); i++)
{
Species* sp = m->getSpecies(i);
printNotes(sp);
}
/* Compartment */
for(i=0; i < m->getNumCompartments(); i++)
{
Compartment* sp = m->getCompartment(i);
//.........这里部分代码省略.........
示例4: main
int main(int argc,char** argv)
{
int retval = 0;
SBMLNamespaces sbmlns(3,1,"comp",1);
// create the document
SBMLDocument *document = new SBMLDocument(&sbmlns);
//Define the external model definition
CompSBMLDocumentPlugin* compdoc
= static_cast<CompSBMLDocumentPlugin*>(document->getPlugin("comp"));
compdoc->setRequired(true);
ExternalModelDefinition* extmod = compdoc->createExternalModelDefinition();
extmod->setId("ExtMod1");
extmod->setSource("enzyme_model.xml");
extmod->setModelRef("enzyme");
//Define the 'simple' model
ModelDefinition* mod1 = compdoc->createModelDefinition();
mod1->setId("simple");
Compartment* comp=mod1->createCompartment();
comp->setSpatialDimensions((unsigned int)3);
comp->setConstant(true);
comp->setId("comp");
comp->setSize(1L);
// We have to construct it this way because we get the comp
// plugin from it later.
Species spec(&sbmlns);
spec.setCompartment("comp");
spec.setHasOnlySubstanceUnits(false);
spec.setConstant(false);
spec.setBoundaryCondition(false);
spec.setId("S");
spec.setInitialConcentration(5);
mod1->addSpecies(&spec);
spec.setId("D");
spec.setInitialConcentration(10);
mod1->addSpecies(&spec);
Reaction rxn(&sbmlns);
rxn.setReversible(true);
rxn.setFast(false);
rxn.setId("J0");
SpeciesReference sr(&sbmlns);
sr.setConstant(true);
sr.setStoichiometry(1);
sr.setSpecies("S");
rxn.addReactant(&sr);
sr.setSpecies("D");
rxn.addProduct(&sr);
mod1->addReaction(&rxn);
CompModelPlugin* mod1plug
= static_cast<CompModelPlugin*>(mod1->getPlugin("comp"));
Port port;
port.setId("S_port");
port.setIdRef("S");
mod1plug->addPort(&port);
Port* port2 = mod1plug->createPort();
port2->setId("D_port");
port2->setIdRef("D");
port.setId("comp_port");
port.setIdRef("comp");
mod1plug->addPort(&port);
port.setId("J0_port");
port.setIdRef("J0");
mod1plug->addPort(&port);
// create the Model
Model* model=document->createModel();
model->setId("complexified");
// Set the submodels
CompModelPlugin* mplugin
= static_cast<CompModelPlugin*>(model->getPlugin("comp"));
Submodel* submod1 = mplugin->createSubmodel();
submod1->setId("A");
submod1->setModelRef("ExtMod1");
Submodel* submod2 = mplugin->createSubmodel();
submod2->setId("B");
submod2->setModelRef("simple");
Deletion* del = submod2->createDeletion();
del->setPortRef("J0_port");
// Synchronize the compartments
Compartment* mcomp=model->createCompartment();
mcomp->setSpatialDimensions((unsigned int)3);
mcomp->setConstant(true);
mcomp->setId("comp");
mcomp->setSize(1L);
CompSBasePlugin* compartplug
= static_cast<CompSBasePlugin*>(mcomp->getPlugin("comp"));
ReplacedElement re;
re.setIdRef("comp");
//.........这里部分代码省略.........
示例5: main
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");
//.........这里部分代码省略.........
示例6: START_TEST
END_TEST
START_TEST (test_conversion_inlineFD_bug)
{
std::string filename = "/inline_bug_minimal.xml";
filename = TestDataDirectory + filename;
SBMLDocument* doc = readSBMLFromFile(filename.c_str());
ConversionProperties props;
props.addOption("expandFunctionDefinitions", "true");
fail_unless(doc->getModel() != NULL);
fail_unless(doc->convert(props) == LIBSBML_OPERATION_SUCCESS);
fail_unless(doc->getModel()->getNumReactions() == 1);
fail_unless(doc->getModel()->getReaction(0)->isSetKineticLaw());
fail_unless(doc->getModel()->getReaction(0)->getKineticLaw()->getMath() != NULL);
// all seems good ... write it
const ASTNode * node = doc->getModel()->getReaction(0)->getKineticLaw()->getMath();
#ifndef LIBSBML_USE_LEGACY_MATH
fail_unless(node->ASTBase::isChild() == false);
#endif
std::string math = writeMathMLToString(node);
ASTNode* test = readMathMLFromString(math.c_str());
fail_unless(test != NULL);
// additional test where the node being converted is the top-level
fail_unless(doc->getModel()->getNumRules() == 1);
fail_unless(doc->getModel()->getRule(0)->isSetMath());
fail_unless(doc->getModel()->getRule(0)->getMath() != NULL);
node = doc->getModel()->getRule(0)->getMath();
#ifndef LIBSBML_USE_LEGACY_MATH
fail_unless(node->ASTBase::isChild() == false);
#endif
math = writeMathMLToString(node);
test = readMathMLFromString(math.c_str());
fail_unless(test != NULL);
delete test;
delete doc;
}
示例7: assert
/**
* This method tries to import CellDesigner annotations.
*/
void DataModelGUI::importCellDesigner()
{
// add code to check for CellDesigner annotations
// ask the user if the annotations should be imported
CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
assert(pDataModel != NULL);
if (pDataModel != NULL)
{
SBMLDocument* pSBMLDocument = pDataModel->getCurrentSBMLDocument();
if (pSBMLDocument != NULL &&
pSBMLDocument->getModel() != NULL &&
pSBMLDocument->getModel()->getAnnotation() != NULL)
{
// check for the CellDesigner namespace
std::pair<bool, std::string> foundNamespace = CCellDesignerImporter::findCellDesignerNamespace(pSBMLDocument);
if (foundNamespace.first == true)
{
const XMLNode* pAnno = CCellDesignerImporter::findCellDesignerAnnotation(pSBMLDocument, pSBMLDocument->getModel()->getAnnotation());
// first we check if there are supported cell designer annotations
if (pAnno != NULL)
{
// check if the file contains the correct version
double version = CCellDesignerImporter::determineVersion(pAnno);
if (version < 4.0)
{
CCopasiMessage(CCopasiMessage::RAW, "CellDesigner annotation was found in the file, but the version is not supported.\nPlease open the file in the latest version of CellDesigner and save it again.");
}
else
{
bool importCD = false;
#if LIBSBML_VERSION >= 50400
// if we don't have a layout import it!
LayoutModelPlugin* mplugin = (LayoutModelPlugin*)pSBMLDocument->getModel()->getPlugin("layout");
if (mplugin == NULL || (mplugin != NULL && mplugin->getNumLayouts() == 0))
importCD = true;
#endif
// ask the user if the CellDesigner annotation should be imported
if (importCD || CQMessageBox::question(NULL, "CellDesigner import", "A CellDesigner diagram was found in this file.\nDo you want to import the diagram?" , QMessageBox::Yes | QMessageBox::No , QMessageBox::No) == QMessageBox::Yes)
{
// do the import
CCellDesignerImporter cd_importer(pSBMLDocument);
if (cd_importer.getLayout() == NULL)
{
CCopasiMessage(CCopasiMessage::WARNING, "Sorry, CellDesigner annotations could not be importet.");
}
else
{
// now we have to import the created layout
// create the model map
std::string s1, s2;
std::map<std::string, std::string> modelmap;
std::map<CCopasiObject*, SBase*>::const_iterator it;
std::map<CCopasiObject*, SBase*>::const_iterator itEnd = pDataModel->getCopasi2SBMLMap().end();
for (it = pDataModel->getCopasi2SBMLMap().begin(); it != itEnd; ++it)
{
s1 = SBMLUtils::getIdFromSBase(it->second);
if (it->first)
{
s2 = it->first->getKey();
}
else
{
s2 = "";
}
if ((s1 != "") && (s2 != ""))
{
modelmap[s1] = s2;
}
}
// the layout map and the id to key map can be empty
std::map<std::string, std::string> layoutmap;
std::map<std::string, std::string> idToKeyMap;
#ifdef USE_CRENDER_EXTENSION
CLayout* pLayout = SBMLDocumentLoader::createLayout(*cd_importer.getLayout(), modelmap, layoutmap, idToKeyMap);
#else
CLayout* pLayout = SBMLDocumentLoader::createLayout(*cd_importer.getLayout(), modelmap, layoutmap);
#endif /* USE_CRENDER_EXTENSION */
// add the layout to the DataModel
if (pLayout != NULL && pDataModel->getListOfLayouts() != NULL)
{
// the addLayout methods expects a map as the second argument which currently is
// ignored, so we just pass an empty one
// TODO maybe the methods actually expects one of the maps above (layoutmap or idToKeyMap), but
//.........这里部分代码省略.........
示例8: START_TEST
END_TEST
START_TEST (test_QualExtension_read_L3V1V1_defaultNS)
{
string filename = string(TestDataDirectory) + "qual-example1-defaultNS.xml";
SBMLDocument *document = readSBMLFromFile(filename.c_str());
fail_unless(document->getPackageName() == "core");
Model *model = document->getModel();
fail_unless(model != NULL);
fail_unless(model->getPackageName() == "core");
// get the Qualitative species
QualModelPlugin* mplugin = static_cast<QualModelPlugin*>(model->getPlugin("qual"));
fail_unless(mplugin != NULL);
fail_unless(mplugin->getNumQualitativeSpecies() == 1);
fail_unless(mplugin->getListOfQualitativeSpecies()->getPackageName() == "qual");
fail_unless(mplugin->getNumTransitions() == 1);
fail_unless(mplugin->getListOfTransitions()->getPackageName() == "qual");
QualitativeSpecies* qs = mplugin->getQualitativeSpecies(0);
fail_unless(qs->getPackageName() == "qual");
fail_unless(qs->getId() == "s1");
fail_unless(qs->getName() == "sss");
fail_unless(qs->getMetaId() == "_ddd");
fail_unless(qs->getCompartment() == "c");
fail_unless(qs->getConstant() == false);
fail_unless(qs->getInitialLevel() == 1);
fail_unless(qs->getMaxLevel() == 4);
Transition* t = mplugin->getTransition(0);
fail_unless(t->getPackageName() == "qual");
fail_unless(t->getId() == "d");
fail_unless(t->getNumInputs() == 1);
fail_unless(t->getNumOutputs() == 1);
fail_unless(t->getNumFunctionTerms() == 1);
fail_unless(t->isSetDefaultTerm() == true);
Input *i = t->getInput(0);
fail_unless(i->getPackageName() == "qual");
fail_unless(i->getId() == "RD");
fail_unless(i->getName() == "aa" );
fail_unless(i->getQualitativeSpecies() == "s1");
fail_unless(i->getTransitionEffect() == INPUT_TRANSITION_EFFECT_NONE );
fail_unless(i->getSign() == INPUT_SIGN_NEGATIVE);
fail_unless(i->getThresholdLevel() == 2);
Output *o = t->getOutput(0);
fail_unless(o->getPackageName() == "qual");
fail_unless(o->getId() == "wd");
fail_unless(o->getName() == "asa" );
fail_unless(o->getQualitativeSpecies() == "s1");
fail_unless(o->getTransitionEffect() == OUTPUT_TRANSITION_EFFECT_PRODUCTION );
fail_unless(o->getOutputLevel() == 2);
FunctionTerm* ft1 = t->getFunctionTerm(0);
fail_unless(ft1->getPackageName() == "qual");
fail_unless(ft1->getResultLevel() == 1);
fail_unless(ft1->getMath() != NULL);
DefaultTerm* dt = t->getDefaultTerm();
fail_unless(dt->getPackageName() == "qual");
fail_unless(dt->getResultLevel() == 2);
delete document;
}
示例9: main
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
//.........这里部分代码省略.........
示例10: getSBMLDocument
/** @cond doxygenLibsbmlInternal */
int
Replacing::updateIDs(SBase* oldnames, SBase* newnames)
{
int ret = LIBSBML_OPERATION_SUCCESS;
SBMLDocument* doc = getSBMLDocument();
if (oldnames->isSetId() && !newnames->isSetId()) {
if (doc) {
string error = "Unable to transform IDs in Replacing::updateIDs during replacement: the '" + oldnames->getId() + "' element's replacement does not have an ID set.";
doc->getErrorLog()->logPackageError("comp", CompMustReplaceIDs, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return LIBSBML_INVALID_OBJECT;
}
if (oldnames->isSetMetaId() && !newnames->isSetMetaId()) {
if (doc) {
string error = "Unable to transform IDs in Replacing::updateIDs during replacement: the replacement of the element with metaid '" + oldnames->getMetaId() + "' does not have a metaid.";
doc->getErrorLog()->logPackageError("comp", CompMustReplaceMetaIDs, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return LIBSBML_INVALID_OBJECT;
}
//LS DEBUG Somehow we need to check identifiers from other packages here (like spatial id's). How, exactly, is anyone's guess.
Model* replacedmod = const_cast<Model*>(CompBase::getParentModel(oldnames));
KineticLaw* replacedkl;
ASTNode newkl;
if (replacedmod==NULL) {
if (doc) {
string error = "Unable to transform IDs in Replacing::updateIDs during replacement: the replacement of '" + oldnames->getId() + "' does not have a valid model.";
doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return LIBSBML_INVALID_OBJECT;
}
List* allElements = replacedmod->getAllElements();
string oldid = oldnames->getId();
string newid = newnames->getId();
if (!oldid.empty()) {
switch(oldnames->getTypeCode()) {
case SBML_UNIT_DEFINITION:
replacedmod->renameUnitSIdRefs(oldid, newid);
for (unsigned int e=0; e<allElements->getSize(); e++) {
SBase* element = static_cast<SBase*>(allElements->get(e));
element->renameUnitSIdRefs(oldid, newid);
}
break;
case SBML_LOCAL_PARAMETER:
replacedkl = static_cast<KineticLaw*>(oldnames->getAncestorOfType(SBML_KINETIC_LAW));
if (replacedkl->isSetMath()) {
newkl = *replacedkl->getMath();
newkl.renameSIdRefs(oldid, newid);
replacedkl->setMath(&newkl);
}
break;
case SBML_COMP_PORT:
break;
//LS DEBUG And here is where we would need some sort of way to check if the id wasn't an SId for some objects.
default:
replacedmod->renameSIdRefs(oldnames->getId(), newnames->getId());
for (unsigned int e=0; e<allElements->getSize(); e++) {
SBase* element = static_cast<SBase*>(allElements->get(e));
element->renameSIdRefs(oldid, newid);
}
}
}
string oldmetaid = oldnames->getMetaId();
string newmetaid = newnames->getMetaId();
if (oldnames->isSetMetaId()) {
replacedmod->renameMetaIdRefs(oldmetaid, newmetaid);
for (unsigned int e=0; e<allElements->getSize(); e++) {
SBase* element = static_cast<SBase*>(allElements->get(e));
element->renameMetaIdRefs(oldmetaid, newmetaid);
}
}
//LS DEBUG And here is where we would need some sort of way to check for ids that were not 'id' or 'metaid'.
delete allElements;
return ret;
}
示例11: START_TEST
END_TEST
START_TEST (test_SBMLTransforms_expandFD)
{
std::string filename(TestDataDirectory);
filename += "multiple-functions.xml";
// test 1: skip expansion of 'f'
SBMLDocument *doc = readSBMLFromFile(filename.c_str());
ConversionProperties props;
props.addOption("expandFunctionDefinitions", true);
props.addOption("skipIds", "f");
fail_unless(doc->convert(props) == LIBSBML_OPERATION_SUCCESS);
fail_unless(doc->getModel() != NULL);
fail_unless(doc->getModel()->getNumFunctionDefinitions() == 1);
fail_unless(doc->getModel()->getFunctionDefinition("f") != NULL);
delete doc;
// test 2: expand all
doc = readSBMLFromFile(filename.c_str());
props = ConversionProperties();
props.addOption("expandFunctionDefinitions", true);
fail_unless(doc->convert(props) == LIBSBML_OPERATION_SUCCESS);
fail_unless(doc->getModel() != NULL);
fail_unless(doc->getModel()->getNumFunctionDefinitions() == 0);
delete doc;
// test 3: don't expand f and g
doc = readSBMLFromFile(filename.c_str());
props = ConversionProperties();
props.addOption("expandFunctionDefinitions", true);
props.addOption("skipIds", "f,g");
fail_unless(doc->convert(props) == LIBSBML_OPERATION_SUCCESS);
fail_unless(doc->getModel() != NULL);
fail_unless(doc->getModel()->getNumFunctionDefinitions() == 2);
delete doc;
// test 4: even though comma separated is advertized, make sure that ';' works
doc = readSBMLFromFile(filename.c_str());
props = ConversionProperties();
props.addOption("expandFunctionDefinitions", true);
props.addOption("skipIds", "f;g");
fail_unless(doc->convert(props) == LIBSBML_OPERATION_SUCCESS);
fail_unless(doc->getModel() != NULL);
fail_unless(doc->getModel()->getNumFunctionDefinitions() == 2);
delete doc;
// test 5: or space
doc = readSBMLFromFile(filename.c_str());
props = ConversionProperties();
props.addOption("expandFunctionDefinitions", true);
props.addOption("skipIds", "f g");
fail_unless(doc->convert(props) == LIBSBML_OPERATION_SUCCESS);
fail_unless(doc->getModel() != NULL);
fail_unless(doc->getModel()->getNumFunctionDefinitions() == 2);
delete doc;
// test 6: or tab
doc = readSBMLFromFile(filename.c_str());
props = ConversionProperties();
props.addOption("expandFunctionDefinitions", true);
props.addOption("skipIds", "f\tg");
fail_unless(doc->convert(props) == LIBSBML_OPERATION_SUCCESS);
fail_unless(doc->getModel() != NULL);
fail_unless(doc->getModel()->getNumFunctionDefinitions() == 2);
delete doc;
// test 7: or a combination
doc = readSBMLFromFile(filename.c_str());
props = ConversionProperties();
props.addOption("expandFunctionDefinitions", true);
props.addOption("skipIds", "f; g");
fail_unless(doc->convert(props) == LIBSBML_OPERATION_SUCCESS);
fail_unless(doc->getModel() != NULL);
fail_unless(doc->getModel()->getNumFunctionDefinitions() == 2);
delete doc;
}
示例12: START_TEST
END_TEST
START_TEST(test_FbcExtension_create_and_write_L3V1V1)
{
FbcPkgNamespaces *sbmlns = new FbcPkgNamespaces(3, 1, 1);
// create the document
SBMLDocument *document = new SBMLDocument(sbmlns);
delete sbmlns;
// 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 = model->createSpecies();
species->setId("Node2");
species->setCompartment("compartment");
species->setBoundaryCondition(false);
Reaction* reaction = model->createReaction();
reaction->setId("J0");
reaction->setReversible(false);
SpeciesReference* reactant = reaction->createReactant();
reactant->setSpecies("Node0");
reactant->setStoichiometry(1);
SpeciesReference* product = reaction->createProduct();
product->setSpecies("Node1");
product->setStoichiometry(1);
// use fbc
FbcModelPlugin* mplugin = static_cast<FbcModelPlugin*>(model->getPlugin("fbc"));
fail_unless(mplugin != NULL);
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");
FluxObjective* fluxObjective = objective->createFluxObjective();
fluxObjective->setReaction("J0");
fluxObjective->setCoefficient(1);
string s1 = writeSBMLToStdString(document);
// check clone()
SBMLDocument* document2 = document->clone();
string s2 = writeSBMLToStdString(document2);
fail_unless(s1 == s2);
// check operator=
Model m = *(document->getModel());
document2->setModel(&m);
s2 = writeSBMLToStdString(document2);
fail_unless(s1 == s2);
delete document2;
delete document;
}
示例13: main
LIBSBML_CPP_NAMESPACE_USE
int
main (int argc, char* argv[])
{
SBMLNamespaces sbmlns(3,1,"multi",1);
// create the document
SBMLDocument *document = new SBMLDocument(&sbmlns);
// set the required attribute to true
MultiSBMLDocumentPlugin * docPlug =
static_cast<MultiSBMLDocumentPlugin*>(document->getPlugin("multi"));
docPlug->setRequired(true);
// create the Model
Model* model=document->createModel();
// create the compartments
Compartment * c = model->createCompartment();
c->setId("membrane");
c->setConstant(true);
// set the multi attribute isType via the compartmentPlugin
MultiCompartmentPlugin * compPlug =
static_cast<MultiCompartmentPlugin*>(c->getPlugin("multi"));
compPlug->setIsType(true);
// create the speciesTypes
MultiModelPlugin * modelPlug =
static_cast<MultiModelPlugin*>(model->getPlugin("multi"));
MultiSpeciesType * st = modelPlug->createMultiSpeciesType();
st->setId("stX");
st->setCompartment("membrane");
// create species
Species *s = model->createSpecies();
s->setId("s1");
s->setCompartment("membrane");
s->setBoundaryCondition(false);
s->setHasOnlySubstanceUnits(false);
s->setConstant(false);
// set the multi attribute speciesType via the compartmentPlugin
MultiSpeciesPlugin * spPlug =
static_cast<MultiSpeciesPlugin*>(s->getPlugin("multi"));
spPlug->setSpeciesType("stX");
// create species feature
SpeciesFeature *sf = spPlug->createSpeciesFeature();
sf->setSpeciesFeatureType("a");
sf->setOccur(1);
sf->setComponent("b");
SpeciesFeatureValue *sfv = sf->createSpeciesFeatureValue();
sfv->setValue("c");
// create a subListOfSpeciesFeatures
SubListOfSpeciesFeatures* subloSF = spPlug->createSubListOfSpeciesFeatures();
subloSF->setRelation(Relation_fromString("and"));
// add speciesFeatures to the subList
SpeciesFeature *sf1 = new SpeciesFeature(3, 1, 1);
sf1->setSpeciesFeatureType("a1");
sf1->setOccur(1);
sf1->setComponent("b1");
SpeciesFeatureValue *sfv1 = sf1->createSpeciesFeatureValue();
sfv1->setValue("c1");
subloSF->appendAndOwn(sf1);
sf1 = new SpeciesFeature(3, 1, 1);
sf1->setSpeciesFeatureType("a2");
sf1->setOccur(1);
sf1->setComponent("b2");
sfv1 = sf1->createSpeciesFeatureValue();
sfv1->setValue("c2");
subloSF->appendAndOwn(sf1);
// create a second subListOfSpeciesfeatures
subloSF = spPlug->createSubListOfSpeciesFeatures();
subloSF->setRelation(Relation_fromString("or"));
sf1 = new SpeciesFeature(3, 1, 1);
sf1->setSpeciesFeatureType("a3");
sf1->setOccur(1);
sf1->setComponent("b3");
sfv1 = sf1->createSpeciesFeatureValue();
sfv1->setValue("c3");
//.........这里部分代码省略.........
示例14: main
LIBSBML_CPP_NAMESPACE_USE
int
main (int argc, char *argv[])
{
SBMLDocument* d;
unsigned int errors, n;
Reaction *r;
if (argc != 3)
{
cout << endl
<< " usage: addingEvidenceCodes_1 <input-filename> <output-filename>" << endl
<< " Adds controlled vocabulary term to a reaction" << endl
<< endl;
return 2;
}
d = readSBML(argv[1]);
errors = d->getNumErrors();
if (errors > 0)
{
cout << "Read Error(s):" << endl;
d->printErrors(cout);
cout << "Correct the above and re-run." << endl;
}
else
{
n = d->getModel()->getNumReactions();
if (n <= 0)
{
cout << "Model has no reactions.\n Cannot add CV terms\n";
}
else
{
r = d->getModel()->getReaction(0);
/* check that the reaction has a metaid
* no CVTerms will be added if there is no metaid to reference
*/
if (!r->isSetMetaId())
r->setMetaId("metaid_0000052");
CVTerm * cv1 = new CVTerm(BIOLOGICAL_QUALIFIER);
cv1->setBiologicalQualifierType(BQB_IS_DESCRIBED_BY);
cv1->addResource("urn:miriam:obo.eco:ECO%3A0000183");
r->addCVTerm(cv1);
CVTerm * cv2 = new CVTerm(BIOLOGICAL_QUALIFIER);
cv2->setBiologicalQualifierType(BQB_IS);
cv2->addResource("urn:miriam:kegg.reaction:R00756");
cv2->addResource("urn:miriam:reactome:REACT_736");
r->addCVTerm(cv2);
writeSBML(d, argv[2]);
}
}
delete d;
return errors;
}
示例15: load_sbml
/**
* Load a gene network from an SBML file. Overrides Structure.load(). Format must
* be equal GeneNetwork.SBML. Note, the SBML file must be in the exact same format
* as the SBML files produced by writeSBML(). In particular, we assume that reactions are listed
* *ordered* as we do in writeSBML().
* @param filename URL to the file describing the network to load
* @param format File format (GML, DOT, etc.)
* @throws IOException
*/
void GeneNetwork::load_sbml(const char *filename) {
SBMLDocument* document;
SBMLReader reader;
document = reader.readSBML(filename);
unsigned int errors = document->getNumErrors();
if (errors > 0) {
std::cerr << "Failed to open file " << filename << std::endl;
exit(1);
}
Model *m = document->getModel();
// -----------------------------------------
// Set the network size and create the genes
// do not count the species _void_
int size = m->getNumSpecies() - 1;
ListOfSpecies *species = m->getListOfSpecies();
for (int g=0; g < size; g++) {
if (species->get(g)->getId() != "_void_") {
//HillGene hg = new HillGene(this);
//hg.setLabel(species.get(g).getId());
HillGene *n = new HillGene(species->get(g)->getId());
//n.setLabel(species->get(g)->getId());
nodes_.push_back(*n);
delete n;
}
}
x_ = Vec_DP(nodes_.size());
x_ = 0;
y_ = Vec_DP(nodes_.size());
y_ = 0;
//vector<string> parameterNames; // the names of the parameters
//vector<double> parameterValues; // the values of the parameters
std::map<std::string, double> params;
std::vector<std::string> inputNodes; // the indexes of the inputs
HillGene src, tgt;
Parameter *param;
// 2 loops for one gene: both synthesis and degradation reactions
// (we assume that reactions are listed *ordered* as we do in writeSBML())
//int counter = 0;
for (unsigned int i=0; i < m->getNumReactions(); i++) {
Reaction *re = m->getReaction(i);
std::string id = re->getId();
std::stringstream ss;
ss << i;
//::logging::log::emit<Debug>() << id.c_str() <<
// ::logging::log::endl;
tgt = nodes_.at(getIndexOfNode(getGeneReactantId(id)));
//tgt->setLabel(getGeneReactantId(*re));
//SpeciesReference *rt = re->getReactant(0);
//Node *tgt = new HillGene();
//tgt->setLabel(rt->getSpecies());
//ListOfSpeciesReferences *modifiers = re->getListOfModifiers();
for (unsigned int j=0; j < re->getNumModifiers(); j++) {
ModifierSpeciesReference *md = re->getModifier(j);
src = nodes_.at(getIndexOfNode(md->getSpecies()));
inputNodes.push_back(src.getLabel());
// set output genes
std::vector<std::string> outputs = src.getOutputGenes();
outputs.push_back(tgt.getLabel());
src.setOutputGenes(outputs);
// The edge type is unknown for now, it is initialized later
Edge *e = new Edge(&src, &tgt, "+-");
edges_.push_back(*e);
//delete src;
delete e;
}
KineticLaw *kl = re->getKineticLaw();
for(unsigned int j=0; j < kl->getNumParameters(); j++) {
param = kl->getParameter(j);
params[param->getId()] = param->getValue();
//char buf[256];
//sprintf(buf, "%s\t%f", param->getId().c_str(), param->getValue());
//::logging::log::emit<Info>() << buf << ::logging::log::endl;
}
//::logging::log::emit<Info>() << ::logging::log::dec << params.size() <<
// ::logging::log::endl;
//.........这里部分代码省略.........