libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pwizmsfilereader.cpp
Go to the documentation of this file.
1/////////////////////// StdLib includes
2#include <iostream>
3#include <iomanip>
4
5
6/////////////////////// Qt includes
7#include <QDebug>
8#include <QFile>
9#include <QFileInfo>
10
11
12/////////////////////// libpwiz includes
13#include <pwiz/data/msdata/DefaultReaderList.hpp>
14
15
16/////////////////////// Local includes
17#include "pwizmsfilereader.h"
18#include "../exception/exceptionnotfound.h"
19#include "../utils.h"
20#include "../types.h"
21#include "../msrun/msrunid.h"
22
23
24namespace pappso
25{
26
27
28PwizMsFileReader::PwizMsFileReader(const QString &file_name)
29 : MsFileReader{file_name}
30{
31}
32
33
37
38
39std::size_t
41{
42 pwiz::msdata::DefaultReaderList defaultReaderList;
43 std::string readerName;
44 try
45 {
46 qDebug() << m_fileName;
47 readerName = defaultReaderList.identify(m_fileName.toStdString());
48 }
49 catch(std::runtime_error &error)
50 {
51 qDebug() << error.what() << " " << typeid(error).name();
52
53 throw PappsoException(
54 QObject::tr(
55 "libpwiz ERROR reading MS data file %1 "
56 "(std::runtime_error):\n%2\nsource file:%3 - source line:%4")
57 .arg(m_fileName)
58 .arg(error.what())
59 .arg(__FILE__)
60 .arg(__LINE__));
61 }
62 catch(std::exception &error)
63 {
64 qDebug() << error.what() << " " << typeid(error).name();
65
66 throw PappsoException(
67 QObject::tr(
68 "libpwiz ERROR reading MS data file %1 "
69 "(std::runtime_error):\n%2\nsource file:%3 - source line:%4")
70 .arg(m_fileName)
71 .arg(error.what())
72 .arg(__FILE__)
73 .arg(__LINE__));
74 }
75
76 if(readerName.empty())
77 {
78 qDebug() << "Failed to identify the file.";
79
80 return 0;
81 }
82
83 // Now convert the string to MsDataFormat.
84 if(readerName == "mzML")
86 else if(readerName == "mzXML")
88 else if(readerName == "Mascot Generic")
90 else if(readerName == "MZ5")
92 else if(readerName == "MSn")
94 else if(readerName == "ABSciex WIFF")
96 else if(readerName == "ABSciex T2D")
98 else if(readerName == "Agilent MassHunter")
100 else if(readerName == "Thermo RAW")
102 else if(readerName == "Water RAW")
104 else if(readerName == "Bruker FID")
106 else if(readerName == "Bruker YEP")
108 else if(readerName == "Bruker BAF")
110 else
111 {
113 return 0;
114 }
115
116 // std::cout << __FILE__ << " @ " << __LINE__ << " " << __FUNCTION__ << " () "
117 // << std::setprecision(15) << "m_fileFormat: " << (int)m_fileFormat
118 // << std::endl;
119
120 // At this point we know pwiz could be able to read the file. Actually fill-in
121 // the MSDataPtr vector!
122 try
123 {
124 defaultReaderList.read(Utils::toUtf8StandardString(m_fileName),
126 }
127 catch(std::runtime_error &error)
128 {
129 qDebug() << error.what() << " " << typeid(error).name();
130
131 throw PappsoException(
132 QObject::tr(
133 "libpwiz ERROR reading MS data file %1 "
134 "(std::runtime_error):\n%2\nsource file:%3 - source line:%4")
135 .arg(m_fileName)
136 .arg(error.what())
137 .arg(__FILE__)
138 .arg(__LINE__));
139 }
140 catch(std::exception &error)
141 {
142 qDebug() << error.what() << " " << typeid(error).name();
143
144 throw PappsoException(
145 QObject::tr(
146 "libpwiz ERROR reading MS data file %1 "
147 "(std::runtime_error):\n%2\nsource file:%3 - source line:%4")
148 .arg(m_fileName)
149 .arg(error.what())
150 .arg(__FILE__)
151 .arg(__LINE__));
152 }
153
154 // qDebug() << "The number of runs is:" << m_msDataPtrVector.size()
155 //<< "The reader type is:" << QString::fromStdString(readerName)
156 //<< "The number of spectra in first run is:"
157 //<< m_msDataPtrVector.at(0)->run.spectrumListPtr->size();
158
159 return m_msDataPtrVector.size();
160}
161
162
165{
166 // std::cout << __FILE__ << " @ " << __LINE__ << " " << __FUNCTION__ << " () "
167 // << std::setprecision(15) << "m_fileFormat: " << (int)m_fileFormat
168 // << std::endl;
169
170 return m_fileFormat;
171}
172
173
174std::vector<MsRunIdCstSPtr>
175PwizMsFileReader::getMsRunIds(const QString &run_prefix)
176{
177 std::vector<MsRunIdCstSPtr> ms_run_ids;
178
179 if(!initialize())
180 return ms_run_ids;
181
182 std::size_t iter = 0;
183
184 for(pwiz::msdata::MSDataPtr ms_data_ptr : m_msDataPtrVector)
185 {
186 MsRunId ms_run_id(m_fileName, QString::fromStdString(ms_data_ptr->run.id));
187
188 // Set the MS data format as determined in initialize().
189 ms_run_id.setMsDataFormat(m_fileFormat);
190
191 // We need to set the unambiguous xmlId string.
192 ms_run_id.setXmlId(QString("%1%2")
193 .arg(run_prefix)
195
196 // Now set the sample name to the run id :
197 ms_run_id.setSampleName(QString::fromStdString(ms_data_ptr->run.id));
198
199 // And if it is possible, the real sample name because this one is for the
200 // end user to recognize his sample:
201 if(ms_data_ptr->run.samplePtr != nullptr)
202 {
203 ms_run_id.setSampleName(
204 QString::fromStdString(ms_data_ptr->run.samplePtr->name));
205 }
206
207 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
208 //<< "Current ms_run_id:" << ms_run_id.toString();
209
210 // Finally make a shared pointer out of it and append it to the vector.
211 ms_run_ids.push_back(std::make_shared<MsRunId>(ms_run_id));
212
213 ++iter;
214 }
215
216 return ms_run_ids;
217}
218
219
220} // namespace pappso
MsDataFormat m_fileFormat
MS run identity MsRunId identifies an MS run with a unique ID (XmlId) and contains eventually informa...
Definition msrunid.h:54
void setXmlId(const QString &xml_id)
set an XML unique identifier for this MsRunId
Definition msrunid.cpp:137
void setMsDataFormat(MsDataFormat format)
Definition msrunid.cpp:158
void setSampleName(const QString &name)
set a sample name for this MsRunId
Definition msrunid.cpp:79
virtual std::vector< MsRunIdCstSPtr > getMsRunIds(const QString &run_prefix) override
PwizMsFileReader(const QString &file_name)
std::vector< pwiz::msdata::MSDataPtr > m_msDataPtrVector
virtual std::size_t initialize()
virtual MsDataFormat getFileFormat() override
static std::string toUtf8StandardString(const QString &text)
Definition utils.cpp:164
static const QString getLexicalOrderedString(unsigned int num)
Definition utils.cpp:73
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
MsDataFormat
Definition types.h:120
@ unknown
unknown format
@ MGF
Mascot format.