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
43 const QString &version)
44{
45 setAutoFormatting(true);
46 writeStartDocument("1.0");
47 // <MzIdentML id="X! Tandem" version="1.1.0"
48 // xmlns="http://psidev.info/psi/pi/mzIdentML/1.1"
49 // xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
50 // xsi:schemaLocation="http://psidev.info/psi/pi/mzIdentML/1.1
51 // http://www.psidev.info/files/mzIdentML1.1.0.xsd"
52 // creationDate="2016:10:06:09:43:19" >
53
54
55 writeDefaultNamespace("http://psidev.info/psi/pi/mzIdentML/1.2");
56 writeStartElement("MzIdentML");
57 writeAttribute("id", id);
58 writeAttribute("version", version);
59 writeAttribute("creationDate",
60 QDateTime::currentDateTime().toString(Qt::ISODate));
61 writeNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
62 // mp_xmlWriter->writeNamespace("http://www.w3.org/2001/XMLSchema-instance","xsi");
63 // xsi:schemaLocation="http://psidev.info/psi/pi/mzIdentML/1.1
64 // http://www.psidev.info/files/mzIdentML1.1.0.xsd"
65 // xmlns:PSI-MS="http://psidev.info/psi/pi/mzIdentML/1.0"
66 writeAttribute(
67 "http://www.w3.org/2001/XMLSchema-instance",
68 "schemaLocation",
69 "http://psidev.info/psi/pi/mzIdentML/1.2 "
70 "https://raw.githubusercontent.com/HUPO-PSI/mzIdentML/master/schema/"
71 "mzIdentML1.2.0-candidate.xsd");
72}
73
74void
76{
77
78 writeStartElement("cvList");
79 // m_ofOut << "<cvList xmlns=\"http://psidev.info/psi/pi/mzIdentML/1.1\">\n";
80 writeStartElement("cv");
81 writeAttribute("id", "PSI-MS");
82 writeAttribute(
83 "uri",
84 "http://psidev.cvs.sourceforge.net/viewvc/*checkout*/psidev/psi/psi-ms/"
85 "mzML/controlledVocabulary/psi-ms.obo");
86 writeAttribute("version", "3.30.0");
87 writeAttribute("fullName", "PSI-MS");
88 writeEndElement();
89 // m_ofOut << " <cv id=\"PSI-MS\" "
90 // "uri=\"http://psidev.cvs.sourceforge.net/viewvc/*checkout*/psidev/"
91 // "psi/psi-ms/mzML/controlledVocabulary/psi-ms.obo\" "
92 // "version=\"3.30.0\" fullName=\"PSI-MS\"/>\n";
93
94 writeStartElement("cv");
95 writeAttribute("id", "PSI-MOD");
96 writeAttribute(
97 "uri", "http://psidev.cvs.sourceforge.net/psidev/psi/mod/data/PSI-MOD.obo");
98 writeAttribute(
99 "fullName",
100 "Proteomics Standards Initiative Protein Modifications Vocabularies");
101 writeAttribute("version", "1.2");
102 writeEndElement();
103
104 // m_ofOut
105 // << " <cv id=\"UNIMOD\" uri=\"http://www.unimod.org/obo/unimod.obo\" "
106 // "fullName=\"UNIMOD\"/>\n";
107
108 writeStartElement("cv");
109 writeAttribute("id", "UO");
110 writeAttribute("uri",
111 "http://obo.cvs.sourceforge.net/*checkout*/"
112 "obo/obo/ontology/phenotype/unit.obo");
113 writeAttribute("fullName", "UNIT-ONTOLOGY");
114 writeEndElement();
115 // m_ofOut << " <cv id=\"UO\" "
116 // "uri=\"http://obo.cvs.sourceforge.net/*checkout*/obo/obo/ontology/"
117 // "phenotype/unit.obo\" fullName=\"UNIT-ONTOLOGY\"/>\n";
118 writeEndElement();
119 // m_ofOut << "</cvList>\n";
120}
121
122void
124 const QString &db_ref_id,
125 const pappso::Protein &protein,
126 bool is_reverse)
127{
128 writeDBSequence(id,
129 db_ref_id,
130 protein.getAccession(),
131 protein.getDescription(),
132 protein.getSequence(),
133 is_reverse);
134}
135
136
137void
139 const QString &db_ref_id,
140 const QString &accession,
141 const QString &description,
142 const QString &sequence,
143 bool is_reverse)
144{
145
146 writeStartElement("DBSequence");
147 writeAttribute("id", id);
148 writeAttribute("searchDatabase_ref", db_ref_id);
149 writeAttribute("accession", accession);
150 writeAttribute("length", QString::number(sequence.size()));
151 // m_ofOut << "<DBSequence accession=\"" << strLabel.c_str()
152 // << "\" searchDatabase_ref=\"SearchDB_"
153 // << _vs[a].m_vseqBest[b].m_siPath << "\" length=\""
154 // << (unsigned long)_vs[a].m_vseqBest[b].m_strSeq.size()
155 // << "\" id=\"DBSeq" << tUid << "\">\n";
156
157
158 writeStartElement("Seq");
159 writeCharacters(sequence);
160 writeEndElement();
161
162
163 if(!description.isEmpty())
164 {
165 writeCvParam("PSI-MS", "MS:1001088", "protein description", description);
166 }
167 // m_ofOut << "<cvParam accession=\"MS:1001088\" cvRef=\"PSI-MS\"
168 // "
169 // "value=\""
170 // << strDesc.c_str()
171 // << "\" name=\"protein description\"/>\n";
172
173 if(is_reverse)
174 {
175 // PSI-MS MS:1001195 decoy DB type reverse
176 writeCvParam("PSI-MS", "MS:1001195", "decoy DB type reverse", "");
177 }
178 writeEndElement();
179 // m_ofOut << "</DBSequence>\n";
180}
181
182
183void
185 const QString &accession,
186 const QString &name,
187 const QString &value)
188{
189
190 //<cvParam accession="MS:1001083" cvRef="PSI-MS" name="ms-ms search"/>
191 writeStartElement("cvParam");
192 writeAttribute("accession", accession);
193 writeAttribute("cvRef", cv_ref);
194 writeAttribute("name", name);
195 if(!value.isEmpty())
196 writeAttribute("value", value);
197 writeEndElement();
198}
199
200void
202 const QString &value)
203{
204 if(term.m_accession.startsWith("MOD:"))
205 {
206 writeCvParam("PSI-MOD", term.m_accession, term.m_name, value);
207 }
208 else
209 {
210 if(term.m_accession.startsWith("MS:"))
211 {
212 writeCvParam("PSI-MS", term.m_accession, term.m_name, value);
213 }
214 else
215 {
217 QObject::tr("The OBO term %1 %2 is not an OBO PSI-MOD term in %3")
218 .arg(term.m_accession)
219 .arg(term.m_name)
220 .arg(__FUNCTION__));
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(
243 "The modification %1 %2 is not an OBO PSI-MOD term in %3")
244 .arg(pmod->getAccession())
245 .arg(pmod->getName())
246 .arg(__FUNCTION__));
247 }
248 }
249}
250
251
252///< cvParam accession="MS:1000894" cvRef="PSI-MS" name="retention time"
253///< value="5468.0193" unitAccession="UO:0000010" unitName="second"
254///< unitCvRef="UO"/>
255void
257 const QString &accession,
258 const QString &name,
259 const QString &value,
260 const QString &unit_cv_ref,
261 const QString &unit_accession,
262 const QString &unit_name)
263{
264 //<cvParam accession="MS:1001083" cvRef="PSI-MS" name="ms-ms search"/>
265 writeStartElement("cvParam");
266 writeAttribute("accession", accession);
267 writeAttribute("cvRef", cv_ref);
268 writeAttribute("name", name);
269 if(!value.isEmpty())
270 writeAttribute("value", value);
271 writeAttribute("unitAccession", unit_accession);
272 writeAttribute("unitName", unit_name);
273 writeAttribute("unitCvRef", unit_cv_ref);
274 writeEndElement();
275}
276
277void
279 const QString &accession,
280 const QString &name,
281 const QString &value,
282 pappso::PrecisionUnit precision_unit)
283{
284 switch(precision_unit)
285 {
287 writeCvParamUo(
288 cv_ref, accession, name, value, "UO", "UO:0000221", "dalton");
289 break;
291 writeCvParamUo(cv_ref,
292 accession,
293 name,
294 value,
295 "UO",
296 "UO:0000169",
297 "parts per million");
298 break;
299 default:
301 QObject::tr("precision unit %1 not implemented in %2")
302 .arg((int)precision_unit)
303 .arg(__FUNCTION__));
304 break;
305 }
306}
307
308
309void
311 const QString &value)
312{
313 writeStartElement("userParam");
314 writeAttribute("name", name);
315 writeAttribute("value", value);
316 writeEndElement();
317}
318
319
320void
322{
323 writeUserParam("DeepProt:match_type",
325}
326
327void
333
334const QString
336{
337 return QString::number(mass, 'f', 10);
338}
339
340const QString
342{
343 return QString::number(mass, 'g', 10);
344}
345
346void
347pappso::MzIdentMlWriter::writeUserParam(const QString &name, double value)
348{
349 writeUserParam(name, QString::number(value, 'g', 10));
350}
351
352const QString
354{
355 return QString::number(value, 'g', 10);
356}
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
Definition protein.cpp:127
const QString & getDescription() const
Definition protein.cpp:137
const QString & getSequence() const
Definition protein.cpp:122
MzIdentML writer.
PrecisionUnit
Definition types.h:76
DeepProtMatchType
definition of different class of PSMs used by DeepProt
DeepProtPeptideCandidateStatus
definition of different status for potential peptide candidates on the same spectrum