libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
converttomzml.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/processing/cbor/mzcbor/converttomzml.cpp
3 * \date 30/11/2025
4 * \author Olivier Langella
5 * \brief convert mzcbor to mzML
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#include "converttomzml.h"
29#include "cvparam.h"
30#include "binarydataarray.h"
31
32namespace pappso
33{
34namespace cbor
35{
36namespace mzcbor
37{
38ConvertToMzml::ConvertToMzml(QXmlStreamWriter *p_writer) : mp_writer(p_writer)
39{
40}
41
45
46void
50
51void
53{
54 qDebug();
55 initCborReader(cborp);
56
57 qDebug();
58 if(mpa_cborReader->isMap())
59 {
60 readRoot(monitor);
61 }
62 qDebug();
63}
64
65void
67{
68 qDebug();
69 initCborReader(cborp);
70
71 qDebug();
72 if(mpa_cborReader->isMap())
73 {
74 readRoot(monitor);
75 }
76 qDebug();
77}
78
79
80void
82{
83 qDebug();
84 mpa_cborReader->enterContainer();
85
86 while(getExpectedString())
87 {
88
89 if(m_expectedString == "mzCBOR")
90 {
91 m_isMzcbor = true;
92 mpa_cborReader->next();
93 }
94 else if(m_expectedString == "mzML")
95 {
96
97 QCborMap mzml_cbor;
98 mpa_cborReader->readCborMap(mzml_cbor);
99 //<mzML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
100 // xsi:schemaLocation="http://psi.hupo.org/ms/mzml
101 // http://psidev.info/files/ms/mzML/xsd/mzML1.1.0.xsd" version="1.1.0"
102 // id="20120906_balliau_extract_1_A01_urnb-1" xmlns="http://psi.hupo.org/ms/mzml">
103
104
105 mp_writer->setAutoFormatting(true);
106 mp_writer->writeStartDocument("1.0");
107 mp_writer->writeDefaultNamespace(mzml_cbor.value("xmlns").toString());
108
109 mp_writer->writeNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
110
111 mp_writer->writeStartElement("mzML");
112
113 mp_writer->writeAttribute("http://www.w3.org/2001/XMLSchema-instance",
114 "schemaLocation",
115 mzml_cbor.value("schemaLocation").toString());
116
117
118 for(auto &str_key : mzml_cbor.keys())
119 {
120 if((str_key != "xmlns") && (str_key != "schemaLocation"))
121 {
122 mp_writer->writeAttribute(str_key.toString(),
123 mzml_cbor.value(str_key).toString());
124 }
125 }
126
127 m_isMzcbor = true;
128 // getExpectedString();
129 // qDebug() << m_expectedString;
130 // mpa_cborReader->next();
131
132 while(getExpectedString())
133 {
134 qDebug() << m_expectedString;
136 }
137 mp_writer->writeEndElement();
138 }
139 }
140 mpa_cborReader->leaveContainer();
141 mp_writer->writeEndDocument();
142}
143
144
145void
148 [[maybe_unused]])
149{
150 bool is_array = false;
151 if(name == "cvParam")
152 { // this is an array
153 qDebug();
154 std::map<QString, pappso::cbor::mzcbor::CvParam> cvparam_map =
156 for(auto &cvparam_pair : cvparam_map)
157 {
158 cvparam_pair.second.toMzml(*mp_writer);
159 }
160 }
161 else if(name == "binaryDataArray")
162 {
163
164 mp_writer->writeStartElement("binaryDataArrayList");
165
166 mp_writer->writeAttribute("count", QString("%1").arg(mpa_cborReader->length()));
167 mpa_cborReader->enterContainer();
168 while(mpa_cborReader->hasNext())
169 {
170 BinaryDataArray binary_data_array;
171 binary_data_array.fromCbor(*mpa_cborReader);
172 binary_data_array.toMzml(*mp_writer);
173 }
174
175 mpa_cborReader->leaveContainer();
176
177 mp_writer->writeEndElement();
178 }
179 else
180 {
181 if(mpa_cborReader->isArray())
182 {
183 is_array = true;
184 }
185 else if(mpa_cborReader->isMap())
186 {
187 }
188 else
189 {
190 // error
191 qWarning() << "not a map, not an array";
192 }
193 if(is_array)
194 {
195 mpa_cborReader->enterContainer();
196 while(mpa_cborReader->hasNext())
197 {
198 writeElementInMzml(name, monitor);
199 }
200
201 mpa_cborReader->leaveContainer();
202 }
203 else
204 {
205 mp_writer->writeStartElement(name);
206 mpa_cborReader->enterContainer();
207
208 while(getExpectedString())
209 {
210 qDebug() << m_expectedString;
211 QString current_attribute = m_expectedString;
212 if(mpa_cborReader->isContainer())
213 {
214 qDebug() << current_attribute;
215 writeElementInMzml(current_attribute, monitor);
216 }
217 else if(mpa_cborReader->isInteger())
218 {
219 qDebug() << current_attribute;
220 mp_writer->writeAttribute(current_attribute,
221 QString("%1").arg(mpa_cborReader->toInteger()));
222 mpa_cborReader->next();
223 }
224 else if(mpa_cborReader->isUnsignedInteger())
225 {
226 qDebug() << current_attribute;
227 mp_writer->writeAttribute(current_attribute,
228 QString("%1").arg(mpa_cborReader->toUnsignedInteger()));
229 }
230 else if(mpa_cborReader->isString())
231 {
233 qDebug() << current_attribute;
234 mp_writer->writeAttribute(current_attribute, m_expectedString);
235 }
236 else
237 {
238 qDebug() << current_attribute;
239 mpa_cborReader->next();
240 }
241 }
242
243 mpa_cborReader->leaveContainer();
244
245 mp_writer->writeEndElement();
246 }
247 }
248}
249
250} // namespace mzcbor
251} // namespace cbor
252} // namespace pappso
PSI BinaryDataArray object for mzML/mzCBOR.
ConvertToMzml(QXmlStreamWriter *p_writer)
virtual void readCbor(QFile *cborp, pappso::UiMonitorInterface &monitor)
void writeElementInMzml(const QString &name, pappso::UiMonitorInterface &monitor)
void readRoot(pappso::UiMonitorInterface &monitor)
PSI cvParam object for mzML/mzCBOR.
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
void fromCbor(CborStreamReader &reader)
void toMzml(QXmlStreamWriter &writer)
static std::map< QString, pappso::cbor::mzcbor::CvParam > getCvParamsMapFromCbor(CborStreamReader &reader)
Definition cvparam.cpp:182