projectwindow.cpp 32.8 KB
Newer Older
1
2

/*******************************************************************************
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * Copyright (c) 2017 Olivier Langella <olivier.langella@u-psud.fr>.
 *
 * This file is part of XTPcpp.
 *
 *     XTPcpp is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     XTPcpp is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with XTPcpp.  If not, see <http://www.gnu.org/licenses/>.
 *
 ******************************************************************************/
21
22
23

#include "projectwindow.h"
#include "ui_project_view.h"
Olivier Langella's avatar
Olivier Langella committed
24
#include "../mainwindow.h"
Olivier Langella's avatar
Olivier Langella committed
25
26
#include "gui/peptide_list_view/peptidelistwindow.h"
#include "gui/protein_list_view/proteinlistwindow.h"
Olivier Langella's avatar
Olivier Langella committed
27
#include "gui/project_view/identification_group_widget/identificationgroupwidget.h"
28
29
#include <QDebug>
#include <QApplication>
Olivier Langella's avatar
Olivier Langella committed
30
#include <QGridLayout>
Olivier Langella's avatar
Olivier Langella committed
31
32
#include <QMessageBox>
#include <pappsomspp/pappsoexception.h>
Olivier Langella's avatar
Olivier Langella committed
33
#include <numeric>
34
#include "../workerthread.h"
35
#include "../../core/labeling/labelingmethod.h"
Langella Olivier's avatar
Langella Olivier committed
36
#include "../../utils/utils.h"
37
#include <qcustomplot.h>
38
#include "../../core/qvalue/computeqvalues.h"
39
#include "gui/lists/ms_identification_run_list_view/msidentificationlistwindow.h"
Renne Thomas's avatar
Renne Thomas committed
40
#include "gui/lists/ms_identification_run_list_view/engine_detail_view/enginedetailwindow.h"
41

42
ProjectWindow::ProjectWindow(MainWindow *parent)
Langella Olivier's avatar
Langella Olivier committed
43
  : QMainWindow(parent), ui(new Ui::ProjectView)
44
{
Langella Olivier's avatar
Langella Olivier committed
45
  main_window = parent;
46

Langella Olivier's avatar
Langella Olivier committed
47
  ui->setupUi(this);
48
49
50
  //   WorkerThread *p_worker = new WorkerThread(this);
  //   p_worker->moveToThread(&_worker_thread);
  //   _worker_thread.start();
51

Langella Olivier's avatar
Langella Olivier committed
52
53
54
  _p_edit_modifications     = new EditModifications(this);
  _p_edit_label_methods     = new EditLabelMethods(this);
  _p_waiting_message_dialog = new WaitingMessageDialog(this);
55

56

Langella Olivier's avatar
Langella Olivier committed
57
58
59
60
61
62
63
64
65
66
  ui->mass_histogram_widget->xAxis->setLabel("mass delta");
  ui->mass_histogram_widget->yAxis->setLabel("count");
  ui->mass_histogram_widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
  ui->mass_histogram_widget->axisRects().at(0)->setRangeDrag(Qt::Horizontal);
  ui->mass_histogram_widget->axisRects().at(0)->setRangeZoom(Qt::Horizontal);
  // legend->setVisible(false);
  ui->mass_histogram_widget->legend->setFont(QFont("Helvetica", 9));
  // set locale to english, so we get english decimal separator:
  // setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom));
  setFocusPolicy(Qt::ClickFocus);
67

Langella Olivier's avatar
Langella Olivier committed
68
69
70
71
72
73
74
75
  QCPGraph *p_graph = ui->mass_histogram_widget->addGraph();
  // p_graph->setName("raw xic");
  // QPen pen;
  // pen.setColor(getNewColors());
  // graph()->setPen(pen);
  // graph()->setName(lineNames.at(i-QCPGraph::lsNone));
  p_graph->setLineStyle(QCPGraph::LineStyle::lsStepCenter);
  // p_graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 2.0));
76

Langella Olivier's avatar
Langella Olivier committed
77
78
  QVBoxLayout *p_layout = new QVBoxLayout();
  ui->identifications_widget->setLayout(p_layout);
79

Langella Olivier's avatar
Langella Olivier committed
80
  ui->apply_filter_button->setEnabled(false);
81

Langella Olivier's avatar
Langella Olivier committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  connect(ui->filter_parameter_widget,
          &AutomaticFilterWidget::automaticFilterParametersChanged,
          this,
          &ProjectWindow::doAutomaticFilterParametersChanged);
  connect(ui->contaminant_widget,
          &ContaminantWidget::changed,
          this,
          &ProjectWindow::doContaminantSelectionChanged);
  connect(ui->decoy_widget,
          &DecoyWidget::changed,
          this,
          &ProjectWindow::doDecoySelectionChanged);
  connect(_p_edit_label_methods,
          &EditLabelMethods::accepted,
          this,
          &ProjectWindow::doAcceptedLabelingMethod);
98
  connect(main_window,
99
          &MainWindow::projectNameChanged,
100
          this,
101
          &ProjectWindow::doProjectNameChanged);
102
103
104
105
  connect(this,
          &ProjectWindow::projectStatusChanged,
          this,
          &ProjectWindow::doProjectStatusChanged);
106
107
108
109
  connect(main_window->getWorkerThread(),
          &WorkerThread::bestMsrunForAlignmentGroupFinished,
          this,
          &ProjectWindow::doBestMsRunForAlignmentFinished);
110
111
112
113
  connect(this,
          &ProjectWindow::operateMassChroqExportDialog,
          main_window,
          &MainWindow::doActionMassChroQ);
Renne Thomas's avatar
Renne Thomas committed
114

115
  //
116
  // grouping
Langella Olivier's avatar
Langella Olivier committed
117
  /*
118
119
120
121
122
123
  connect(this,
          &ProjectWindow::operateGrouping,
          main_window->getWorkerThread(),
          &WorkerThread::doGrouping);
          */
  main_window->getWorkerThread()->connectProjectWindow(this);
124

Langella Olivier's avatar
Langella Olivier committed
125
  this->setDisabled(true);
126
127
128
129
}

ProjectWindow::~ProjectWindow()
{
130
  qDebug();
131

Langella Olivier's avatar
Langella Olivier committed
132
  // if (_p_ms_data_file != nullptr) delete _p_ms_data_file;
133
134
  //   _worker_thread.quit();
  //   _worker_thread.wait();
135
  qDebug();
Langella Olivier's avatar
Langella Olivier committed
136
  delete ui;
137
  qDebug();
Langella Olivier's avatar
Langella Olivier committed
138
  delete _p_edit_modifications;
139
  qDebug();
Langella Olivier's avatar
Langella Olivier committed
140
  delete _p_edit_label_methods;
141
  qDebug();
Langella Olivier's avatar
Langella Olivier committed
142
  delete _p_waiting_message_dialog;
143
  qDebug();
144
145
146
147
148
}

Project *
ProjectWindow::getProjectP()
{
Langella Olivier's avatar
Langella Olivier committed
149
  return _project_sp.get();
150
}
151
152
153
154
155
156
157

ProjectSp
ProjectWindow::getProjectSP()
{
  return _project_sp;
}

158
159
void
ProjectWindow::setDefaultProteinListWindow(
Langella Olivier's avatar
Langella Olivier committed
160
  ProteinListWindow *p_protein_list_window)
161
{
162
  qDebug();
Langella Olivier's avatar
Langella Olivier committed
163
  _p_current_protein_list_window = p_protein_list_window;
164
  qDebug();
Olivier Langella's avatar
Olivier Langella committed
165
}
166

167
168
169
void
ProjectWindow::connectNewPtmIslandListWindow()
{
170
  qDebug();
Langella Olivier's avatar
Langella Olivier committed
171
172
173
  _p_current_ptm_island_list_window = new PtmIslandListWindow(this);
  _ptm_island_list_window_collection.push_back(
    _p_current_ptm_island_list_window);
174
  qDebug();
175
176
177
178
}
void
ProjectWindow::connectNewProteinListWindow()
{
179
  qDebug();
Langella Olivier's avatar
Langella Olivier committed
180
  _p_current_protein_list_window = new ProteinListWindow(this);
181

Langella Olivier's avatar
Langella Olivier committed
182
  _protein_list_window_collection.push_back(_p_current_protein_list_window);
183

184
  qDebug();
Olivier Langella's avatar
Olivier Langella committed
185
186
}

187
188
189
void
ProjectWindow::connectNewProteinDetailWindow()
{
190
  qDebug();
Langella Olivier's avatar
Langella Olivier committed
191
192
  _p_current_protein_detail_window = new ProteinWindow(this);
  _protein_detail_window_collection.push_back(_p_current_protein_detail_window);
Olivier Langella's avatar
Olivier Langella committed
193

194
  qDebug();
Olivier Langella's avatar
Olivier Langella committed
195
196
}

Renne Thomas's avatar
Renne Thomas committed
197
198
199
200
201
202
203
204
void
ProjectWindow::connectNewEngineDetailWindow()
{
  qDebug() << "";
  m_current_engine_detail_window = new EngineDetailWindow(this);
  m_engine_detail_window_collection.push_back(m_current_engine_detail_window);
}

205
206
207
void
ProjectWindow::connectNewMsRunListWindow()
{
208
  qDebug();
Renne Thomas's avatar
Renne Thomas committed
209
210
  _p_current_ms_identification_list_window =
    new MsIdentificationListWindow(this);
211

Renne Thomas's avatar
Renne Thomas committed
212
213
  _ms_identification_list_window_collection.push_back(
    _p_current_ms_identification_list_window);
214

215
  qDebug();
216
217
}

218
219
220
void
ProjectWindow::connectNewPeptideDetailWindow()
{
Langella Olivier's avatar
Langella Olivier committed
221
222
223
  qDebug() << "ProjectWindow::connectNewPeptideDetailWindow begin";
  _p_current_peptide_detail_window = new PeptideWindow(this);
  _peptide_detail_window_collection.push_back(_p_current_peptide_detail_window);
Olivier Langella's avatar
Olivier Langella committed
224

Langella Olivier's avatar
Langella Olivier committed
225
  qDebug() << "ProjectWindow::connectNewPeptideDetailWindow end";
Olivier Langella's avatar
Olivier Langella committed
226
}
227
228
229
void
ProjectWindow::connectNewPeptideListWindow()
{
Langella Olivier's avatar
Langella Olivier committed
230
231
232
  qDebug() << "ProjectWindow::connectNewPeptideListWindow begin";
  _p_current_peptide_list_window = new PeptideListWindow(this);
  _peptide_list_window_collection.push_back(_p_current_peptide_list_window);
Olivier Langella's avatar
Olivier Langella committed
233

Langella Olivier's avatar
Langella Olivier committed
234
  qDebug() << "ProjectWindow::connectNewPeptideListWindow end";
Olivier Langella's avatar
Olivier Langella committed
235
}
236
237
238
void
ProjectWindow::refreshPtmGroup(IdentificationGroup *p_ident_group)
{
Langella Olivier's avatar
Langella Olivier committed
239
240
241
  qDebug() << "ProjectWindow::refreshPtmGroup begin";
  hideWaitingMessage();
  if(p_ident_group == nullptr)
242
    {
Langella Olivier's avatar
Langella Olivier committed
243
      qDebug() << "ProjectWindow::refreshPtmGroup p_ident_group == nullptr";
244
    }
Langella Olivier's avatar
Langella Olivier committed
245
  else
246
    {
Langella Olivier's avatar
Langella Olivier committed
247
      try
248
        {
Langella Olivier's avatar
Langella Olivier committed
249
          emit identificationPtmGroupGrouped(p_ident_group);
Olivier Langella's avatar
Olivier Langella committed
250
        }
251
      catch(pappso::PappsoException &exception_pappso)
252
        {
Langella Olivier's avatar
Langella Olivier committed
253
254
          QMessageBox::warning(
            this, tr("Unable to display project :"), exception_pappso.qwhat());
Olivier Langella's avatar
Olivier Langella committed
255
        }
256
      catch(std::exception &exception_std)
257
        {
Langella Olivier's avatar
Langella Olivier committed
258
259
          QMessageBox::warning(
            this, tr("Unable to display project :"), exception_std.what());
Olivier Langella's avatar
Olivier Langella committed
260
261
        }
    }
Langella Olivier's avatar
Langella Olivier committed
262
  qDebug() << "ProjectWindow::refreshPtmGroup end";
Olivier Langella's avatar
Olivier Langella committed
263
}
264
265
266
void
ProjectWindow::refreshGroup(IdentificationGroup *p_ident_group)
{
Langella Olivier's avatar
Langella Olivier committed
267
268
269
  qDebug() << "ProjectWindow::refreshGroup begin";
  hideWaitingMessage();
  if(p_ident_group == nullptr)
270
    {
Langella Olivier's avatar
Langella Olivier committed
271
      qDebug() << "ProjectWindow::refreshGroup p_ident_group == nullptr";
272
    }
Langella Olivier's avatar
Langella Olivier committed
273
  else
274
    {
Langella Olivier's avatar
Langella Olivier committed
275
      try
276
        {
Langella Olivier's avatar
Langella Olivier committed
277
          emit identificationGroupGrouped(p_ident_group);
Olivier Langella's avatar
Olivier Langella committed
278
        }
279
      catch(pappso::PappsoException &exception_pappso)
280
        {
Langella Olivier's avatar
Langella Olivier committed
281
282
          QMessageBox::warning(
            this, tr("Unable to display project :"), exception_pappso.qwhat());
Olivier Langella's avatar
Olivier Langella committed
283
        }
284
      catch(std::exception &exception_std)
285
        {
Langella Olivier's avatar
Langella Olivier committed
286
287
          QMessageBox::warning(
            this, tr("Unable to display project :"), exception_std.what());
Olivier Langella's avatar
Olivier Langella committed
288
289
        }
    }
Langella Olivier's avatar
Langella Olivier committed
290
  qDebug() << "ProjectWindow::refreshGroup end";
291
}
292

293
294
295
void
ProjectWindow::computeFdr()
{
Langella Olivier's avatar
Langella Olivier committed
296
297
  qDebug() << "ProjectWindow::computeFdr begin ";
  try
298
    {
Langella Olivier's avatar
Langella Olivier committed
299
300
301
302
303
304
305
306
307
      ValidationState state     = ValidationState::valid;
      std::size_t total_prot    = 0;
      std::size_t false_prot    = 0;
      std::size_t total_peptide = 0;
      std::size_t false_peptide = 0;
      std::size_t total_psm     = 0;
      std::size_t false_psm     = 0;
      for(IdentificationGroup *identification_group :
          _project_sp.get()->getIdentificationGroupList())
308
        {
Langella Olivier's avatar
Langella Olivier committed
309
310
311
312
313
314
315
316
          total_prot += identification_group->countProteinMatch(state);
          false_prot += identification_group->countDecoyProteinMatch(state);
          total_psm += identification_group->countPeptideEvidence(state);
          false_psm += identification_group->countDecoyPeptideEvidence(state);

          total_peptide += identification_group->countPeptideMassSample(state);
          false_peptide +=
            identification_group->countDecoyPeptideMassSample(state);
317
        }
Langella Olivier's avatar
Langella Olivier committed
318
319
320
321
322
323
324
325
326
327
328
329
330
      ui->protein_fdr_label->setText(QString("%1 %").arg(QString::number(
        (Utils::computeFdr(false_prot, total_prot - false_prot)) * 100.0,
        'f',
        4)));
      ui->peptide_fdr_label->setText(QString("%1 %").arg(QString::number(
        (Utils::computeFdr(false_peptide, total_peptide - false_peptide)) *
          100.0,
        'f',
        4)));
      ui->psm_fdr_label->setText(QString("%1 %").arg(QString::number(
        (Utils::computeFdr(false_psm, total_psm - false_psm)) * 100.0,
        'f',
        4)));
331
    }
332
  catch(pappso::PappsoException &exception_pappso)
333
    {
Langella Olivier's avatar
Langella Olivier committed
334
335
      QMessageBox::warning(
        this, tr("Unable to compute FDR :"), exception_pappso.qwhat());
336
    }
337
  catch(std::exception &exception_std)
338
    {
Langella Olivier's avatar
Langella Olivier committed
339
340
      QMessageBox::warning(
        this, tr("Unable to compute FDR :"), exception_std.what());
Olivier Langella's avatar
Olivier Langella committed
341
    }
Langella Olivier's avatar
Langella Olivier committed
342
  qDebug() << "ProjectWindow::computeFdr end";
Olivier Langella's avatar
Olivier Langella committed
343
344
}

345
346
347
void
ProjectWindow::computeMassPrecision()
{
Langella Olivier's avatar
Langella Olivier committed
348
349
  qDebug() << "ProjectWindow::computeMassPrecision begin";
  try
350
    {
Langella Olivier's avatar
Langella Olivier committed
351
352
353
354
      ValidationState state = ValidationState::validAndChecked;
      std::vector<pappso::pappso_double> delta_list;
      pappso::PrecisionUnit unit = pappso::PrecisionUnit::dalton;
      if(ui->precision_unit_combobox->currentText() == "ppm")
355
        {
Langella Olivier's avatar
Langella Olivier committed
356
          unit = pappso::PrecisionUnit::ppm;
357
        }
Olivier Langella's avatar
Olivier Langella committed
358

Langella Olivier's avatar
Langella Olivier committed
359
360
      for(IdentificationGroup *identification_group :
          _project_sp.get()->getIdentificationGroupList())
361
        {
Langella Olivier's avatar
Langella Olivier committed
362
          identification_group->collectMhDelta(delta_list, unit, state);
363
        }
Olivier Langella's avatar
Olivier Langella committed
364
365


Langella Olivier's avatar
Langella Olivier committed
366
367
368
      qDebug() << "ProjectWindow::computeMassPrecision accumulate";
      pappso::pappso_double sum =
        std::accumulate(delta_list.begin(), delta_list.end(), 0);
Olivier Langella's avatar
Olivier Langella committed
369

Langella Olivier's avatar
Langella Olivier committed
370
371
372
373
      qDebug() << "ProjectWindow::computeMassPrecision delta_list.size()="
               << delta_list.size();
      pappso::pappso_double mean = 0;
      if(delta_list.size() > 0)
374
        {
Langella Olivier's avatar
Langella Olivier committed
375
          mean = sum / ((pappso::pappso_double)delta_list.size());
376
        }
Langella Olivier's avatar
Langella Olivier committed
377
      else
378
        {
Langella Olivier's avatar
Langella Olivier committed
379
380
381
          throw pappso::PappsoException(QObject::tr(
            "division by zero : no valid peptide found. Please check your "
            "filter parameters (decoy regexp or database particularly)"));
382
        }
Olivier Langella's avatar
Olivier Langella committed
383

Langella Olivier's avatar
Langella Olivier committed
384
385
      std::sort(delta_list.begin(), delta_list.end());
      pappso::pappso_double median = delta_list[(delta_list.size() / 2)];
Olivier Langella's avatar
Olivier Langella committed
386

387

Langella Olivier's avatar
Langella Olivier committed
388
389
390
      qDebug() << "ProjectWindow::computeMassPrecision sd";
      pappso::pappso_double sd = 0;
      for(pappso::pappso_double val : delta_list)
391
        {
Langella Olivier's avatar
Langella Olivier committed
392
393
          // sd = sd + ((val - mean) * (val - mean));
          sd += std::pow((val - mean), 2);
394
        }
Langella Olivier's avatar
Langella Olivier committed
395
396
      sd = sd / delta_list.size();
      sd = std::sqrt(sd);
Olivier Langella's avatar
Olivier Langella committed
397

Langella Olivier's avatar
Langella Olivier committed
398
399
400
401
      ui->mass_precision_mean_label->setText(QString::number(mean, 'f', 10));
      ui->mass_precision_median_label->setText(
        QString::number(median, 'f', 10));
      ui->mass_precision_sd_label->setText(QString::number(sd, 'f', 10));
402
403


Langella Olivier's avatar
Langella Olivier committed
404
405
406
407
408
      std::vector<std::pair<pappso::pappso_double, size_t>> histogram =
        Utils::getHistogram(delta_list, 100);
      // generate some data:
      QVector<double> x, y;
      for(std::pair<pappso::pappso_double, size_t> &mass_pair : histogram)
409
        {
Langella Olivier's avatar
Langella Olivier committed
410
411
          x.push_back(mass_pair.first);
          y.push_back(mass_pair.second);
412
413
        }

Langella Olivier's avatar
Langella Olivier committed
414
415
416
417
418
      QCPGraph *p_graph = ui->mass_histogram_widget->graph();
      p_graph->setData(x, y);
      p_graph->rescaleAxes(true);
      ui->mass_histogram_widget->rescaleAxes();
      ui->mass_histogram_widget->replot();
419
    }
420
  catch(pappso::PappsoException &exception_pappso)
421
    {
Langella Olivier's avatar
Langella Olivier committed
422
423
424
425
426
427
      ui->mass_precision_mean_label->setText("0");
      ui->mass_precision_median_label->setText("0");
      ui->mass_precision_sd_label->setText("0");
      QMessageBox::warning(this,
                           tr("Unable to compute mass precision :"),
                           exception_pappso.qwhat());
428
    }
429
  catch(std::exception &exception_std)
430
    {
Langella Olivier's avatar
Langella Olivier committed
431
432
433
434
435
      ui->mass_precision_mean_label->setText("0");
      ui->mass_precision_median_label->setText("0");
      ui->mass_precision_sd_label->setText("0");
      QMessageBox::warning(
        this, tr("Unable to compute mass precision :"), exception_std.what());
436
    }
Langella Olivier's avatar
Langella Olivier committed
437
  qDebug() << "ProjectWindow::computeMassPrecision end";
438
439
440
441
}
void
ProjectWindow::refresh()
{
Langella Olivier's avatar
Langella Olivier committed
442
443
444
445
  qDebug() << "ProjectWindow::refresh begin ";
  computeFdr();
  computeMassPrecision();
  qDebug() << "ProjectWindow::refresh end ";
446
}
447

448
449
450
void
ProjectWindow::doContaminantSelectionChanged()
{
Langella Olivier's avatar
Langella Olivier committed
451
452
453
  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
  ui->apply_filter_button->setEnabled(true);
  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
454
455
}

456
457
458
void
ProjectWindow::doDecoySelectionChanged()
{
Langella Olivier's avatar
Langella Olivier committed
459
460
461
  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
  ui->apply_fdr_button->setEnabled(true);
  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
462
463
}

464
465
void
ProjectWindow::doAutomaticFilterParametersChanged(
Langella Olivier's avatar
Langella Olivier committed
466
  AutomaticFilterParameters parameters [[maybe_unused]])
467
{
Langella Olivier's avatar
Langella Olivier committed
468
469
470
  qDebug() << "ProjectWindow::doAutomaticFilterParametersChanged begin ";
  ui->apply_filter_button->setEnabled(true);
  qDebug() << "ProjectWindow::doAutomaticFilterParametersChanged end ";
471
472
}

473
474
475
void
ProjectWindow::doOperationFailed(QString error)
{
Langella Olivier's avatar
Langella Olivier committed
476
477
  hideWaitingMessage();
  viewError(error);
478
}
479
480
481
void
ProjectWindow::doOperationFinished()
{
Langella Olivier's avatar
Langella Olivier committed
482
  hideWaitingMessage();
483
}
484

485
486
487
void
ProjectWindow::doDisplayLoadingMessage(QString message)
{
Langella Olivier's avatar
Langella Olivier committed
488
489
  qDebug() << "ProjectWindow::doDisplayLoadingMessage " << message;
  _p_waiting_message_dialog->message(message);
Olivier Langella's avatar
Olivier Langella committed
490
}
Olivier Langella's avatar
Olivier Langella committed
491

492
493
494
void
ProjectWindow::doDisplayLoadingMessagePercent(QString message, int value)
{
Langella Olivier's avatar
Langella Olivier committed
495
496
497
  qDebug() << "ProjectWindow::doDisplayLoadingMessagePercent " << message << " "
           << value;
  _p_waiting_message_dialog->message(message, value);
Langella Olivier's avatar
Langella Olivier committed
498
499
}

500
501
502
void
ProjectWindow::doGroupingFinished()
{
Langella Olivier's avatar
Langella Olivier committed
503
504
  qDebug() << "ProjectWindow::doGroupingFinished begin ";
  hideWaitingMessage();
505

Langella Olivier's avatar
Langella Olivier committed
506
507
508
  // re group
  for(IdentificationGroup *p_ident_group :
      _project_sp.get()->getIdentificationGroupList())
509
    {
Langella Olivier's avatar
Langella Olivier committed
510
      refreshGroup(p_ident_group);
Olivier Langella's avatar
Olivier Langella committed
511
    }
Olivier Langella's avatar
Olivier Langella committed
512

Langella Olivier's avatar
Langella Olivier committed
513
  refresh();
Olivier Langella's avatar
Olivier Langella committed
514

Langella Olivier's avatar
Langella Olivier committed
515
  qDebug() << "ProjectWindow::doGroupingFinished end";
Olivier Langella's avatar
Olivier Langella committed
516
517
}

518

519
520
521
void
ProjectWindow::doMassPrecisionUnitChanged(QString combo_value)
{
Langella Olivier's avatar
Langella Olivier committed
522
  qDebug() << "ProjectWindow::doMassPrecisionUnitChanged begin " << combo_value;
523

Langella Olivier's avatar
Langella Olivier committed
524
525
  refresh();
  qDebug() << "ProjectWindow::doMassPrecisionUnitChanged end ";
526
}
527
528
529
530
void
ProjectWindow::doViewPeptideList(IdentificationGroup *p_ident_group,
                                 ProteinMatch *protein_match)
{
531
532


Langella Olivier's avatar
Langella Olivier committed
533
534
  qDebug() << "ProjectWindow::doViewPeptideList begin";
  if(_peptide_list_window_collection.size() == 0)
535
    {
Langella Olivier's avatar
Langella Olivier committed
536
      connectNewPeptideListWindow();
Olivier Langella's avatar
Olivier Langella committed
537
    }
Langella Olivier's avatar
Langella Olivier committed
538
539
  Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
  if(modifier == Qt::ControlModifier)
540
    {
Langella Olivier's avatar
Langella Olivier committed
541
      connectNewPeptideListWindow();
Olivier Langella's avatar
Olivier Langella committed
542
543
544
    }


Langella Olivier's avatar
Langella Olivier committed
545
546
547
548
549
  _p_current_peptide_list_window->setProteinMatch(p_ident_group, protein_match);
  _p_current_peptide_list_window->show();
  //_p_current_peptide_list_window->raise();
  //_p_current_peptide_list_window->activateWindow();
  qDebug() << "ProjectWindow::doViewPeptideList end";
Olivier Langella's avatar
Olivier Langella committed
550
551
}

552
553
554
void
ProjectWindow::doViewPeptideDetail(PeptideEvidence *peptide_evidence)
{
555

Langella Olivier's avatar
Langella Olivier committed
556
557
  qDebug() << "ProjectWindow::doViewPeptideDetail begin " << peptide_evidence;
  if(_peptide_detail_window_collection.size() == 0)
558
    {
Langella Olivier's avatar
Langella Olivier committed
559
      connectNewPeptideDetailWindow();
Olivier Langella's avatar
Olivier Langella committed
560
    }
Langella Olivier's avatar
Langella Olivier committed
561
562
  Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
  if(modifier == Qt::ControlModifier)
563
    {
Langella Olivier's avatar
Langella Olivier committed
564
      connectNewPeptideDetailWindow();
Olivier Langella's avatar
Olivier Langella committed
565
566
567
    }


Langella Olivier's avatar
Langella Olivier committed
568
569
570
571
  _p_current_peptide_detail_window->setPeptideEvidence(peptide_evidence);
  _p_current_peptide_detail_window->show();
  //_p_current_peptide_detail_window->raise();
  //_p_current_peptide_detail_window->activateWindow();
572

Langella Olivier's avatar
Langella Olivier committed
573
574
  emit peptideEvidenceSelected(peptide_evidence);
  qDebug() << "ProjectWindow::doViewPeptideDetail end";
Olivier Langella's avatar
Olivier Langella committed
575
576
}

577
578
579
void
ProjectWindow::doViewProteinDetail(ProteinMatch *protein_match)
{
Olivier Langella's avatar
Olivier Langella committed
580
581


Langella Olivier's avatar
Langella Olivier committed
582
583
  qDebug() << "ProjectWindow::doViewProteinDetail begin";
  if(_protein_detail_window_collection.size() == 0)
584
    {
Langella Olivier's avatar
Langella Olivier committed
585
      connectNewProteinDetailWindow();
Olivier Langella's avatar
Olivier Langella committed
586
    }
Langella Olivier's avatar
Langella Olivier committed
587
588
  Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
  if(modifier == Qt::ControlModifier)
589
    {
Langella Olivier's avatar
Langella Olivier committed
590
      connectNewProteinDetailWindow();
Olivier Langella's avatar
Olivier Langella committed
591
592
593
    }


Langella Olivier's avatar
Langella Olivier committed
594
595
596
597
598
  _p_current_protein_detail_window->setProteinMatch(protein_match);
  _p_current_protein_detail_window->show();
  //_p_current_protein_detail_window->raise();
  //_p_current_protein_detail_window->activateWindow();
  qDebug() << "ProjectWindow::doViewProteinDetail end";
Olivier Langella's avatar
Olivier Langella committed
599
600
}

Renne Thomas's avatar
Renne Thomas committed
601
void
602
603
ProjectWindow::doViewEngineDetail(
  IdentificationDataSourceSp *identificationEngine)
Renne Thomas's avatar
Renne Thomas committed
604
605
606
607
608
{
  qDebug() << "begin";
  if(m_engine_detail_window_collection.size() == 0)
    {
      connectNewEngineDetailWindow();
609
610
611
      m_current_engine_detail_window->setIdentificationEngineParam(
        identificationEngine);
      m_current_engine_detail_window->show();
Renne Thomas's avatar
Renne Thomas committed
612
613
614
615
616
    }
  Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
  if(modifier == Qt::ControlModifier)
    {
      connectNewEngineDetailWindow();
617
618
619
      m_current_engine_detail_window->setIdentificationEngineParam(
        identificationEngine);
      m_current_engine_detail_window->show();
Renne Thomas's avatar
Renne Thomas committed
620
621
622
623
624
    }

  qDebug() << "end";
}

625
626
627
628
629
630
void
ProjectWindow::popEngineDetailView()
{
  m_engine_detail_window_collection.pop_back();
}

631
632
633
void
ProjectWindow::doPtmIslandGrouping(IdentificationGroup *p_identification_group)
{
Olivier Langella's avatar
Olivier Langella committed
634

Langella Olivier's avatar
Langella Olivier committed
635
  if(p_identification_group->getPtmGroupingExperiment() == nullptr)
636
    {
Langella Olivier's avatar
Langella Olivier committed
637
      showWaitingMessage(tr("Computing PTM islands"));
638
639
      emit operatePtmGroupingOnIdentification(p_identification_group,
                                              getPtmMode());
Olivier Langella's avatar
Olivier Langella committed
640
641
    }
}
Renne Thomas's avatar
Renne Thomas committed
642

643
644
645
void
ProjectWindow::doViewPtmIslandList(IdentificationGroup *p_identification_group)
{
Langella Olivier's avatar
Langella Olivier committed
646
647
648
649
650
  qDebug() << "ProjectWindow::doViewPtmIslandList begin "
           << p_identification_group;
  // if (p_identification_group == nullptr) {
  //}
  if(_ptm_island_list_window_collection.size() == 0)
651
    {
Langella Olivier's avatar
Langella Olivier committed
652
      connectNewPtmIslandListWindow();
Olivier Langella's avatar
Olivier Langella committed
653
    }
Langella Olivier's avatar
Langella Olivier committed
654
655
  Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
  if(modifier == Qt::ControlModifier)
656
    {
Langella Olivier's avatar
Langella Olivier committed
657
      connectNewPtmIslandListWindow();
Olivier Langella's avatar
Olivier Langella committed
658
659
660
    }


Langella Olivier's avatar
Langella Olivier committed
661
662
663
  _p_current_ptm_island_list_window->show();
  //_p_current_protein_list_window->raise();
  //_p_current_protein_list_window->activateWindow();
Olivier Langella's avatar
Olivier Langella committed
664

Langella Olivier's avatar
Langella Olivier committed
665
666
667
668
  qDebug() << "ProjectWindow::doViewPtmIslandList end "
           << p_identification_group;
  _p_current_ptm_island_list_window->setIdentificationGroup(
    p_identification_group);
Olivier Langella's avatar
Olivier Langella committed
669

Langella Olivier's avatar
Langella Olivier committed
670
671
672
  doPtmIslandGrouping(p_identification_group);
  // emit identificationGroupGrouped(p_identification_group);
  qDebug() << "ProjectWindow::doViewPtmIslandList end";
Olivier Langella's avatar
Olivier Langella committed
673
674
}

675
676
677
void
ProjectWindow::doViewProteinList(IdentificationGroup *p_identification_group)
{
678
  qDebug() << "p_identification_group=" << p_identification_group;
Langella Olivier's avatar
Langella Olivier committed
679
680
681
  // if (p_identification_group == nullptr) {
  //}
  if(_protein_list_window_collection.size() == 0)
682
    {
683
      qDebug();
Langella Olivier's avatar
Langella Olivier committed
684
      connectNewProteinListWindow();
Olivier Langella's avatar
Olivier Langella committed
685
    }
Langella Olivier's avatar
Langella Olivier committed
686
687
  Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
  if(modifier == Qt::ControlModifier)
688
    {
689
      qDebug();
Langella Olivier's avatar
Langella Olivier committed
690
      connectNewProteinListWindow();
691
692
693
    }


Langella Olivier's avatar
Langella Olivier committed
694
695
696
  _p_current_protein_list_window->show();
  _p_current_protein_list_window->raise();
  _p_current_protein_list_window->activateWindow();
Olivier Langella's avatar
Olivier Langella committed
697

698
  qDebug() << "p_identification_group=" << p_identification_group;
Langella Olivier's avatar
Langella Olivier committed
699
700
  _p_current_protein_list_window->setIdentificationGroup(
    p_identification_group);
Olivier Langella's avatar
Olivier Langella committed
701

Langella Olivier's avatar
Langella Olivier committed
702
  emit identificationGroupGrouped(p_identification_group);
703
  qDebug() << "p_identification_group=";
Olivier Langella's avatar
Olivier Langella committed
704
705
}

706
void
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
ProjectWindow::doViewMsIdentificationList()
{
  qDebug() << "ProjectWindow::doViewMsIdentificationList begin ";

  if(_ms_identification_list_window_collection.size() == 0)
    {
      connectNewMsRunListWindow();
    }
  Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
  if(modifier == Qt::ControlModifier)
    {
      connectNewMsRunListWindow();
    }
  _p_current_ms_identification_list_window->show();
  _p_current_ms_identification_list_window->raise();
  _p_current_ms_identification_list_window->activateWindow();

724
  qDebug();
725
726
727
728
729
730
731

  auto identification_list = _project_sp.get()
                               ->getIdentificationDataSourceStore()
                               .getIdentificationDataSourceList();
  _p_current_ms_identification_list_window->setIdentificationDataSourceSpList(
    identification_list);

732
  qDebug();
733
734
}

735
736
737
void
ProjectWindow::setProjectSp(ProjectSp project_sp)
{
738
  qDebug();
739

740
741
742
  if(project_sp.get() == _project_sp.get())
    return;

Langella Olivier's avatar
Langella Olivier committed
743
744
745
  _project_sp = project_sp;
  ui->contaminant_widget->getProjectContaminants(_project_sp.get());
  ui->decoy_widget->getProjectDecoys(_project_sp.get());
746

747

748
  qDebug() << " project getFastaFileList size="
Langella Olivier's avatar
Langella Olivier committed
749
750
           << _project_sp.get()->getFastaFileStore().getFastaFileList().size();
  _fastafile_list = _project_sp.get()->getFastaFileStore().getFastaFileList();
751

Langella Olivier's avatar
Langella Olivier committed
752
  for(auto &&p_window : _ptm_island_list_window_collection)
753
    {
Langella Olivier's avatar
Langella Olivier committed
754
      delete p_window;
Olivier Langella's avatar
Olivier Langella committed
755
    }
Langella Olivier's avatar
Langella Olivier committed
756
757
  _ptm_island_list_window_collection.clear();
  _p_current_ptm_island_list_window = nullptr;
Olivier Langella's avatar
Olivier Langella committed
758

759

Langella Olivier's avatar
Langella Olivier committed
760
  for(auto &&p_window : _peptide_list_window_collection)
761
    {
Langella Olivier's avatar
Langella Olivier committed
762
      delete p_window;
763
    }
Langella Olivier's avatar
Langella Olivier committed
764
765
  _peptide_list_window_collection.clear();
  _p_current_peptide_list_window = nullptr;
Olivier Langella's avatar
Olivier Langella committed
766

Langella Olivier's avatar
Langella Olivier committed
767
  for(auto &&p_window : _protein_list_window_collection)
768
    {
Langella Olivier's avatar
Langella Olivier committed
769
      delete p_window;
770
    }
Langella Olivier's avatar
Langella Olivier committed
771
772
  _protein_list_window_collection.clear();
  _p_current_protein_list_window = nullptr;
Olivier Langella's avatar
Olivier Langella committed
773

Langella Olivier's avatar
Langella Olivier committed
774
  for(auto &&p_window : _protein_detail_window_collection)
775
    {
Langella Olivier's avatar
Langella Olivier committed
776
      delete p_window;
Olivier Langella's avatar
Olivier Langella committed
777
    }
Langella Olivier's avatar
Langella Olivier committed
778
779
  _protein_detail_window_collection.clear();
  _p_current_protein_detail_window = nullptr;
Olivier Langella's avatar
Olivier Langella committed
780

Langella Olivier's avatar
Langella Olivier committed
781
  for(auto &&p_window : _peptide_detail_window_collection)
782
    {
Langella Olivier's avatar
Langella Olivier committed
783
      delete p_window;
Olivier Langella's avatar
Olivier Langella committed
784
    }
Langella Olivier's avatar
Langella Olivier committed
785
786
  _peptide_detail_window_collection.clear();
  _p_current_peptide_detail_window = nullptr;
Olivier Langella's avatar
Olivier Langella committed
787

Langella Olivier's avatar
Langella Olivier committed
788
  if(_p_identification_widget != nullptr)
789
    {
Langella Olivier's avatar
Langella Olivier committed
790
      delete _p_identification_widget;
791
792
    }

Langella Olivier's avatar
Langella Olivier committed
793
794
  std::vector<IdentificationGroup *> identification_list =
    _project_sp.get()->getIdentificationGroupList();
Olivier Langella's avatar
Olivier Langella committed
795
796


Langella Olivier's avatar
Langella Olivier committed
797
  doViewProteinList(identification_list[0]);
798

Langella Olivier's avatar
Langella Olivier committed
799
800
  // qDeleteAll(ui->identifications_widget->children());
  QLayoutItem *wItem;
Langella Olivier's avatar
Langella Olivier committed
801
  while((wItem = ui->identifications_widget->layout()->takeAt(0)))
802
    {
Langella Olivier's avatar
Langella Olivier committed
803
804
      wItem->widget()->setVisible(false);
      delete wItem;
805
    }
806

Langella Olivier's avatar
Langella Olivier committed
807
  if(_p_xic_window != nullptr)
808
    {
Langella Olivier's avatar
Langella Olivier committed
809
810
811
812
      _p_xic_window->clear();
      _p_xic_window->hide();
      delete _p_xic_window;
      _p_xic_window = nullptr;
Langella Olivier's avatar
Langella Olivier committed
813
814
    }

815
  qDebug() << " ProjectWindow::setProjectSp size="
Langella Olivier's avatar
Langella Olivier committed
816
817
           << identification_list.size();
  if(identification_list.size() == 1)
818
    {
Langella Olivier's avatar
Langella Olivier committed
819
      ui->identifications_combobox->setVisible(false);
820

Langella Olivier's avatar
Langella Olivier committed
821
822
823
824
      IdentificationGroupWidget *p_identification_widget =
        new IdentificationGroupWidget(this);
      p_identification_widget->setIdentificationGroup(this,
                                                      identification_list[0]);
825

Langella Olivier's avatar
Langella Olivier committed
826
      ui->identifications_widget->layout()->addWidget(p_identification_widget);
827

Langella Olivier's avatar
Langella Olivier committed
828
      refreshGroup(identification_list[0]);
Olivier Langella's avatar
Olivier Langella committed
829
    }
Langella Olivier's avatar
Langella Olivier committed
830
  else
831
    {
Langella Olivier's avatar
Langella Olivier committed
832
833
      ui->identifications_combobox->clear();
      ui->identifications_combobox->setVisible(true);
834

Langella Olivier's avatar
Langella Olivier committed
835
      for(IdentificationGroup *identification_group : identification_list)
836
        {
Langella Olivier's avatar
Langella Olivier committed
837
838
839
          IdentificationGroupWidget *p_identification_widget =
            new IdentificationGroupWidget(this);
          p_identification_widget->setVisible(false);
840
841


Langella Olivier's avatar
Langella Olivier committed
842
843
844
          ui->identifications_combobox->addItem(
            identification_group->getTabName(),
            QVariant::fromValue(p_identification_widget));
845

Langella Olivier's avatar
Langella Olivier committed
846
847
          p_identification_widget->setIdentificationGroup(this,
                                                          identification_group);
848

Langella Olivier's avatar
Langella Olivier committed
849
850
          ui->identifications_widget->layout()->addWidget(
            p_identification_widget);
851

Langella Olivier's avatar
Langella Olivier committed
852
          refreshGroup(identification_group);
853
        }
Langella Olivier's avatar
Langella Olivier committed
854
855
856
857
      ui->identifications_combobox->setCurrentIndex(0);
      qobject_cast<IdentificationGroupWidget *>(
        qvariant_cast<QObject *>(ui->identifications_combobox->itemData(
          ui->identifications_combobox->currentIndex())))
858
        ->setVisible(true);
Olivier Langella's avatar
Olivier Langella committed
859
    }
860

Langella Olivier's avatar
Langella Olivier committed
861
862
  AutomaticFilterParameters params =
    _project_sp.get()->getAutomaticFilterParameters();
Olivier Langella's avatar
Olivier Langella committed
863

Langella Olivier's avatar
Langella Olivier committed
864
865
866
  ui->filter_parameter_widget->setAutomaticFilterParameters(params);
  //_protein_list_window->setIdentificationGroup(_project_sp.get()->getCurrentIdentificationGroupP());
  //_protein_list_window->show();
867

Langella Olivier's avatar
Langella Olivier committed
868
869
  refresh();
  this->setEnabled(true);
Olivier Langella's avatar
Olivier Langella committed
870

871
  qDebug();
Langella Olivier's avatar
Langella Olivier committed
872
873
  // doAutomaticFilterParametersChanged(params);
  // doFdrChanged();
Olivier Langella's avatar
Olivier Langella committed
874
}
875
876
877
void
ProjectWindow::doIdentificationsComboboxChanged(int index_in)
{
878

Langella Olivier's avatar
Langella Olivier committed
879
880
  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
  for(int index = 0; index < ui->identifications_combobox->count(); index++)
881
    {