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"
22
23namespace pappso
24{
25
26
27PwizMsFileReader::PwizMsFileReader(const QString &file_name)
28 : MsFileReader{file_name}
29{
30}
31
35
36std::size_t
38{
39 pwiz::msdata::DefaultReaderList defaultReaderList;
40 std::string readerName;
41 try
42 {
43 // qDebug() << m_fileName;
44 readerName = defaultReaderList.identify(m_fileName.toStdString());
45 }
46 catch(std::runtime_error &error)
47 {
48 qDebug() << error.what() << " " << typeid(error).name();
49
50 throw PappsoException(
51 QObject::tr(
52 "libpwiz ERROR reading MS data file %1 "
53 "(std::runtime_error):\n%2\nsource file:%3 - source line:%4")
54 .arg(m_fileName)
55 .arg(error.what())
56 .arg(__FILE__)
57 .arg(__LINE__));
58 }
59 catch(std::exception &error)
60 {
61 qDebug() << error.what() << " " << typeid(error).name();
62
63 throw PappsoException(
64 QObject::tr(
65 "libpwiz ERROR reading MS data file %1 "
66 "(std::runtime_error):\n%2\nsource file:%3 - source line:%4")
67 .arg(m_fileName)
68 .arg(error.what())
69 .arg(__FILE__)
70 .arg(__LINE__));
71 }
72
73 if(readerName.empty())
74 {
75 // qDebug() << "Failed to identify the file.";
76
77 return 0;
78 }
79
80 // Now convert the string to Enums::MsDataFormat.
81 if(readerName == "mzML")
83 else if(readerName == "mzXML")
85 else if(readerName == "Mascot Generic")
87 else if(readerName == "MZ5")
89 else if(readerName == "MSn")
91 else if(readerName == "ABSciex WIFF")
93 else if(readerName == "ABSciex T2D")
95 else if(readerName == "Agilent MassHunter")
97 else if(readerName == "Thermo RAW")
99 else if(readerName == "Water RAW")
101 else if(readerName == "Bruker FID")
103 else if(readerName == "Bruker YEP")
105 else if(readerName == "Bruker BAF")
107 else
108 {
110 return 0;
111 }
112
113 // std::cout << __FILE__ << " @ " << __LINE__ << " " << __FUNCTION__ << " () "
114 // << std::setprecision(15) << "m_fileFormat: " << (int)m_fileFormat
115 // << std::endl;
116
117 // At this point we know pwiz could be able to read the file. Actually fill-in
118 // the MSDataPtr vector!
119 try
120 {
121 defaultReaderList.read(Utils::toUtf8StandardString(m_fileName),
123 }
124 catch(std::runtime_error &error)
125 {
126 qDebug() << error.what() << " " << typeid(error).name();
127
128 throw PappsoException(
129 QObject::tr(
130 "libpwiz ERROR reading MS data file %1 "
131 "(std::runtime_error):\n%2\nsource file:%3 - source line:%4")
132 .arg(m_fileName)
133 .arg(error.what())
134 .arg(__FILE__)
135 .arg(__LINE__));
136 }
137 catch(std::exception &error)
138 {
139 qDebug() << error.what() << " " << typeid(error).name();
140
141 throw PappsoException(
142 QObject::tr(
143 "libpwiz ERROR reading MS data file %1 "
144 "(std::runtime_error):\n%2\nsource file:%3 - source line:%4")
145 .arg(m_fileName)
146 .arg(error.what())
147 .arg(__FILE__)
148 .arg(__LINE__));
149 }
150
151 // qDebug() << "The number of runs is:" << m_msDataPtrVector.size()
152 //<< "The reader type is:" << QString::fromStdString(readerName)
153 //<< "The number of spectra in first run is:"
154 //<< m_msDataPtrVector.at(0)->run.spectrumListPtr->size();
155
156 return m_msDataPtrVector.size();
157}
158
161{
162 // std::cout << __FILE__ << " @ " << __LINE__ << " " << __FUNCTION__ << " () "
163 // << std::setprecision(15) << "m_fileFormat: " << (int)m_fileFormat
164 // << std::endl;
165
166 return m_fileFormat;
167}
168
169std::vector<MsRunIdCstSPtr>
170PwizMsFileReader::getMsRunIds(const QString &run_prefix)
171{
172 std::vector<MsRunIdCstSPtr> ms_run_ids;
173
174 if(!initialize())
175 return ms_run_ids;
176
177 std::size_t iter = 0;
178
179 for(const pwiz::msdata::MSDataPtr &ms_data_ptr : m_msDataPtrVector)
180 {
181 MsRunId ms_run_id(m_fileName,
182 QString::fromStdString(ms_data_ptr->run.id));
183
184 // Set the MS data format as determined in initialize().
185 ms_run_id.setMsDataFormat(m_fileFormat);
186
187 // We need to set the unambiguous xmlId string.
188 ms_run_id.setXmlId(QString("%1%2")
189 .arg(run_prefix)
191
192 // Now set the sample name to the run id : we can not do that, this is not
193 // the use sample name
194 // ms_run_id.setSampleName(QString::fromStdString(ms_data_ptr->run.id));
195
196 // And if it is possible, the real sample name because this one is for the
197 // end user to recognize his sample:
198 if(ms_data_ptr->run.samplePtr != nullptr)
199 {
200 ms_run_id.setSampleName(
201 QString::fromStdString(ms_data_ptr->run.samplePtr->name));
202 }
203
204 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
205 //<< "Current ms_run_id:" << ms_run_id.toString();
206
207 // Finally make a shared pointer out of it and append it to the vector.
208 ms_run_ids.push_back(std::make_shared<MsRunId>(ms_run_id));
209
210 ++iter;
211 }
212
213 return ms_run_ids;
214}
215
216
217} // namespace pappso
MsFileReader(const QString &file_name)
Enums::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 setMsDataFormat(Enums::MsDataFormat format)
Definition msrunid.cpp:168
void setXmlId(const QString &xml_id)
set an XML unique identifier for this MsRunId
Definition msrunid.cpp:147
void setSampleName(const QString &name)
set a sample name for this MsRunId
Definition msrunid.cpp:77
virtual std::vector< MsRunIdCstSPtr > getMsRunIds(const QString &run_prefix) override
PwizMsFileReader(const QString &file_name)
virtual Enums::MsDataFormat getFileFormat() override
std::vector< pwiz::msdata::MSDataPtr > m_msDataPtrVector
virtual std::size_t initialize()
static std::string toUtf8StandardString(const QString &text)
Definition utils.cpp:166
static const QString getLexicalOrderedString(unsigned int num)
Definition utils.cpp:72
@ unknown
unknown format
Definition types.h:149
@ MGF
Mascot format.
Definition types.h:152
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39