libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::cbor::mzcbor::CvParam Struct Reference

#include <cvparam.h>

Public Member Functions

void fromCbor (CborStreamReader &reader)
 
void toCbor (CborStreamWriter &writer)
 
void fromMzml (QXmlStreamReader &reader)
 
void toMzml (QXmlStreamWriter &writer)
 
void xmlValueToCbor (CborStreamWriter &writer, const QStringView &value_str)
 
void setValue (const QString &value_str)
 

Static Public Member Functions

static std::map< QString, pappso::cbor::mzcbor::CvParamgetCvParamsMapFromCbor (CborStreamReader &reader)
 

Public Attributes

QString cvRef
 
QString accession
 
double valueDouble
 
qint64 valueInt
 
QString valueStr
 
QString name
 
QString unitAccession
 
QString unitName
 
QString unitCvRef
 
QCborStreamReader::Type cborType = QCborStreamReader::Type::Invalid
 

Detailed Description

Todo:
write docs

Definition at line 45 of file cvparam.h.

Member Function Documentation

◆ fromCbor()

void pappso::cbor::mzcbor::CvParam::fromCbor ( CborStreamReader reader)

Definition at line 33 of file cvparam.cpp.

34{
35 qDebug();
36 reader.enterContainer();
37 QString attribute_cvparam;
38 while(reader.hasNext())
39 {
40 reader.decodeString(attribute_cvparam);
41 qDebug() << attribute_cvparam;
42 if(attribute_cvparam == "cvRef")
43 {
44 reader.decodeString(cvRef);
45 }
46 else if(attribute_cvparam == "accession")
47 {
48 reader.decodeString(accession);
49 }
50 else if(attribute_cvparam == "name")
51 {
52 reader.decodeString(name);
53 }
54 else if(attribute_cvparam == "value")
55 {
56 cborType = reader.type();
57 if(reader.isDouble())
58 {
59 valueDouble = reader.toDouble();
60 reader.next();
61 }
62 else if(reader.isUnsignedInteger())
63 {
64 valueInt = reader.toUnsignedInteger();
65 reader.next();
66 }
67 else if(reader.isInteger())
68 {
69 valueInt = reader.toInteger();
70 reader.next();
71 }
72 else if(reader.type() == QCborStreamReader::Type::String)
73 {
74 if(reader.decodeString(attribute_cvparam))
75 {
76 valueStr = attribute_cvparam;
77 }
78 else
79 {
81 QObject::tr("cvParam value string failed for accession %1").arg(accession));
82 }
83 }
84 else
85 {
87 QObject::tr("cvParam value type not known for accession %1").arg(accession));
88 }
89 }
90 else if(attribute_cvparam == "unitAccession")
91 {
92 reader.decodeString(unitAccession);
93 }
94
95 else if(attribute_cvparam == "unitCvRef")
96 {
97 reader.decodeString(unitCvRef);
98 }
99 else if(attribute_cvparam == "unitName")
100 {
101 reader.decodeString(unitName);
102 }
103 else
104 {
105 reader.next();
106 }
107 }
108
109 reader.leaveContainer();
110}
QCborStreamReader::Type cborType
Definition cvparam.h:70

References accession, cborType, cvRef, pappso::cbor::CborStreamReader::decodeString(), name, unitAccession, unitCvRef, unitName, valueDouble, valueInt, and valueStr.

Referenced by pappso::cbor::mzcbor::MzcborReaderBase::getCvParamsMap(), and getCvParamsMapFromCbor().

◆ fromMzml()

void pappso::cbor::mzcbor::CvParam::fromMzml ( QXmlStreamReader &  reader)

Definition at line 113 of file cvparam.cpp.

114{
115 qDebug();
116 for(auto &the_attribute : reader.attributes())
117 {
118 if(the_attribute.name() == "cvRef")
119 {
120 cvRef = the_attribute.value().toString();
121 }
122 else if(the_attribute.name() == "accession")
123 {
124 accession = the_attribute.value().toString();
125 }
126 else if(the_attribute.name() == "name")
127 {
128 name = the_attribute.value().toString();
129 }
130 else if(the_attribute.name() == "value")
131 {
132 valueStr = the_attribute.value().toString();
133 }
134 else if(the_attribute.name() == "unitCvRef")
135 {
136 unitCvRef = the_attribute.value().toString();
137 }
138 else if(the_attribute.name() == "unitAccession")
139 {
140 unitAccession = the_attribute.value().toString();
141 }
142 else if(the_attribute.name() == "unitName")
143 {
144 unitName = the_attribute.value().toString();
145 }
146 }
147
148 reader.readNextStartElement();
149 qDebug();
150}

Referenced by pappso::cbor::mzcbor::MzmlConvert::insideElement().

◆ getCvParamsMapFromCbor()

std::map< QString, pappso::cbor::mzcbor::CvParam > pappso::cbor::mzcbor::CvParam::getCvParamsMapFromCbor ( CborStreamReader reader)
static

Definition at line 182 of file cvparam.cpp.

183{
184 qDebug();
185 std::map<QString, CvParam> accession_values;
186 reader.enterContainer(); // start array
187
188 while(reader.hasNext())
189 {
190
191 CvParam cv_param;
192 cv_param.fromCbor(reader);
193 accession_values.insert({cv_param.accession, cv_param});
194 }
195
196 reader.leaveContainer(); // end array
197 return accession_values;
198}

References accession, and fromCbor().

Referenced by pappso::cbor::mzcbor::SelectedIon::fromCbor(), pappso::cbor::mzcbor::Precursor::fromCbor(), pappso::cbor::mzcbor::Spectrum::fromCbor(), pappso::cbor::mzcbor::Spectrum::readScanCvParams(), and pappso::cbor::mzcbor::ConvertToMzml::writeElementInMzml().

◆ setValue()

void pappso::cbor::mzcbor::CvParam::setValue ( const QString &  value_str)

Definition at line 201 of file cvparam.cpp.

202{
203 valueInt = 0;
204 valueDouble = 0;
205 valueStr = value_str;
206}

Referenced by pappso::cbor::mzcbor::BinaryDataArray::toMzml().

◆ toCbor()

void pappso::cbor::mzcbor::CvParam::toCbor ( CborStreamWriter writer)

Definition at line 153 of file cvparam.cpp.

154{
155
156 writer.startMap();
157 writer.append("cvRef");
158 writer.append(cvRef);
159
160 writer.append("accession");
161 writer.append(accession);
162 writer.append("name");
163 writer.append(name);
164
165 writer.append("value");
166 xmlValueToCbor(writer, valueStr);
167
168 if(!unitAccession.isEmpty())
169 {
170 writer.append("unitCvRef");
171 writer.append(unitCvRef);
172 writer.append("unitAccession");
173 writer.append(unitAccession);
174 writer.append("unitName");
175 writer.append(unitName);
176 }
177 writer.endMap();
178}
void xmlValueToCbor(CborStreamWriter &writer, const QStringView &value_str)
Definition cvparam.cpp:249

Referenced by pappso::cbor::mzcbor::MzmlConvert::insideElement().

◆ toMzml()

void pappso::cbor::mzcbor::CvParam::toMzml ( QXmlStreamWriter &  writer)

Definition at line 209 of file cvparam.cpp.

210{
211 // <cvParam cvRef="MS" accession="MS:1000514" value="" name="m/z array"
212 writer.writeStartElement("cvParam");
213
214 writer.writeAttribute("cvRef", cvRef);
215 writer.writeAttribute("accession", accession);
216
217
218 if(cborType == QCborStreamReader::Type::Double)
219 {
220 valueStr = QString::number(valueDouble, 'g', 15);
221 }
222 else if(cborType == QCborStreamReader::Type::UnsignedInteger)
223 {
224 valueStr = QString("%1").arg(valueInt);
225 }
226 else if(cborType == QCborStreamReader::Type::NegativeInteger)
227 {
228 valueStr = QString("%1").arg(valueInt);
229 }
230 else if(cborType == QCborStreamReader::Type::String)
231 {
232 }
233 writer.writeAttribute("value", valueStr);
234
235 writer.writeAttribute("name", name);
236 // unitAccession="MS:1000040" unitName="m/z" unitCvRef="MS" />
237 if(!unitAccession.isEmpty())
238 {
239 writer.writeAttribute("unitAccession", unitAccession);
240 writer.writeAttribute("unitName", unitName);
241 writer.writeAttribute("unitCvRef", unitCvRef);
242 }
243
244 writer.writeEndElement(); // cvParam
245}

Referenced by pappso::cbor::mzcbor::BinaryDataArray::toMzml().

◆ xmlValueToCbor()

void pappso::cbor::mzcbor::CvParam::xmlValueToCbor ( CborStreamWriter writer,
const QStringView &  value_str 
)

Definition at line 249 of file cvparam.cpp.

251{
252 bool ok(false);
253 double d = value_str.toDouble(&ok);
254 if(ok)
255 {
256 if(value_str.contains('.'))
257 {
258 cborType = QCborStreamReader::Type::Double;
259 writer.append(d);
260 }
261 else
262 {
263 qint64 bigint = value_str.toLongLong(&ok);
264 if(ok)
265 {
266 cborType = QCborStreamReader::Type::NegativeInteger;
267 writer.append(bigint);
268 }
269 }
270 }
271 else
272 {
273 cborType = QCborStreamReader::Type::String;
274 writer.append(value_str);
275 }
276}

Member Data Documentation

◆ accession

QString pappso::cbor::mzcbor::CvParam::accession

◆ cborType

QCborStreamReader::Type pappso::cbor::mzcbor::CvParam::cborType = QCborStreamReader::Type::Invalid

Definition at line 70 of file cvparam.h.

Referenced by fromCbor().

◆ cvRef

QString pappso::cbor::mzcbor::CvParam::cvRef

Definition at line 60 of file cvparam.h.

Referenced by fromCbor(), and pappso::cbor::mzcbor::BinaryDataArray::toMzml().

◆ name

QString pappso::cbor::mzcbor::CvParam::name

Definition at line 65 of file cvparam.h.

Referenced by fromCbor(), and pappso::cbor::mzcbor::BinaryDataArray::toMzml().

◆ unitAccession

QString pappso::cbor::mzcbor::CvParam::unitAccession

Definition at line 66 of file cvparam.h.

Referenced by fromCbor(), and pappso::cbor::mzcbor::BinaryDataArray::toMzml().

◆ unitCvRef

QString pappso::cbor::mzcbor::CvParam::unitCvRef

Definition at line 68 of file cvparam.h.

Referenced by fromCbor(), and pappso::cbor::mzcbor::BinaryDataArray::toMzml().

◆ unitName

QString pappso::cbor::mzcbor::CvParam::unitName

Definition at line 67 of file cvparam.h.

Referenced by fromCbor(), and pappso::cbor::mzcbor::BinaryDataArray::toMzml().

◆ valueDouble

double pappso::cbor::mzcbor::CvParam::valueDouble

Definition at line 62 of file cvparam.h.

Referenced by fromCbor().

◆ valueInt

qint64 pappso::cbor::mzcbor::CvParam::valueInt

Definition at line 63 of file cvparam.h.

Referenced by fromCbor().

◆ valueStr

QString pappso::cbor::mzcbor::CvParam::valueStr

Definition at line 64 of file cvparam.h.

Referenced by fromCbor().


The documentation for this struct was generated from the following files: