libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
psmcbor2json.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/processing/cbor/psm/psmcbor2json.cpp
3 * \date 19/07/2025
4 * \author Olivier Langella
5 * \brief convert CBOR PSM to JSON
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2025 Olivier Langella <Olivier.Langella@universite-paris-saclay.fr>.
10 *
11 * This file is part of PAPPSOms-tools.
12 *
13 * PAPPSOms-tools is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * PAPPSOms-tools is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>.
25 *
26 ******************************************************************************/
27
28
29#include "psmcbor2json.h"
30#include <QJsonDocument>
31#include <QJsonObject>
32#include <QJsonValue>
34
36{
37 mp_jsonOutput = json_output_p;
38
39 *mp_jsonOutput << "{" << Qt::endl;
40}
41
42
46
47void
53
54void
56 [[maybe_unused]])
57{
58 if(!m_targetFastaFiles.isEmpty())
59 {
60 mp_jsonOutput->appendKey("target_fasta_files");
62 }
63 if(!m_decoyFastaFiles.isEmpty())
64 {
65 mp_jsonOutput->appendKey("decoy_fasta_files");
67 }
68}
69
70void
72 [[maybe_unused]])
73{
74
75 mp_jsonOutput->appendKey("informations");
76 mp_jsonOutput->writeCborMap(m_cborInformations);
77}
78
79void
81{
82 mp_jsonOutput->appendKey("log");
83 mp_jsonOutput->writeCborArray(m_cborLog);
84}
85
86
87void
89 [[maybe_unused]])
90{
91 mp_jsonOutput->appendKey("parameter_map");
92 mp_jsonOutput->writeCborMap(m_cborParameterMap);
93}
94
95void
97 [[maybe_unused]])
98{
99
100 mp_jsonOutput->appendKey("sample_list");
101 mp_jsonOutput->startArray();
102}
103
104void
106 [[maybe_unused]])
107{
108
109 mp_jsonOutput->endArray();
110}
111
112void
114 [[maybe_unused]])
115{
116 mp_jsonOutput->appendKey("protein_map");
117 mp_jsonOutput->startMap();
118 if(!mpa_cborReader->enterContainer())
119 {
120 throw pappso::PappsoException(QObject::tr("enterContainer in protein map failed"));
121 }
122 QString accession;
123 while(!mpa_cborReader->lastError() && mpa_cborReader->hasNext())
124 {
125 mpa_cborReader->decodeString(accession);
126 mp_jsonOutput->appendKey(accession);
127
128 QCborMap cbor_protein;
129 mpa_cborReader->readCborMap(cbor_protein);
130 mp_jsonOutput->writeCborMap(cbor_protein);
131 }
132
133 mpa_cborReader->leaveContainer();
134 mp_jsonOutput->endMap();
135}
136
137void
139{
140
141 mp_jsonOutput->startMap();
142 mp_jsonOutput->appendKey("id");
143 mp_jsonOutput->writeCborMap(m_cborScanId);
144 mp_jsonOutput->appendKey("precursor");
145 mp_jsonOutput->writeCborMap(m_cborScanPrecursor);
146 mp_jsonOutput->appendKey("ms2");
147 mp_jsonOutput->writeCborMap(m_cborScanMs2);
148 mp_jsonOutput->appendKey("psm_list");
149 mp_jsonOutput->startArray();
150}
151
152void
154{
155 mp_jsonOutput->endArray(); // psm_list
156 mp_jsonOutput->endMap(); // scan
157}
158
159
160void
162{
163 //"name": "tandem2017_nopatch_20120906_balliau_extract_1_A01_urnb-1",
164 qDebug();
165 mp_jsonOutput->startMap(); // sample
166 mp_jsonOutput->appendKey("name");
168
169
170 mp_jsonOutput->appendKey("identification_file_list");
171 mp_jsonOutput->startArray();
172 for(auto &identification_file : m_currentIdentificationFileList)
173 {
174 mp_jsonOutput->startMap();
175 mp_jsonOutput->appendKey("name");
176 mp_jsonOutput->appendValue(identification_file.name);
177 mp_jsonOutput->endMap();
178 }
179 mp_jsonOutput->endArray();
180
181
182 mp_jsonOutput->appendKey("peaklist_file");
183 mp_jsonOutput->startMap();
184 mp_jsonOutput->appendKey("name");
185 mp_jsonOutput->appendValue(m_currentPeaklistFile.name);
186 mp_jsonOutput->endMap();
187
188 mp_jsonOutput->appendKey("scan_list");
189 mp_jsonOutput->startArray();
190}
191
192void
194 [[maybe_unused]])
195{
196 mp_jsonOutput->endArray(); // scan_list
197 mp_jsonOutput->endMap(); // sample
198}
199
200void
202{
203 mp_jsonOutput->startMap(); // psm
204 mp_jsonOutput->appendKey("proforma");
206 mp_jsonOutput->appendKey("protein_list");
207 mp_jsonOutput->startArray();
208 for(auto &protein_ref : m_currentPsmProteinRefList)
209 {
210 mp_jsonOutput->startMap();
211 mp_jsonOutput->appendKey("accession");
212 mp_jsonOutput->appendValue(protein_ref.accession);
213 mp_jsonOutput->appendKey("positions");
214 mp_jsonOutput->startArray();
215 for(auto position : protein_ref.positions)
216 {
217 mp_jsonOutput->appendValue(position);
218 }
219 mp_jsonOutput->endArray();
220 mp_jsonOutput->endMap();
221 }
222 mp_jsonOutput->endArray();
223 if(!m_cborScanPsmProps.isEmpty())
224 {
225 mp_jsonOutput->appendKey("props");
226 mp_jsonOutput->writeCborMap(m_cborScanPsmProps);
227 }
228 mp_jsonOutput->appendKey("eval");
229 mp_jsonOutput->writeCborMap(m_cborScanPsmEval);
230
231 mp_jsonOutput->endMap(); // psm
232}
helper class to write json text using CBOR data structures
void informationsReady(pappso::UiMonitorInterface &monitor) override
void scanFinished(pappso::UiMonitorInterface &monitor) override
void sampleStarted(pappso::UiMonitorInterface &monitor) override
void sampleFinished(pappso::UiMonitorInterface &monitor) override
void psmReady(pappso::UiMonitorInterface &monitor) override
pappso::cbor::JsonStreamWriter * mp_jsonOutput
void readProteinMap(pappso::UiMonitorInterface &monitor) override
void fastaFilesReady(pappso::UiMonitorInterface &monitor) override
void logReady(pappso::UiMonitorInterface &monitor) override
void sampleListStarted(pappso::UiMonitorInterface &monitor) override
void parameterMapReady(pappso::UiMonitorInterface &monitor) override
void close() override
convenient function to clean pointer before leaving
void sampleListFinished(pappso::UiMonitorInterface &monitor) override
void scanStarted(pappso::UiMonitorInterface &monitor) override
PsmCbor2Json(pappso::cbor::JsonStreamWriter *json_output_p)
std::vector< PsmProteinRef > m_currentPsmProteinRefList
std::vector< PsmFile > m_currentIdentificationFileList