Newer
Older
/**
* \file /gui/workerthread.cpp
* \date 8/5/2017
* \author Olivier Langella
* \brief worker thread
*/
/*******************************************************************************
* 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/>.
*
* Contributors:
* Olivier Langella <olivier.langella@u-psud.fr> - initial API and
*implementation
******************************************************************************/
#include "workerthread.h"
#include <odsstream/odsdocwriter.h>
#include <odsstream/tsvoutputstream.h>
#include <odsstream/odsexception.h>
#include <pappsomspp/pappsoexception.h>
#include "../output/masschroqml.h"
#include "../output/ods/odsexport.h"
#include "../output/xpip.h"
#include "../output/mcqrspectralcount.h"
#include "mainwindow.h"
#include "project_view/projectwindow.h"
#include "../core/tandem_run/tandembatchprocess.h"
#include "../core/tandem_run/tandemcondorprocess.h"
#include <QSettings>
WorkerThread::WorkerThread(MainWindow *p_main_window)
_p_main_window = p_main_window;
qDebug() << "WorkerThread::WorkerThread begin MainWindow";
_p_work_monitor = new WorkMonitor();
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Qt5 code
// worker message
connect(_p_work_monitor, &WorkMonitor::workerMessage, p_main_window,
&MainWindow::doDisplayLoadingMessage);
connect(_p_work_monitor, &WorkMonitor::workerMessagePercent, p_main_window,
&MainWindow::doDisplayLoadingMessagePercent);
connect(_p_work_monitor, &WorkMonitor::workerAppendText, p_main_window,
&MainWindow::doWorkerAppendText);
connect(_p_work_monitor, &WorkMonitor::workerSetText, p_main_window,
&MainWindow::doWorkerSetText);
connect(_p_work_monitor, &WorkMonitor::workerJobFinished, p_main_window,
&MainWindow::doDisplayJobFinished);
connect(p_main_window, &MainWindow::operateXpipFile, this,
&WorkerThread::doXpipFileLoad);
connect(p_main_window, &MainWindow::operateWritingXpipFile, this,
&WorkerThread::doWritingXpipFile);
connect(this, &WorkerThread::projectReady, p_main_window,
&MainWindow::doProjectReady);
connect(this, &WorkerThread::loadingResultsFinished, p_main_window,
&MainWindow::doLoadingResultsReady);
connect(p_main_window, &MainWindow::operateLoadingResults, this,
&WorkerThread::doLoadingResults);
connect(p_main_window, &MainWindow::operateRunningXtandem, this,
&WorkerThread::doRunningXtandem);
connect(this, &WorkerThread::loadingMessage, p_main_window,
&MainWindow::doDisplayLoadingMessage);
connect(this, &WorkerThread::projectNotReady, p_main_window,
&MainWindow::doProjectNotReady);
// grouping
connect(p_main_window, &MainWindow::operateGrouping, this,
&WorkerThread::doGrouping);
connect(this, &WorkerThread::groupingFinished, p_main_window,
&MainWindow::doGroupingFinished);
// masschroq write
connect(p_main_window, &MainWindow::operateWritingMassChroqFile, this,
&WorkerThread::doWritingMassChroqFile);
connect(p_main_window, &MainWindow::operateWritingMassChroqPrmFile, this,
&WorkerThread::doWritingMassChroqPrmFile);
connect(p_main_window, &MainWindow::operateWritingMcqrSpectralCountFile, this,
&WorkerThread::doWritingMcqrSpectralCountFile);
// protic write
connect(p_main_window, &MainWindow::operateWritingProticFile, this,
&WorkerThread::doWritingProticFile);
// writing ODS file :
connect(p_main_window, &MainWindow::operateWritingOdsFile, this,
&WorkerThread::doWritingOdsFile);
connect(this, &WorkerThread::operationFailed, p_main_window,
&MainWindow::doOperationFailed);
connect(this, &WorkerThread::operationFinished, p_main_window,
&MainWindow::doOperationFinished);
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Qt4 code
// worker message
connect(_p_work_monitor, SIGNAL(workerMessage(QString)), p_main_window,
SLOT(doDisplayLoadingMessage(QString)));
connect(_p_work_monitor, SIGNAL(workerMessage(QString, int)), p_main_window,
SLOT(doDisplayLoadingMessage(QString, int)));
connect(_p_work_monitor, SIGNAL(workerAppendText(char *)), p_main_window,
SLOT(doWorkerAppendText(char *)));
connect(p_main_window, SIGNAL(operateXpipFile(QString)), this,
SLOT(doXpipFileLoad(QString)));
connect(this, SIGNAL(projectReady(ProjectSp)), p_main_window,
SLOT(doProjectReady(ProjectSp)));
connect(
p_main_window,
SIGNAL(operateLoadingResults(bool, AutomaticFilterParameters, QStringList)),
this, SLOT(doLoadingResults(bool, AutomaticFilterParameters, QStringList)));
connect(p_main_window, SIGNAL(operateRunningXtandem(TandemRunBatch)), this,
SLOT(doRunningXtandem(TandemRunBatch)));
connect(this, SIGNAL(loadingMessage(QString)), p_main_window,
SLOT(doDisplayLoadingMessage(QString)));
connect(this, SIGNAL(projectNotReady(QString)), p_main_window,
SLOT(doProjectNotReady(QString)));
// grouping
connect(p_main_window, SIGNAL(operateGrouping(ProjectSp)), this,
SLOT(doGrouping(ProjectSp)));
connect(this, SIGNAL(groupingFinished()), p_main_window,
SLOT(doGroupingFinished()));
// masschroq write
connect(p_main_window,
SIGNAL(operateWritingMassChroqFile(QString, ProjectSp)), this,
SLOT(doWritingMassChroqFile(QString, ProjectSp)));
// protic write
connect(p_main_window, SIGNAL(operateWritingProticFile(QString, ProjectSp)),
this, SLOT(doWritingProticFile(QString, ProjectSp)));
// writing ODS file :
connect(p_main_window, SIGNAL(operateWritingOdsFile(QString, ProjectSp)),
this, SLOT(doWritingOdsFile(QString, ProjectSp)));
connect(this, SIGNAL(operationFailed(QString)), p_main_window,
SLOT(doOperationFailed(QString)));
connect(this, SIGNAL(operationFinished()), p_main_window,
SLOT(doOperationFinished()));
qDebug() << "WorkerThread::WorkerThread end MainWindow";
WorkerThread::WorkerThread(ProjectWindow *p_project_window)
qDebug() << "WorkerThread::WorkerThread begin ProjectWindow";
_p_work_monitor = new WorkMonitor();
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// Qt5 code
// worker message
connect(_p_work_monitor, &WorkMonitor::workerMessage, p_project_window,
&ProjectWindow::doDisplayLoadingMessage);
connect(_p_work_monitor, &WorkMonitor::workerMessagePercent, p_project_window,
&ProjectWindow::doDisplayLoadingMessagePercent);
connect(this, &WorkerThread::loadingMessage, p_project_window,
&ProjectWindow::doDisplayLoadingMessage);
// grouping
connect(p_project_window, &ProjectWindow::operateGrouping, this,
&WorkerThread::doGrouping);
connect(this, &WorkerThread::groupingFinished, p_project_window,
&ProjectWindow::doGroupingFinished);
// PTM grouping on IdentificationGroup
connect(p_project_window, &ProjectWindow::operatePtmGroupingOnIdentification,
this, &WorkerThread::doPtmGroupingOnIdentification);
connect(this, &WorkerThread::ptmGroupingOnIdentificationFinished,
p_project_window, &ProjectWindow::refreshPtmGroup);
// grouping on IdentificationGroup
connect(p_project_window, &ProjectWindow::operateGroupingOnIdentification,
this, &WorkerThread::doGroupingOnIdentification);
connect(this, &WorkerThread::groupingOnIdentificationFinished,
p_project_window, &ProjectWindow::refreshGroup);
connect(this, &WorkerThread::operationFailed, p_project_window,
&ProjectWindow::doOperationFailed);
connect(this, &WorkerThread::operationFinished, p_project_window,
&ProjectWindow::doOperationFinished);
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
// Qt4 code
qDebug() << "WorkerThread::WorkerThread Qt4 code";
// worker message
connect(_p_work_monitor, SIGNAL(workerMessage(QString)), p_project_window,
SLOT(doDisplayLoadingMessage(QString)));
connect(_p_work_monitor, SIGNAL(workerMessage(QString, int)),
p_project_window, SLOT(doDisplayLoadingMessage(QString, int)));
connect(this, SIGNAL(loadingMessage(QString)), p_project_window,
SLOT(doDisplayLoadingMessage(QString)));
// grouping
connect(p_project_window, SIGNAL(operateGrouping(ProjectSp)), this,
SLOT(doGrouping(ProjectSp)));
connect(this, SIGNAL(groupingFinished()), p_project_window,
SLOT(doGroupingFinished()));
// PTM grouping on IdentificationGroup
connect(p_project_window,
SIGNAL(operatePtmGroupingOnIdentification(IdentificationGroup *)),
this, SLOT(doPtmGroupingOnIdentification(IdentificationGroup *)));
connect(this,
SIGNAL(ptmGroupingOnIdentificationFinished(IdentificationGroup *)),
p_project_window, SLOT(refreshPtmGroup(IdentificationGroup *)));
// grouping on IdentificationGroup
connect(
p_project_window,
SIGNAL(
operateGroupingOnIdentification(IdentificationGroup *, GroupingType)),
this,
SLOT(doGroupingOnIdentification(IdentificationGroup *, GroupingType)));
connect(this, SIGNAL(groupingOnIdentificationFinished(IdentificationGroup *)),
p_project_window, SLOT(refreshGroup(IdentificationGroup *)));
connect(this, SIGNAL(operationFailed(QString)), p_project_window,
SLOT(doOperationFailed(QString)));
connect(this, SIGNAL(operationFinished()), p_project_window,
SLOT(doOperationFinished()));
qDebug() << "WorkerThread::WorkerThread end ProjectWindow";
}
WorkerThread::~WorkerThread()
{
qDebug() << "WorkerThread::WorkerThread destructor";
void
WorkerThread::doXpipFileLoad(QString filename)
{
qDebug() << "WorkerThread::doXpipFileLoad begin " << filename;
try
{
QFileInfo new_xpip_file(filename);
emit loadingMessage(tr("loading XPIP file"));
qDebug() << "WorkerThread::doXpipFileLoad new_xpip_file "
<< new_xpip_file.absoluteFilePath();
XpipFile xpip_file(new_xpip_file);
ProjectSp project_sp = xpip_file.getProjectSp(_p_work_monitor);
emit projectReady(project_sp);
catch(pappso::PappsoException &error)
{
emit projectNotReady(
tr("Error while reading XPIP file :\n%1").arg(error.qwhat()));
qDebug() << "WorkerThread::doXpipFileLoad end";
void
WorkerThread::doPtmGroupingOnIdentification(
IdentificationGroup *p_identification_group)
{
qDebug() << "WorkerThread::doPtmGroupingOnIdentification begin ";
try
{
emit loadingMessage(tr("computing PTM islands"));
try
{
p_identification_group->startPtmGrouping();
catch(pappso::PappsoException exception_pappso)
{
emit operationFailed(tr("Error computing PTM islands : %1")
.arg(exception_pappso.qwhat()));
catch(std::exception exception_std)
{
emit operationFailed(
tr("Error computing PTM islands : %1").arg(exception_std.what()));
emit loadingMessage(tr("computing PTM islands finished"));
emit ptmGroupingOnIdentificationFinished(p_identification_group);
catch(pappso::PappsoException &error)
{
emit operationFailed(
tr("Error while computing PTM islands :\n%1").arg(error.qwhat()));
qDebug() << "WorkerThread::doPtmGroupingOnIdentification end ";
void
WorkerThread::doGroupingOnIdentification(
IdentificationGroup *p_identification_group, GroupingType grouping_type)
{
qDebug() << "WorkerThread::doGroupingOnIdentification begin ";
try
{
emit loadingMessage(tr("grouping proteins"));
try
{
p_identification_group->startGrouping(grouping_type, _p_work_monitor);
catch(pappso::PappsoException exception_pappso)
{
emit operationFailed(tr("Error grouping identification : %1")
.arg(exception_pappso.qwhat()));
catch(std::exception exception_std)
{
emit operationFailed(
tr("Error grouping identification : %1").arg(exception_std.what()));
emit loadingMessage(tr("grouping proteins finished"));
emit groupingOnIdentificationFinished(p_identification_group);
catch(pappso::PappsoException &error)
{
emit operationFailed(tr("Error while grouping :\n%1").arg(error.qwhat()));
qDebug() << "WorkerThread::doGroupingOnIdentification end ";
void
WorkerThread::doGrouping(ProjectSp project_sp)
{
qDebug() << "WorkerThread::doGrouping begin ";
try
{
emit loadingMessage(tr("grouping proteins"));
try
{
project_sp.get()->startGrouping(_p_work_monitor);
catch(pappso::PappsoException exception_pappso)
{
emit operationFailed(
tr("Error grouping project : %1").arg(exception_pappso.qwhat()));
catch(std::exception exception_std)
{
emit operationFailed(
tr("Error grouping project : %1").arg(exception_std.what()));
emit loadingMessage(tr("grouping proteins finished"));
emit groupingFinished();
catch(pappso::PappsoException &error)
{
emit operationFailed(tr("Error while grouping :\n%1").arg(error.qwhat()));
qDebug() << "WorkerThread::doGrouping end ";
void
WorkerThread::doWritingXpipFile(QString filename, ProjectSp project_sp)
{
try
{
emit loadingMessage(tr("writing XPIP file, please wait"));
project_sp.get()->checkPsimodCompliance();
Xpip xpip_file(filename);
xpip_file.write(project_sp);
xpip_file.close();
catch(pappso::PappsoException &error)
{
emit operationFailed(
tr("Error while writing XPIP file :\n%1").arg(error.qwhat()));
void
WorkerThread::doWritingOdsFile(QString filename, ProjectSp project_sp)
{
try
{
emit loadingMessage(tr("writing ODS file, please wait"));
OdsDocWriter writer(filename);
OdsExport export_ods(project_sp.get());
export_ods.write(&writer, _p_work_monitor);
writer.close();
emit operationFinished();
catch(pappso::PappsoException &error)
{
emit operationFailed(
tr("Error while writing ODS file :\n%1").arg(error.qwhat()));
void
WorkerThread::doWritingMassChroqFile(QString filename, ProjectSp project_sp)
{
try
{
emit loadingMessage(tr("writing MassChroqML file, please wait"));
project_sp.get()->checkPsimodCompliance();
MassChroQml output(filename);
output.write(project_sp);
output.close();
emit operationFinished();
catch(pappso::PappsoException &error)
{
emit operationFailed(
tr("Error while writing MassChroqML file :\n%1").arg(error.qwhat()));
void
WorkerThread::doWritingMassChroqPrmFile(QString filename, ProjectSp project_sp)
{
try
{
emit loadingMessage(tr("writing MassChroqPRM file, please wait"));
project_sp.get()->checkPsimodCompliance();
MassChroqPrm output(filename);
output.write(project_sp);
output.close();
emit operationFinished();
catch(pappso::PappsoException &error)
{
emit operationFailed(
tr("Error while writing MassChroqPRM file :\n%1").arg(error.qwhat()));
void
WorkerThread::doWritingProticFile(QString filename, ProjectSp project_sp)
{
try
{
emit loadingMessage(tr("writing PROTICdbML file, please wait"));
project_sp.get()->checkPsimodCompliance();
ProticdbMl output(filename);
output.write(project_sp);
output.close();
emit operationFinished();
catch(pappso::PappsoException &error)
{
emit operationFailed(
tr("Error while writing PROTICdbML file :\n%1").arg(error.qwhat()));
void
WorkerThread::doWritingMcqrSpectralCountFile(QString filename,
ProjectSp project_sp)
{
try
{
emit loadingMessage(
tr("Writing %1 spectral count file for MassChroqR").arg(filename));
QFile outFile;
outFile.setFileName(filename);
outFile.open(QIODevice::WriteOnly);
QTextStream *p_outputStream = new QTextStream(&outFile);
TsvOutputStream *p_writer = new TsvOutputStream(*p_outputStream);
p_writer->setNoSheetName(true);
McqrSpectralCount spectra_sheet(p_writer, project_sp.get());
spectra_sheet.writeSheet();
p_writer->close();
delete p_writer;
delete p_outputStream;
outFile.close();
emit operationFinished();
catch(OdsException &error)
{
emit operationFailed(
tr("Error while writing spectral count file for MassChroqR :\n%1")
.arg(error.qwhat()));
catch(pappso::PappsoException &errorb)
{
emit operationFailed(
tr("Error while writing spectral count file for MassChroqR :\n%1")
.arg(errorb.qwhat()));
void
WorkerThread::doLoadingResults(bool is_individual,
AutomaticFilterParameters param,
QStringList file_list)
{
qDebug() << "WorkerThread::doLoadingResults begin ";
try
{
if(file_list.size() == 0)
{
throw pappso::PappsoException(QObject::tr("file list is empty"));
ProjectSp project_sp = Project().makeProjectSp();
if(is_individual)
{
project_sp.get()->setProjectMode(ProjectMode::individual);
else
{
project_sp.get()->setProjectMode(ProjectMode::combined);
_p_work_monitor->setProgressMaximumValue(file_list.size());
int i = 0;
for(QString filename : file_list)
{
_p_work_monitor->message(tr("loading result file %1 (%2 on %3)")
.arg(filename)
.arg(i)
.arg(file_list.size()),
i);
project_sp.get()->readResultFile(filename);
i++;
emit loadingMessage(tr("filtering proteins"));
project_sp.get()->updateAutomaticFilters(param);
qDebug() << "WorkerThread::doLoadingResults emit "
"loadingResultsFinished(project_sp) ";
emit loadingResultsFinished(project_sp);
catch(pappso::PappsoException &error)
{
qDebug() << "WorkerThread::doLoadingResults error ";
emit projectNotReady(
tr("Error while reading result files :\n%1").arg(error.qwhat()));
qDebug() << "WorkerThread::doLoadingResults end ";
void
WorkerThread::doRunningXtandem(TandemRunBatch tandem_run_batch)
{
qDebug() << "WorkerThread::doRunningXtandem begin ";
try
{
emit loadingMessage(tr("Running X!Tandem, please wait"));
qDebug() << "WorkerThread::doRunningXtandem tandem_run_batch "
<< tandem_run_batch._tandem_bin_path;
QSettings settings;
bool use_htcondor =
settings.value("tandem/use_HTCondor", "false").toBool();
if(use_htcondor)
{
TandemCondorProcess xt_process(_p_main_window, _p_work_monitor,
tandem_run_batch);
xt_process.run();
else
{
TandemBatchProcess xt_process(_p_main_window, _p_work_monitor,
tandem_run_batch);
xt_process.run();
catch(pappso::PappsoException &error)
{
emit operationFailed(
tr("Error while running X!Tandem job :\n%1").arg(error.qwhat()));
qDebug() << "WorkerThread::doRunningXtandem end ";