Skip to content
Snippets Groups Projects
Commit 89e28cbf authored by Langella Olivier's avatar Langella Olivier
Browse files

separate fasta file output in worker thread with dedicated output object

parent 427e2586
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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)
{
......
......@@ -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);
......
......@@ -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()));
}
}
......@@ -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);
......
......@@ -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
{
......
/**
* \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;
}
/**
* \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();
};
......@@ -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_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment