libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
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 "
pappsomspp/core/exception/exceptionnotfound.h
"
19
#include "
pappsomspp/core/utils.h
"
20
#include "
pappsomspp/core/types.h
"
21
#include "
pappsomspp/core/msrun/msrunid.h
"
22
23
namespace
pappso
24
{
25
26
27
PwizMsFileReader::PwizMsFileReader
(
const
QString &file_name)
28
:
MsFileReader
{file_name}
29
{
30
}
31
32
PwizMsFileReader::~PwizMsFileReader
()
33
{
34
}
35
36
std::size_t
37
PwizMsFileReader::initialize
()
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"
)
82
m_fileFormat
=
Enums::MsDataFormat::mzML
;
83
else
if
(readerName ==
"mzXML"
)
84
m_fileFormat
=
Enums::MsDataFormat::mzXML
;
85
else
if
(readerName ==
"Mascot Generic"
)
86
m_fileFormat
=
Enums::MsDataFormat::MGF
;
87
else
if
(readerName ==
"MZ5"
)
88
m_fileFormat
=
Enums::MsDataFormat::mz5
;
89
else
if
(readerName ==
"MSn"
)
90
m_fileFormat
=
Enums::MsDataFormat::msn
;
91
else
if
(readerName ==
"ABSciex WIFF"
)
92
m_fileFormat
=
Enums::MsDataFormat::abSciexWiff
;
93
else
if
(readerName ==
"ABSciex T2D"
)
94
m_fileFormat
=
Enums::MsDataFormat::abSciexT2D
;
95
else
if
(readerName ==
"Agilent MassHunter"
)
96
m_fileFormat
=
Enums::MsDataFormat::agilentMassHunter
;
97
else
if
(readerName ==
"Thermo RAW"
)
98
m_fileFormat
=
Enums::MsDataFormat::thermoRaw
;
99
else
if
(readerName ==
"Water RAW"
)
100
m_fileFormat
=
Enums::MsDataFormat::watersRaw
;
101
else
if
(readerName ==
"Bruker FID"
)
102
m_fileFormat
=
Enums::MsDataFormat::brukerFid
;
103
else
if
(readerName ==
"Bruker YEP"
)
104
m_fileFormat
=
Enums::MsDataFormat::brukerYep
;
105
else
if
(readerName ==
"Bruker BAF"
)
106
m_fileFormat
=
Enums::MsDataFormat::brukerBaf
;
107
else
108
{
109
m_fileFormat
=
Enums::MsDataFormat::unknown
;
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
),
122
m_msDataPtrVector
);
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
159
Enums::MsDataFormat
160
PwizMsFileReader::getFileFormat
()
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
169
std::vector<MsRunIdCstSPtr>
170
PwizMsFileReader::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)
190
.arg(
Utils::getLexicalOrderedString
(iter)));
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
pappso::MsFileReader::MsFileReader
MsFileReader(const QString &file_name)
Definition
msfilereader.cpp:19
pappso::MsFileReader::m_fileFormat
Enums::MsDataFormat m_fileFormat
Definition
msfilereader.h:17
pappso::MsFileReader::m_fileName
QString m_fileName
Definition
msfilereader.h:16
pappso::MsRunId
MS run identity MsRunId identifies an MS run with a unique ID (XmlId) and contains eventually informa...
Definition
msrunid.h:54
pappso::MsRunId::setMsDataFormat
void setMsDataFormat(Enums::MsDataFormat format)
Definition
msrunid.cpp:168
pappso::MsRunId::setXmlId
void setXmlId(const QString &xml_id)
set an XML unique identifier for this MsRunId
Definition
msrunid.cpp:147
pappso::MsRunId::setSampleName
void setSampleName(const QString &name)
set a sample name for this MsRunId
Definition
msrunid.cpp:77
pappso::PappsoException
Definition
pappsoexception.h:41
pappso::PwizMsFileReader::getMsRunIds
virtual std::vector< MsRunIdCstSPtr > getMsRunIds(const QString &run_prefix) override
Definition
pwizmsfilereader.cpp:170
pappso::PwizMsFileReader::PwizMsFileReader
PwizMsFileReader(const QString &file_name)
Definition
pwizmsfilereader.cpp:27
pappso::PwizMsFileReader::getFileFormat
virtual Enums::MsDataFormat getFileFormat() override
Definition
pwizmsfilereader.cpp:160
pappso::PwizMsFileReader::m_msDataPtrVector
std::vector< pwiz::msdata::MSDataPtr > m_msDataPtrVector
Definition
pwizmsfilereader.h:20
pappso::PwizMsFileReader::initialize
virtual std::size_t initialize()
Definition
pwizmsfilereader.cpp:37
pappso::PwizMsFileReader::~PwizMsFileReader
virtual ~PwizMsFileReader()
Definition
pwizmsfilereader.cpp:32
pappso::Utils::toUtf8StandardString
static std::string toUtf8StandardString(const QString &text)
Definition
utils.cpp:166
pappso::Utils::getLexicalOrderedString
static const QString getLexicalOrderedString(unsigned int num)
Definition
utils.cpp:72
exceptionnotfound.h
msrunid.h
pappso::Enums::MsDataFormat
MsDataFormat
Definition
types.h:141
pappso::Enums::MsDataFormat::msn
@ msn
Definition
types.h:149
pappso::Enums::MsDataFormat::agilentMassHunter
@ agilentMassHunter
Definition
types.h:152
pappso::Enums::MsDataFormat::abSciexT2D
@ abSciexT2D
Definition
types.h:151
pappso::Enums::MsDataFormat::mzXML
@ mzXML
mzXML
Definition
types.h:144
pappso::Enums::MsDataFormat::watersRaw
@ watersRaw
Definition
types.h:154
pappso::Enums::MsDataFormat::mz5
@ mz5
Definition
types.h:148
pappso::Enums::MsDataFormat::brukerBaf
@ brukerBaf
Definition
types.h:157
pappso::Enums::MsDataFormat::mzML
@ mzML
mzML
Definition
types.h:143
pappso::Enums::MsDataFormat::abSciexWiff
@ abSciexWiff
Definition
types.h:150
pappso::Enums::MsDataFormat::brukerFid
@ brukerFid
Definition
types.h:155
pappso::Enums::MsDataFormat::unknown
@ unknown
unknown format
Definition
types.h:142
pappso::Enums::MsDataFormat::MGF
@ MGF
Mascot format.
Definition
types.h:145
pappso::Enums::MsDataFormat::thermoRaw
@ thermoRaw
Definition
types.h:153
pappso::Enums::MsDataFormat::brukerYep
@ brukerYep
Definition
types.h:156
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition
aa.cpp:39
pwizmsfilereader.h
types.h
utils.h
pappsomspp
core
msfile
pwizmsfilereader.cpp
Generated on
for libpappsomspp by
1.17.0