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
23
24namespace pappso
25{
26
27
28PwizMsFileReader::PwizMsFileReader(const QString &file_name) : MsFileReader{file_name}
29{
30}
31
32
36
37
38std::size_t
40{
41 pwiz::msdata::DefaultReaderList defaultReaderList;
42 std::string readerName;
43 try
44 {
45 qDebug() << m_fileName;
46 readerName = defaultReaderList.identify(m_fileName.toStdString());
47 }
48 catch(std::runtime_error &error)
49 {
50 qDebug() << error.what() << " " << typeid(error).name();
51
52 throw PappsoException(
53 QObject::tr("libpwiz ERROR reading MS data file %1 "
54 "(std::runtime_error):\n%2\nsource file:%3 - source line:%4")
55 .arg(m_fileName)
56 .arg(error.what())
57 .arg(__FILE__)
58 .arg(__LINE__));
59 }
60 catch(std::exception &error)
61 {
62 qDebug() << error.what() << " " << typeid(error).name();
63
64 throw PappsoException(
65 QObject::tr("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 {
122 }
123 catch(std::runtime_error &error)
124 {
125 qDebug() << error.what() << " " << typeid(error).name();
126
127 throw PappsoException(
128 QObject::tr("libpwiz ERROR reading MS data file %1 "
129 "(std::runtime_error):\n%2\nsource file:%3 - source line:%4")
130 .arg(m_fileName)
131 .arg(error.what())
132 .arg(__FILE__)
133 .arg(__LINE__));
134 }
135 catch(std::exception &error)
136 {
137 qDebug() << error.what() << " " << typeid(error).name();
138
139 throw PappsoException(
140 QObject::tr("libpwiz ERROR reading MS data file %1 "
141 "(std::runtime_error):\n%2\nsource file:%3 - source line:%4")
142 .arg(m_fileName)
143 .arg(error.what())
144 .arg(__FILE__)
145 .arg(__LINE__));
146 }
147
148 // qDebug() << "The number of runs is:" << m_msDataPtrVector.size()
149 //<< "The reader type is:" << QString::fromStdString(readerName)
150 //<< "The number of spectra in first run is:"
151 //<< m_msDataPtrVector.at(0)->run.spectrumListPtr->size();
152
153 return m_msDataPtrVector.size();
154}
155
156
159{
160 // std::cout << __FILE__ << " @ " << __LINE__ << " " << __FUNCTION__ << " () "
161 // << std::setprecision(15) << "m_fileFormat: " << (int)m_fileFormat
162 // << std::endl;
163
164 return m_fileFormat;
165}
166
167
168std::vector<MsRunIdCstSPtr>
169PwizMsFileReader::getMsRunIds(const QString &run_prefix)
170{
171 std::vector<MsRunIdCstSPtr> ms_run_ids;
172
173 if(!initialize())
174 return ms_run_ids;
175
176 std::size_t iter = 0;
177
178 for(const pwiz::msdata::MSDataPtr &ms_data_ptr : m_msDataPtrVector)
179 {
180 MsRunId ms_run_id(m_fileName, QString::fromStdString(ms_data_ptr->run.id));
181
182 // Set the MS data format as determined in initialize().
183 ms_run_id.setMsDataFormat(m_fileFormat);
184
185 // We need to set the unambiguous xmlId string.
186 ms_run_id.setXmlId(QString("%1%2").arg(run_prefix).arg(Utils::getLexicalOrderedString(iter)));
187
188 // Now set the sample name to the run id : we can not do that, this is not the use sample name
189 // ms_run_id.setSampleName(QString::fromStdString(ms_data_ptr->run.id));
190
191 // And if it is possible, the real sample name because this one is for the
192 // end user to recognize his sample:
193 if(ms_data_ptr->run.samplePtr != nullptr)
194 {
195 ms_run_id.setSampleName(QString::fromStdString(ms_data_ptr->run.samplePtr->name));
196 }
197
198 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
199 //<< "Current ms_run_id:" << ms_run_id.toString();
200
201 // Finally make a shared pointer out of it and append it to the vector.
202 ms_run_ids.push_back(std::make_shared<MsRunId>(ms_run_id));
203
204 ++iter;
205 }
206
207 return ms_run_ids;
208}
209
210
211} // 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:167
static const QString getLexicalOrderedString(unsigned int num)
Definition utils.cpp:73
@ 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