workerthread.cpp 29.1 KB
Newer Older
1
2
3
4
5
6
7
8
/**
 * \file /gui/workerthread.cpp
 * \date 8/5/2017
 * \author Olivier Langella
 * \brief worker thread
 */

/*******************************************************************************
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 * 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
 ******************************************************************************/
30
31
32

#include "workerthread.h"
#include <odsstream/odsdocwriter.h>
33
34
#include <odsstream/tsvoutputstream.h>
#include <odsstream/odsexception.h>
35
#include <pappsomspp/pappsoexception.h>
36
#include <QDebug>
37
#include "../output/exportfastafile.h"
38
#include "../output/masschroqml.h"
Langella Olivier's avatar
Langella Olivier committed
39
#include "../output/masschroqprm.h"
Olivier Langella's avatar
Olivier Langella committed
40
#include "../output/proticdbml.h"
41
#include "../output/ods/odsexport.h"
42
#include "../output/xpip.h"
43
#include "../output/mcqrspectralcount.h"
44
#include "files/xpipfile.h"
Olivier Langella's avatar
Olivier Langella committed
45
46
#include "mainwindow.h"
#include "project_view/projectwindow.h"
47
#include "../core/tandem_run/tandembatchprocess.h"
Olivier Langella's avatar
Olivier Langella committed
48
49
#include "../core/tandem_run/tandemcondorprocess.h"
#include <QSettings>
50

51
WorkerThread::WorkerThread(MainWindow *p_main_window)
52
{
53
54
    _p_main_window = p_main_window;
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
55

56
    _p_work_monitor = new WorkMonitor();
57

58
#if QT_VERSION >= 0x050000
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
112
113
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
158
159
160
161
    // 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);
    // FASTA file write
    connect(p_main_window,
            &MainWindow::operateWritingFastaFile,
            this,
            &WorkerThread::doWritingFastaFile);
Olivier Langella's avatar
Olivier Langella committed
162

163
#else
164
165
166
167
168
169
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
202
203
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
    // 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()));
238
239
#endif

240
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
241
242
}

243
WorkerThread::WorkerThread(ProjectWindow *p_project_window)
244
{
245
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
246

247
    _p_work_monitor = new WorkMonitor();
Olivier Langella's avatar
Olivier Langella committed
248

249
#if QT_VERSION >= 0x050000
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
    // 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);
Langella Olivier's avatar
Langella Olivier committed
304

305
#else
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
    // Qt4 code
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;

    // 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()));
364
365

#endif
366
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
367
368
369
370
}

WorkerThread::~WorkerThread()
{
371
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
372
373
}

374
375
376
void
WorkerThread::doXpipFileLoad(QString filename)
{
377
378
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << filename;
    try
379
    {
380
381
382
383
384
385
386
387
        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);
388
    }
389
    catch(pappso::PappsoException &error)
390
    {
391
392
        emit projectNotReady(
            tr("Error while reading XPIP file :\n%1").arg(error.qwhat()));
393
394
    }

395
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
396
397
}

398
399
void
WorkerThread::doPtmGroupingOnIdentification(
400
    IdentificationGroup *p_identification_group)
401
{
402
403
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
    try
404
    {
405
406
        emit loadingMessage(tr("computing PTM islands"));
        try
407
        {
408
            p_identification_group->startPtmGrouping();
Olivier Langella's avatar
Olivier Langella committed
409
        }
410
        catch(pappso::PappsoException exception_pappso)
411
        {
412
            emit operationFailed(tr("Error computing PTM islands : %1")
413
                                 .arg(exception_pappso.qwhat()));
Olivier Langella's avatar
Olivier Langella committed
414
        }
415
        catch(std::exception exception_std)
416
        {
417
418
            emit operationFailed(
                tr("Error computing PTM islands : %1").arg(exception_std.what()));
Olivier Langella's avatar
Olivier Langella committed
419
        }
420
421
        emit loadingMessage(tr("computing PTM islands finished"));
        emit ptmGroupingOnIdentificationFinished(p_identification_group);
Olivier Langella's avatar
Olivier Langella committed
422
    }
423
    catch(pappso::PappsoException &error)
424
    {
425
426
        emit operationFailed(
            tr("Error while computing PTM islands :\n%1").arg(error.qwhat()));
Olivier Langella's avatar
Olivier Langella committed
427
    }
428
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
Olivier Langella's avatar
Olivier Langella committed
429
}
430

431
432
void
WorkerThread::doGroupingOnIdentification(
433
434
435
    IdentificationGroup *p_identification_group,
    ContaminantRemovalMode contaminant_removal_mode,
    GroupingType grouping_type)
436
{
437
438
439
    qDebug() << "TEST";
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
    try
440
    {
441
442
        emit loadingMessage(tr("grouping proteins"));
        try
443
        {
444
445
            p_identification_group->startGrouping(
                contaminant_removal_mode, grouping_type, _p_work_monitor);
446
        }
447
        catch(pappso::PappsoException exception_pappso)
448
        {
449
            emit operationFailed(tr("Error grouping identification : %1")
450
                                 .arg(exception_pappso.qwhat()));
451
        }
452
        catch(std::exception exception_std)
453
        {
454
455
            emit operationFailed(
                tr("Error grouping identification : %1").arg(exception_std.what()));
456
        }
457
458
        emit loadingMessage(tr("grouping proteins finished"));
        emit groupingOnIdentificationFinished(p_identification_group);
459
    }
460
    catch(pappso::PappsoException &error)
461
    {
462
        emit operationFailed(tr("Error while grouping :\n%1").arg(error.qwhat()));
463
    }
464
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
465
}
466
467
468
void
WorkerThread::doGrouping(ProjectSp project_sp)
{
469
470
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
    try
471
    {
472
473
        emit loadingMessage(tr("grouping proteins"));
        try
474
        {
475
            project_sp.get()->startGrouping(_p_work_monitor);
476
        }
477
        catch(pappso::PappsoException exception_pappso)
478
        {
479
480
            emit operationFailed(
                tr("Error grouping project : %1").arg(exception_pappso.qwhat()));
481
        }
482
        catch(std::exception exception_std)
483
        {
484
485
            emit operationFailed(
                tr("Error grouping project : %1").arg(exception_std.what()));
486
        }
487
488
        emit loadingMessage(tr("grouping proteins finished"));
        emit groupingFinished();
489
    }
490
    catch(pappso::PappsoException &error)
491
    {
492
        emit operationFailed(tr("Error while grouping :\n%1").arg(error.qwhat()));
493
    }
494
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
495
}
496

497
498
499
void
WorkerThread::doWritingXpipFile(QString filename, ProjectSp project_sp)
{
500

501
    try
502
    {
503
504
505
506
507
        emit loadingMessage(tr("writing XPIP file, please wait"));
        project_sp.get()->checkPsimodCompliance();
        Xpip xpip_file(filename);
        xpip_file.write(project_sp);
        xpip_file.close();
508

509
        emit operationFinished();
510
    }
511
    catch(pappso::PappsoException &error)
512
    {
513
514
        emit operationFailed(
            tr("Error while writing XPIP file :\n%1").arg(error.qwhat()));
515
516
    }
}
517
void
518
519
WorkerThread::doWritingOdsFile(QString filename,
                               QString format,
520
                               ProjectSp project_sp)
521
522
{

523
    try
524
    {
525

526
527
528
        qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
        CalcWriterInterface *p_writer = nullptr;
        if(format == "tsv")
529
        {
530
531
            emit loadingMessage(tr("writing TSV files, please wait"));
            p_writer = new TsvDirectoryWriter(filename);
532
        }
533
        else
534
        {
535
536
            emit loadingMessage(tr("writing ODS file, please wait"));
            p_writer = new OdsDocWriter(filename);
537
538
        }

539
540
        OdsExport export_ods(project_sp);
        try
541
        {
542
            export_ods.write(p_writer, _p_work_monitor);
543
        }
544
        catch(pappso::PappsoException &error)
545
        {
546
547
548
            p_writer->close();
            delete p_writer;
            throw error;
549
        }
550
551
552
        p_writer->close();
        delete p_writer;
        emit operationFinished();
553
    }
554
    catch(pappso::PappsoException &error)
555
    {
556

557
558
        emit operationFailed(
            tr("Error while writing ODS file :\n%1").arg(error.qwhat()));
559
560
561
562
    }
}


563
void
564
565
WorkerThread::doWritingMassChroqFile(QString filename,
                                     ProjectSp project_sp,
566
                                     MasschroqFileParameters params)
567
568
{

569
    try
570
    {
571
        emit loadingMessage(tr("writing MassChroqML file, please wait"));
572

573
574
575
576
577
        project_sp.get()->checkPsimodCompliance();
        MassChroQml output(filename, params);
        output.write(project_sp);
        output.close();
        emit operationFinished();
578
    }
579
    catch(pappso::PappsoException &error)
580
    {
581
582
        emit operationFailed(
            tr("Error while writing MassChroqML file :\n%1").arg(error.qwhat()));
583
584
    }
}
585

586
587
588
589
void
WorkerThread::doWritingMassChroqPrmFile(QString filename, ProjectSp project_sp)
{

590
    try
591
    {
592
        emit loadingMessage(tr("writing MassChroqPRM file, please wait"));
Langella Olivier's avatar
Langella Olivier committed
593

594
595
596
597
598
        project_sp.get()->checkPsimodCompliance();
        MassChroqPrm output(filename);
        output.write(project_sp);
        output.close();
        emit operationFinished();
Langella Olivier's avatar
Langella Olivier committed
599
    }
600
    catch(pappso::PappsoException &error)
601
    {
602
603
        emit operationFailed(
            tr("Error while writing MassChroqPRM file :\n%1").arg(error.qwhat()));
Langella Olivier's avatar
Langella Olivier committed
604
605
606
    }
}

607
608
609
610
void
WorkerThread::doWritingProticFile(QString filename, ProjectSp project_sp)
{

611
    try
612
    {
613
        emit loadingMessage(tr("writing PROTICdbML file, please wait"));
Olivier Langella's avatar
Olivier Langella committed
614

615
616
617
618
619
        project_sp.get()->checkPsimodCompliance();
        ProticdbMl output(filename);
        output.write(project_sp);
        output.close();
        emit operationFinished();
Olivier Langella's avatar
Olivier Langella committed
620
    }
621
    catch(pappso::PappsoException &error)
622
    {
623
624
        emit operationFailed(
            tr("Error while writing PROTICdbML file :\n%1").arg(error.qwhat()));
Olivier Langella's avatar
Olivier Langella committed
625
626
627
    }
}

628

629
630
void
WorkerThread::doWritingMcqrSpectralCountFile(QString filename,
631
        ProjectSp project_sp)
632
{
633
    try
634
    {
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
        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();
651
    }
652
    catch(OdsException &error)
653
    {
654
655
656
        emit operationFailed(
            tr("Error while writing spectral count file for MassChroqR :\n%1")
            .arg(error.qwhat()));
657
    }
658
    catch(pappso::PappsoException &errorb)
659
    {
660
661
662
        emit operationFailed(
            tr("Error while writing spectral count file for MassChroqR :\n%1")
            .arg(errorb.qwhat()));
663
    }
664
665
666
}


667
668
669
670
671
void
WorkerThread::doLoadingResults(bool is_individual,
                               AutomaticFilterParameters param,
                               QStringList file_list)
{
672

673
674
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
    try
675
    {
676
        if(file_list.size() == 0)
677
        {
678
            throw pappso::PappsoException(QObject::tr("file list is empty"));
679
        }
680
681
        ProjectSp project_sp = Project().makeProjectSp();
        if(is_individual)
682
        {
683
            project_sp.get()->setProjectMode(ProjectMode::individual);
684
        }
685
        else
686
        {
687
            project_sp.get()->setProjectMode(ProjectMode::combined);
688
        }
689

690
691
692
        _p_work_monitor->setProgressMaximumValue(file_list.size());
        int i = 0;
        for(QString filename : file_list)
693
        {
694
            _p_work_monitor->message(tr("loading result file %1 (%2 on %3)")
695
696
697
                                     .arg(filename)
                                     .arg(i)
                                     .arg(file_list.size()),
698
699
700
                                     i);
            project_sp.get()->readResultFile(filename);
            i++;
701
702
        }

703
704
705
706
        emit loadingMessage(tr("filtering proteins"));
        project_sp.get()->updateAutomaticFilters(param);
        qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
        emit loadingResultsFinished(project_sp);
707
    }
708
    catch(pappso::PappsoException &error)
709
    {
710
711
712
713
        qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
                 << error.qwhat();
        emit projectNotReady(
            tr("Error while reading result files :\n%1").arg(error.qwhat()));
714
    }
715
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
716
}
717
718
719
void
WorkerThread::doRunningXtandem(TandemRunBatch tandem_run_batch)
{
720
721
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
    try
722
    {
723
724
725
        emit loadingMessage(tr("Running X!Tandem, please wait"));
        qDebug() << "WorkerThread::doRunningXtandem tandem_run_batch "
                 << tandem_run_batch._tandem_bin_path;
726

727
728
729
        QSettings settings;
        bool use_htcondor =
            settings.value("tandem/use_HTCondor", "false").toBool();
730

731
        if(use_htcondor)
732
        {
733
734
735
            TandemCondorProcess xt_process(
                _p_main_window, _p_work_monitor, tandem_run_batch);
            xt_process.run();
Olivier Langella's avatar
Olivier Langella committed
736
        }
737
        else
738
        {
739
740
741
            TandemBatchProcess xt_process(
                _p_main_window, _p_work_monitor, tandem_run_batch);
            xt_process.run();
742
        }
Langella Olivier's avatar
Langella Olivier committed
743

744
        emit operationFinished();
745
    }
746
    catch(pappso::PappsoException &error)
747
    {
748
749
750
751
        qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
                 << error.qwhat();
        emit operationFailed(
            tr("Error while running X!Tandem job :\n%1").arg(error.qwhat()));
752
    }
753
    qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
754
}
755
756
757


void
758
759
WorkerThread::doWritingFastaFile(QString filename,
                                 ProjectSp project_sp,
760
761
762
                                 ExportFastaType type)
{

763
    try
764
765
    {

766
767
        qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
        emit loadingMessage(tr("writing FASTA file, please wait"));
768

769

770
771
772
        ExportFastaFile output(filename, type);
        output.write(project_sp);
        output.close();
773

774
775
        // emit operateXpipFile(filename);
        emit operationFinished();
776
    }
777
    catch(pappso::PappsoException &error)
778
    {
779
780
        emit operationFailed(
            tr("Error while writing FASTA file :\n%1").arg(error.qwhat()));
781
782
    }
}
783
784
785
786
787
788


void
WorkerThread::doFindBestMsrunForAlignment(ProjectSp project_sp)
{

789
    try
790
791
    {

792
793
794
        qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
        emit loadingMessage(
            tr("looking for the best MSrun reference for alignment, please wait"));
795

796
797
798
799
800
801
        _p_work_monitor->message("checking MS run file path");
        _p_work_monitor->setProgressMaximumValue(
            project_sp->getMsRunStore().getMsRunList().size());
        std::size_t i = 0;
        bool is_ok    = true;
        for(auto &msrun_sp : project_sp->getMsRunStore().getMsRunList())
802
        {
803
            _p_work_monitor->message(tr("checking MS run file path for sample %1")
804
                                     .arg(msrun_sp->getSampleName()),
805
806
                                     i);
            if(msrun_sp->findMsRunFile())
807
808
            {
            }
809
            else
810
            {
811
812
813
814
815
                throw pappso::PappsoException(
                    tr("Error while checking MS run file path :\nMSrun \"%1\" for "
                       "sample named \"%2\" not found")
                    .arg(msrun_sp->getXmlId())
                    .arg(msrun_sp->getSampleName()));
816
            }
817
            i++;
818
        }
819
820
        _p_work_monitor->message("preparing MS run retention times");
        try
821
        {
822
            project_sp->prepareMsrunRetentionTimesForAlignment();
823
        }
824
        catch(pappso::PappsoException &error)
825
        {
826
827
828
            throw pappso::PappsoException(
                tr("Error while preparing MS run retention times :\n%1")
                .arg(error.qwhat()));
829
        }
830

831
832
        _p_work_monitor->message("choosing MS run");
        try
833
        {
834
835
836
            MsRunSp ms_run_best_reference;
            std::size_t best_number = 0;
            for(auto &msrun_ref_sp : project_sp->getMsRunStore().getMsRunList())
837
            {
838
                if(ms_run_best_reference == nullptr)
839
                {
840
                    ms_run_best_reference = msrun_ref_sp;
841
                }
842

843
844
                std::size_t min_number = std::numeric_limits<std::size_t>::max();
                for(auto &msrun_sp : project_sp->getMsRunStore().getMsRunList())
845
                {
846
                    if(msrun_sp.get() != msrun_ref_sp.get())
847
                    {
848
849
850
851
852
                        pappso::Trace trace;
                        trace =
                            msrun_sp.get()
                            ->getMsRunRetentionTimePtr()
                            ->getCommonDeltaRt(msrun_ref_sp.get()
853
854
                                               ->getMsRunRetentionTimePtr()
                                               ->getSeamarks());
855
                        if(trace.size() < min_number)
856
                        {
857
                            min_number = trace.size();
858
                        }
859
860
861
                    }
                }

862
                if(min_number > best_number)
863
                {
864
                    best_number = min_number;
865

866
                    ms_run_best_reference = msrun_ref_sp;
867
                }
868
            }
869
            if(ms_run_best_reference != nullptr)
870
            {
871
872
873
                qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
                         << " " << ms_run_best_reference.get()->getXmlId()
                         << " best_number=" << best_number;
874
875
            }

876
877
878
            _p_work_monitor->message("done");
            // emit operateXpipFile(filename);
            emit findingBestMsrunForAlignmentFinished(ms_run_best_reference);
879
        }
880
        catch(pappso::PappsoException &error)
881
        {
882
883
            throw pappso::PappsoException(
                tr("Error while choosing best MS run :\n%1").arg(error.qwhat()));
884
885
        }
    }
886
    catch(pappso::PappsoException &error)
887
    {
888
889
890
        emit operationFailed(
            tr("Error looking for the best MSrun reference for alignment :\n%1")
            .arg(error.qwhat()));
891
892
    }
}
893
894
895
896
897
898


void
WorkerThread::doCheckMsrunFilePath(ProjectSp msp_project)
{

899
900
    MsRunSp msrun_sp = nullptr;
    try
901
902
    {

903
904
905
906
        _p_work_monitor->setProgressMaximumValue(
            msp_project->getIdentificationDataSourceStore()
            .getIdentificationDataSourceList()
            .size());
907

908
909
910
911
        std::size_t i = 0;
        for(IdentificationDataSourceSp p_ident_data_source :
                msp_project->getIdentificationDataSourceStore()
                .getIdentificationDataSourceList())
912
        {
913
914
915
916
917
918
919
920
            msrun_sp = p_ident_data_source->getMsRunSp();
            _p_work_monitor->message(
                tr("checking MS run file path for \"%1\", named \"%2\"")
                .arg(msrun_sp.get()->getXmlId())
                .arg(msrun_sp.get()->getSampleName()),
                i);

            if(msrun_sp->findMsRunFile())
921
            {
922
923
                // msrun_sp->checkMsRunStatistics();
                msrun_sp = nullptr;
924
            }
925
            else
926
            {
927
928
                // is_ok = false;
                break;
929
            }
930
            i++;
931
932
933
        }
    }

934
    catch(pappso::PappsoException &error)
935
    {
936
937
        emit operationFailed(
            tr("Error checking MSrun files path :\n%1").arg(error.qwhat()));
938
939
    }

940
    emit checkingMsrunFilePathFinished(msrun_sp);
941
}