-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlsSBMLModel.cpp
118 lines (100 loc) · 2.65 KB
/
lsSBMLModel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifdef USE_PCH
#include "rr_pch.h"
#endif
#pragma hdrstop
#include <string>
#include <vector>
#include <sbml/SBMLDocument.h>
#include <sbml/Model.h>
#include <sbml/SBMLReader.h>
#include "lsSBMLModel.h"
#include "lsUtils.h"
//---------------------------------------------------------------------------
using namespace std;
static const char* InvalidModelMessage = "Invalid SBML Model";
static const char* InvalidModelDetailedMessage = "The SBML model was invalid. Please validate it using a SBML validator such as: http://sys-bio.org/validate.";
namespace ls
{
SBMLmodel::SBMLmodel(const string &sSBML)
:
_Document(readSBMLFromString(sSBML.c_str())),
_Model(_Document->getModel())
{
if (_Model == NULL)
throw ApplicationException(InvalidModelMessage, InvalidModelDetailedMessage);
}
SBMLmodel::SBMLmodel(SBMLDocument *document)
:
_Document(document),
_Model(_Document->getModel())
{
if (_Model == NULL)
throw ApplicationException(InvalidModelMessage, InvalidModelDetailedMessage);
}
SBMLmodel::SBMLmodel(const libsbml::Model *model)
:
_Document(0),
_Model(model)
{
if (_Model == NULL)
throw ApplicationException(InvalidModelMessage, InvalidModelDetailedMessage);
}
SBMLmodel::~SBMLmodel(void)
{
delete _Document;
}
SBMLmodel* SBMLmodel::FromFile(string &sFileName)
{
SBMLDocument *document = readSBMLFromFile(sFileName.c_str());
return new SBMLmodel(document);
}
SBMLmodel* SBMLmodel::FromSBML(string &sSBML)
{
SBMLDocument *document = readSBMLFromString(sSBML.c_str());
return new SBMLmodel(document);
}
const Model* SBMLmodel::getModel() const
{
return _Model;
}
int SBMLmodel::numFloatingSpecies() const
{
return (int) _Model->getNumSpecies() - _Model->getNumSpeciesWithBoundaryCondition();
}
int SBMLmodel::numReactions() const
{
return (int) _Model->getNumReactions();
}
const Species* SBMLmodel::getNthFloatingSpecies(int n) const
{
int nCount = 0;
for (unsigned int i = 0; i < _Model->getNumSpecies(); i++)
{
if (!_Model->getSpecies(i)->getBoundaryCondition())
{
if (nCount == n)
return _Model->getSpecies(i);
nCount ++;
}
}
return NULL;
}
const Species* SBMLmodel::getNthBoundarySpecies(int n) const
{
int nCount = 0;
for (unsigned int i = 0; i < _Model->getNumSpecies(); i++)
{
if (_Model->getSpecies(i)->getBoundaryCondition())
{
if (nCount == n)
return _Model->getSpecies(i);
nCount ++;
}
}
return NULL;
}
const Reaction* SBMLmodel::getNthReaction(int n) const
{
return _Model->getReaction(n);
}
}//namespace ls