COPASI API  4.16.103
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CModelAnalyzer Class Reference

#include <CModelAnalyzer.h>

Collaboration diagram for CModelAnalyzer:
Collaboration graph
[legend]

Classes

class  ReactionResult
 

Public Member Functions

 CModelAnalyzer (const CModel *model)
 
void writeReport (std::ostream &os, bool rt, bool verbose) const
 

Protected Member Functions

void checkModel (const CModel *model)
 
ReactionResult checkReaction (const CReaction *reaction)
 

Protected Attributes

const CModelmpModel
 
std::vector< ReactionResultmReactionResults
 

Detailed Description

Definition at line 24 of file CModelAnalyzer.h.

Constructor & Destructor Documentation

CModelAnalyzer::CModelAnalyzer ( const CModel model)

Definition at line 33 of file CModelAnalyzer.cpp.

References checkModel().

34 {
35  checkModel(model);
36 }
void checkModel(const CModel *model)

Member Function Documentation

void CModelAnalyzer::checkModel ( const CModel model)
protected

Definition at line 38 of file CModelAnalyzer.cpp.

References checkReaction(), CModel::getReactions(), CModel::getTotSteps(), mpModel, and mReactionResults.

Referenced by CModelAnalyzer().

39 {
40  if (!model) return;
41 
42  mpModel = model;
43 
44  size_t i, imax = model->getTotSteps();
45 
46  for (i = 0; i < imax; ++i)
47  {
48  mReactionResults.push_back(checkReaction(model->getReactions()[i]));
49  }
50 }
const CModel * mpModel
size_t getTotSteps() const
Definition: CModel.cpp:1136
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
std::vector< ReactionResult > mReactionResults
ReactionResult checkReaction(const CReaction *reaction)
CModelAnalyzer::ReactionResult CModelAnalyzer::checkReaction ( const CReaction reaction)
protected

Definition at line 52 of file CModelAnalyzer.cpp.

References CReaction::getChemEq(), CModel::getCompartments(), CReaction::getFunction(), CReaction::getFunctionParameters(), CCopasiParameter::getKey(), CModel::getKey(), CCopasiObject::getKey(), CCopasiRootContainer::getKeyFactory(), CModel::getModelValues(), CChemEq::getModifiers(), CCopasiObject::getObjectName(), CCopasiParameterGroup::getParameter(), CReaction::getParameterMappings(), CReaction::getParameters(), CChemEq::getProducts(), CChemEq::getSubstrates(), CFunction::isReversible(), CReaction::isReversible(), CModelAnalyzer::ReactionResult::mChemEqMods, CModelAnalyzer::ReactionResult::mChemEqProds, CModelAnalyzer::ReactionResult::mChemEqSubs, CModelAnalyzer::ReactionResult::mFunctionParametersMods, CModelAnalyzer::ReactionResult::mFunctionParametersParams, CModelAnalyzer::ReactionResult::mFunctionParametersProds, CModelAnalyzer::ReactionResult::mFunctionParametersSubs, CModelAnalyzer::ReactionResult::mFunctionParametersTime, CModelAnalyzer::ReactionResult::mFunctionParametersVar, CModelAnalyzer::ReactionResult::mFunctionParametersVol, CModelAnalyzer::ReactionResult::mFunctionResult, CModelAnalyzer::ReactionResult::mKineticUnspecifiedReversibility, CModelAnalyzer::ReactionResult::mNotMetabolite, CFunctionParameter::MODIFIER, mpModel, CModelAnalyzer::ReactionResult::mReactionName, CModelAnalyzer::ReactionResult::mReversibilityMismatch, CFunctionParameter::PARAMETER, CFunctionParameter::PRODUCT, CFunctionParameters::size(), CCopasiVector< T >::size(), CCopasiParameterGroup::size(), CFunctionParameter::SUBSTRATE, CFunctionParameter::TEMPORARY, CFunctionParameter::TIME, TriFalse, TriTrue, TriUnspecified, CFunctionParameter::VARIABLE, and CFunctionParameter::VOLUME.

Referenced by checkModel().

53 {
54  ReactionResult ret;
55 
56  if (!reaction) return ret;
57 
58  ret.mReactionName = reaction->getObjectName();
59 
60  //reversibility
61  if (reaction->getFunction()->isReversible() == TriUnspecified)
62  {
63  //warning
64  // Kinetics is of unspecified reversibility.
65  ret.mKineticUnspecifiedReversibility = true;
66  }
67  else if (((reaction->getFunction()->isReversible() == TriTrue) && !reaction->isReversible())
68  || ((reaction->getFunction()->isReversible() == TriFalse) && reaction->isReversible()))
69  {
70  //error; or COPASI error?
71  // Reversibility of function and kinetics does not match.
72  ret.mReversibilityMismatch = true;
73  }
74  else
75  {
76  //OK.
77  }
78 
79  if (dynamic_cast<const CMassAction*>(reaction->getFunction())) return ret;
80 
81  //TODO special case mass action
82 
83  //********* mapping **********************
84 
85  size_t i, imax;
86  imax = reaction->getChemEq().getSubstrates().size();
87 
88  for (i = 0; i < imax; ++i)
89  {
90  //each substrate of the reaction needs to be mapped to a function parameter with role SUBSTRATE
91  std::string tmpkey = reaction->getChemEq().getSubstrates()[i]->getMetaboliteKey();
92 
93  size_t j, jmax = reaction->getFunctionParameters().size();
94 
95  for (j = 0; j < jmax; ++j)
96  {
97  if ((reaction->getFunctionParameters()[j]->getUsage() == CFunctionParameter::SUBSTRATE)
98  && reaction->getParameterMappings()[j][0] == tmpkey)
99  break;
100  }
101 
102  if (j == jmax)
103  {
104  //warning/error?
105  // A substrate of this reaction is not mapped to a corresponding function parameter.
106  const CMetab * pM = reaction->getChemEq().getSubstrates()[i]->getMetabolite();
107 
108  if (pM)
109  ret.mChemEqSubs.push_back(pM->getObjectName());
110  }
111  }
112 
113  //for reversible reactions each product of the reaction needs to be mapped to a function parameter with role PRODUCT
114  if (reaction->getFunction()->isReversible() == TriTrue)
115  {
116  imax = reaction->getChemEq().getProducts().size();
117 
118  for (i = 0; i < imax; ++i)
119  {
120  std::string tmpkey = reaction->getChemEq().getProducts()[i]->getMetaboliteKey();
121 
122  size_t j, jmax = reaction->getFunctionParameters().size();
123 
124  for (j = 0; j < jmax; ++j)
125  {
126  if ((reaction->getFunctionParameters()[j]->getUsage() == CFunctionParameter::PRODUCT)
127  && reaction->getParameterMappings()[j][0] == tmpkey)
128  break;
129  }
130 
131  if (j == jmax)
132  {
133  //warning/error?
134  // A product of this reaction is not mapped to a corresponding function parameter.
135  const CMetab * pM = reaction->getChemEq().getProducts()[i]->getMetabolite();
136 
137  if (pM)
138  ret.mChemEqProds.push_back(pM->getObjectName());
139  }
140  }
141  }
142 
143  imax = reaction->getChemEq().getModifiers().size();
144 
145  for (i = 0; i < imax; ++i)
146  {
147  //each modifier of the reaction should be mapped to a function parameter with role MODIFIER
148  std::string tmpkey = reaction->getChemEq().getModifiers()[i]->getMetaboliteKey();
149 
150  size_t j, jmax = reaction->getFunctionParameters().size();
151 
152  for (j = 0; j < jmax; ++j)
153  {
154  if ((reaction->getFunctionParameters()[j]->getUsage() == CFunctionParameter::MODIFIER)
155  && reaction->getParameterMappings()[j][0] == tmpkey)
156  break;
157  }
158 
159  if (j == jmax)
160  {
161  //warning
162  // A modifier of this reaction is not mapped to a corresponding function parameter.
163  const CMetab * pM = reaction->getChemEq().getModifiers()[i]->getMetabolite();
164 
165  if (pM)
166  ret.mChemEqMods.push_back(pM->getObjectName());
167  }
168  }
169 
170  size_t j, jmax;
171 
172  //loop over all function parameters
173  imax = reaction->getFunctionParameters().size();
174 
175  for (i = 0; i < imax; ++i)
176  {
177  CFunctionParameter::Role role = reaction->getFunctionParameters()[i]->getUsage();
178 
179  // substr., product, modifier must be matched to a metab (COPASI bug!)
181  || role == CFunctionParameter::PRODUCT
182  || role == CFunctionParameter::MODIFIER)
183  {
184  if (!dynamic_cast<CMetab*>(CCopasiRootContainer::getKeyFactory()->get(reaction->getParameterMappings()[i][0])))
185  {
186  //COPASI bug!
187  // COPASI bug! Something that is not a metabolite is mapped to a (subs/prod/mod) function parameter.
188  ret.mNotMetabolite.push_back(reaction->getFunctionParameters()[i]->getObjectName());
189  }
190  }
191 
192  switch (role)
193  {
194  //substrate must be matched to a substr. of the reaction (COPASI bug?)
196  jmax = reaction->getChemEq().getSubstrates().size();
197 
198  for (j = 0; j < jmax; ++j)
199  {
200  if (reaction->getParameterMappings()[i][0]
201  == reaction->getChemEq().getSubstrates()[j]->getMetaboliteKey())
202  break;
203  }
204 
205  if (j == jmax)
206  {
207  //COPASI error?
208  // A SUBSTRATE function parameter is not mapped to a substrate of the reaction.
209  ret.mFunctionParametersSubs.push_back(reaction->getFunctionParameters()[i]->getObjectName());
210  }
211 
212  break;
213 
214  //Product must be matched to a product of the reaction (COPASI bug?)
216  jmax = reaction->getChemEq().getProducts().size();
217 
218  for (j = 0; j < jmax; ++j)
219  {
220  if (reaction->getParameterMappings()[i][0]
221  == reaction->getChemEq().getProducts()[j]->getMetaboliteKey())
222  break;
223  }
224 
225  if (j == jmax)
226  {
227  //COPASI error?
228  // A PRODUCT function parameter is not mapped to a product of the reaction." << std::endl;
229  ret.mFunctionParametersProds.push_back(reaction->getFunctionParameters()[i]->getObjectName());
230  }
231 
232  break;
233 
234  //modifier should be matched to a modifier in the chemeq
236  jmax = reaction->getChemEq().getModifiers().size();
237 
238  for (j = 0; j < jmax; ++j)
239  {
240  if (reaction->getParameterMappings()[i][0]
241  == reaction->getChemEq().getModifiers()[j]->getMetaboliteKey())
242  break;
243  }
244 
245  if (j == jmax)
246  {
247  //COPASI error?
248  // A MODIFIER function parameter is not mapped to a modifier of the reaction.
249  ret.mFunctionParametersMods.push_back(reaction->getFunctionParameters()[i]->getObjectName());
250  //this is not a user error. The modifier should have been added to the chemeq automatically.
251  }
252 
253  break;
254 
255  //parameter must be matched to a local or global parameter (COPASI bug)
257  //first search in local parameters list
258  jmax = reaction->getParameters().size();
259 
260  for (j = 0; j < jmax; ++j)
261  {
262  if (reaction->getParameterMappings()[i][0]
263  == reaction->getParameters().getParameter(j)->getKey())
264  break;
265  }
266 
267  if (j == jmax) //not a local parameter
268  {
269  //now search in global value list
270  jmax = mpModel->getModelValues().size();
271 
272  for (j = 0; j < jmax; ++j)
273  {
274  if (reaction->getParameterMappings()[i][0]
275  == mpModel->getModelValues()[j]->getKey())
276  break;
277  }
278 
279  if (j == jmax) //not a global parameter
280  {
281  //COPASI bug
282  // A PARAMETER function parameter is mapped neither to a local parameter nor a global value.
283  ret.mFunctionParametersParams.push_back(reaction->getFunctionParameters()[i]->getObjectName());
284  }
285  }
286 
287  break;
288 
290  jmax = mpModel->getCompartments().size();
291 
292  for (j = 0; j < jmax; ++j)
293  {
294  if (reaction->getParameterMappings()[i][0]
295  == mpModel->getCompartments()[j]->getKey())
296  break;
297  }
298 
299  if (j == jmax)
300  {
301  //COPASI bug
302  // A VOLUME function parameter is not mapped to a compartment.
303  ret.mFunctionParametersVol.push_back(reaction->getFunctionParameters()[i]->getObjectName());
304  }
305 
306  break;
307 
309 
310  if (reaction->getParameterMappings()[i][0] != mpModel->getKey())
311  {
312  //COPASI bug
313  // Internal Copasi bug: TIME parameter not mapped correctly.
314  ret.mFunctionParametersTime.push_back(reaction->getFunctionParameters()[i]->getObjectName());
315  }
316 
317  break;
318 
321  {
322  //COPASI bug
323  // Don't know what to do with a VARIABLE parameter here..."
324  ret.mFunctionParametersVar.push_back(reaction->getFunctionParameters()[i]->getObjectName());
325  }
326  break;
327  }
328  }
329 
330  //check function:
331  // irrev: no products should occur
332  // irrev: if substr=0 -> kinetics=0
333  CFunctionAnalyzer fa(reaction->getFunction() , reaction);
334  ret.mFunctionResult = fa.getResult();
335 
336  return ret;
337 }
const std::string & getObjectName() const
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
virtual size_t size() const
const CModel * mpModel
const Result & getResult() const
Definition: CMetab.h:178
virtual const std::string & getKey() const
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
const CFunction * getFunction() const
Definition: CReaction.cpp:252
const CFunctionParameters & getFunctionParameters() const
Definition: CReaction.cpp:576
const TriLogic & isReversible() const
Definition: CFunction.cpp:145
virtual const std::string & getKey() const
CCopasiParameter * getParameter(const std::string &name)
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
const std::string & getKey() const
Definition: CModel.cpp:1142
bool isReversible() const
Definition: CReaction.cpp:229
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
static CKeyFactory * getKeyFactory()
const CCopasiVector< CChemEqElement > & getModifiers() const
Definition: CChemEq.cpp:66
const CCopasiParameterGroup & getParameters() const
Definition: CReaction.cpp:333
const std::vector< std::vector< std::string > > & getParameterMappings() const
Definition: CReaction.h:285
const CChemEq & getChemEq() const
Definition: CReaction.cpp:223
void CModelAnalyzer::writeReport ( std::ostream &  os,
bool  rt,
bool  verbose 
) const

Definition at line 478 of file CModelAnalyzer.cpp.

References mReactionResults.

Referenced by CopasiUI3Window::slotCheckModel().

479 {
480 
481  //reaction results
482  size_t i, imax = mReactionResults.size();
483 
484  for (i = 0; i < imax; ++i)
485  {
486  //std::ostringstream tmpss;
487  mReactionResults[i].writeResult(os, rt, verbose);
488  }
489 }
std::vector< ReactionResult > mReactionResults

Member Data Documentation

const CModel* CModelAnalyzer::mpModel
protected

Definition at line 72 of file CModelAnalyzer.h.

Referenced by checkModel(), and checkReaction().

std::vector<ReactionResult> CModelAnalyzer::mReactionResults
protected

Definition at line 74 of file CModelAnalyzer.h.

Referenced by checkModel(), and writeReport().


The documentation for this class was generated from the following files: