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 ()
 

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 }

◆ ~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 151 of file pwizmsfilereader.cpp.

152 {
153  // std::cout << __FILE__ << " @ " << __LINE__ << " " << __FUNCTION__ << " () "
154  // << std::setprecision(15) << "m_fileFormat: " << (int)m_fileFormat
155  // << std::endl;
156 
157  return m_fileFormat;
158 }

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 162 of file pwizmsfilereader.cpp.

163 {
164  std::vector<MsRunIdCstSPtr> ms_run_ids;
165 
166  if(!initialize())
167  return ms_run_ids;
168 
169  std::size_t iter = 0;
170 
171  // If the initialization failed, then there is not a single MSDataPtr in the
172  // vector, so the loop below is not gone through.
173 
174  for(pwiz::msdata::MSDataPtr ms_data_ptr : m_msDataPtrVector)
175  {
176  // For each ms run in the file, we will create a MsRunId instance that
177  // will hold the file name of the data file
178 
179  // Finally create the MsRunId with the file name.
180  MsRunId ms_run_id(m_fileName, QString::fromStdString(ms_data_ptr->id));
181  ms_run_id.setMzFormat(m_fileFormat);
182 
183  // We need to set the unambiguous xmlId string.
184  ms_run_id.setXmlId(QString("%1%2")
185  .arg(run_prefix)
186  .arg(Utils::getLexicalOrderedString(iter)));
187 
188  // Now set the sample name to the run id :
189  ms_run_id.setSampleName(QString::fromStdString(ms_data_ptr->run.id));
190  // and if it is possible, the real sample name because this one is for the
191  // end user to recognize his sample:
192  if(ms_data_ptr->run.samplePtr != nullptr)
193  {
194  ms_run_id.setSampleName(
195  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 }

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

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 (std::runtime_error):\n%2")
55  .arg(m_fileName)
56  .arg(error.what()));
57  }
58  catch(std::exception &error)
59  {
60  qDebug() << error.what() << " " << typeid(error).name();
61 
62  throw PappsoException(
63  QObject::tr(
64  "libpwiz ERROR reading MS data file %1 (std::exception):\n%2")
65  .arg(m_fileName)
66  .arg(error.what()));
67  }
68 
69 
70  if(readerName.empty())
71  {
72  qDebug() << "Failed to identify the file.";
73 
74  return 0;
75  }
76 
77  // Now convert the string to MzFormat.
78  if(readerName == "mzML")
80  else if(readerName == "mzXML")
82  else if(readerName == "Mascot Generic")
84  else if(readerName == "MZ5")
86  else if(readerName == "MSn")
88  else if(readerName == "ABSciex WIFF")
90  else if(readerName == "ABSciex T2D")
92  else if(readerName == "Agilent MassHunter")
94  else if(readerName == "Thermo RAW")
96  else if(readerName == "Water RAW")
98  else if(readerName == "Bruker FID")
100  else if(readerName == "Bruker YEP")
102  else if(readerName == "Bruker BAF")
104  else
105  {
107  return 0;
108  }
109 
110  // std::cout << __FILE__ << " @ " << __LINE__ << " " << __FUNCTION__ << " () "
111  // << std::setprecision(15) << "m_fileFormat: " << (int)m_fileFormat
112  // << std::endl;
113 
114  // At this point we know pwiz could be able to read the file. Actually fill-in
115  // the MSDataPtr vector!
116  try
117  {
118  defaultReaderList.read(Utils::toUtf8StandardString(m_fileName),
120  }
121  catch(std::runtime_error &error)
122  {
123  qDebug() << error.what() << " " << typeid(error).name();
124 
125  throw PappsoException(
126  QObject::tr(
127  "libpwiz ERROR reading MS data file %1 (std::runtime_error):\n%2")
128  .arg(m_fileName)
129  .arg(error.what()));
130  }
131  catch(std::exception &error)
132  {
133  qDebug() << error.what() << " " << typeid(error).name();
134 
135  throw PappsoException(
136  QObject::tr(
137  "libpwiz ERROR reading MS data file %1 (std::exception):\n%2")
138  .arg(m_fileName)
139  .arg(error.what()));
140  }
141  qDebug() << "The number of runs is:" << m_msDataPtrVector.size()
142  << "The reader type is:" << QString::fromStdString(readerName)
143  << "The number of spectra in first run is:"
144  << m_msDataPtrVector.at(0)->run.spectrumListPtr->size();
145 
146  return m_msDataPtrVector.size();
147 }

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:
pappso::MzFormat::agilentMassHunter
@ agilentMassHunter
pappso::PwizMsFileReader::m_msDataPtrVector
std::vector< pwiz::msdata::MSDataPtr > m_msDataPtrVector
Definition: pwizmsfilereader.h:20
pappso::MzFormat::thermoRaw
@ thermoRaw
pappso::MzFormat::brukerYep
@ brukerYep
pappso::MzFormat::abSciexT2D
@ abSciexT2D
pappso::MzFormat::unknown
@ unknown
unknown format
pappso::MzFormat::mzXML
@ mzXML
mzXML
pappso::PwizMsFileReader::initialize
virtual std::size_t initialize()
Definition: pwizmsfilereader.cpp:40
pappso::MzFormat::mz5
@ mz5
pappso::Utils::toUtf8StandardString
static std::string toUtf8StandardString(const QString &text)
Definition: utils.cpp:136
pappso::MzFormat::msn
@ msn
pappso::MsFileReader::m_fileFormat
MzFormat m_fileFormat
Definition: msfilereader.h:18
pappso::MzFormat::abSciexWiff
@ abSciexWiff
pappso::MzFormat::brukerFid
@ brukerFid
pappso::MsFileReader::m_fileName
QString m_fileName
Definition: msfilereader.h:17
pappso::MsFileReader::MsFileReader
MsFileReader(const QString &file_name)
Definition: msfilereader.cpp:19
pappso::MzFormat::brukerBaf
@ brukerBaf
pappso::MzFormat::mzML
@ mzML
mzML
pappso::Utils::getLexicalOrderedString
static const QString getLexicalOrderedString(unsigned int num)
Definition: utils.cpp:73
pappso::MzFormat::watersRaw
@ watersRaw
pappso::MzFormat::MGF
@ MGF
Mascot format.