libpappsomspp
Library for mass spectrometry
wraptandemresults.cpp
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/processing/tandemwrapper/wraptandemresults.cpp
3  * \date 13/11/2021
4  * \author Olivier Langella
5  * \brief rewrites tandem xml output file with temporary files
6  */
7 
8 /*******************************************************************************
9  * Copyright (c) 2021 Olivier Langella <Olivier.Langella@u-psud.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 "wraptandemresults.h"
29 #include <QFileInfo>
30 #include "../../pappsoexception.h"
31 
32 
33 namespace pappso
34 {
35 
36 WrapTandemResults::WrapTandemResults(const QString &final_tandem_output,
37  const QString &original_msdata_file_name)
38  : m_destinationTandemOutputFile(final_tandem_output)
39 {
40  qDebug() << final_tandem_output;
42  QFileInfo(original_msdata_file_name).absoluteFilePath();
43  if(!m_destinationTandemOutputFile.open(QIODevice::WriteOnly))
44  {
46  QObject::tr("ERROR: unable to open %1 to write XML output")
47  .arg(final_tandem_output));
48  }
50  m_writerXmlTandemOutput.writeStartDocument("1.0");
51  m_writerXmlTandemOutput.setAutoFormatting(true);
52 }
53 
55 {
56 }
57 
58 void
59 WrapTandemResults::setInputParameters(const QString &label_name_attribute,
60  const QString &input_value)
61 {
63  std::pair<QString, QString>(label_name_attribute, input_value));
64 }
65 
66 void
68 {
70  while(m_qxmlStreamReader.readNext() && !m_qxmlStreamReader.isEndElement())
71  {
72  if(m_qxmlStreamReader.isStartElement())
73  {
74  QString type =
75  m_qxmlStreamReader.attributes().value("type").toString();
76  QString label =
77  m_qxmlStreamReader.attributes().value("label").toString();
78  qDebug() << "type=" << type << " label=" << label;
79  // qDebug() << "XtandemParamSaxHandler::endElement_note begin " <<
80  // <note type="input" label="spectrum,
81  // path">/tmp/tandemwrapper-IehrEL/msdata.mzxml</note>
82 
83  if(label == "spectrum, path")
84  {
85  //<note type="input"
86  // label="spectrum,path">/gorgone/pappso/jouy/raw/2019_Lumos/20191222_107_Juste/20191222_18_EF1.mzXML</note>
87  // m_originMzDataFileName = m_currentText;
88  // p_writeXmlTandemOutput->writeCharacters(m_destinationMzXmlFileName);
89 
90  m_writerXmlTandemOutput.writeStartElement("note");
91  m_writerXmlTandemOutput.writeAttributes(
92  m_qxmlStreamReader.attributes());
94  m_writerXmlTandemOutput.writeEndElement();
95 
96 
97  for(auto pair_input : m_mapTandemInputParameters)
98  {
99  m_writerXmlTandemOutput.writeStartElement("note");
100  m_writerXmlTandemOutput.writeAttribute("type", "input");
101  m_writerXmlTandemOutput.writeAttribute("label",
102  pair_input.first);
103  m_writerXmlTandemOutput.writeCharacters(pair_input.second);
104 
105  m_writerXmlTandemOutput.writeEndElement();
106  }
107  m_qxmlStreamReader.skipCurrentElement();
108  }
109  else if(label == "output, path")
110  {
111 
112  //<note type="input" label="output,
113  // path">/tmp/tandemwrapper-sSGxtE/output_tandem.xml</note>
114 
115  m_writerXmlTandemOutput.writeStartElement("note");
116  m_writerXmlTandemOutput.writeAttributes(
117  m_qxmlStreamReader.attributes());
118  m_writerXmlTandemOutput.writeCharacters(
119  QFileInfo(m_destinationTandemOutputFile).absoluteFilePath());
120  m_writerXmlTandemOutput.writeEndElement();
121  m_qxmlStreamReader.skipCurrentElement();
122  }
123  else
124  {
126  }
127  }
128  }
129  m_writerXmlTandemOutput.writeEndElement();
130 }
131 
132 void
134 {
135  qDebug();
136  if(m_qxmlStreamReader.readNextStartElement())
137  {
138  if(m_qxmlStreamReader.name().toString() == "bioml")
139  {
141  qDebug();
142  while(m_qxmlStreamReader.readNextStartElement())
143  {
144  if(m_qxmlStreamReader.name().toString() == "group")
145  {
146  QString type =
147  m_qxmlStreamReader.attributes().value("type").toString();
148  if(type == "model")
149  {
151  }
152  else if(type == "parameters")
153  {
154  QString label = m_qxmlStreamReader.attributes()
155  .value("label")
156  .toString();
157  if(label == "performance parameters")
158  {
160  }
161  else if(label == "input parameters")
162  {
164  // cloneElement(m_writerXmlTandemOutput);
165  }
166  else if(label == "unused input parameters")
167  {
169  }
170  else
171  {
172  m_qxmlStreamReader.skipCurrentElement();
173  }
174  }
175  }
176  else
177  {
178  qDebug() << m_qxmlStreamReader.name();
179  // read_note();
181 
182 
183  m_writerXmlTandemOutput.writeCharacters(
184  m_qxmlStreamReader.readElementText());
185 
186  m_writerXmlTandemOutput.writeEndElement();
187  }
188  }
189  }
190  else
191  {
192  m_qxmlStreamReader.raiseError(
193  QObject::tr("Not an X!Tandem result file"));
194  m_qxmlStreamReader.skipCurrentElement();
195  }
196  }
197  m_writerXmlTandemOutput.writeEndDocument();
199  qDebug();
200 }
201 
202 } // namespace pappso
QXmlStreamWriter m_writerXmlTandemOutput
WrapTandemResults(const QString &final_tandem_output, const QString &original_msdata_file_name)
virtual void readStream() override
std::map< QString, QString > m_mapTandemInputParameters
void setInputParameters(const QString &label_name_attribute, const QString &input_value)
void cloneStartElement(QXmlStreamWriter &output) const
void cloneElement(QXmlStreamWriter &output)
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
rewrites tandem xml output file with temporary files