COPASI API  4.16.103
CMCAResultSubwidget.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2004 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 /*
16  * CMCAResultSubwidget.cpp
17  *
18  *
19  * Created by Paul on 4/2/10.
20  *
21  */
22 
23 #include "CMCAResultSubwidget.h"
24 
25 #include <QtCore/QFileInfo>
26 #include <QtGui/QLineEdit>
27 #include <QtGui/QCheckBox>
28 #include <QtGui/QPainter>
29 #include <QtGui/QMessageBox>
30 
31 #include "copasi.h"
32 
33 #include "qtUtilities.h"
34 #include "model/CModel.h"
35 #include "steadystate/CMCAMethod.h"
37 
39 #include "steadystate/CMCATask.h"
40 #include "UI/CopasiFileDialog.h"
42 
43 /*
44  * Constructs a CMCAResultSubwidget as a child of 'parent', with the
45  * name 'name' and widget flags set to 'f'.
46  */
47 CMCAResultSubwidget::CMCAResultSubwidget(QWidget* parent, const char* name, Qt::WindowFlags fl)
48  : CopasiWidget(parent, name, fl)
49 {
50  setupUi(this);
51 
52  init();
53 }
54 
55 /*
56  * Destroys the object and frees any allocated resources
57  */
59 {
60  // no need to delete child widgets, Qt does it all for us
61 }
62 
64 {
65  /*
66  mSaveButton->setEnabled(false);
67  mSaveButton->hide();
68  */
69  mMCAMethod = NULL;
70 
71  clear();
72 }
73 
75 {
76  mMCAMethod = mcaMethod;
77 
78  if (mcaMethod)
79  {
80  if (!mcaMethod->getModel())
81  {
82  clear();
83  return;
84  }
85 
87  {
88  mTopLabel->setText("Steady State found. All coefficients available.");
89  this->loadElasticities(mcaMethod);
90  this->loadConcentrationCCs(mcaMethod);
91  this->loadFluxCCs(mcaMethod);
92  mTabWidget->setTabEnabled(1, true);
93  mTabWidget->setTabEnabled(2, true);
94  }
95  else
96  {
97  this->loadElasticities(mcaMethod);
98  mTabWidget->setTabEnabled(1, false);
99  mTabWidget->setTabEnabled(2, false);
100 
102  mTopLabel->setText("Equilibrium steady state. Only elasticities available!");
103 
105  mTopLabel->setText("Invalid steady state (negative concentrations)!");
106 
108  mTopLabel->setText("No steady state found. Only elasticities available!");
109  }
110  }
111  else
112  {
113  clear();
114  return;
115  }
116 }
117 
119 {
120  // const CModel* model = mcaMethod->getModel();
121  // assert(model);
122  // unsigned C_INT32 numRows, numCols;
123  // numRows = model->getTotSteps();
124  // numCols = model->getMetabolitesX().size();
125  // mTableElasticities->setNumRows(numRows);
126  // mTableElasticities->setNumCols(numCols);
127  // unsigned C_INT32 i, j;
128  // QHeader* header = mTableElasticities->verticalHeader();
129  // for (i = 0; i < numRows;++i)
130  // {
131  // header->setLabel(i, FROM_UTF8(model->getReactions()[i]->getObjectName()));
132  //}
133  // header = mTableElasticities->horizontalHeader();
134  // for (i = 0; i < numCols;++i)
135  // {
136  // header->setLabel(i, FROM_UTF8(model->getMetabolitesX()[i]->getObjectName()));
137  //}
138  // const CMatrix<C_FLOAT64> & elasticities = (mComboScale->currentIndex() == 0) ? mcaMethod->getScaledElasticities() : mcaMethod->getUnscaledElasticities();
139  // if (elasticities.numRows() == 0 || elasticities.numCols() == 0) return;
140  // for (i = 0; i < numRows;++i)
141  // {
142  // for (j = 0; j < numCols;++j)
143  // {
144  // mTableElasticities->setText(i, j, QString::number(elasticities[i][j]));
145  //}
146  //}
147 
148  const CArrayAnnotation * elasticitiesAnn;
149 
150  if (mComboScale->currentIndex() == 0)
151  {
152  elasticitiesAnn = mcaMethod->getScaledElasticitiesAnn();
153 
154  CColorScaleBiLog * tcs = new CColorScaleBiLog();
155  mpArrayElasticities->setColorCoding(tcs);
156  mpArrayElasticities->setColorScalingAutomatic(true);
157  }
158  else
159  {
160  elasticitiesAnn = mcaMethod->getUnscaledElasticitiesAnn();
161 
162  CColorScaleBiLog * tcs = new CColorScaleBiLog();
163  mpArrayElasticities->setColorCoding(tcs);
164  mpArrayElasticities->setColorScalingAutomatic(true);
165  }
166 
167  mpArrayElasticities->setArrayAnnotation(elasticitiesAnn);
168 }
169 
171 {
172  /* const CModel* model = mcaMethod->getModel();
173  assert(model);
174  unsigned C_INT32 numRows, numCols;
175  numRows = model->getNumVariableMetabs();
176  numCols = model->getTotSteps();
177  mTableCCC->setNumRows(numRows);
178  mTableCCC->setNumCols(numCols);
179  unsigned C_INT32 i, j;
180  QHeader* header = mTableCCC->verticalHeader();
181  for (i = 0; i < numRows;++i)
182  {
183  header->setLabel(i, FROM_UTF8(model->getMetabolitesX()[i]->getObjectName()));
184  }
185  header = mTableCCC->horizontalHeader();
186  for (i = 0; i < numCols;++i)
187  {
188  header->setLabel(i, FROM_UTF8(model->getReactions()[i]->getObjectName()));
189  }
190  const CMatrix<C_FLOAT64> & CCCs = (mComboScale->currentIndex() == 0) ? mcaMethod->getScaledConcentrationCC() : mcaMethod->getUnscaledConcentrationCC();
191  if (CCCs.numRows() == 0 || CCCs.numCols() == 0) return;
192  for (i = 0; i < numRows;++i)
193  {
194  for (j = 0; j < numCols;++j)
195  {
196  mTableCCC->setText(i, j, QString::number(CCCs[i][j]));
197  }
198  }*/
199  const CArrayAnnotation * CCCAnn;
200 
201  if (mComboScale->currentIndex() == 0)
202  {
203  CCCAnn = mcaMethod->getScaledConcentrationCCAnn();
204 
205  CColorScaleBiLog * tcs = new CColorScaleBiLog();
206  mpArrayCCC->setColorCoding(tcs);
207  mpArrayCCC->setColorScalingAutomatic(true);
208  }
209  else
210  {
211  CCCAnn = mcaMethod->getUnscaledConcentrationCCAnn();
212 
213  CColorScaleBiLog * tcs = new CColorScaleBiLog();
214  mpArrayCCC->setColorCoding(tcs);
215  mpArrayCCC->setColorScalingAutomatic(true);
216  }
217 
218  mpArrayCCC->setArrayAnnotation(CCCAnn);
219 }
220 
222 {
223  /* const CModel* model = mcaMethod->getModel();
224  assert(model);
225  unsigned C_INT32 numRows, numCols;
226  numCols = numRows = model->getTotSteps();
227  mTableFCC->setNumRows(numRows);
228  mTableFCC->setNumCols(numCols);
229 
230  unsigned C_INT32 i, j;
231  QHeader* header = mTableFCC->verticalHeader();
232  for (i = 0; i < numRows;++i)
233  {
234  header->setLabel(i, FROM_UTF8(model->getReactions()[i]->getObjectName()));
235  }
236  header = mTableFCC->horizontalHeader();
237  for (i = 0; i < numCols;++i)
238  {
239  header->setLabel(i, FROM_UTF8(model->getReactions()[i]->getObjectName()));
240  }
241  const CMatrix<C_FLOAT64> & FCCs = (mComboScale->currentIndex() == 0) ? mcaMethod->getScaledFluxCC() : mcaMethod->getUnscaledFluxCC();
242  if (FCCs.numRows() == 0 || FCCs.numCols() == 0) return;
243  for (i = 0; i < numRows;++i)
244  {
245  for (j = 0; j < numCols;++j)
246  {
247  mTableFCC->setText(i, j, QString::number(FCCs[i][j]));
248  }
249  }*/
250 
251  const CArrayAnnotation * FCCAnn;
252 
253  if (mComboScale->currentIndex() == 0)
254  {
255  FCCAnn = mcaMethod->getScaledFluxCCAnn();
256 
257  CColorScaleBiLog * tcs = new CColorScaleBiLog();
258  mpArrayFCC->setColorCoding(tcs);
259  mpArrayFCC->setColorScalingAutomatic(true);
260  }
261  else
262  {
263  FCCAnn = mcaMethod->getUnscaledFluxCCAnn();
264 
265  CColorScaleBiLog * tcs = new CColorScaleBiLog();
266  mpArrayFCC->setColorCoding(tcs);
267  mpArrayFCC->setColorScalingAutomatic(true);
268  }
269 
270  mpArrayFCC->setArrayAnnotation(FCCAnn);
271 }
272 
274 {
275  C_INT32 Answer = QMessageBox::No;
276  QString fileName;
277 
278  while (Answer == QMessageBox::No)
279  {
280  fileName =
281  CopasiFileDialog::getSaveFileName(this, "Save File Dialog",
282  "untitled.txt", "TEXT Files (*.txt)", "Save to");
283 
284  if (fileName.isEmpty()) return;
285 
286  // Checks whether the file exists
287  Answer = checkSelection(fileName);
288 
289  if (Answer == QMessageBox::Cancel) return;
290  }
291 
292  std::ofstream file(CLocaleString::fromUtf8(TO_UTF8(fileName)).c_str());
293 
294  if (file.fail())
295  return;
296 
297  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
298  CCopasiTask* mpTask =
299  dynamic_cast<CMCATask *>((*(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList())["Metabolic Control Analysis"]);
300 
301  if (mpTask != NULL)
302  file << mpTask->getResult();
303 
304 // mpTask->printResult(file);
305 
306  return;
307 }
308 
310 {
312 }
313 
315 {
316  mTopLabel->setText("No result available, please execute the MCA task.");
317 
318  // mTableElasticities->setNumRows(0);
319  // mTableElasticities->setNumCols(0);
320  //
321  // mTableCCC->setNumRows(0);
322  // mTableCCC->setNumCols(0);
323  //
324  // mTableFCC->setNumRows(0);
325  // mTableFCC->setNumCols(0);
326 
327  mpArrayElasticities->setArrayAnnotation(NULL);
328  mpArrayFCC->setArrayAnnotation(NULL);
329  mpArrayCCC->setArrayAnnotation(NULL);
330 
331  return;
332 }
const CArrayAnnotation * getUnscaledFluxCCAnn() const
Definition: CMCAMethod.h:94
virtual void loadFluxCCs(const CMCAMethod *mcaMethod)
const CArrayAnnotation * getScaledConcentrationCCAnn() const
Definition: CMCAMethod.h:92
virtual void loadAll(const CMCAMethod *mcaMethod)
virtual void loadElasticities(const CMCAMethod *mcaMethod)
#define C_INT32
Definition: copasi.h:90
virtual void loadConcentrationCCs(const CMCAMethod *mcaMethod)
const CModel * getModel() const
Definition: CMCAMethod.cpp:797
const CSteadyStateMethod::ReturnCode & getSteadyStateStatus() const
Definition: CMCAMethod.h:147
const CArrayAnnotation * getUnscaledConcentrationCCAnn() const
Definition: CMCAMethod.h:90
const CArrayAnnotation * getScaledElasticitiesAnn() const
Definition: CMCAMethod.h:88
const CArrayAnnotation * getScaledFluxCCAnn() const
Definition: CMCAMethod.h:96
C_INT32 checkSelection(const QString &file)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
const CMCAMethod * mMCAMethod
Header file of class CArrayAnnotation.
const CResult & getResult() const
const CArrayAnnotation * getUnscaledElasticitiesAnn() const
Definition: CMCAMethod.h:86
bool fl(const C_FLOAT64 &d1, const C_FLOAT64 &d2)
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
static CLocaleString fromUtf8(const std::string &utf8)
CMCAResultSubwidget(QWidget *parent=0, const char *name=0, Qt::WindowFlags fl=0)
static QString getSaveFileName(QWidget *parent=0, const char *name=0, const QString &startWith=QString::null, const QString &filter=QString::null, const QString &caption=QString::null, QString *pSelectedFilter=NULL, QFileDialog::Options options=0)