From 89e28cbf46242a64dfa7e75c9ed1632a899a7667 Mon Sep 17 00:00:00 2001 From: Olivier Langella <olivier.langella@u-psud.fr> Date: Tue, 15 Jan 2019 15:04:14 +0100 Subject: [PATCH] separate fasta file output in worker thread with dedicated output object --- src/CMakeLists.txt | 1 + src/gui/mainwindow.cpp | 41 +++---------------- src/gui/mainwindow.h | 3 ++ src/gui/workerthread.cpp | 34 ++++++++++++++++ src/gui/workerthread.h | 3 ++ src/main.cpp | 1 + src/output/exportfastafile.cpp | 74 ++++++++++++++++++++++++++++++++++ src/output/exportfastafile.h | 43 ++++++++++++++++++++ src/utils/types.h | 12 ++++++ 9 files changed, 177 insertions(+), 35 deletions(-) create mode 100644 src/output/exportfastafile.cpp create mode 100644 src/output/exportfastafile.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 798433f06..65b17ed76 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -146,6 +146,7 @@ SET(CPP_FILES output/ods/samplesheet.cpp output/ods/simplesheet.cpp output/ods/spectrasheet.cpp + output/exportfastafile.cpp output/masschroqml.cpp output/masschroqprm.cpp output/mcqrspectralcount.cpp diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 938cfcd81..492888c67 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -32,7 +32,6 @@ #include "ui_main.h" #include <pappsomspp/pappsoexception.h> -#include <pappsomspp/fasta/fastaoutputstream.h> #include "../utils/utils.h" #include "workerthread.h" #include "output/xpip.h" @@ -503,6 +502,9 @@ MainWindow::doActionFasta() { try { + // export all grouped proteins + // or only one protein by sub grouped + // or only one protein by group QSettings settings; QString default_location = @@ -521,41 +523,10 @@ MainWindow::doActionFasta() settings.setValue("path/fastafile", QFileInfo(filename).absolutePath()); + showWaitingMessage( + tr("Writing %1 FASTA file").arg(QFileInfo(filename).fileName())); + emit operateWritingFastaFile(filename, _project_sp, ExportFastaType::all); - QFile outFile; - outFile.setFileName(filename); - outFile.open(QIODevice::WriteOnly); - QTextStream *p_outputStream = new QTextStream(&outFile); - - - pappso::FastaOutputStream fasta_output(*p_outputStream); - - for(IdentificationGroup *identification : - _project_sp.get()->getIdentificationGroupList()) - { - for(ProteinMatch *protein_match : - identification->getProteinMatchList()) - { - if(protein_match->getValidationState() >= - ValidationState::grouped) - { - pappso::Protein protein( - QString("%1 %2") - .arg( - protein_match->getProteinXtpSp().get()->getAccession()) - .arg(protein_match->getProteinXtpSp() - .get() - ->getDescription()), - protein_match->getProteinXtpSp().get()->getSequence()); - fasta_output.writeProtein(protein); - } - } - } - - p_outputStream->flush(); - delete p_outputStream; - outFile.close(); - // emit operateXpipFile(filename); } catch(pappso::PappsoException &error) { diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 21762189b..4acaa6c1c 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -109,6 +109,9 @@ class MainWindow : public QMainWindow void operateWritingProticFile(QString filename, ProjectSp project_sp); void operateWritingMcqrSpectralCountFile(QString filename, ProjectSp project_sp); + void operateWritingFastaFile(QString filename, + ProjectSp project_sp, + ExportFastaType type); void operateGrouping(ProjectSp project_sp); void operateRunningXtandem(TandemRunBatch tandem_run_batch); diff --git a/src/gui/workerthread.cpp b/src/gui/workerthread.cpp index 5c0d3dd46..add639e0d 100644 --- a/src/gui/workerthread.cpp +++ b/src/gui/workerthread.cpp @@ -34,6 +34,7 @@ #include <odsstream/odsexception.h> #include <pappsomspp/pappsoexception.h> #include <QDebug> +#include "../output/exportfastafile.h" #include "../output/masschroqml.h" #include "../output/masschroqprm.h" #include "../output/proticdbml.h" @@ -153,6 +154,11 @@ WorkerThread::WorkerThread(MainWindow *p_main_window) &WorkerThread::operationFinished, p_main_window, &MainWindow::doOperationFinished); + // FASTA file write + connect(p_main_window, + &MainWindow::operateWritingFastaFile, + this, + &WorkerThread::doWritingFastaFile); #else // Qt4 code @@ -730,3 +736,31 @@ WorkerThread::doRunningXtandem(TandemRunBatch tandem_run_batch) } qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__; } + + +void +WorkerThread::doWritingFastaFile(QString filename, + ProjectSp project_sp, + ExportFastaType type) +{ + + try + { + + qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__; + emit loadingMessage(tr("writing FASTA file, please wait")); + + + ExportFastaFile output(filename, type); + output.write(project_sp); + output.close(); + + // emit operateXpipFile(filename); + emit operationFinished(); + } + catch(pappso::PappsoException &error) + { + emit operationFailed( + tr("Error while writing FASTA file :\n%1").arg(error.qwhat())); + } +} diff --git a/src/gui/workerthread.h b/src/gui/workerthread.h index 309a35dc0..6bb87eaec 100644 --- a/src/gui/workerthread.h +++ b/src/gui/workerthread.h @@ -64,6 +64,9 @@ class WorkerThread : public QObject void doWritingMassChroqPrmFile(QString filename, ProjectSp project_sp); void doWritingProticFile(QString filename, ProjectSp project_sp); void doWritingMcqrSpectralCountFile(QString filename, ProjectSp project_sp); + void doWritingFastaFile(QString filename, + ProjectSp project_sp, + ExportFastaType type); void doGrouping(ProjectSp project_sp); void doGroupingOnIdentification(IdentificationGroup *p_identification_group, GroupingType grouping_type); diff --git a/src/main.cpp b/src/main.cpp index c42ce2257..8cf6312fc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,6 +48,7 @@ main(int argc, char *argv[]) qRegisterMetaType<MsRunSp>("MsRunSp"); qRegisterMetaType<std::vector<pappso::PeptideNaturalIsotopeAverageSp>>( "std::vector<pappso::PeptideNaturalIsotopeAverageSp>"); + qRegisterMetaType<ExportFastaType>("ExportFastaType"); try { diff --git a/src/output/exportfastafile.cpp b/src/output/exportfastafile.cpp new file mode 100644 index 000000000..c8cbf49e1 --- /dev/null +++ b/src/output/exportfastafile.cpp @@ -0,0 +1,74 @@ +/** + * \file output/exportfastafile.cpp + * \date 15/01/2019 + * \author Olivier Langella + * \brief FASTA file writer + */ + +/******************************************************************************* + * Copyright (c) 2019 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/>. + * + ******************************************************************************/ + +#include "exportfastafile.h" +#include <pappsomspp/fasta/fastaoutputstream.h> + +ExportFastaFile::ExportFastaFile(QString filename, ExportFastaType type) +{ + p_outputFastaFile = new QFile(filename); +} + +void +ExportFastaFile::write(ProjectSp project_sp) +{ + + p_outputFastaFile->open(QIODevice::WriteOnly); + QTextStream *p_outputStream = new QTextStream(p_outputFastaFile); + + + pappso::FastaOutputStream fasta_output(*p_outputStream); + + for(IdentificationGroup *identification : + project_sp.get()->getIdentificationGroupList()) + { + for(ProteinMatch *protein_match : identification->getProteinMatchList()) + { + if(protein_match->getValidationState() >= ValidationState::grouped) + { + pappso::Protein protein( + QString("%1 %2") + .arg(protein_match->getProteinXtpSp().get()->getAccession()) + .arg( + protein_match->getProteinXtpSp().get()->getDescription()), + protein_match->getProteinXtpSp().get()->getSequence()); + fasta_output.writeProtein(protein); + } + } + } + + p_outputStream->flush(); + delete p_outputStream; + p_outputFastaFile->close(); +} + +void +ExportFastaFile::close() +{ + delete p_outputFastaFile; + p_outputFastaFile = nullptr; +} diff --git a/src/output/exportfastafile.h b/src/output/exportfastafile.h new file mode 100644 index 000000000..c681f63d0 --- /dev/null +++ b/src/output/exportfastafile.h @@ -0,0 +1,43 @@ +/** + * \file output/exportfastafile.h + * \date 15/01/2019 + * \author Olivier Langella + * \brief FASTA file writer + */ + +/******************************************************************************* + * Copyright (c) 2019 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/>. + * + ******************************************************************************/ + +#pragma once + +#include <QString> +#include "../utils/types.h" +#include "../core/project.h" + +class ExportFastaFile +{ + private: + QFile *p_outputFastaFile = nullptr; + + public: + ExportFastaFile(QString filename, ExportFastaType type); + void write(ProjectSp project_sp); + void close(); +}; diff --git a/src/utils/types.h b/src/utils/types.h index 91f06ca30..03d3cb6d6 100644 --- a/src/utils/types.h +++ b/src/utils/types.h @@ -168,4 +168,16 @@ enum class ValidationState : std::int8_t }; +/** \def export fasta files + * + */ + +enum class ExportFastaType : std::int8_t +{ + all = 0, ///< all grouped proteins + oneBySubgroup = 1, ///< export only one by subgroup + oneByGroup = 2, ///< export only one by group +}; + + #endif /* _TYPES_H_ */ -- GitLab