COPASI API  4.16.103
Public Member Functions | Static Public Member Functions | List of all members
CMetabNameInterface Class Reference

#include <CMetabNameInterface.h>

Public Member Functions

 CMetabNameInterface ()
 
 ~CMetabNameInterface ()
 

Static Public Member Functions

static bool doesExist (const CModel *model, const std::string &metabolite, const std::string &compartment)
 
static std::string getDisplayName (const CModel *model, const std::string &key, const bool &quoted)
 
static std::string getDisplayName (const CModel *model, const CMetab &metab, const bool &quoted)
 
static std::string getDisplayName (const CModel *model, const std::string &metabolite, const std::string &compartment, const bool &quoted)
 
static CMetabgetMetabolite (const CModel *model, const std::string &metabolite, const std::string &compartment)
 
static std::string getMetaboliteKey (const CModel *model, const std::string &metabolite, const std::string &compartment)
 
static bool isUnique (const CModel *model, const std::string &name)
 
static std::pair< std::string,
std::string > 
splitDisplayName (const std::string &name)
 
static std::string unQuote (const std::string &displayName)
 

Detailed Description

This class handles the display names of metabolites. It converts "Species" to "Species {Compartment}" if the metabolite name is not unique. If it is unique (that means it occurs in only one compartment) then the "{Compartment}" is not added.

Definition at line 40 of file CMetabNameInterface.h.

Constructor & Destructor Documentation

CMetabNameInterface::CMetabNameInterface ( )
CMetabNameInterface::~CMetabNameInterface ( )

Definition at line 38 of file CMetabNameInterface.cpp.

39 {}

Member Function Documentation

bool CMetabNameInterface::doesExist ( const CModel model,
const std::string &  metabolite,
const std::string &  compartment 
)
static

This returns whether a metabolite with the given name does exist. If a compartment is also given (as an appendix to the name) then it only returns true if the metabolite exists in the specified compartment.

Definition at line 154 of file CMetabNameInterface.cpp.

References C_INVALID_INDEX, CModel::findMetabByName(), CModel::getCompartments(), and CCopasiVectorN< CType >::getIndex().

Referenced by getDisplayName(), and CChemEqInterface::listOfNonExistingMetabNames().

157 {
158  if (compartment != "")
159  {
160  size_t Index = model->getCompartments().getIndex(compartment);
161 
162  if (Index == C_INVALID_INDEX) return false;
163 
164  Index = model->getCompartments()[Index]->getMetabolites().getIndex(metabolite);
165 
166  return (Index != C_INVALID_INDEX);
167  }
168  else
169  return (model->findMetabByName(metabolite) != C_INVALID_INDEX);
170 }
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual size_t getIndex(const std::string &name) const
size_t findMetabByName(const std::string &Target) const
Definition: CModel.cpp:1198
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
std::string CMetabNameInterface::getDisplayName ( const CModel model,
const std::string &  key,
const bool &  quoted 
)
static

This returns a name to use for display in the GUI. If the name of the metabolite is unique it is used unaltered. If it is not then the compartment is added to the name to make it unique.

Definition at line 41 of file CMetabNameInterface.cpp.

References CKeyFactory::get(), and CCopasiRootContainer::getKeyFactory().

Referenced by CChemEqInterface::buildDisplayNames(), CTimeSeries::compile(), CODEExporter::exportMetabolites(), CODEExporter::exportMetabolitesConcentrations(), CMoiety::getDescription(), getDisplayName(), CEFMTask::getInternalSpecies(), ParameterTable::getListOfAllMetabNames(), CModelParameterSpecies::getName(), CEFMTask::getNetReaction(), CMetab::getObjectDisplayName(), CQEFMSpeciesDM::headerData(), CQBrowserPaneDM::load(), CReactionInterface::loadMappingAndValues(), StateSubwidget::loadMetabolites(), operator<<(), CModel::printParameterOverview(), CEFMProblem::printResult(), and CQBrowserPaneDM::slotNotify().

42 {
43  CMetab * metab = dynamic_cast< CMetab * >(CCopasiRootContainer::getKeyFactory()->get(key));
44 
45  if (metab)
46  return getDisplayName(model, *metab, quoted);
47  else
48  return "";
49 }
CCopasiObject * get(const std::string &key)
static std::string getDisplayName(const CModel *model, const std::string &key, const bool &quoted)
Definition: CMetab.h:178
static CKeyFactory * getKeyFactory()
std::string CMetabNameInterface::getDisplayName ( const CModel model,
const CMetab metab,
const bool &  quoted 
)
static

This returns a name to use for display in the GUI. If the name of the metabolite is unique it is used unaltered. If it is not then the compartment is added to the name to make it unique.

Definition at line 51 of file CMetabNameInterface.cpp.

References CMetab::getCompartment(), getDisplayName(), and CCopasiObject::getObjectName().

52 {
53  return getDisplayName(model, metab.getObjectName(), metab.getCompartment()->getObjectName(), quoted);
54 }
const std::string & getObjectName() const
static std::string getDisplayName(const CModel *model, const std::string &key, const bool &quoted)
const CCompartment * getCompartment() const
Definition: CMetab.cpp:222
std::string CMetabNameInterface::getDisplayName ( const CModel model,
const std::string &  metabolite,
const std::string &  compartment,
const bool &  quoted 
)
static

This returns a name to use for display in the GUI. If the name of the metabolite is unique it is used unaltered. If it is not then the compartment is added to the name to make it unique.

Definition at line 56 of file CMetabNameInterface.cpp.

References doesExist(), CModel::getCompartments(), CCopasiObject::getObjectName(), isNumber(), isUnique(), quote(), and CCopasiVector< T >::size().

60 {
61  std::string DefaultCompartment;
62 
63  if (model->getCompartments().size() == 0)
64  DefaultCompartment = "compartment";
65  else
66  DefaultCompartment = model->getCompartments()[0]->getObjectName();
67 
68  std::string Metabolite = quoted ? quote(metabolite, "{}") : metabolite;
69 
70  if (quoted && isNumber(Metabolite))
71  Metabolite = "\"" + Metabolite + "\"";
72 
73  if ((CMetabNameInterface::doesExist(model, metabolite, compartment) &&
74  CMetabNameInterface::isUnique(model, metabolite)) ||
75  (!CMetabNameInterface::doesExist(model, metabolite, "") &&
76  compartment == DefaultCompartment))
77  return Metabolite;
78 
79  std::string Compartment = quoted ? quote(compartment, "{}") : compartment;
80 
81  if ((quoted && isNumber(Compartment)) ||
82  (Compartment.find(' ') != std::string::npos && Compartment.find('"') == std::string::npos))
83  Compartment = "\"" + Compartment + "\"";
84 
85  return Metabolite + '{' + Compartment + '}';
86 }
bool isNumber(const std::string &str)
Definition: utility.cpp:75
const std::string & getObjectName() const
virtual size_t size() const
std::string quote(const std::string &name, const std::string &additionalEscapes)
Definition: utility.cpp:144
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
static bool isUnique(const CModel *model, const std::string &name)
static bool doesExist(const CModel *model, const std::string &metabolite, const std::string &compartment)
CMetab * CMetabNameInterface::getMetabolite ( const CModel model,
const std::string &  metabolite,
const std::string &  compartment 
)
static

Definition at line 100 of file CMetabNameInterface.cpp.

References C_INVALID_INDEX, CModel::findMetabByName(), CModel::getCompartments(), CCopasiVectorN< CType >::getIndex(), CCompartment::getMetabolites(), and CModel::getMetabolites().

Referenced by CChemEqInterface::completeCompartments(), and getMetaboliteKey().

103 {
104  size_t Index;
105 
106  if (compartment != "")
107  {
108  Index = model->getCompartments().getIndex(compartment);
109 
110  if (Index != C_INVALID_INDEX)
111  {
112  CCompartment *pCompartment = model->getCompartments()[Index];
113 
114  Index = pCompartment->getMetabolites().getIndex(metabolite);
115 
116  if (Index != C_INVALID_INDEX)
117  return pCompartment->getMetabolites()[Index];
118  }
119 
120  return NULL;
121  }
122 
123  Index = model->findMetabByName(metabolite);
124 
125  if (Index != C_INVALID_INDEX)
126  return model->getMetabolites()[Index];
127 
128  return NULL;
129 }
CCopasiVectorNS< CMetab > & getMetabolites()
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual size_t getIndex(const std::string &name) const
size_t findMetabByName(const std::string &Target) const
Definition: CModel.cpp:1198
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
std::string CMetabNameInterface::getMetaboliteKey ( const CModel model,
const std::string &  metabolite,
const std::string &  compartment 
)
static

This tries to find the metabolite with the given name. If the name is not unique and is given without a compartment then the first occurrence of a metabolite with this name is returned.

Definition at line 88 of file CMetabNameInterface.cpp.

References CModelEntity::getKey(), and getMetabolite().

Referenced by CReactionInterface::writeBackToReaction(), and CChemEqInterface::writeToChemEq().

91 {
92  CMetab * metab = getMetabolite(model, metabolite, compartment);
93 
94  if (metab)
95  return metab->getKey();
96  else
97  return "";
98 }
static CMetab * getMetabolite(const CModel *model, const std::string &metabolite, const std::string &compartment)
Definition: CMetab.h:178
virtual const std::string & getKey() const
bool CMetabNameInterface::isUnique ( const CModel model,
const std::string &  name 
)
static

This returns whether the metabolite name is unique.

Definition at line 131 of file CMetabNameInterface.cpp.

References CModel::getMetabolites(), CCopasiObject::getObjectName(), and CCopasiVector< T >::size().

Referenced by CChemEqInterface::completeCompartments(), getDisplayName(), and CChemEqInterface::listOfNonUniqueMetabNames().

132 {
133  bool unique = true;
134  size_t i;
135  const CCopasiVector< CMetab > & metabs = model->getMetabolites();
136  std::string metabName;
137 
138  for (i = 0; i < metabs.size(); i++)
139  {
140  metabName = metabs[i]->getObjectName();
141 
142  if (metabName == name)
143  {
144  if (unique)
145  unique = false;
146  else
147  return false; //return true
148  }
149  }
150 
151  return true; //return unique;
152 }
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
const std::string & getObjectName() const
virtual size_t size() const
std::pair< std::string, std::string > CMetabNameInterface::splitDisplayName ( const std::string &  name)
static

Definition at line 173 of file CMetabNameInterface.cpp.

References CChemEqParserBase::getSubstrateCompartments(), CChemEqParserBase::getSubstrateNames(), quote(), and CChemEqParserBase::yyparse().

Referenced by CChemEqInterface::addModifier(), and CReactionInterface::writeBackToReaction().

174 {
175  // parse the description into a linked node tree
176  std::stringstream buffer((name.find('"') != std::string::npos ? name : quote(name)) + " ->");
177 
178  CChemEqParser Parser(&buffer);
179 
180  std::pair< std::string, std::string > Result;
181 
182  if (Parser.yyparse() != 0)
183  {
184  Result.first = "";
185  Result.second = "";
186  }
187  else
188  {
189  Result.first = Parser.getSubstrateNames()[0];
190  Result.second = Parser.getSubstrateCompartments()[0];
191  }
192 
193  return Result;
194 }
std::string quote(const std::string &name, const std::string &additionalEscapes)
Definition: utility.cpp:144
std::string CMetabNameInterface::unQuote ( const std::string &  displayName)
static

Definition at line 197 of file CMetabNameInterface.cpp.

References CChemEqParserBase::getSubstrateCompartments(), CChemEqParserBase::getSubstrateNames(), and CChemEqParserBase::yyparse().

Referenced by ParameterTable::getListOfAllMetabNames(), and ParameterTable::updateTable().

198 {
199  // parse the description into a linked node tree
200  std::stringstream buffer(displayName + " ->");
201 
202  CChemEqParser Parser(&buffer);
203 
204  std::pair< std::string, std::string > Names;
205 
206  if (Parser.yyparse() != 0)
207  {
208  Names.first = displayName;
209  Names.second = "";
210  }
211  else
212  {
213  Names.first = Parser.getSubstrateNames()[0];
214  Names.second = Parser.getSubstrateCompartments()[0];
215  }
216 
217  std::string Name = Names.first;
218 
219  if (Names.second != "")
220  {
221  std::string compartment = Names.second;
222 
223  if (compartment.find(' '))
224  compartment = "\"" + compartment + "\"";
225 
226  Name += "{" + compartment + "}";
227  }
228 
229  return Name;
230 }

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