libpappsomspp
Library for mass spectrometry
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>
32
36
40
41void
42pappso::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
71void
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
115void
117 const QString &db_ref_id,
118 const pappso::Protein &protein,
119 bool is_reverse)
120{
122 db_ref_id,
123 protein.getAccession(),
124 protein.getDescription(),
125 protein.getSequence(),
126 is_reverse);
127}
128
129
130void
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
176void
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
193void
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 {
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
225void
227{
228 if(pmod == nullptr)
229 {
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 {
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"/>
254void
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
276void
278 const QString &accession,
279 const QString &name,
280 const QString &value,
281 Enums::PrecisionUnit precision_unit)
282{
283 switch(precision_unit)
284 {
286 writeCvParamUo(cv_ref, accession, name, value, "UO", "UO:0000221", "dalton");
287 break;
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
300void
301pappso::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
310void
315
316void
321
322const QString
324{
325 return QString::number(mass, 'f', 10);
326}
327
328const QString
330{
331 return QString::number(mass, 'g', 10);
332}
333
334void
335pappso::MzIdentMlWriter::writeUserParam(const QString &name, double value)
336{
337 writeUserParam(name, QString::number(value, 'g', 10));
338}
339
340const QString
342{
343 return QString::number(value, 'g', 10);
344}
const QString & getName() const
const QString & getAccession() const
static const QString toString(DeepProtMatchType match_type)
static const QString toXmlMassDelta(double mass)
static const QString toXmlDouble(double value)
void writeDBSequence(const QString &id, const QString &db_ref_id, const pappso::Protein &protein, bool is_reverse)
void writeStartMzIdentMlDocument(const QString &id, const QString &version)
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)
void writeCvParam(pappso::AaModificationP modification)
static const QString toXmlMass(double mass)
void writeUserParam(const QString &name, const QString &value)
const QString & getAccession() const
const QString & getAccession() const
Definition protein.cpp:127
const QString & getDescription() const
Definition protein.cpp:137
const QString & getSequence() const
Definition protein.cpp:122
MzIdentML writer.
const AaModification * AaModificationP
DeepProtMatchType
definition of different class of PSMs used by DeepProt
DeepProtPeptideCandidateStatus
definition of different status for potential peptide candidates on the same spectrum