Loading...
Searching...
No Matches
psmfilescanprocessandcopy.cpp
Go to the documentation of this file.
/**
* \file pappsomspp/processing/cbor/psm/psmfilescanprocessandcopy.cpp
* \date 15/07/2025
* \author Olivier Langella
* \brief PSM file reader designed to parallelize scan process and then copy the results in PSM cbor
* output stream
*/
/*******************************************************************************
* Copyright (c) 2025 Olivier Langella <Olivier.Langella@universite-paris-saclay.fr>.
*
* This file is part of PAPPSOms-tools.
*
* PAPPSOms-tools 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.
*
* PAPPSOms-tools 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 PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#include "psmfilescanprocessandcopy.h"
#include "pappsomspp/core/pappsoexception.h"
#include "pappsomspp/core/utils.h"
namespace pappso
{
namespace cbor
{
namespace psm
{
PsmFileScanProcessAndCopy::PsmFileScanProcessAndCopy(std::size_t buffer_scan_size,
CborStreamWriter *cbor_output_p,
const QString &operation)
: PsmFileScanProcess(buffer_scan_size)
{
mp_cborOutput = cbor_output_p;
m_operation = operation;
mp_cborOutput->startMap();
mp_copyCborOutput = nullptr;
}
PsmFileScanProcessAndCopy::~PsmFileScanProcessAndCopy()
{
if(mpa_bufferAfterProteinMap != nullptr)
{
delete mpa_bufferAfterProteinMap;
}
if(mpa_bufferWriterAfterProteinMap != nullptr)
{
delete mpa_bufferWriterAfterProteinMap;
}
}
void
PsmFileScanProcessAndCopy::delayProteinMapInMemory()
{
mp_copyCborOutput = mp_cborOutput;
mpa_bufferAfterProteinMap = new QBuffer();
mpa_bufferAfterProteinMap->open(QIODevice::ReadWrite);
mpa_bufferWriterAfterProteinMap = new pappso::cbor::CborStreamWriter(mpa_bufferAfterProteinMap);
}
void
PsmFileScanProcessAndCopy::close()
{
if(mp_copyCborOutput == nullptr)
{
mp_cborOutput->endMap();
}
else
{
// mpa_bufferWriterAfterProteinMap->endArray(); // end scan_list
// mpa_bufferWriterAfterProteinMap->endMap(); // end sample
// mpa_bufferWriterAfterProteinMap->endArray(); // end sample_list
mp_copyCborOutput->append("protein_map");
m_psmNewProteinMap.writeMap(*mp_copyCborOutput);
// copy buffer
mp_copyCborOutput->append("sample_list");
// mpa_writer->startArray(); // sample_list
// mpa_writer->endArray(); // end sample_list
mpa_bufferAfterProteinMap->seek(0);
// qWarning() << "size=" << mpa_buffer->data().size();
mp_copyCborOutput->device()->write(mpa_bufferAfterProteinMap->data());
mp_copyCborOutput->endMap();
}
}
void
PsmFileScanProcessAndCopy::informationsReady(pappso::UiMonitorInterface &monitor [[maybe_unused]])
{
mp_cborOutput->writeInformations("pappsomspp_copy", Utils::getVersion(), "psm", m_operation);
}
void
PsmFileScanProcessAndCopy::logReady(pappso::UiMonitorInterface &monitor [[maybe_unused]])
{
m_cborLog.append(m_cborInformations);
mp_cborOutput->append("log");
mp_cborOutput->writeCborArray(m_cborLog);
}
void
PsmFileScanProcessAndCopy::parameterMapReady(pappso::UiMonitorInterface &monitor [[maybe_unused]])
{
mp_cborOutput->append("parameter_map");
mp_cborOutput->writeCborMap(m_cborParameterMap);
}
void
PsmFileScanProcessAndCopy::fastaFilesReady(pappso::UiMonitorInterface &monitor [[maybe_unused]])
{
// "target_fasta_files": ["zea_mays.fasta", "contaminant.fasta"],
if(!m_targetFastaFiles.isEmpty())
{
mp_cborOutput->append("target_fasta_files");
mp_cborOutput->writeArray(m_targetFastaFiles);
}
//"decoy_fasta_files" : ["rev_zea_mays.fasta", "rev_contaminant.fasta"],
if(!m_decoyFastaFiles.isEmpty())
{
mp_cborOutput->append("decoy_fasta_files");
mp_cborOutput->writeArray(m_decoyFastaFiles);
}
}
void
PsmFileScanProcessAndCopy::proteinMapReady(pappso::UiMonitorInterface &monitor [[maybe_unused]])
{
if(mp_copyCborOutput == nullptr)
{
mp_cborOutput->append("protein_map");
m_proteinMap.writeMap(*mp_cborOutput);
}
else
{
// protein map writing is delayed : swap to temporary buffer writer
mp_cborOutput = mpa_bufferWriterAfterProteinMap;
}
}
void
PsmFileScanProcessAndCopy::processBufferScanDone(pappso::UiMonitorInterface &monitor
[[maybe_unused]])
{
// monitor.setStatus(QObject::tr("PsmFileScanProcessAndCopy::processBufferScanDone"));
for(CborScanMapBase *cbor_scan_p : m_cborScanList)
{
// qDebug() << cbor_scan_p->keys();
cbor_scan_p->filterAndSortPsmList();
if(mp_copyCborOutput != nullptr)
{
// populate new protein map
cbor_scan_p->populateProteinMapUsingOldProteinMap(m_proteinMap, m_psmNewProteinMap);
}
// qWarning() << "PsmFileScanProcessAndCopy::processBufferScanDone "
// << cbor_scan_p->value("psm_list").toArray().size();
// cbor_scan_p->write(*mp_cborOutput);
mp_cborOutput->writeCborMap(*cbor_scan_p);
if(!cbor_scan_p->keys().contains("id"))
{
throw pappso::PappsoException(
QObject::tr("missing scan id %1").arg(cbor_scan_p->keys().size()));
}
}
}
void
PsmFileScanProcessAndCopy::sampleStarted(pappso::UiMonitorInterface &monitor [[maybe_unused]])
{
mp_cborOutput->startMap();
mp_cborOutput->append("name");
mp_cborOutput->append(m_currentSampleName);
if(m_currentIdentificationFileList.size() > 0)
{
mp_cborOutput->append("identification_file_list");
writePsmFileList(*mp_cborOutput, m_currentIdentificationFileList);
}
mp_cborOutput->append("peaklist_file");
writePsmFile(*mp_cborOutput, m_currentPeaklistFile);
mp_cborOutput->append("scan_list");
mp_cborOutput->startArray();
}
void
PsmFileScanProcessAndCopy::sampleFinished(pappso::UiMonitorInterface &monitor [[maybe_unused]])
{
processBufferScan(monitor);
clearScanBuffer();
mp_cborOutput->endArray();
mp_cborOutput->endMap();
}
void
PsmFileScanProcessAndCopy::sampleListStarted(pappso::UiMonitorInterface &monitor [[maybe_unused]])
{
if(mp_copyCborOutput == nullptr)
{
mp_cborOutput->append("sample_list");
}
mp_cborOutput->startArray();
}
void
PsmFileScanProcessAndCopy::sampleListFinished(pappso::UiMonitorInterface &monitor [[maybe_unused]])
{
mp_cborOutput->endArray();
}
} // namespace psm
} // namespace cbor
} // namespace pappso
pappso::PappsoException
Definition pappsoexception.h:41
pappso::UiMonitorInterface
Definition uimonitorinterface.h:50
pappso::Utils::getVersion
static QString getVersion()
Definition utils.cpp:650
pappso::cbor::CborStreamWriter
overrides QCborStreamWriter base class to provide convenient functions
Definition cborstreamwriter.h:45
pappso::cbor::psm::PsmFileReaderBase::m_cborLog
QCborArray m_cborLog
Definition psmfilereaderbase.h:134
pappso::cbor::psm::PsmFileReaderBase::m_currentPeaklistFile
PsmFile m_currentPeaklistFile
Definition psmfilereaderbase.h:131
pappso::cbor::psm::PsmFileReaderBase::m_targetFastaFiles
QStringList m_targetFastaFiles
Definition psmfilereaderbase.h:127
pappso::cbor::psm::PsmFileReaderBase::m_decoyFastaFiles
QStringList m_decoyFastaFiles
Definition psmfilereaderbase.h:128
pappso::cbor::psm::PsmFileReaderBase::writePsmFileList
void writePsmFileList(CborStreamWriter &writer, const std::vector< PsmFile > &file_list)
Definition psmfilereaderbase.cpp:331
pappso::cbor::psm::PsmFileReaderBase::m_currentSampleName
QString m_currentSampleName
Definition psmfilereaderbase.h:130
pappso::cbor::psm::PsmFileReaderBase::m_proteinMap
PsmProteinMap m_proteinMap
Definition psmfilereaderbase.h:129
pappso::cbor::psm::PsmFileReaderBase::m_cborParameterMap
QCborMap m_cborParameterMap
Definition psmfilereaderbase.h:135
pappso::cbor::psm::PsmFileReaderBase::m_cborInformations
QCborMap m_cborInformations
Definition psmfilereaderbase.h:133
pappso::cbor::psm::PsmFileReaderBase::m_currentIdentificationFileList
std::vector< PsmFile > m_currentIdentificationFileList
Definition psmfilereaderbase.h:132
pappso::cbor::psm::PsmFileReaderBase::writePsmFile
void writePsmFile(CborStreamWriter &writer, const PsmFile &psm_file)
Definition psmfilereaderbase.cpp:322
pappso::cbor::psm::PsmFileScanProcessAndCopy::delayProteinMapInMemory
void delayProteinMapInMemory()
Definition psmfilescanprocessandcopy.cpp:69
pappso::cbor::psm::PsmFileScanProcessAndCopy::~PsmFileScanProcessAndCopy
virtual ~PsmFileScanProcessAndCopy()
Definition psmfilescanprocessandcopy.cpp:55
pappso::cbor::psm::PsmFileScanProcessAndCopy::sampleStarted
void sampleStarted(pappso::UiMonitorInterface &monitor) override
Definition psmfilescanprocessandcopy.cpp:201
pappso::cbor::psm::PsmFileScanProcessAndCopy::fastaFilesReady
void fastaFilesReady(pappso::UiMonitorInterface &monitor) override
Definition psmfilescanprocessandcopy.cpp:135
pappso::cbor::psm::PsmFileScanProcessAndCopy::sampleFinished
void sampleFinished(pappso::UiMonitorInterface &monitor) override
Definition psmfilescanprocessandcopy.cpp:219
pappso::cbor::psm::PsmFileScanProcessAndCopy::mp_cborOutput
CborStreamWriter * mp_cborOutput
Definition psmfilescanprocessandcopy.h:87
pappso::cbor::psm::PsmFileScanProcessAndCopy::mp_copyCborOutput
CborStreamWriter * mp_copyCborOutput
Definition psmfilescanprocessandcopy.h:88
pappso::cbor::psm::PsmFileScanProcessAndCopy::PsmFileScanProcessAndCopy
PsmFileScanProcessAndCopy(std::size_t buffer_scan_size, CborStreamWriter *cbor_output_p, const QString &operation)
Definition psmfilescanprocessandcopy.cpp:41
pappso::cbor::psm::PsmFileScanProcessAndCopy::sampleListStarted
void sampleListStarted(pappso::UiMonitorInterface &monitor) override
Definition psmfilescanprocessandcopy.cpp:230
pappso::cbor::psm::PsmFileScanProcessAndCopy::mpa_bufferWriterAfterProteinMap
pappso::cbor::CborStreamWriter * mpa_bufferWriterAfterProteinMap
Definition psmfilescanprocessandcopy.h:94
pappso::cbor::psm::PsmFileScanProcessAndCopy::sampleListFinished
void sampleListFinished(pappso::UiMonitorInterface &monitor) override
Definition psmfilescanprocessandcopy.cpp:240
pappso::cbor::psm::PsmFileScanProcessAndCopy::m_operation
QString m_operation
Definition psmfilescanprocessandcopy.h:89
pappso::cbor::psm::PsmFileScanProcessAndCopy::proteinMapReady
virtual void proteinMapReady(pappso::UiMonitorInterface &monitor) override
Definition psmfilescanprocessandcopy.cpp:153
pappso::cbor::psm::PsmFileScanProcessAndCopy::close
void close() override
convenient function to clean pointer before leaving
Definition psmfilescanprocessandcopy.cpp:79
pappso::cbor::psm::PsmFileScanProcessAndCopy::informationsReady
void informationsReady(pappso::UiMonitorInterface &monitor) override
Definition psmfilescanprocessandcopy.cpp:113
pappso::cbor::psm::PsmFileScanProcessAndCopy::mpa_bufferAfterProteinMap
QBuffer * mpa_bufferAfterProteinMap
Definition psmfilescanprocessandcopy.h:93
pappso::cbor::psm::PsmFileScanProcessAndCopy::processBufferScanDone
virtual void processBufferScanDone(pappso::UiMonitorInterface &monitor) override
Definition psmfilescanprocessandcopy.cpp:169
pappso::cbor::psm::PsmFileScanProcessAndCopy::parameterMapReady
void parameterMapReady(pappso::UiMonitorInterface &monitor) override
Definition psmfilescanprocessandcopy.cpp:128
pappso::cbor::psm::PsmFileScanProcessAndCopy::logReady
void logReady(pappso::UiMonitorInterface &monitor) override
Definition psmfilescanprocessandcopy.cpp:120
pappso::cbor::psm::PsmFileScanProcessAndCopy::m_psmNewProteinMap
pappso::cbor::psm::PsmProteinMap m_psmNewProteinMap
Definition psmfilescanprocessandcopy.h:92
pappso::cbor::psm::PsmFileScanProcess::m_cborScanList
std::vector< CborScanMapBase * > m_cborScanList
Definition psmfilescanprocess.h:74
pappso::cbor::psm::PsmFileScanProcess::CborScanMapBase
friend CborScanMapBase
Definition psmfilescanprocess.h:49
pappso::cbor::psm::PsmFileScanProcess::PsmFileScanProcess
PsmFileScanProcess(std::size_t buffer_scan_size)
Definition psmfilescanprocess.cpp:41
pappso::cbor::psm::PsmFileScanProcess::processBufferScan
virtual void processBufferScan(pappso::UiMonitorInterface &monitor)
Definition psmfilescanprocess.cpp:102
pappso::cbor::psm::PsmFileScanProcess::clearScanBuffer
void clearScanBuffer()
Definition psmfilescanprocess.cpp:51
pappso::cbor::psm
Definition cborscanmapbase.h:40
pappso::cbor
Definition cborstreamreader.cpp:35
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
pappsoexception.h
psmfilescanprocessandcopy.h
utils.h