COPASI API  4.16.103
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
CModelMerging Class Reference

#include <CModelMerging.h>

Collaboration diagram for CModelMerging:
Collaboration graph
[legend]

Public Types

enum  Type { ignore = 0, merge }
 

Public Member Functions

 CModelMerging (CModel *pModel)
 
void setModel (CModel *pModel)
 
void simpleCall (std::vector< std::string > &toKey, std::vector< std::string > &objectKey)
 just a simple method to call during development More...
 

Static Public Attributes

static const std::string TypeName []
 

Protected Member Functions

bool mergeInExpression (std::string toKey, std::string key, CExpression *pExpression)
 
bool mergeMetabolites (std::string toKey, std::string key)
 

Protected Attributes

CModelmpModel
 

Detailed Description

Definition at line 72 of file CModelMerging.h.

Member Enumeration Documentation

Enumeration of the types of columns known to COPASI.

Enumerator
ignore 
merge 

Definition at line 85 of file CModelMerging.h.

86  {
87  ignore = 0,
88  merge
89  };

Constructor & Destructor Documentation

CModelMerging::CModelMerging ( CModel pModel)

Definition at line 932 of file CModelMerging.cpp.

933  : mpModel(pModel)
934 {
935 }
CModel * mpModel

Member Function Documentation

bool CModelMerging::mergeInExpression ( std::string  toKey,
std::string  key,
CExpression pExpression 
)
protected

Definition at line 1219 of file CModelMerging.cpp.

References CKeyFactory::get(), CCopasiObject::getCN(), CCopasiObject::getKey(), CCopasiRootContainer::getKeyFactory(), CEvaluationTree::getNodeList(), CCopasiContainer::getObject(), CEvaluationNodeObject::getObjectCN(), CCopasiObject::getObjectDataModel(), CCopasiObject::getObjectName(), CCopasiObject::getObjectParent(), CCopasiObject::isReference(), mpModel, CEvaluationNode::OBJECT, CEvaluationNodeObject::setData(), CEvaluationNode::type(), and CEvaluationTree::updateTree().

Referenced by mergeMetabolites().

1220 {
1221 
1222  bool info = false;
1223 
1224  if (pExpression == NULL) return info;
1225 
1226  const std::vector<CEvaluationNode*>& objectNodes = pExpression->getNodeList();
1227  size_t j, jmax = objectNodes.size();
1228 
1229  for (j = 0; j < jmax; ++j)
1230  {
1231  if (CEvaluationNode::type(objectNodes[j]->getType()) == CEvaluationNode::OBJECT)
1232  {
1233  CEvaluationNodeObject* pObjectNode = dynamic_cast<CEvaluationNodeObject*>(objectNodes[j]);
1234 
1235  if (pObjectNode == NULL) return info;
1236 
1237  CCopasiObjectName cn = pObjectNode->getObjectCN();
1238 
1239  const CCopasiObject* mObject =
1240  static_cast< const CCopasiObject * >(mpModel->getObjectDataModel()->getObject(cn));
1241 
1242  if (mObject == NULL) return info;
1243 
1244  std::string host = "";
1245 
1246  if (mObject->isReference())
1247  {
1248  host = ",Reference=" + mObject->getObjectName();
1249  mObject = mObject->getObjectParent();
1250  }
1251 
1252  if (mObject == NULL) return info;
1253 
1254  CCopasiObject* pObject;
1255 
1256  std::string ikey = (dynamic_cast<const CModelEntity * >(mObject))->getKey();
1257 
1258  if (ikey == key)
1259  {
1260  pObject = (CCopasiRootContainer::getKeyFactory()->get(toKey));
1261 
1262  cn = pObject->getCN() + host;
1263 
1264  pObjectNode->setData("<" + cn + ">");
1265  }
1266  }
1267  }
1268 
1269  pExpression->updateTree();
1270 
1271  return true;
1272 }
CCopasiDataModel * getObjectDataModel()
virtual CCopasiObjectName getCN() const
const std::string & getObjectName() const
const CRegisteredObjectName & getObjectCN() const
CCopasiObject * get(const std::string &key)
CModel * mpModel
virtual const std::string & getKey() const
static Type type(const Type &type)
bool isReference() const
static CKeyFactory * getKeyFactory()
virtual bool setData(const Data &data)
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
const std::vector< CEvaluationNode * > & getNodeList() const
CCopasiContainer * getObjectParent() const
bool CModelMerging::mergeMetabolites ( std::string  toKey,
std::string  key 
)
protected

Definition at line 989 of file CModelMerging.cpp.

References CModelEntity::ASSIGNMENT, CModelEntity::FIXED, CReaction::getChemEq(), CModel::getCompartments(), CModel::getEvents(), CEventAssignment::getExpressionPtr(), CModelEntity::getExpressionPtr(), CReaction::getFunctionParameters(), CModelEntity::getInitialExpression(), CModelEntity::getInitialExpressionPtr(), CModelEntity::getKey(), CChemEqElement::getMetabolite(), CModel::getMetabolites(), CModel::getModelValues(), CChemEq::getModifiers(), CReaction::getParameterMappings(), CChemEq::getProducts(), CModel::getReactions(), CModelEntity::getStatus(), CChemEq::getSubstrates(), CEventAssignment::getTargetKey(), mergeInExpression(), CFunctionParameter::MODIFIER, mpModel, CModelEntity::ODE, CFunctionParameter::PARAMETER, CFunctionParameter::PRODUCT, CModelEntity::REACTIONS, CChemEqElement::setMetabolite(), CEventAssignment::setTargetKey(), CFunctionParameters::size(), CCopasiVector< T >::size(), CFunctionParameter::SUBSTRATE, CFunctionParameter::TIME, and CFunctionParameter::VOLUME.

Referenced by simpleCall().

990 {
991 
992  bool info = false;
993 
994  //merge in the relevant reactions
995 
996  size_t i, imax = mpModel->getReactions().size();
997  size_t j, jmax;
998 
999  for (i = 0; i < imax; ++i)
1000  {
1001  CReaction * reac = mpModel->getReactions()[i];
1002 
1003  jmax = reac->getChemEq().getSubstrates().size();
1004 
1005  for (j = 0; j < jmax; ++j)
1006  {
1007  CChemEqElement * subst = reac->getChemEq().getSubstrates()[j];
1008 
1009  if (subst->getMetabolite()->getKey() == key)
1010  subst->setMetabolite(toKey);
1011  }
1012 
1013  jmax = reac->getChemEq().getProducts().size();
1014 
1015  for (j = 0; j < jmax; ++j)
1016  {
1017  CChemEqElement * prod = reac->getChemEq().getProducts()[j];
1018 
1019  if (prod->getMetabolite()->getKey() == key)
1020  prod->setMetabolite(toKey);
1021  }
1022 
1023  jmax = reac->getChemEq().getModifiers().size();
1024 
1025  for (j = 0; j < jmax; ++j)
1026  {
1027  CChemEqElement * modif = reac->getChemEq().getModifiers()[j];
1028 
1029  if (modif->getMetabolite()->getKey() == key)
1030  modif->setMetabolite(toKey);
1031  }
1032 
1033  //change parameters of the kinetic function
1034 
1035  for (j = 0; j < reac->getFunctionParameters().size(); ++j)
1036  {
1037  switch (reac->getFunctionParameters()[j]->getUsage())
1038  {
1042  //translate the metab keys
1043  {
1044 
1045  //we assume that only SUBSTRATE, PRODUCT, MODIFIER can be vectors
1046 
1047  size_t k, kmax = reac->getParameterMappings()[j].size();
1048 
1049  for (k = 0; k < kmax; ++k)
1050  if (reac->getParameterMappings()[j][k] == key)
1051  reac->getParameterMappings()[j][k] = toKey;
1052  }
1053  break;
1054 
1056  break;
1057 
1059  // ??? TODO : have to ask
1060  break;
1061 
1063  break;
1064 
1065  default:
1066  return info;
1067  break;
1068  }
1069  }
1070  }
1071 
1072  imax = mpModel->getEvents().size();
1073 
1074  for (i = 0; i < imax; ++i)
1075  {
1076  CEvent* event = mpModel->getEvents()[i];
1077 
1078  if (!event) return info;
1079 
1080  /* merge in trigger expressions */
1081  CExpression* pExpression = event->getTriggerExpressionPtr();
1082 
1083  if (pExpression == NULL) return info;
1084 
1085  if (!mergeInExpression(toKey, key, pExpression)) return info;
1086 
1087  pExpression = event->getDelayExpressionPtr();
1088 
1089  if (pExpression)
1090  if (!mergeInExpression(toKey, key, pExpression))
1091  return info;
1092 
1093  jmax = event->getAssignments().size();
1094 
1095  for (j = 0; j < jmax; ++j)
1096  {
1097  CEventAssignment* assignment = event->getAssignments()[j];
1098 
1099  if (!assignment) return info;
1100 
1101  std::string assignmentKey = assignment->getTargetKey();
1102 
1103  if (assignmentKey == key) assignment->setTargetKey(toKey);
1104 
1105  pExpression = assignment->getExpressionPtr();
1106 
1107  if (pExpression == NULL) return info;
1108 
1109  if (!mergeInExpression(toKey, key, pExpression)) return info;
1110  }
1111  }
1112 
1113  imax = mpModel->getMetabolites().size();
1114 
1115  for (i = 0; i < imax; ++i)
1116  {
1117  CMetab* metab = mpModel->getMetabolites()[i];
1118 
1119  if (!metab) return info;
1120 
1121  switch (metab->getStatus())
1122  {
1123  case CModelEntity::FIXED:
1125 
1126  break;
1128 
1129  if (!mergeInExpression(toKey, key, metab->getExpressionPtr())) return info;
1130 
1131  break;
1132 
1133  case CModelEntity::ODE:
1134 
1135  if (!mergeInExpression(toKey, key, metab->getExpressionPtr())) return info;
1136 
1137  if (metab->getInitialExpression() != "")
1138  if (!mergeInExpression(toKey, key, metab->getInitialExpressionPtr())) return info;
1139 
1140  break;
1141 
1142  default:
1143  return info;
1144  break;
1145  }
1146  }
1147 
1148  imax = mpModel->getCompartments().size();
1149 
1150  for (i = 0; i < imax; ++i)
1151  {
1152  CCompartment* comp = mpModel->getCompartments()[i];
1153 
1154  if (!comp) return info;
1155 
1156  switch (comp ->getStatus())
1157  {
1158  case CModelEntity::FIXED:
1159 
1160  break;
1162 
1163  if (!mergeInExpression(toKey, key, comp->getExpressionPtr())) return info;
1164 
1165  break;
1166 
1167  case CModelEntity::ODE:
1168 
1169  if (!mergeInExpression(toKey, key, comp->getExpressionPtr())) return info;
1170 
1171  if (comp->getInitialExpression() != "")
1172  if (!mergeInExpression(toKey, key, comp->getInitialExpressionPtr())) return info;
1173 
1174  break;
1175 
1176  default:
1177  return info;
1178  break;
1179  }
1180  }
1181 
1182  imax = mpModel->getModelValues().size();
1183 
1184  for (i = 0; i < imax; ++i)
1185  {
1186  CModelValue* modval = mpModel->getModelValues()[i];
1187 
1188  if (!modval) return info;
1189 
1190  switch (modval ->getStatus())
1191  {
1192  case CModelEntity::FIXED:
1193 
1194  break;
1196 
1197  if (!mergeInExpression(toKey, key, modval->getExpressionPtr())) return info;
1198 
1199  break;
1200 
1201  case CModelEntity::ODE:
1202 
1203  if (!mergeInExpression(toKey, key, modval->getExpressionPtr())) return info;
1204 
1205  if (modval->getInitialExpression() != "")
1206  if (!mergeInExpression(toKey, key, modval->getInitialExpressionPtr())) return info;
1207 
1208  break;
1209 
1210  default:
1211  return info;
1212  break;
1213  }
1214  }
1215 
1216  return true;
1217 }
const CExpression * getExpressionPtr() const
Definition: CEvent.h:152
CCopasiVectorN< CEvent > & getEvents()
Definition: CModel.cpp:1110
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
virtual size_t size() const
const std::string & getTargetKey() const
Definition: CEvent.cpp:162
const CMetab * getMetabolite() const
const CExpression * getExpressionPtr() const
Definition: CEvent.cpp:226
bool setTargetKey(const std::string &targetKey)
Definition: CEvent.cpp:151
bool mergeInExpression(std::string toKey, std::string key, CExpression *pExpression)
Definition: CMetab.h:178
CModel * mpModel
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
const CFunctionParameters & getFunctionParameters() const
Definition: CReaction.cpp:576
void setMetabolite(const std::string &key)
virtual const std::string & getKey() const
std::string getInitialExpression() const
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
const CCopasiVector< CChemEqElement > & getModifiers() const
Definition: CChemEq.cpp:66
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
const CModelEntity::Status & getStatus() const
const std::vector< std::vector< std::string > > & getParameterMappings() const
Definition: CReaction.h:285
const CChemEq & getChemEq() const
Definition: CReaction.cpp:223
const CExpression * getInitialExpressionPtr() const
void CModelMerging::setModel ( CModel pModel)

Definition at line 937 of file CModelMerging.cpp.

References mpModel.

938 {
939  mpModel = pModel;
940 }
CModel * mpModel
void CModelMerging::simpleCall ( std::vector< std::string > &  toKey,
std::vector< std::string > &  objectKey 
)

just a simple method to call during development

Definition at line 942 of file CModelMerging.cpp.

References CModel::compileIfNecessary(), CCopasiMessage::ERROR, fatalError, CModelEntity::getKey(), CModel::getMetabolites(), CCopasiObject::getObjectName(), MCModelMerging, mergeMetabolites(), mpModel, CModel::removeMetabolite(), and CCopasiVector< T >::size().

943 {
944  if (!mpModel)
945  {
946  fatalError();
947  }
948 
949  size_t i, j, imax = mpModel->getMetabolites().size();
950 
951  CMetab * metab;
952  CMetab * metab1;
953  CMetab* tmp;
954  std::string empty = "";
955 
956  for (i = 0; i < imax; ++i)
957  {
958  metab = mpModel->getMetabolites()[i];
959 
960  for (j = 0; j < imax; ++j)
961  {
962  if (objectKey[i] != "")
963  {
964  tmp = mpModel->getMetabolites()[j];
965 
966  if (tmp->getKey() == objectKey[i])
967  {
968  metab1 = tmp;
969  }
970  }
971  }
972 
973  if (! mergeMetabolites(metab->getKey(), objectKey[i]))
974  {
976  metab1->getObjectName().c_str(), metab->getObjectName().c_str());
977  return;
978  }
979  }
980 
981  for (i = 0; i < imax; ++i)
982  {
983  if (objectKey[i] != empty) mpModel->removeMetabolite(objectKey[i] , false);
984  }
985 
987 }
bool mergeMetabolites(std::string toKey, std::string key)
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
const std::string & getObjectName() const
virtual size_t size() const
bool removeMetabolite(const std::string &key, const bool &recursive=true)
Definition: CModel.cpp:2667
#define fatalError()
Definition: CMetab.h:178
CModel * mpModel
virtual const std::string & getKey() const
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
#define MCModelMerging

Member Data Documentation

CModel* CModelMerging::mpModel
protected

Definition at line 102 of file CModelMerging.h.

Referenced by mergeInExpression(), mergeMetabolites(), setModel(), and simpleCall().

const std::string CModelMerging::TypeName
static
Initial value:
=
{
"ignore",
"merge",
""
}

String literals for the GUI to display type names of columns known to COPASI.

Definition at line 95 of file CModelMerging.h.


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