Loading...
Searching...
No Matches
psmcbor2json.cpp
Go to the documentation of this file.
/**
* \file pappsomspp/processing/cbor/psm/psmcbor2json.cpp
* \date 19/07/2025
* \author Olivier Langella
* \brief convert CBOR PSM to JSON
*/
/*******************************************************************************
* 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 "psmcbor2json.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include "pappsomspp/core/pappsoexception.h"
pappso::cbor::psm::PsmCbor2Json::PsmCbor2Json(pappso::cbor::JsonStreamWriter *json_output_p)
{
mp_jsonOutput = json_output_p;
*mp_jsonOutput << "{" << Qt::endl;
}
pappso::cbor::psm::PsmCbor2Json::~PsmCbor2Json()
{
}
void
pappso::cbor::psm::PsmCbor2Json::close()
{
mp_jsonOutput->endMap();
}
void
pappso::cbor::psm::PsmCbor2Json::fastaFilesReady(pappso::UiMonitorInterface &monitor
[[maybe_unused]])
{
if(!m_targetFastaFiles.isEmpty())
{
mp_jsonOutput->appendKey("target_fasta_files");
mp_jsonOutput->writeArray(m_targetFastaFiles);
}
if(!m_decoyFastaFiles.isEmpty())
{
mp_jsonOutput->appendKey("decoy_fasta_files");
mp_jsonOutput->writeArray(m_decoyFastaFiles);
}
}
void
pappso::cbor::psm::PsmCbor2Json::informationsReady(pappso::UiMonitorInterface &monitor
[[maybe_unused]])
{
mp_jsonOutput->appendKey("informations");
mp_jsonOutput->writeCborMap(m_cborInformations);
}
void
pappso::cbor::psm::PsmCbor2Json::logReady(pappso::UiMonitorInterface &monitor [[maybe_unused]])
{
mp_jsonOutput->appendKey("log");
mp_jsonOutput->writeCborArray(m_cborLog);
}
void
pappso::cbor::psm::PsmCbor2Json::parameterMapReady(pappso::UiMonitorInterface &monitor
[[maybe_unused]])
{
mp_jsonOutput->appendKey("parameter_map");
mp_jsonOutput->writeCborMap(m_cborParameterMap);
}
void
pappso::cbor::psm::PsmCbor2Json::sampleListStarted(pappso::UiMonitorInterface &monitor
[[maybe_unused]])
{
mp_jsonOutput->appendKey("sample_list");
mp_jsonOutput->startArray();
}
void
pappso::cbor::psm::PsmCbor2Json::sampleListFinished(pappso::UiMonitorInterface &monitor
[[maybe_unused]])
{
mp_jsonOutput->endArray();
}
void
pappso::cbor::psm::PsmCbor2Json::readProteinMap(pappso::UiMonitorInterface &monitor
[[maybe_unused]])
{
mp_jsonOutput->appendKey("protein_map");
mp_jsonOutput->startMap();
if(!mpa_cborReader->enterContainer())
{
throw pappso::PappsoException(QObject::tr("enterContainer in protein map failed"));
}
QString accession;
while(!mpa_cborReader->lastError() && mpa_cborReader->hasNext())
{
mpa_cborReader->decodeString(accession);
mp_jsonOutput->appendKey(accession);
QCborMap cbor_protein;
mpa_cborReader->readCborMap(cbor_protein);
mp_jsonOutput->writeCborMap(cbor_protein);
}
mpa_cborReader->leaveContainer();
mp_jsonOutput->endMap();
}
void
pappso::cbor::psm::PsmCbor2Json::scanStarted(pappso::UiMonitorInterface &monitor [[maybe_unused]])
{
mp_jsonOutput->startMap();
mp_jsonOutput->appendKey("id");
mp_jsonOutput->writeCborMap(m_cborScanId);
mp_jsonOutput->appendKey("precursor");
mp_jsonOutput->writeCborMap(m_cborScanPrecursor);
mp_jsonOutput->appendKey("ms2");
mp_jsonOutput->writeCborMap(m_cborScanMs2);
if(!m_cborScanProps.isEmpty())
{
mp_jsonOutput->appendKey("props");
mp_jsonOutput->writeCborMap(m_cborScanProps);
};
mp_jsonOutput->appendKey("psm_list");
mp_jsonOutput->startArray();
}
void
pappso::cbor::psm::PsmCbor2Json::scanFinished(pappso::UiMonitorInterface &monitor [[maybe_unused]])
{
mp_jsonOutput->endArray(); // psm_list
mp_jsonOutput->endMap(); // scan
}
void
pappso::cbor::psm::PsmCbor2Json::sampleStarted(pappso::UiMonitorInterface &monitor [[maybe_unused]])
{
//"name": "tandem2017_nopatch_20120906_balliau_extract_1_A01_urnb-1",
qDebug();
mp_jsonOutput->startMap(); // sample
mp_jsonOutput->appendKey("name");
mp_jsonOutput->appendValue(m_currentSampleName);
mp_jsonOutput->appendKey("identification_file_list");
mp_jsonOutput->startArray();
for(auto &identification_file : m_currentIdentificationFileList)
{
mp_jsonOutput->startMap();
mp_jsonOutput->appendKey("name");
mp_jsonOutput->appendValue(identification_file.name);
mp_jsonOutput->endMap();
}
mp_jsonOutput->endArray();
mp_jsonOutput->appendKey("peaklist_file");
mp_jsonOutput->startMap();
mp_jsonOutput->appendKey("name");
mp_jsonOutput->appendValue(m_currentPeaklistFile.name);
mp_jsonOutput->endMap();
mp_jsonOutput->appendKey("scan_list");
mp_jsonOutput->startArray();
}
void
pappso::cbor::psm::PsmCbor2Json::sampleFinished(pappso::UiMonitorInterface &monitor
[[maybe_unused]])
{
mp_jsonOutput->endArray(); // scan_list
mp_jsonOutput->endMap(); // sample
}
void
pappso::cbor::psm::PsmCbor2Json::psmReady(pappso::UiMonitorInterface &monitor [[maybe_unused]])
{
mp_jsonOutput->startMap(); // psm
mp_jsonOutput->appendKey("proforma");
mp_jsonOutput->appendValue(m_currentPsmProforma);
mp_jsonOutput->appendKey("protein_list");
mp_jsonOutput->startArray();
for(auto &protein_ref : m_currentPsmProteinRefList)
{
mp_jsonOutput->startMap();
mp_jsonOutput->appendKey("accession");
mp_jsonOutput->appendValue(protein_ref.accession);
mp_jsonOutput->appendKey("positions");
mp_jsonOutput->startArray();
for(auto position : protein_ref.positions)
{
mp_jsonOutput->appendValue(position);
}
mp_jsonOutput->endArray();
mp_jsonOutput->endMap();
}
mp_jsonOutput->endArray();
if(!m_cborScanPsmProps.isEmpty())
{
mp_jsonOutput->appendKey("props");
mp_jsonOutput->writeCborMap(m_cborScanPsmProps);
}
mp_jsonOutput->appendKey("eval");
mp_jsonOutput->writeCborMap(m_cborScanPsmEval);
mp_jsonOutput->endMap(); // psm
}
pappso::PappsoException
Definition pappsoexception.h:41
pappso::UiMonitorInterface
Definition uimonitorinterface.h:50
pappso::cbor::CborStreamReaderInterface::mpa_cborReader
CborStreamReader * mpa_cborReader
Definition cborstreamreaderinterface.h:68
pappso::cbor::JsonStreamWriter
helper class to write json text using CBOR data structures
Definition jsonstreamwriter.h:43
pappso::cbor::psm::PsmCbor2Json::informationsReady
void informationsReady(pappso::UiMonitorInterface &monitor) override
Definition psmcbor2json.cpp:71
pappso::cbor::psm::PsmCbor2Json::scanFinished
void scanFinished(pappso::UiMonitorInterface &monitor) override
Definition psmcbor2json.cpp:158
pappso::cbor::psm::PsmCbor2Json::sampleStarted
void sampleStarted(pappso::UiMonitorInterface &monitor) override
Definition psmcbor2json.cpp:166
pappso::cbor::psm::PsmCbor2Json::sampleFinished
void sampleFinished(pappso::UiMonitorInterface &monitor) override
Definition psmcbor2json.cpp:198
pappso::cbor::psm::PsmCbor2Json::psmReady
void psmReady(pappso::UiMonitorInterface &monitor) override
Definition psmcbor2json.cpp:206
pappso::cbor::psm::PsmCbor2Json::mp_jsonOutput
pappso::cbor::JsonStreamWriter * mp_jsonOutput
Definition psmcbor2json.h:78
pappso::cbor::psm::PsmCbor2Json::readProteinMap
void readProteinMap(pappso::UiMonitorInterface &monitor) override
Definition psmcbor2json.cpp:113
pappso::cbor::psm::PsmCbor2Json::fastaFilesReady
void fastaFilesReady(pappso::UiMonitorInterface &monitor) override
Definition psmcbor2json.cpp:55
pappso::cbor::psm::PsmCbor2Json::logReady
void logReady(pappso::UiMonitorInterface &monitor) override
Definition psmcbor2json.cpp:80
pappso::cbor::psm::PsmCbor2Json::sampleListStarted
void sampleListStarted(pappso::UiMonitorInterface &monitor) override
Definition psmcbor2json.cpp:96
pappso::cbor::psm::PsmCbor2Json::~PsmCbor2Json
virtual ~PsmCbor2Json()
Definition psmcbor2json.cpp:43
pappso::cbor::psm::PsmCbor2Json::parameterMapReady
void parameterMapReady(pappso::UiMonitorInterface &monitor) override
Definition psmcbor2json.cpp:88
pappso::cbor::psm::PsmCbor2Json::close
void close() override
convenient function to clean pointer before leaving
Definition psmcbor2json.cpp:48
pappso::cbor::psm::PsmCbor2Json::sampleListFinished
void sampleListFinished(pappso::UiMonitorInterface &monitor) override
Definition psmcbor2json.cpp:105
pappso::cbor::psm::PsmCbor2Json::scanStarted
void scanStarted(pappso::UiMonitorInterface &monitor) override
Definition psmcbor2json.cpp:138
pappso::cbor::psm::PsmCbor2Json::PsmCbor2Json
PsmCbor2Json(pappso::cbor::JsonStreamWriter *json_output_p)
Definition psmcbor2json.cpp:35
pappso::cbor::psm::PsmFileReaderBase::m_cborLog
QCborArray m_cborLog
Definition psmfilereaderbase.h:134
pappso::cbor::psm::PsmFileReaderBase::m_currentPsmProteinRefList
std::vector< PsmProteinRef > m_currentPsmProteinRefList
Definition psmfilereaderbase.h:143
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::m_currentSampleName
QString m_currentSampleName
Definition psmfilereaderbase.h:130
pappso::cbor::psm::PsmFileReaderBase::m_cborScanProps
QCborMap m_cborScanProps
Definition psmfilereaderbase.h:139
pappso::cbor::psm::PsmFileReaderBase::m_cborScanPsmProps
QCborMap m_cborScanPsmProps
Definition psmfilereaderbase.h:141
pappso::cbor::psm::PsmFileReaderBase::m_currentPsmProforma
QString m_currentPsmProforma
Definition psmfilereaderbase.h:142
pappso::cbor::psm::PsmFileReaderBase::m_cborScanPrecursor
QCborMap m_cborScanPrecursor
Definition psmfilereaderbase.h:137
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::m_cborScanId
QCborMap m_cborScanId
Definition psmfilereaderbase.h:136
pappso::cbor::psm::PsmFileReaderBase::m_cborScanMs2
QCborMap m_cborScanMs2
Definition psmfilereaderbase.h:138
pappso::cbor::psm::PsmFileReaderBase::m_cborScanPsmEval
QCborMap m_cborScanPsmEval
Definition psmfilereaderbase.h:140
pappsoexception.h
psmcbor2json.h