libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
Loading...
Searching...
No Matches
mzidentmlwriter.cpp
Go to the documentation of this file.
1
/**
2
* \file processing/xml/mzidentmlwriter.cpp
3
* \date 07/02/2024
4
* \author Olivier Langella
5
* \brief MzIdentML writer
6
*/
7
8
/*******************************************************************************
9
* Copyright (c) 2024 Olivier Langella
10
*<Olivier.Langella@universite-paris-saclay.fr>.
11
*
12
* This file is part of PAPPSOms-tools.
13
*
14
* PAPPSOms-tools is free software: you can redistribute it and/or modify
15
* it under the terms of the GNU General Public License as published by
16
* the Free Software Foundation, either version 3 of the License, or
17
* (at your option) any later version.
18
*
19
* PAPPSOms-tools is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
* GNU General Public License for more details.
23
*
24
* You should have received a copy of the GNU General Public License
25
* along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>.
26
*
27
******************************************************************************/
28
29
#include "
mzidentmlwriter.h
"
30
#include <QDateTime>
31
#include "
pappsomspp/core/pappsoexception.h
"
32
33
pappso::MzIdentMlWriter::MzIdentMlWriter
()
34
{
35
}
36
37
pappso::MzIdentMlWriter::~MzIdentMlWriter
()
38
{
39
}
40
41
void
42
pappso::MzIdentMlWriter::writeStartMzIdentMlDocument
(
const
QString &
id
,
const
QString &version)
43
{
44
setAutoFormatting(
true
);
45
writeStartDocument(
"1.0"
);
46
// <MzIdentML id="X! Tandem" version="1.1.0"
47
// xmlns="http://psidev.info/psi/pi/mzIdentML/1.1"
48
// xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
49
// xsi:schemaLocation="http://psidev.info/psi/pi/mzIdentML/1.1
50
// http://www.psidev.info/files/mzIdentML1.1.0.xsd"
51
// creationDate="2016:10:06:09:43:19" >
52
53
54
writeDefaultNamespace(
"http://psidev.info/psi/pi/mzIdentML/1.2"
);
55
writeStartElement(
"MzIdentML"
);
56
writeAttribute(
"id"
,
id
);
57
writeAttribute(
"version"
, version);
58
writeAttribute(
"creationDate"
, QDateTime::currentDateTime().toString(Qt::ISODate));
59
writeNamespace(
"http://www.w3.org/2001/XMLSchema-instance"
,
"xsi"
);
60
// mp_xmlWriter->writeNamespace("http://www.w3.org/2001/XMLSchema-instance","xsi");
61
// xsi:schemaLocation="http://psidev.info/psi/pi/mzIdentML/1.1
62
// http://www.psidev.info/files/mzIdentML1.1.0.xsd"
63
// xmlns:PSI-MS="http://psidev.info/psi/pi/mzIdentML/1.0"
64
writeAttribute(
"http://www.w3.org/2001/XMLSchema-instance"
,
65
"schemaLocation"
,
66
"http://psidev.info/psi/pi/mzIdentML/1.2 "
67
"https://raw.githubusercontent.com/HUPO-PSI/mzIdentML/master/schema/"
68
"mzIdentML1.2.0-candidate.xsd"
);
69
}
70
71
void
72
pappso::MzIdentMlWriter::writeCvList
()
73
{
74
75
writeStartElement(
"cvList"
);
76
// m_ofOut << "<cvList xmlns=\"http://psidev.info/psi/pi/mzIdentML/1.1\">\n";
77
writeStartElement(
"cv"
);
78
writeAttribute(
"id"
,
"PSI-MS"
);
79
writeAttribute(
"uri"
,
80
"http://psidev.cvs.sourceforge.net/viewvc/*checkout*/psidev/psi/psi-ms/"
81
"mzML/controlledVocabulary/psi-ms.obo"
);
82
writeAttribute(
"version"
,
"3.30.0"
);
83
writeAttribute(
"fullName"
,
"PSI-MS"
);
84
writeEndElement();
85
// m_ofOut << " <cv id=\"PSI-MS\" "
86
// "uri=\"http://psidev.cvs.sourceforge.net/viewvc/*checkout*/psidev/"
87
// "psi/psi-ms/mzML/controlledVocabulary/psi-ms.obo\" "
88
// "version=\"3.30.0\" fullName=\"PSI-MS\"/>\n";
89
90
writeStartElement(
"cv"
);
91
writeAttribute(
"id"
,
"PSI-MOD"
);
92
writeAttribute(
"uri"
,
"http://psidev.cvs.sourceforge.net/psidev/psi/mod/data/PSI-MOD.obo"
);
93
writeAttribute(
"fullName"
,
"Proteomics Standards Initiative Protein Modifications Vocabularies"
);
94
writeAttribute(
"version"
,
"1.2"
);
95
writeEndElement();
96
97
// m_ofOut
98
// << " <cv id=\"UNIMOD\" uri=\"http://www.unimod.org/obo/unimod.obo\" "
99
// "fullName=\"UNIMOD\"/>\n";
100
101
writeStartElement(
"cv"
);
102
writeAttribute(
"id"
,
"UO"
);
103
writeAttribute(
"uri"
,
104
"http://obo.cvs.sourceforge.net/*checkout*/"
105
"obo/obo/ontology/phenotype/unit.obo"
);
106
writeAttribute(
"fullName"
,
"UNIT-ONTOLOGY"
);
107
writeEndElement();
108
// m_ofOut << " <cv id=\"UO\" "
109
// "uri=\"http://obo.cvs.sourceforge.net/*checkout*/obo/obo/ontology/"
110
// "phenotype/unit.obo\" fullName=\"UNIT-ONTOLOGY\"/>\n";
111
writeEndElement();
112
// m_ofOut << "</cvList>\n";
113
}
114
115
void
116
pappso::MzIdentMlWriter::writeDBSequence
(
const
QString &
id
,
117
const
QString &db_ref_id,
118
const
pappso::Protein
&protein,
119
bool
is_reverse)
120
{
121
writeDBSequence
(
id
,
122
db_ref_id,
123
protein.
getAccession
(),
124
protein.
getDescription
(),
125
protein.
getSequence
(),
126
is_reverse);
127
}
128
129
130
void
131
pappso::MzIdentMlWriter::writeDBSequence
(
const
QString &
id
,
132
const
QString &db_ref_id,
133
const
QString &accession,
134
const
QString &description,
135
const
QString &sequence,
136
bool
is_reverse)
137
{
138
139
writeStartElement(
"DBSequence"
);
140
writeAttribute(
"id"
,
id
);
141
writeAttribute(
"searchDatabase_ref"
, db_ref_id);
142
writeAttribute(
"accession"
, accession);
143
writeAttribute(
"length"
, QString::number(sequence.size()));
144
// m_ofOut << "<DBSequence accession=\"" << strLabel.c_str()
145
// << "\" searchDatabase_ref=\"SearchDB_"
146
// << _vs[a].m_vseqBest[b].m_siPath << "\" length=\""
147
// << (unsigned long)_vs[a].m_vseqBest[b].m_strSeq.size()
148
// << "\" id=\"DBSeq" << tUid << "\">\n";
149
150
151
writeStartElement(
"Seq"
);
152
writeCharacters(sequence);
153
writeEndElement();
154
155
156
if
(!description.isEmpty())
157
{
158
writeCvParam
(
"PSI-MS"
,
"MS:1001088"
,
"protein description"
, description);
159
}
160
// m_ofOut << "<cvParam accession=\"MS:1001088\" cvRef=\"PSI-MS\"
161
// "
162
// "value=\""
163
// << strDesc.c_str()
164
// << "\" name=\"protein description\"/>\n";
165
166
if
(is_reverse)
167
{
168
// PSI-MS MS:1001195 decoy DB type reverse
169
writeCvParam
(
"PSI-MS"
,
"MS:1001195"
,
"decoy DB type reverse"
,
""
);
170
}
171
writeEndElement();
172
// m_ofOut << "</DBSequence>\n";
173
}
174
175
176
void
177
pappso::MzIdentMlWriter::writeCvParam
(
const
QString &cv_ref,
178
const
QString &accession,
179
const
QString &name,
180
const
QString &value)
181
{
182
183
//<cvParam accession="MS:1001083" cvRef="PSI-MS" name="ms-ms search"/>
184
writeStartElement(
"cvParam"
);
185
writeAttribute(
"accession"
, accession);
186
writeAttribute(
"cvRef"
, cv_ref);
187
writeAttribute(
"name"
, name);
188
if
(!value.isEmpty())
189
writeAttribute(
"value"
, value);
190
writeEndElement();
191
}
192
193
void
194
pappso::MzIdentMlWriter::writeCvParam
(
const
pappso::OboPsiModTerm
&term,
const
QString &value)
195
{
196
if
(term.
getAccession
().startsWith(
"MOD:"
))
197
{
198
writeCvParam
(
"PSI-MOD"
, term.
getAccession
(), term.
m_name
, value);
199
}
200
else
201
{
202
if
(term.
getAccession
().startsWith(
"MS:"
))
203
{
204
writeCvParam
(
"PSI-MS"
, term.
getAccession
(), term.
m_name
, value);
205
}
206
else
207
{
208
209
if
(term.
getAccession
().startsWith(
"UNIMOD:"
))
210
{
211
writeCvParam
(
"UNIMOD"
, term.
getAccession
(), term.
m_name
, value);
212
}
213
else
214
{
215
throw
pappso::PappsoException
(
216
QObject::tr(
"The OBO term %1 %2 is not an OBO PSI-MOD or UNIMOD term in %3"
)
217
.arg(term.
getAccession
())
218
.arg(term.
m_name
)
219
.arg(__FUNCTION__));
220
}
221
}
222
}
223
}
224
225
void
226
pappso::MzIdentMlWriter::writeCvParam
(
pappso::AaModificationP
pmod)
227
{
228
if
(pmod ==
nullptr
)
229
{
230
throw
pappso::PappsoException
(
231
QObject::tr(
"pappso::AaModificationP is null in %1"
).arg(__FUNCTION__));
232
}
233
else
234
{
235
if
(pmod->
getAccession
().startsWith(
"MOD:"
))
236
{
237
writeCvParam
(
"PSI-MOD"
, pmod->
getAccession
(), pmod->
getName
(),
""
);
238
}
239
else
240
{
241
throw
pappso::PappsoException
(
242
QObject::tr(
"The modification %1 %2 is not an OBO PSI-MOD term in %3"
)
243
.arg(pmod->
getAccession
())
244
.arg(pmod->
getName
())
245
.arg(__FUNCTION__));
246
}
247
}
248
}
249
250
251
///< cvParam accession="MS:1000894" cvRef="PSI-MS" name="retention time"
252
///< value="5468.0193" unitAccession="UO:0000010" unitName="second"
253
///< unitCvRef="UO"/>
254
void
255
pappso::MzIdentMlWriter::writeCvParamUo
(
const
QString &cv_ref,
256
const
QString &accession,
257
const
QString &name,
258
const
QString &value,
259
const
QString &unit_cv_ref,
260
const
QString &unit_accession,
261
const
QString &unit_name)
262
{
263
//<cvParam accession="MS:1001083" cvRef="PSI-MS" name="ms-ms search"/>
264
writeStartElement(
"cvParam"
);
265
writeAttribute(
"accession"
, accession);
266
writeAttribute(
"cvRef"
, cv_ref);
267
writeAttribute(
"name"
, name);
268
if
(!value.isEmpty())
269
writeAttribute(
"value"
, value);
270
writeAttribute(
"unitAccession"
, unit_accession);
271
writeAttribute(
"unitName"
, unit_name);
272
writeAttribute(
"unitCvRef"
, unit_cv_ref);
273
writeEndElement();
274
}
275
276
void
277
pappso::MzIdentMlWriter::writeCvParamUo
(
const
QString &cv_ref,
278
const
QString &accession,
279
const
QString &name,
280
const
QString &value,
281
Enums::PrecisionUnit
precision_unit)
282
{
283
switch
(precision_unit)
284
{
285
case
Enums::PrecisionUnit::dalton
:
286
writeCvParamUo
(cv_ref, accession, name, value,
"UO"
,
"UO:0000221"
,
"dalton"
);
287
break
;
288
case
Enums::PrecisionUnit::ppm
:
289
writeCvParamUo
(cv_ref, accession, name, value,
"UO"
,
"UO:0000169"
,
"parts per million"
);
290
break
;
291
default
:
292
throw
pappso::PappsoException
(QObject::tr(
"precision unit %1 not implemented in %2"
)
293
.arg((
int
)precision_unit)
294
.arg(__FUNCTION__));
295
break
;
296
}
297
}
298
299
300
void
301
pappso::MzIdentMlWriter::writeUserParam
(
const
QString &name,
const
QString &value)
302
{
303
writeStartElement(
"userParam"
);
304
writeAttribute(
"name"
, name);
305
writeAttribute(
"value"
, value);
306
writeEndElement();
307
}
308
309
310
void
311
pappso::MzIdentMlWriter::writeUserParam
(
pappso::DeepProtMatchType
matchType)
312
{
313
writeUserParam
(
"DeepProt:match_type"
,
pappso::DeepProtEnumStr::toString
(matchType));
314
}
315
316
void
317
pappso::MzIdentMlWriter::writeUserParam
(
pappso::DeepProtPeptideCandidateStatus
status)
318
{
319
writeUserParam
(
"DeepProt:status"
,
pappso::DeepProtEnumStr::toString
(status));
320
}
321
322
const
QString
323
pappso::MzIdentMlWriter::toXmlMass
(
double
mass)
324
{
325
return
QString::number(mass,
'f'
, 10);
326
}
327
328
const
QString
329
pappso::MzIdentMlWriter::toXmlMassDelta
(
double
mass)
330
{
331
return
QString::number(mass,
'g'
, 10);
332
}
333
334
void
335
pappso::MzIdentMlWriter::writeUserParam
(
const
QString &name,
double
value)
336
{
337
writeUserParam
(name, QString::number(value,
'g'
, 10));
338
}
339
340
const
QString
341
pappso::MzIdentMlWriter::toXmlDouble
(
double
value)
342
{
343
return
QString::number(value,
'g'
, 10);
344
}
pappso::AaModification::getName
const QString & getName() const
Definition
aamodification.cpp:137
pappso::AaModification::getAccession
const QString & getAccession() const
Definition
aamodification.cpp:94
pappso::DeepProtEnumStr::toString
static const QString toString(DeepProtMatchType match_type)
Definition
deepprotenum.cpp:112
pappso::MzIdentMlWriter::toXmlMassDelta
static const QString toXmlMassDelta(double mass)
Definition
mzidentmlwriter.cpp:329
pappso::MzIdentMlWriter::MzIdentMlWriter
MzIdentMlWriter()
Definition
mzidentmlwriter.cpp:33
pappso::MzIdentMlWriter::toXmlDouble
static const QString toXmlDouble(double value)
Definition
mzidentmlwriter.cpp:341
pappso::MzIdentMlWriter::writeDBSequence
void writeDBSequence(const QString &id, const QString &db_ref_id, const pappso::Protein &protein, bool is_reverse)
Definition
mzidentmlwriter.cpp:116
pappso::MzIdentMlWriter::writeCvList
void writeCvList()
Definition
mzidentmlwriter.cpp:72
pappso::MzIdentMlWriter::writeStartMzIdentMlDocument
void writeStartMzIdentMlDocument(const QString &id, const QString &version)
Definition
mzidentmlwriter.cpp:42
pappso::MzIdentMlWriter::writeCvParamUo
void writeCvParamUo(const QString &cv_ref, const QString &accession, const QString &name, const QString &value, const QString &unit_cv_ref, const QString &unit_accession, const QString &unit_name)
Definition
mzidentmlwriter.cpp:255
pappso::MzIdentMlWriter::writeCvParam
void writeCvParam(pappso::AaModificationP modification)
Definition
mzidentmlwriter.cpp:226
pappso::MzIdentMlWriter::toXmlMass
static const QString toXmlMass(double mass)
Definition
mzidentmlwriter.cpp:323
pappso::MzIdentMlWriter::~MzIdentMlWriter
virtual ~MzIdentMlWriter()
Definition
mzidentmlwriter.cpp:37
pappso::MzIdentMlWriter::writeUserParam
void writeUserParam(const QString &name, const QString &value)
Definition
mzidentmlwriter.cpp:301
pappso::OboPsiModTerm
Definition
obopsimodterm.h:34
pappso::OboPsiModTerm::getAccession
const QString & getAccession() const
Definition
obopsimodterm.cpp:261
pappso::OboPsiModTerm::m_name
QString m_name
Definition
obopsimodterm.h:58
pappso::PappsoException
Definition
pappsoexception.h:41
pappso::Protein
Definition
protein.h:50
pappso::Protein::getAccession
const QString & getAccession() const
Definition
protein.cpp:127
pappso::Protein::getDescription
const QString & getDescription() const
Definition
protein.cpp:137
pappso::Protein::getSequence
const QString & getSequence() const
Definition
protein.cpp:122
mzidentmlwriter.h
MzIdentML writer.
pappso::Enums::PrecisionUnit
PrecisionUnit
Definition
types.h:90
pappso::Enums::PrecisionUnit::ppm
@ ppm
Definition
types.h:93
pappso::Enums::PrecisionUnit::dalton
@ dalton
Definition
types.h:92
pappso::AaModificationP
const AaModification * AaModificationP
Definition
aamodification.h:52
pappso::DeepProtMatchType
DeepProtMatchType
definition of different class of PSMs used by DeepProt
Definition
deepprotenum.h:42
pappso::DeepProtPeptideCandidateStatus
DeepProtPeptideCandidateStatus
definition of different status for potential peptide candidates on the same spectrum
Definition
deepprotenum.h:61
pappsoexception.h
pappsomspp
core
processing
xml
mzidentmlwriter.cpp
Generated on
for libpappsomspp by
1.17.0