/******************************************************************************* * Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.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@moulon.inra.fr> - initial API and implementation ******************************************************************************/ #include <QDockWidget> #include <QSettings> #include <QFileDialog> #include <QMessageBox> #include <QDebug> #include "mainwindow.h" #include "ui_main.h" #include <pappsomspp/pappsoexception.h> #include <odsstream/odsdocwriter.h> #include "../output/masschroqml.h" #include "../output/ods/odsexport.h" void XtpLoaderThread::doXpipFileLoad(QString filename) { qDebug() << "XtpLoaderThread::doXpipFileLoad begin "<< filename; try { QFileInfo new_xpip_file; new_xpip_file.setFile(filename); emit loadingMessage(tr("loading XPIP file")); XpipFile xpip_file(new_xpip_file); ProjectSp project_sp = xpip_file.getProjectSp(); emit projectReady(project_sp); } catch (pappso::PappsoException & error) { emit projectNotReady(tr("Error while reading XPIP file :\n%1").arg(error.qwhat())); } qDebug() << "XtpLoaderThread::doXpipFileLoad end"; } void XtpLoaderThread::doLoadingResults(bool is_individual, AutomaticFilterParameters param, QStringList file_list) { qDebug() << "XtpLoaderThread::doLoadingResults begin "; try { if (file_list.size() == 0) { throw pappso::PappsoException(QObject::tr("file list is empty")); } ProjectSp project_sp = Project().makeProjectSp(); project_sp.get()->setCombineMode(!is_individual); for (QString filename : file_list) { emit loadingMessage(tr("loading result file %1").arg(filename)); project_sp.get()->readResultFile(filename); } emit loadingMessage(tr("filtering proteins")); project_sp.get()->updateAutomaticFilters(param); emit projectReady(project_sp); } catch (pappso::PappsoException & error) { emit projectNotReady(tr("Error while reading result files :\n%1").arg(error.qwhat())); } qDebug() << "XtpLoaderThread::doLoadingResults end "; } MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::Main) { ui->setupUi(this); XtpLoaderThread *worker = new XtpLoaderThread; worker->moveToThread(&workerThread); /* */ workerThread.start(); _p_load_results_dialog = new LoadResultsDialog(this); _p_export_spreadsheet_dialog = new ExportSpreadsheetDialog(this); _project_window = new ProjectWindow(this); ui->menu_export_files->setDisabled(true); ui->centralwidget->layout()->addWidget(_project_window); _project_window->show(); //_protein_list_window = new ProteinListWindow(this); //QDockWidget *dock = new QDockWidget(tr("Protein List"), this); //dock->setWidget(_protein_list_window); //addDockWidget(Qt::RightDockWidgetArea, dock); qRegisterMetaType<ProjectSp>("ProjectSp"); qRegisterMetaType<AutomaticFilterParameters>("AutomaticFilterParameters"); #if QT_VERSION >= 0x050000 // Qt5 code /* connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); connect(this, &PtSpectrumViewer::operateMsDataFile, worker, &PwizLoaderThread::doMsDataFileLoad); connect(worker, &PwizLoaderThread::msDataReady, this, &PtSpectrumViewer::handleMsDataFile); */ #else // Qt4 code connect(this, SIGNAL(operateXpipFile(QString)), worker,SLOT(doXpipFileLoad(QString))); connect(worker, SIGNAL(projectReady(ProjectSp)), this,SLOT(doProjectReady(ProjectSp))); connect(this, SIGNAL(operateLoadingResults(bool,AutomaticFilterParameters,QStringList)), worker,SLOT(doLoadingResults(bool,AutomaticFilterParameters,QStringList))); connect(_p_load_results_dialog, SIGNAL(accepted()), this,SLOT(doAcceptedLoadResultDialog())); connect(_p_export_spreadsheet_dialog, SIGNAL(accepted()), this,SLOT(doAcceptedExportSpreadsheetDialog())); connect(worker, SIGNAL(loadingMessage(QString)), this,SLOT(doDisplayLoadingMessage(QString))); connect(worker, SIGNAL(projectNotReady(QString)), this,SLOT(doProjectNotReady(QString))); /* connect(&workerThread, SIGNAL(finished()), worker, SLOT(deleteLater())); connect(this, SIGNAL(operateMsDataFile(QString)), worker,SLOT(doMsDataFileLoad(QString))); connect(worker, SIGNAL(msDataReady(pwiz::msdata::MSDataFile *)), this, SLOT(handleMsDataFile(pwiz::msdata::MSDataFile *))); */ #endif } MainWindow::~MainWindow() { workerThread.quit(); workerThread.wait(); //if (_p_ms_data_file != nullptr) delete _p_ms_data_file; delete ui; delete _project_window; } void MainWindow::closeEvent(QCloseEvent * event) { if (true) { event->accept(); } else { event->ignore(); } } void MainWindow::viewError(QString error) { QMessageBox::warning(this, tr("Oops! an error occurred in XTPCPP. Dont Panic :"), error); } void MainWindow::doDisplayLoadingMessage(QString message) { qDebug() << "MainWindow::doDisplayLoadingMessage " << message; ui->statusbar->showMessage(message); } void MainWindow::doActionQuit() { qDebug() << "MainWindow::doActionQuit begin"; this->close(); } void MainWindow::doAcceptedExportSpreadsheetDialog() { qDebug() << "MainWindow::doAcceptedExportSpreadsheetDialog begin"; try { QSettings settings; QString default_location = settings.value("path/export_ods", "").toString(); QString filename = QFileDialog::getSaveFileName(this, tr("Save ODS file"), QString("%1/untitled.ods").arg(default_location), tr("Open Document Spreadsheet (*.ods)")); if (filename.isEmpty()) { return; } settings.setValue("path/export_ods", QFileInfo(filename).absolutePath()); OdsDocWriter writer(filename); OdsExport export_ods(_project_sp.get()); export_ods.write(&writer); writer.close(); //emit operateXpipFile(filename); } catch (pappso::PappsoException & error) { viewError(tr("Error while writing ODS file :\n%1").arg(error.qwhat())); } qDebug() << "MainWindow::doAcceptedExportSpreadsheetDialog end"; } void MainWindow::doAcceptedLoadResultDialog() { qDebug() << "MainWindow::doAcceptedLoadResultDialog begin"; AutomaticFilterParameters param = _p_load_results_dialog->getAutomaticFilterParameters(); QSettings settings; settings.setValue("automatic_filter/cross_sample", QString("%1").arg(param.getFilterCrossSamplePeptideNumber())); settings.setValue("automatic_filter/peptide_number", QString("%1").arg(param.getFilterMinimumPeptidePerMatch())); settings.setValue("automatic_filter/peptide_evalue", QString("%1").arg(param.getFilterPeptideEvalue())); settings.setValue("automatic_filter/protein_evalue", QString("%1").arg(param.getFilterProteinEvalue())); QStringList file_list = _p_load_results_dialog->getFileList(); bool is_individual = _p_load_results_dialog->isIndividual(); emit operateLoadingResults(is_individual, param, file_list); qDebug() << "MainWindow::doAcceptedLoadResultDialog end"; } void MainWindow::doProjectReady(ProjectSp project_sp) { qDebug() << "MainWindow::doProjectReady begin"; try { _project_sp = project_sp; doDisplayLoadingMessage(tr("grouping proteins")); project_sp.get()->startGrouping(); doDisplayLoadingMessage(tr("grouping proteins finished")); } catch (pappso::PappsoException & error) { viewError(tr("Error while grouping :\n%1").arg(error.qwhat())); } _project_window->setProjectSp(project_sp); ui->menu_export_files->setDisabled(false); qDebug() << "MainWindow::doProjectReady end"; } void MainWindow::doProjectNotReady(QString error) { viewError(error); } void MainWindow::loadResults() { _p_load_results_dialog->show(); _p_load_results_dialog->raise(); _p_load_results_dialog->activateWindow(); } void MainWindow::selectXpipFile() { try { QSettings settings; QString default_location = settings.value("path/xpipfile", "").toString(); QString filename = QFileDialog::getOpenFileName(this, tr("Open XPIP File"), default_location, tr("xpip files (*.xpip);;all files (*)")); if (filename.isEmpty()) { return; } settings.setValue("path/xpipfile", QFileInfo(filename).absolutePath()); emit operateXpipFile(filename); } catch (pappso::PappsoException & error) { viewError(tr("Error while reading XPIP file :\n%1").arg(error.qwhat())); } } void MainWindow::doActionSpreadsheet() { qDebug() << "MainWindow::doActionSpreadsheet begin"; try { _p_export_spreadsheet_dialog->show(); _p_export_spreadsheet_dialog->raise(); _p_export_spreadsheet_dialog->activateWindow(); } catch (pappso::PappsoException & error) { viewError(tr("Error doActionSpreadsheet :\n%1").arg(error.qwhat())); } qDebug() << "MainWindow::doActionSpreadsheet end"; } void MainWindow::doActionMassChroQ() { qDebug() << "MainWindow::doActionMassChroQ begin"; try { _project_sp.get()->checkPsimodCompliance(); QSettings settings; QString default_location = settings.value("path/mcqfile", "").toString(); QString filename = QFileDialog::getSaveFileName(this, tr("Save MassChroqML file"), QString("%1/untitled.masschroqml").arg(default_location), tr("MassChroqML (*.masschroqml)")); if (filename.isEmpty()) { return; } settings.setValue("path/mcqfile", QFileInfo(filename).absolutePath()); MassChroQml output(filename); output.write(_project_sp); output.close(); //emit operateXpipFile(filename); } catch (pappso::PappsoException & error) { viewError(tr("Error while writing MassChroqML file :\n%1").arg(error.qwhat())); } qDebug() << "MainWindow::doActionMassChroQ end"; }