libpappsomspp
Library for mass spectrometry
pappso::PwizMsRunReader Class Reference

#include <pwizmsrunreader.h>

Inheritance diagram for pappso::PwizMsRunReader:
pappso::MsRunReader

Public Member Functions

 PwizMsRunReader (MsRunIdCstSPtr &msrun_id_csp)
 
virtual ~PwizMsRunReader ()
 
virtual MassSpectrumSPtr massSpectrumSPtr (std::size_t spectrum_index) override
 get a MassSpectrumSPtr class given its spectrum index More...
 
virtual MassSpectrumCstSPtr massSpectrumCstSPtr (std::size_t spectrum_index) override
 
virtual QualifiedMassSpectrum qualifiedMassSpectrum (std::size_t spectrum_index, bool want_binary_data=true) const override
 get a QualifiedMassSpectrum class given its scan number More...
 
virtual void readSpectrumCollection (SpectrumCollectionHandlerInterface &handler) override
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler More...
 
virtual std::size_t spectrumListSize () const override
 get the totat number of spectrum conained in the MSrun data file More...
 
virtual bool hasScanNumbers () const override
 tells if spectra can be accessed using scan numbers by default, it returns false. Only overrided functions can check if scan numbers are available in the current file More...
 
virtual bool releaseDevice () override
 release data back end device if a the data back end is released, the developper has to use acquireDevice before using the msrunreader object More...
 
virtual bool acquireDevice () override
 acquire data back end device More...
 
- Public Member Functions inherited from pappso::MsRunReader
 MsRunReader (MsRunIdCstSPtr &ms_run_id)
 
 MsRunReader (const MsRunReader &other)
 
virtual ~MsRunReader ()
 
const MsRunIdCstSPtrgetMsRunId () const
 
virtual std::size_t scanNumber2SpectrumIndex (std::size_t scan_number)
 if possible, converts a scan number into a spectrum index This is a convenient function to help transition from the old scan number (not implemented by all vendors) to more secure spectrum index (not vendor dependant). It is better to not rely on this function. More...
 

Protected Member Functions

virtual void initialize () override
 
virtual bool accept (const QString &file_name) const override
 tells if the reader is able to handle this file must be implemented by private MS run reader, specific of one or more file format More...
 
bool processRetentionTime (pwiz::msdata::Spectrum *spectrum_p, QualifiedMassSpectrum &qualified_mass_spectrum) const
 
bool processDriftTime (pwiz::msdata::Spectrum *spectrum_p, QualifiedMassSpectrum &qualified_mass_spectrum) const
 
QualifiedMassSpectrum qualifiedMassSpectrumFromPwizMSData (std::size_t spectrum_index, bool want_binary_data, bool &ok) const
 
QualifiedMassSpectrum qualifiedMassSpectrumFromPwizSpectrumPtr (const MassSpectrumId &massSpectrumId, pwiz::msdata::Spectrum *spectrum_p, bool want_binary_data, bool &ok) const
 
pwiz::msdata::SpectrumPtr getPwizSpectrumPtr (pwiz::msdata::SpectrumList *p_spectrum_list, std::size_t spectrum_index, bool want_binary_data) const
 

Protected Attributes

pwiz::msdata::MSDataPtr msp_msData = nullptr
 
- Protected Attributes inherited from pappso::MsRunReader
MsRunIdCstSPtr mcsp_msRunId
 
MsRunReaderScanNumberMultiMapmpa_multiMapScanNumber = nullptr
 

Private Attributes

bool m_hasScanNumbers = false
 

Friends

class MsFileAccessor
 

Detailed Description

Definition at line 66 of file pwizmsrunreader.h.

Constructor & Destructor Documentation

◆ PwizMsRunReader()

pappso::PwizMsRunReader::PwizMsRunReader ( MsRunIdCstSPtr msrun_id_csp)

Definition at line 74 of file pwizmsrunreader.cpp.

85  {

◆ ~PwizMsRunReader()

pappso::PwizMsRunReader::~PwizMsRunReader ( )
virtual

Definition at line 192 of file pwizmsrunreader.cpp.

194  :\n%2")

Member Function Documentation

◆ accept()

bool pappso::PwizMsRunReader::accept ( const QString &  file_name) const
overrideprotectedvirtual

tells if the reader is able to handle this file must be implemented by private MS run reader, specific of one or more file format

Implements pappso::MsRunReader.

Definition at line 753 of file pwizmsrunreader.cpp.

755 {
756  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
757  return qualifiedMassSpectrum(spectrum_index, true).getMassSpectrumCstSPtr();
758 }
759 
760 QualifiedMassSpectrum
761 PwizMsRunReader::qualifiedMassSpectrum(std::size_t spectrum_index,
762  bool want_binary_data) const
763 {
764 

References pappso::QualifiedMassSpectrum::getMassSpectrumCstSPtr(), and qualifiedMassSpectrum().

◆ acquireDevice()

bool pappso::PwizMsRunReader::acquireDevice ( )
overridevirtual

acquire data back end device

Returns
bool true if done

Implements pappso::MsRunReader.

Definition at line 956 of file pwizmsrunreader.cpp.

◆ getPwizSpectrumPtr()

pwiz::msdata::SpectrumPtr pappso::PwizMsRunReader::getPwizSpectrumPtr ( pwiz::msdata::SpectrumList *  p_spectrum_list,
std::size_t  spectrum_index,
bool  want_binary_data 
) const
protected

Definition at line 198 of file pwizmsrunreader.cpp.

199  {
200  qDebug() << "getPwizSpectrumPtr error " << error.what()
201  << typeid(error).name();
202 
203  throw ExceptionNotFound(
204  QObject::tr("Pwiz spectrum index %1 not found in MS file :\n%2")
205  .arg(spectrum_index)
206  .arg(error.what()));
207  }
208 
209  if(native_pwiz_spectrum_sp.get() == nullptr)
210  {
211  throw ExceptionNotFound(
212  QObject::tr(
213  "Pwiz spectrum index %1 not found in MS file : null pointer")
214  .arg(spectrum_index));
215  }
216 
217  return native_pwiz_spectrum_sp;
218 }
219 
220 
221 bool
223  pwiz::msdata::Spectrum *spectrum_p,
224  QualifiedMassSpectrum &qualified_mass_spectrum) const
225 {
226 
227  // We now have to set the retention time at which this mass spectrum
228  // was acquired. This is the scan start time.
229 
230  if(!spectrum_p->scanList.scans[0].hasCVParam(
231  pwiz::msdata::MS_scan_start_time))
232  {
233  if(mcsp_msRunId.get()->getMzFormat() == MzFormat::MGF)
234  { // MGF could not have scan start time
235  qualified_mass_spectrum.setRtInSeconds(-1);
236  }
237  else
238  {
239  throw(ExceptionNotPossible(

◆ hasScanNumbers()

bool pappso::PwizMsRunReader::hasScanNumbers ( ) const
overridevirtual

tells if spectra can be accessed using scan numbers by default, it returns false. Only overrided functions can check if scan numbers are available in the current file

Reimplemented from pappso::MsRunReader.

Definition at line 943 of file pwizmsrunreader.cpp.

◆ initialize()

void pappso::PwizMsRunReader::initialize ( )
overrideprotectedvirtual

Implements pappso::MsRunReader.

Definition at line 86 of file pwizmsrunreader.cpp.

89  {
90  qDebug() << QString("Failed to read the data from file %1")
91  .arg(QString::fromStdString(file_name_std));
92 
93  throw(PappsoException(
94  QString("Error reading file %1 in PwizMsRunReader, for msrun %2:\n%3")
95  .arg(mcsp_msRunId->getFileName())
96  .arg(mcsp_msRunId.get()->toString())
97  .arg(error.what())));
98  }
99 
100  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
101  //<< "The number of runs is:" << msDataPtrVector.size()
102  //<< "The number of spectra in first run is:"
103  //<< msDataPtrVector.at(0)->run.spectrumListPtr->size();
104 
105  // Single-run file handling here.
106 
107  // Specific case of the MGF data format: we do not have a run id for that kind
108  // of data. In this case there must be a single run!
109 
110  if(mcsp_msRunId->getRunId().isEmpty())
111  {
112  if(msDataPtrVector.size() != 1)
113  throw(
114  ExceptionNotPossible("For the kind of file at hand there can only be "
115  "one run in the file."));
116 
117  // At this point we know the single msDataPtr is the one we are looking
118  // for.
119 
120  msp_msData = msDataPtrVector.front();
121  }
122 
123  else
124  {
125  // Multi-run file handling here.
126  for(auto &msDataPtr : msDataPtrVector)
127  {
128  if(msDataPtr->run.id == mcsp_msRunId->getRunId().toStdString())
129  {
130  msp_msData = msDataPtr;
131 
132  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
133  //<< "Found the right MSDataPtr for run id.";
134 
135  break;
136  }
137  }
138  }
139 
140  if(msp_msData == nullptr)
141  {
142  throw(ExceptionNotPossible(
143  QString("Could not find a MSDataPtr matching the requested run id : %1")
144  .arg(mcsp_msRunId.get()->toString())));
145  }
146 
147 
148  // check if this MS run can be used with scan numbers
149  // MS:1000490 Agilent instrument model
150  pwiz::cv::CVID native_id_format =
151  pwiz::msdata::id::getDefaultNativeIDFormat(*msp_msData.get());
152 
153  // msp_msData.get()->getDefaultNativeIDFormat();
154 
155  if(native_id_format == pwiz::cv::CVID::MS_Thermo_nativeID_format)
156  {
157  m_hasScanNumbers = true;
158  }
159  else
160  {
161  m_hasScanNumbers = false;
162  }
163 
164  if(mcsp_msRunId.get()->getMzFormat() == MzFormat::mzXML)
165  {
166  m_hasScanNumbers = true;
167  }
168 }
169 
170 
172 {
173 }
174 
175 
176 pwiz::msdata::SpectrumPtr
177 PwizMsRunReader::getPwizSpectrumPtr(pwiz::msdata::SpectrumList *p_spectrum_list,
178  std::size_t spectrum_index,
179  bool want_binary_data) const
180 {
181  pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp;
182 
183  try
184  {
185  native_pwiz_spectrum_sp =
186  p_spectrum_list->spectrum(spectrum_index, want_binary_data);
187  }
188  catch(std::runtime_error &error)
189  {

Referenced by spectrumListSize().

◆ massSpectrumCstSPtr()

pappso::MassSpectrumCstSPtr pappso::PwizMsRunReader::massSpectrumCstSPtr ( std::size_t  spectrum_index)
overridevirtual

Implements pappso::MsRunReader.

Definition at line 775 of file pwizmsrunreader.cpp.

◆ massSpectrumSPtr()

pappso::MassSpectrumSPtr pappso::PwizMsRunReader::massSpectrumSPtr ( std::size_t  spectrum_index)
overridevirtual

get a MassSpectrumSPtr class given its spectrum index

Implements pappso::MsRunReader.

Definition at line 768 of file pwizmsrunreader.cpp.

772  {

◆ processDriftTime()

bool pappso::PwizMsRunReader::processDriftTime ( pwiz::msdata::Spectrum *  spectrum_p,
QualifiedMassSpectrum qualified_mass_spectrum 
) const
protected

Definition at line 311 of file pwizmsrunreader.cpp.

331  {
332  // qDebug() << "detected as nan or inf.";
333 
334  return false;
335  }
336  else
337  {
338  // The mzML standard stipulates that drift times are in
339  // milliseconds.
340  qualified_mass_spectrum.setDtInMilliSeconds(driftTime);
341  }
342  }
343  // End of
344  // if(spectrum_p->scanList.scans[0].hasCVParam(
345  // pwiz::msdata::MS_ion_mobility_drift_time))
346  else
347  {
348  // Not a bogus mass spectrum but also not a drift spectrum, set -1
349  // as the drift time value.
350  qualified_mass_spectrum.setDtInMilliSeconds(-1);
351  }
352 
353  return true;
354 }
355 
356 
357 QualifiedMassSpectrum
359  const MassSpectrumId &massSpectrumId,
360  pwiz::msdata::Spectrum *spectrum_p,
361  bool want_binary_data,
362  bool &ok) const
363 {
364  // qDebug();
365 
366  std::string env;
367  env = setlocale(LC_ALL, "");
368  setlocale(LC_ALL, "C");
369 
370  QualifiedMassSpectrum qualified_mass_spectrum(massSpectrumId);
371 
372  try
373  {
374 
375  // We want to store the ms level for this spectrum

◆ processRetentionTime()

bool pappso::PwizMsRunReader::processRetentionTime ( pwiz::msdata::Spectrum *  spectrum_p,
QualifiedMassSpectrum qualified_mass_spectrum 
) const
protected

Definition at line 243 of file pwizmsrunreader.cpp.

244  {
245  pwiz::data::CVParam retention_time_cv_param =
246  spectrum_p->scanList.scans[0].cvParam(pwiz::msdata::MS_scan_start_time);
247 
248  // Try to get the units of the retention time value.
249 
250  std::string unit_name = retention_time_cv_param.unitsName();
251  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
252  //<< "Unit name for the retention time:"
253  //<< QString::fromStdString(unit_name);
254 
255  if(unit_name == "second")
256  {
257  qualified_mass_spectrum.setRtInSeconds(
258  retention_time_cv_param.valueAs<double>());
259  }
260  else if(unit_name == "minute")
261  {
262  qualified_mass_spectrum.setRtInSeconds(
263  retention_time_cv_param.valueAs<double>() * 60);
264  }
265  else
266  throw(
267  ExceptionNotPossible("Could not determine the unit for the "
268  "scan start time value."));
269  }
270 
271  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
272  //<< "Retention time for spectrum is:"
273  //<< qualified_mass_spectrum.getRtInSeconds();
274 
275  // Old version not checking unit (by default unit is minutes for RT,
276  // not seconds)
277  //
278  // pappso_double retentionTime =
279  // QString(spectrum_p->scanList.scans[0]
280  //.cvParam(pwiz::msdata::MS_scan_start_time)
281  //.value.c_str())
282  //.toDouble();
283  // qualified_mass_spectrum.setRtInSeconds(retentionTime);
284 
285  return true;
286 }
287 
288 
289 bool
291  pwiz::msdata::Spectrum *spectrum_p,
292  QualifiedMassSpectrum &qualified_mass_spectrum) const
293 {
294  // Not all the acquisitions have ion mobility data. We need to test
295  // that:
296 
297  if(spectrum_p->scanList.scans[0].hasCVParam(
298  pwiz::msdata::MS_ion_mobility_drift_time))
299  {
300 
301  // qDebug() << "as strings:"
302  //<< QString::fromStdString(
303  // spectrum_p->scanList.scans[0]
304  //.cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
305  //.valueAs<std::string>());
306 
307  pappso_double driftTime =

◆ qualifiedMassSpectrum()

QualifiedMassSpectrum pappso::PwizMsRunReader::qualifiedMassSpectrum ( std::size_t  spectrum_index,
bool  want_binary_data = true 
) const
overridevirtual

get a QualifiedMassSpectrum class given its scan number

Implements pappso::MsRunReader.

Definition at line 782 of file pwizmsrunreader.cpp.

789 {
790 
791  acquireDevice();
792  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()";
793 
794  // We want to iterate in the pwiz-spectrum-list and for each pwiz-spectrum
795  // create a pappso-spectrum (QualifiedMassSpectrum). Once the pappso mass
796  // spectrum has been fully qualified (that is, the member data have been
797  // set), it is transferred to the handler passed as parameter to this
798  // function for the consumer to do what it wants with it.
799 
800  // Does the handler consuming the mass spectra read from file want these
801  // mass spectra to hold the binary data arrays (mz/i vectors)?
802 
803  const bool want_binary_data = handler.needPeakList();
804 

Referenced by accept().

◆ qualifiedMassSpectrumFromPwizMSData()

QualifiedMassSpectrum pappso::PwizMsRunReader::qualifiedMassSpectrumFromPwizMSData ( std::size_t  spectrum_index,
bool  want_binary_data,
bool &  ok 
) const
protected

Definition at line 699 of file pwizmsrunreader.cpp.

707  {
708  setlocale(LC_ALL, env.c_str());
709  throw ExceptionNotFound(
710  QObject::tr("The spectrum index cannot be equal to the size of the "
711  "spectrum list."));
712  }
713 
714  // At this point we know the spectrum index might be sane, so store it in
715  // the mass spec id object.
716  massSpectrumId.setSpectrumIndex(spectrum_index);
717 
718  pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
719  getPwizSpectrumPtr(spectrum_list_p.get(), spectrum_index, want_binary_data);
720 
721  setlocale(LC_ALL, env.c_str());
722 
723  massSpectrumId.setNativeId(
724  QString::fromStdString(native_pwiz_spectrum_sp->id));
725 
727  massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
728 }
729 
730 
731 bool
732 PwizMsRunReader::accept(const QString &file_name) const
733 {
734  // We want to know if we can handle the file_name.
735  pwiz::msdata::ReaderList reader_list;
736 
737  std::string reader_type = reader_list.identify(file_name.toStdString());
738 
739  if(!reader_type.empty())
740  return true;
741 
742  return false;
743 }
744 
745 
747 PwizMsRunReader::massSpectrumSPtr(std::size_t spectrum_index)
748 {
749  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;

◆ qualifiedMassSpectrumFromPwizSpectrumPtr()

QualifiedMassSpectrum pappso::PwizMsRunReader::qualifiedMassSpectrumFromPwizSpectrumPtr ( const MassSpectrumId massSpectrumId,
pwiz::msdata::Spectrum *  spectrum_p,
bool  want_binary_data,
bool &  ok 
) const
protected

Definition at line 379 of file pwizmsrunreader.cpp.

393  {
394 
395  // Sanity check
396  if(msLevel < 2)
397  {
398  qDebug() << "Going to throw: msLevel cannot be less than two for "
399  "a spectrum that has items in its Precursor list.";
400 
401  throw(ExceptionNotPossible(
402  "msLevel cannot be less than two for "
403  "a spectrum that has items in its Precursor list."));
404  }
405 
406  // See what is the first precursor in the list.
407 
408  for(auto &precursor : spectrum_p->precursors)
409  {
410 
411  // Set this variable ready as we need that default value in
412  // certain circumstances.
413 
414  std::size_t precursor_spectrum_index =
415  std::numeric_limits<std::size_t>::max();
416 
417  // The spectrum ID of the precursor might be empty.
418 
419  if(precursor.spectrumID.empty())
420  {
421  // qDebug() << "The precursor's spectrum ID is empty.";
422 
423  if(mcsp_msRunId.get()->getMzFormat() == MzFormat::MGF)
424  {
425  // qDebug()
426  //<< "Format is MGF, precursor's spectrum ID can be
427  // empty.";
428  }
429  else
430  {
431  // When performing Lumos Fusion fragmentation experiments
432  // in Tune mode and with recording, the first spectrum of
433  // the list is a fragmentation spectrum (ms level 2) that
434  // has no identity for the precursor spectrum because
435  // there is no full scan accquisition.
436  }
437  }
438  // End of
439  // if(precursor.spectrumID.empty())
440  else
441  {
442  // We could get a native precursor spectrum id, so convert
443  // that native id to a spectrum index.
444 
445  qualified_mass_spectrum.setPrecursorNativeId(
446  QString::fromStdString(precursor.spectrumID));
447 
448  if(qualified_mass_spectrum.getPrecursorNativeId().isEmpty())
449  {
450  // qDebug() << "The native id of the precursor spectrum is
451  // empty.";
452  }
453 
454  // Get the spectrum index of the spectrum that contained the
455  // precursor ion.
456 
457  precursor_spectrum_index =
458  msp_msData->run.spectrumListPtr->find(precursor.spectrumID);
459 
460  // Note that the Mascot MGF format has a peculiar handling of
461  // the precursor ion stuff so we cannot throw.
462  if(precursor_spectrum_index ==
463  msp_msData->run.spectrumListPtr->size())
464  {
465  if(mcsp_msRunId.get()->getMzFormat() != MzFormat::MGF)
466  {
467  throw(ExceptionNotPossible(
468  "Failed to find the index of the "
469  "precursor ion's spectrum."));
470  }
471  }
472 
473  qualified_mass_spectrum.setPrecursorSpectrumIndex(
474  precursor_spectrum_index);
475 
476  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ <<
477  // "()"
478  //<< "Set the precursor spectrum index to:"
479  //<< qualified_mass_spectrum.getPrecursorSpectrumIndex()
480  //<< "for qualified mass spectrum:"
481  //<< &qualified_mass_spectrum;
482  }
483 
484  if(!precursor.selectedIons.size())
485  {
486  qDebug()
487  << "Going to throw The spectrum has msLevel > 1 but the "
488  "precursor ions's selected ions list is empty..";
489 
490  throw(
491  ExceptionNotPossible("The spectrum has msLevel > 1 but the "
492  "precursor ions's selected ions "
493  "list is empty."));
494  }
495 
496  pwiz::msdata::SelectedIon &ion =
497  *(precursor.selectedIons.begin());
498 
499  // selected ion m/z
500 
501  pappso_double selected_ion_mz =
502  QString(
503  ion.cvParam(pwiz::cv::MS_selected_ion_m_z).value.c_str())
504  .toDouble();
505 
506  // selected ion peak intensity
507 
508  pappso_double selected_ion_peak_intensity =
509  QString(ion.cvParam(pwiz::cv::MS_peak_intensity).value.c_str())
510  .toDouble();
511 
512  // charge state
513 
514  unsigned int selected_ion_charge_state =
515  QString(ion.cvParam(pwiz::cv::MS_charge_state).value.c_str())
516  .toUInt();
517 
518  // At this point we can craft a new PrecursorIonData instance and
519  // push it back to the vector.
520 
521  PrecursorIonData precursor_ion_data(selected_ion_mz,
522  selected_ion_charge_state,
523  selected_ion_peak_intensity);
524 
525  qualified_mass_spectrum.appendPrecursorIonData(
526  precursor_ion_data);
527 
528  // General sum-up
529 
530  // qDebug()
531  //<< "Appended new PrecursorIonData:"
532  //<< "mz:"
533  //<< qualified_mass_spectrum.getPrecursorIonData().back().mz
534  //<< "charge:"
535  //<< qualified_mass_spectrum.getPrecursorIonData().back().charge
536  //<< "intensity:"
537  //<< qualified_mass_spectrum.getPrecursorIonData()
538  //.back()
539  //.intensity;
540  }
541  // End of
542  // for(auto &precursor : spectrum_p->precursors)
543  }
544  // End of
545  // if(precursor_list_size > 0)
546  else
547  {
548  // Sanity check
549 
550  // Unfortunately, logic here is defeated by some vendors that have
551  // files with MS2 spectra without <precursorList>. Thus we have
552  // spectrum_p->precursors.size() == 0 and msLevel > 1.
553 
554  // if(msLevel != 1)
555  //{
556  // throw(
557  // ExceptionNotPossible("msLevel cannot be different than 1 if "
558  //"there is not a single precursor ion."));
559  //}
560  }
561 
562  // Sanity check.
563 
564  if(precursor_list_size !=
565  qualified_mass_spectrum.getPrecursorIonData().size())
566  {
567  qDebug() << "Going to throw The number of precursors in the file is "
568  "different from the number of precursors in memory.";
569 
571  QObject::tr("The number of precursors in the file is different "
572  "from the number of precursors in memory."));
573  }
574 
575  // if(precursor_list_size == 1)
576  //{
577  // qDebug() << "Trying to get the mz value of the unique precursor ion:"
578  //<< qualified_mass_spectrum.getPrecursorMz();
579  //}
580 
581  processRetentionTime(spectrum_p, qualified_mass_spectrum);
582 
583  processDriftTime(spectrum_p, qualified_mass_spectrum);
584 
585  // for(pwiz::data::CVParam cv_param : ion.cvParams)
586  //{
587  // pwiz::msdata::CVID param_id = cv_param.cvid;
588  // qDebug() << param_id;
589  // qDebug() << cv_param.cvid.c_str();
590  // qDebug() << cv_param.name().c_str();
591  // qDebug() << cv_param.value.c_str();
592  //}
593 
594  if(want_binary_data)
595  {
596 
597  // Fill-in MZIntensityPair vector for convenient access to binary
598  // data
599 
600  std::vector<pwiz::msdata::MZIntensityPair> pairs;
601  spectrum_p->getMZIntensityPairs(pairs);
602 
603  MassSpectrum spectrum;
604  double tic = 0;
605  // std::size_t iterCount = 0;
606 
607  // Iterate through the m/z-intensity pairs
608  for(std::vector<pwiz::msdata::MZIntensityPair>::const_iterator
609  it = pairs.begin(),
610  end = pairs.end();
611  it != end;
612  ++it)
613  {
614  //++iterCount;
615 
616  // qDebug() << "it->mz " << it->mz << " it->intensity" <<
617  // it->intensity;
618  if(it->intensity)
619  {
620  spectrum.push_back(DataPoint(it->mz, it->intensity));
621  tic += it->intensity;
622  }
623  }
624 
625  if(mcsp_msRunId.get()->getMzFormat() == MzFormat::MGF)
626  {
627  // Sort peaks by mz
628  spectrum.sortMz();
629  }
630 
631  // lc = localeconv ();
632  // qDebug() << " env=" << localeconv () << " lc->decimal_point "
633  // << lc->decimal_point;
634  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()
635  // "<< spectrum.size();
636  MassSpectrumSPtr spectrum_sp = spectrum.makeMassSpectrumSPtr();
637  qualified_mass_spectrum.setMassSpectrumSPtr(spectrum_sp);
638 
639  // double sumY =
640  // qualified_mass_spectrum.getMassSpectrumSPtr()->sumY(); qDebug()
641  // <<
642  // __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
643  //<< "iterCount:" << iterCount << "Spectrum size "
644  //<< spectrum.size() << "with tic:" << tic
645  //<< "and sumY:" << sumY;
646  }
647  else
648  qualified_mass_spectrum.setMassSpectrumSPtr(nullptr);
649  }
650  catch(PappsoException &errorp)
651  {
652  qDebug() << "Going to throw";
653 
655  QObject::tr("Error reading data using the proteowizard library: %1")
656  .arg(errorp.qwhat()));
657  }
658  catch(std::exception &error)
659  {
660  qDebug() << "Going to throw";
661 
663  QObject::tr("Error reading data using the proteowizard library: %1")
664  .arg(error.what()));
665  }
666 
667  // setlocale(LC_ALL, env.c_str());
668 
669  ok = true;
670 
671  // qDebug() << "QualifiedMassSpectrum: " <<
672  // qualified_mass_spectrum.toString();
673  return qualified_mass_spectrum;
674 }
675 
676 
677 QualifiedMassSpectrum
679  bool want_binary_data,
680  bool &ok) const
681 {
682 
683  std::string env;
684  env = setlocale(LC_ALL, "");
685  // struct lconv *lc = localeconv();
686 
687  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
688  //<< "env=" << env.c_str()
689  //<< "lc->decimal_point:" << lc->decimal_point;
690 
691  setlocale(LC_ALL, "C");
692 
693  MassSpectrumId massSpectrumId(mcsp_msRunId);
694 
695  if(msp_msData == nullptr)

References pappso::MsRunReader::mcsp_msRunId, pappso::MGF, and msp_msData.

◆ readSpectrumCollection()

void pappso::PwizMsRunReader::readSpectrumCollection ( SpectrumCollectionHandlerInterface handler)
overridevirtual

function to visit an MsRunReader and get each Spectrum in a spectrum collection handler

Implements pappso::MsRunReader.

Definition at line 808 of file pwizmsrunreader.cpp.

829  {
830 
831  // If the user of this reader instance wants to stop reading the
832  // spectra, then break this loop.
833  if(handler.shouldStop())
834  {
835  qDebug() << "The operation was cancelled. Breaking the loop.";
836  break;
837  }
838 
839  // Get the native pwiz-spectrum from the spectrum list.
840  // Note that this pointer is a shared pointer from pwiz.
841 
842  pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
843  getPwizSpectrumPtr(spectrum_list_p.get(), iter, want_binary_data);
844 
845  /*
846  * we want to load metadata of the spectrum even if it does not contain
847  peaks
848 
849  * if(!native_pwiz_spectrum_sp->hasBinaryData())
850  {
851  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ <<
852  "
853  ()"
854  //<< "native pwiz spectrum is empty, continuing.";
855  continue;
856  }
857  */
858 
859  // Instantiate the mass spectrum id that will hold critical information
860  // like the the native id string and the spectrum index.
861 
862  MassSpectrumId massSpectrumId(mcsp_msRunId, iter /* spectrum index*/);
863 
864  // Get the spectrum native id as a QString to store it in the mass
865  // spectrum id class. This is will allow later to refer to the same
866  // spectrum starting back from the file.
867 
868  QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
869  massSpectrumId.setNativeId(native_id);
870 
871  // Finally, instantiate the qualified mass spectrum with its id. This
872  // function will continue performing pappso-spectrum detailed
873  // qualification.
874 
875  bool ok = false;
876 
877  QualifiedMassSpectrum qualified_mass_spectrum =
879  massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
880 
881  if(!ok)
882  {
883  // qDebug() << "Encountered a mass spectrum for which the returned "
884  //"status is bad.";
885  continue;
886  }
887 
888  // Before handing the mass spectrum out to the handler, see if the
889  // native mass spectrum was empty or not.
890 
891  // if(!native_pwiz_spectrum_sp->defaultArrayLength)
892  // qDebug() << "The mass spectrum has not defaultArrayLength";
893 
894  qualified_mass_spectrum.setEmptyMassSpectrum(
895  !native_pwiz_spectrum_sp->defaultArrayLength);
896 
897  // The handler will receive the index of the mass spectrum in the
898  // current run via the mass spectrum id member datum.
899  handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
900  }
901 
902  setlocale(LC_ALL, env.c_str());
903  // End of
904  // for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
905 
906  // Now let the loading handler know that the loading of the data has ended.
907  // The handler might need this "signal" to perform additional tasks or to
908  // cleanup cruft.
909 
910  // qDebug() << "Loading ended";
911  handler.loadingEnded();
912 }
913 
914 
915 std::size_t
917 {
918  return msp_msData->run.spectrumListPtr.get()->size();
919 }
920 
921 bool
923 {
924  return m_hasScanNumbers;
925 }
926 
927 bool
929 {
930  msp_msData = nullptr;
931  return true;
932 }
933 

◆ releaseDevice()

bool pappso::PwizMsRunReader::releaseDevice ( )
overridevirtual

release data back end device if a the data back end is released, the developper has to use acquireDevice before using the msrunreader object

Returns
bool true if done

Implements pappso::MsRunReader.

Definition at line 949 of file pwizmsrunreader.cpp.

◆ spectrumListSize()

std::size_t pappso::PwizMsRunReader::spectrumListSize ( ) const
overridevirtual

get the totat number of spectrum conained in the MSrun data file

Implements pappso::MsRunReader.

Definition at line 937 of file pwizmsrunreader.cpp.

938  {
939  initialize();
940  }

References initialize().

Friends And Related Function Documentation

◆ MsFileAccessor

friend class MsFileAccessor
friend

Definition at line 89 of file pwizmsrunreader.h.

Member Data Documentation

◆ m_hasScanNumbers

bool pappso::PwizMsRunReader::m_hasScanNumbers = false
private

Definition at line 142 of file pwizmsrunreader.h.

◆ msp_msData

pwiz::msdata::MSDataPtr pappso::PwizMsRunReader::msp_msData = nullptr
protected

Definition at line 116 of file pwizmsrunreader.h.

Referenced by qualifiedMassSpectrumFromPwizSpectrumPtr().


The documentation for this class was generated from the following files:
pappso::PwizMsRunReader::initialize
virtual void initialize() override
Definition: pwizmsrunreader.cpp:86
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:69
pappso::PwizMsRunReader::qualifiedMassSpectrumFromPwizMSData
QualifiedMassSpectrum qualifiedMassSpectrumFromPwizMSData(std::size_t spectrum_index, bool want_binary_data, bool &ok) const
Definition: pwizmsrunreader.cpp:699
pappso::PwizMsRunReader::m_hasScanNumbers
bool m_hasScanNumbers
Definition: pwizmsrunreader.h:142
pappso::PwizMsRunReader::hasScanNumbers
virtual bool hasScanNumbers() const override
tells if spectra can be accessed using scan numbers by default, it returns false. Only overrided func...
Definition: pwizmsrunreader.cpp:943
pappso::PwizMsRunReader::massSpectrumSPtr
virtual MassSpectrumSPtr massSpectrumSPtr(std::size_t spectrum_index) override
get a MassSpectrumSPtr class given its spectrum index
Definition: pwizmsrunreader.cpp:768
pappso::PwizMsRunReader::qualifiedMassSpectrumFromPwizSpectrumPtr
QualifiedMassSpectrum qualifiedMassSpectrumFromPwizSpectrumPtr(const MassSpectrumId &massSpectrumId, pwiz::msdata::Spectrum *spectrum_p, bool want_binary_data, bool &ok) const
Definition: pwizmsrunreader.cpp:379
pappso::PwizMsRunReader::~PwizMsRunReader
virtual ~PwizMsRunReader()
Definition: pwizmsrunreader.cpp:192
pappso::PwizMsRunReader::acquireDevice
virtual bool acquireDevice() override
acquire data back end device
Definition: pwizmsrunreader.cpp:956
pappso::MsRunReader::mcsp_msRunId
MsRunIdCstSPtr mcsp_msRunId
Definition: msrunreader.h:241
pappso::MzFormat::mzXML
@ mzXML
mzXML
pappso::PwizMsRunReader::processRetentionTime
bool processRetentionTime(pwiz::msdata::Spectrum *spectrum_p, QualifiedMassSpectrum &qualified_mass_spectrum) const
Definition: pwizmsrunreader.cpp:243
pappso::PwizMsRunReader::processDriftTime
bool processDriftTime(pwiz::msdata::Spectrum *spectrum_p, QualifiedMassSpectrum &qualified_mass_spectrum) const
Definition: pwizmsrunreader.cpp:311
pappso::QualifiedMassSpectrum::getMassSpectrumCstSPtr
MassSpectrumCstSPtr getMassSpectrumCstSPtr() const
Get the MassSpectrumCstSPtr.
Definition: qualifiedmassspectrum.cpp:159
pappso::PwizMsRunReader::accept
virtual bool accept(const QString &file_name) const override
tells if the reader is able to handle this file must be implemented by private MS run reader,...
Definition: pwizmsrunreader.cpp:753
pappso::PwizMsRunReader::qualifiedMassSpectrum
virtual QualifiedMassSpectrum qualifiedMassSpectrum(std::size_t spectrum_index, bool want_binary_data=true) const override
get a QualifiedMassSpectrum class given its scan number
Definition: pwizmsrunreader.cpp:782
pappso::PwizMsRunReader::releaseDevice
virtual bool releaseDevice() override
release data back end device if a the data back end is released, the developper has to use acquireDev...
Definition: pwizmsrunreader.cpp:949
pappso::PwizMsRunReader::msp_msData
pwiz::msdata::MSDataPtr msp_msData
Definition: pwizmsrunreader.h:116
pappso::PwizMsRunReader::getPwizSpectrumPtr
pwiz::msdata::SpectrumPtr getPwizSpectrumPtr(pwiz::msdata::SpectrumList *p_spectrum_list, std::size_t spectrum_index, bool want_binary_data) const
Definition: pwizmsrunreader.cpp:198
pappso::PwizMsRunReader::spectrumListSize
virtual std::size_t spectrumListSize() const override
get the totat number of spectrum conained in the MSrun data file
Definition: pwizmsrunreader.cpp:937
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:75
pappso::PappsoException
Definition: pappsoexception.h:63
pappso::MzFormat::MGF
@ MGF
Mascot format.