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"
32
33namespace pappso
34{
35namespace cbor
36{
37namespace mzcbor
38{
39ConvertToMzml::ConvertToMzml(QXmlStreamWriter *p_writer) : mp_writer(p_writer)
40{
41}
42
46
47void
51
52void
54{
55 qDebug();
56 initCborReader(cborp);
57
58 qDebug();
59 if(mpa_cborReader->isMap())
60 {
61 readRoot(monitor);
62 }
63 qDebug();
64}
65
66void
68{
69 qDebug();
70 initCborReader(cborp);
71
72 qDebug();
73 if(mpa_cborReader->isMap())
74 {
75 readRoot(monitor);
76 }
77 qDebug();
78}
79
80
81void
83{
84 qDebug();
85 mpa_cborReader->enterContainer();
86
87 while(getExpectedString())
88 {
89
90 if(m_expectedString == "mzCBOR")
91 {
92 m_isMzcbor = true;
93 mpa_cborReader->next();
94 }
95 else if(m_expectedString == "mzML")
96 {
97
98 QCborMap mzml_cbor;
99 mpa_cborReader->readCborMap(mzml_cbor);
100 //<mzML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
101 // xsi:schemaLocation="http://psi.hupo.org/ms/mzml
102 // http://psidev.info/files/ms/mzML/xsd/mzML1.1.0.xsd" version="1.1.0"
103 // id="20120906_balliau_extract_1_A01_urnb-1" xmlns="http://psi.hupo.org/ms/mzml">
104
105
106 mp_writer->setAutoFormatting(true);
107 mp_writer->writeStartDocument("1.0");
108 mp_writer->writeDefaultNamespace(mzml_cbor.value("xmlns").toString());
109
110 mp_writer->writeNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
111
112 mp_writer->writeStartElement("mzML");
113
114 mp_writer->writeAttribute("http://www.w3.org/2001/XMLSchema-instance",
115 "schemaLocation",
116 mzml_cbor.value("schemaLocation").toString());
117
118
119 for(auto &str_key : mzml_cbor.keys())
120 {
121 if((str_key != "xmlns") && (str_key != "schemaLocation"))
122 {
123 mp_writer->writeAttribute(str_key.toString(),
124 mzml_cbor.value(str_key).toString());
125 }
126 }
127
128 m_isMzcbor = true;
129 // getExpectedString();
130 // qDebug() << m_expectedString;
131 // mpa_cborReader->next();
132
133 while(getExpectedString())
134 {
135 qDebug() << m_expectedString;
137 }
138 mp_writer->writeEndElement();
139 }
140 }
141 mpa_cborReader->leaveContainer();
142 mp_writer->writeEndDocument();
143}
144
145
146void
149 [[maybe_unused]])
150{
151 bool is_array = false;
152 if(name == "cvParam")
153 { // this is an array
154 qDebug();
155 CvParamMap cvparam_map;
156 cvparam_map.fromCbor(*mpa_cborReader);
157 for(auto &cvparam_pair : cvparam_map)
158 {
159 cvparam_pair.second.toMzml(*mp_writer);
160 }
161 }
162 else if(name == "binaryDataArray")
163 {
164
165 mp_writer->writeStartElement("binaryDataArrayList");
166
167 mp_writer->writeAttribute("count", QString("%1").arg(mpa_cborReader->length()));
168 mpa_cborReader->enterContainer();
169 while(mpa_cborReader->hasNext())
170 {
171 BinaryDataArray binary_data_array;
172 binary_data_array.fromCbor(*mpa_cborReader);
173 binary_data_array.toMzml(*mp_writer);
174 }
175
176 mpa_cborReader->leaveContainer();
177
178 mp_writer->writeEndElement();
179 }
180 else
181 {
182 if(mpa_cborReader->isArray())
183 {
184 is_array = true;
185 }
186 else if(mpa_cborReader->isMap())
187 {
188 }
189 else
190 {
191 // error
192 qWarning() << "not a map, not an array";
193 }
194 if(is_array)
195 {
196 mpa_cborReader->enterContainer();
197 while(mpa_cborReader->hasNext())
198 {
199 writeElementInMzml(name, monitor);
200 }
201
202 mpa_cborReader->leaveContainer();
203 }
204 else
205 {
206 mp_writer->writeStartElement(name);
207 mpa_cborReader->enterContainer();
208
209 while(getExpectedString())
210 {
211 qDebug() << m_expectedString;
212 QString current_attribute = m_expectedString;
213 if(mpa_cborReader->isContainer())
214 {
215 qDebug() << current_attribute;
216 writeElementInMzml(current_attribute, monitor);
217 }
218 else if(mpa_cborReader->isInteger())
219 {
220 qDebug() << current_attribute;
221 mp_writer->writeAttribute(current_attribute,
222 QString("%1").arg(mpa_cborReader->toInteger()));
223 mpa_cborReader->next();
224 }
225 else if(mpa_cborReader->isUnsignedInteger())
226 {
227 qDebug() << current_attribute;
228 mp_writer->writeAttribute(current_attribute,
229 QString("%1").arg(mpa_cborReader->toUnsignedInteger()));
230 }
231 else if(mpa_cborReader->isString())
232 {
234 qDebug() << current_attribute;
235 mp_writer->writeAttribute(current_attribute, m_expectedString);
236 }
237 else
238 {
239 qDebug() << current_attribute;
240 mpa_cborReader->next();
241 }
242 }
243
244 mpa_cborReader->leaveContainer();
245
246 mp_writer->writeEndElement();
247 }
248 }
249}
250
251} // namespace mzcbor
252} // namespace cbor
253} // namespace pappso
PSI BinaryDataArray object for mzML/mzCBOR.
ConvertToMzml(QXmlStreamWriter *p_writer)
virtual void readCbor(QFile *cborp, pappso::UiMonitorInterface &monitor)
virtual void close()
convenient function to clean pointer before leaving
void writeElementInMzml(const QString &name, pappso::UiMonitorInterface &monitor)
void readRoot(pappso::UiMonitorInterface &monitor)
PSI cvParam object for mzML/mzCBOR.
cvParam map
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)
void fromCbor(CborStreamReader &reader)
fill the structure reading data from a CBOR stream