libpappsomspp
Library for mass spectrometry
pappso::PwizMsFileReader Class Reference

#include <pwizmsfilereader.h>

Inheritance diagram for pappso::PwizMsFileReader:
pappso::MsFileReader

Public Member Functions

 PwizMsFileReader (const QString &file_name)
 
virtual ~PwizMsFileReader ()
 
virtual MzFormat getFileFormat () override
 
virtual std::vector< MsRunIdCstSPtrgetMsRunIds (const QString &run_prefix) override
 

Private Member Functions

virtual std::size_t initialize ()
 
- Private Member Functions inherited from pappso::MsFileReader
 MsFileReader (const QString &file_name)
 
virtual ~MsFileReader ()
 
virtual MzFormat getFileFormat ()=0
 
virtual std::vector< MsRunIdCstSPtrgetMsRunIds (const QString &run_prefix)=0
 

Private Attributes

std::vector< pwiz::msdata::MSDataPtr > m_msDataPtrVector
 
- Private Attributes inherited from pappso::MsFileReader
QString m_fileName
 
MzFormat m_fileFormat = MzFormat::unknown
 

Detailed Description

Definition at line 17 of file pwizmsfilereader.h.

Constructor & Destructor Documentation

◆ PwizMsFileReader()

pappso::PwizMsFileReader::PwizMsFileReader ( const QString &  file_name)

Definition at line 28 of file pwizmsfilereader.cpp.

29 : MsFileReader{file_name}
30{
31}
MsFileReader(const QString &file_name)

◆ ~PwizMsFileReader()

pappso::PwizMsFileReader::~PwizMsFileReader ( )
virtual

Definition at line 34 of file pwizmsfilereader.cpp.

35{
36}

Member Function Documentation

◆ getFileFormat()

MzFormat pappso::PwizMsFileReader::getFileFormat ( )
overridevirtual

Implements pappso::MsFileReader.

Definition at line 163 of file pwizmsfilereader.cpp.

164{
165 // std::cout << __FILE__ << " @ " << __LINE__ << " " << __FUNCTION__ << " () "
166 // << std::setprecision(15) << "m_fileFormat: " << (int)m_fileFormat
167 // << std::endl;
168
169 return m_fileFormat;
170}

References pappso::MsFileReader::m_fileFormat.

Referenced by pappso::MsFileAccessor::getMsRunIds().

◆ getMsRunIds()

std::vector< MsRunIdCstSPtr > pappso::PwizMsFileReader::getMsRunIds ( const QString &  run_prefix)
overridevirtual

Implements pappso::MsFileReader.

Definition at line 174 of file pwizmsfilereader.cpp.

175{
176 std::vector<MsRunIdCstSPtr> ms_run_ids;
177
178 if(!initialize())
179 return ms_run_ids;
180
181 std::size_t iter = 0;
182
183 // If the initialization failed, then there is not a single MSDataPtr in the
184 // vector, so the loop below is not gone through.
185
186 for(pwiz::msdata::MSDataPtr ms_data_ptr : m_msDataPtrVector)
187 {
188 // For each ms run in the file, we will create a MsRunId instance that
189 // will hold the file name of the data file
190
191 // Finally create the MsRunId with the file name.
192 MsRunId ms_run_id(m_fileName, QString::fromStdString(ms_data_ptr->id));
193 ms_run_id.setMzFormat(m_fileFormat);
194
195 // We need to set the unambiguous xmlId string.
196 ms_run_id.setXmlId(QString("%1%2")
197 .arg(run_prefix)
199
200 // Now set the sample name to the run id :
201 ms_run_id.setSampleName(QString::fromStdString(ms_data_ptr->run.id));
202 // and if it is possible, the real sample name because this one is for the
203 // end user to recognize his sample:
204 if(ms_data_ptr->run.samplePtr != nullptr)
205 {
206 ms_run_id.setSampleName(
207 QString::fromStdString(ms_data_ptr->run.samplePtr->name));
208 }
209
210 //qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
211 //<< "Current ms_run_id:" << ms_run_id.toString();
212
213 // Finally make a shared pointer out of it and append it to the vector.
214 ms_run_ids.push_back(std::make_shared<MsRunId>(ms_run_id));
215
216 ++iter;
217 }
218
219 return ms_run_ids;
220}
std::vector< pwiz::msdata::MSDataPtr > m_msDataPtrVector
virtual std::size_t initialize()
static const QString getLexicalOrderedString(unsigned int num)
Definition: utils.cpp:52

References pappso::Utils::getLexicalOrderedString(), initialize(), pappso::MsFileReader::m_fileFormat, pappso::MsFileReader::m_fileName, m_msDataPtrVector, pappso::MsRunId::setMzFormat(), pappso::MsRunId::setSampleName(), and pappso::MsRunId::setXmlId().

Referenced by pappso::MsFileAccessor::getMsRunIds().

◆ initialize()

std::size_t pappso::PwizMsFileReader::initialize ( )
privatevirtual

Definition at line 40 of file pwizmsfilereader.cpp.

41{
42 pwiz::msdata::DefaultReaderList defaultReaderList;
43 std::string readerName;
44 try
45 {
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(
54 "libpwiz ERROR reading MS data file %1 "
55 "(std::runtime_error):\n%2\nsource file:%3 - source line:%4")
56 .arg(m_fileName)
57 .arg(error.what())
58 .arg(__FILE__)
59 .arg(__LINE__));
60 }
61 catch(std::exception &error)
62 {
63 qDebug() << error.what() << " " << typeid(error).name();
64
65 throw PappsoException(
66 QObject::tr(
67 "libpwiz ERROR reading MS data file %1 "
68 "(std::runtime_error):\n%2\nsource file:%3 - source line:%4")
69 .arg(m_fileName)
70 .arg(error.what())
71 .arg(__FILE__)
72 .arg(__LINE__));
73 }
74
75 if(readerName.empty())
76 {
77 qDebug() << "Failed to identify the file.";
78
79 return 0;
80 }
81
82 // Now convert the string to MzFormat.
83 if(readerName == "mzML")
85 else if(readerName == "mzXML")
87 else if(readerName == "Mascot Generic")
89 else if(readerName == "MZ5")
91 else if(readerName == "MSn")
93 else if(readerName == "ABSciex WIFF")
95 else if(readerName == "ABSciex T2D")
97 else if(readerName == "Agilent MassHunter")
99 else if(readerName == "Thermo RAW")
101 else if(readerName == "Water RAW")
103 else if(readerName == "Bruker FID")
105 else if(readerName == "Bruker YEP")
107 else if(readerName == "Bruker BAF")
109 else
110 {
112 return 0;
113 }
114
115 // std::cout << __FILE__ << " @ " << __LINE__ << " " << __FUNCTION__ << " () "
116 // << std::setprecision(15) << "m_fileFormat: " << (int)m_fileFormat
117 // << std::endl;
118
119 // At this point we know pwiz could be able to read the file. Actually fill-in
120 // the MSDataPtr vector!
121 try
122 {
123 defaultReaderList.read(Utils::toUtf8StandardString(m_fileName),
125 }
126 catch(std::runtime_error &error)
127 {
128 qDebug() << error.what() << " " << typeid(error).name();
129
130 throw PappsoException(
131 QObject::tr(
132 "libpwiz ERROR reading MS data file %1 "
133 "(std::runtime_error):\n%2\nsource file:%3 - source line:%4")
134 .arg(m_fileName)
135 .arg(error.what())
136 .arg(__FILE__)
137 .arg(__LINE__));
138 }
139 catch(std::exception &error)
140 {
141 qDebug() << error.what() << " " << typeid(error).name();
142
143 throw PappsoException(
144 QObject::tr(
145 "libpwiz ERROR reading MS data file %1 "
146 "(std::runtime_error):\n%2\nsource file:%3 - source line:%4")
147 .arg(m_fileName)
148 .arg(error.what())
149 .arg(__FILE__)
150 .arg(__LINE__));
151 }
152
153 //qDebug() << "The number of runs is:" << m_msDataPtrVector.size()
154 //<< "The reader type is:" << QString::fromStdString(readerName)
155 //<< "The number of spectra in first run is:"
156 //<< m_msDataPtrVector.at(0)->run.spectrumListPtr->size();
157
158 return m_msDataPtrVector.size();
159}
static std::string toUtf8StandardString(const QString &text)
Definition: utils.cpp:143
@ unknown
unknown format
@ MGF
Mascot format.

References pappso::abSciexT2D, pappso::abSciexWiff, pappso::agilentMassHunter, pappso::brukerBaf, pappso::brukerFid, pappso::brukerYep, pappso::MsFileReader::m_fileFormat, pappso::MsFileReader::m_fileName, m_msDataPtrVector, pappso::MGF, pappso::msn, pappso::mz5, pappso::mzML, pappso::mzXML, pappso::thermoRaw, pappso::Utils::toUtf8StandardString(), pappso::unknown, and pappso::watersRaw.

Referenced by getMsRunIds().

Member Data Documentation

◆ m_msDataPtrVector

std::vector<pwiz::msdata::MSDataPtr> pappso::PwizMsFileReader::m_msDataPtrVector
private

Definition at line 20 of file pwizmsfilereader.h.

Referenced by getMsRunIds(), and initialize().


The documentation for this class was generated from the following files: