pappsomspp
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...
 
- 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...
 
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 64 of file pwizmsrunreader.h.

Constructor & Destructor Documentation

◆ PwizMsRunReader()

pappso::PwizMsRunReader::PwizMsRunReader ( MsRunIdCstSPtr msrun_id_csp)

Definition at line 72 of file pwizmsrunreader.cpp.

◆ ~PwizMsRunReader()

pappso::PwizMsRunReader::~PwizMsRunReader ( )
virtual

Definition at line 184 of file pwizmsrunreader.cpp.

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 711 of file pwizmsrunreader.cpp.

715 {
716  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
717  return qualifiedMassSpectrum(spectrum_index, true).getMassSpectrumCstSPtr();
718 }
719 
720 QualifiedMassSpectrum
721 PwizMsRunReader::qualifiedMassSpectrum(std::size_t spectrum_index,
722  bool want_binary_data) const

◆ 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 190 of file pwizmsrunreader.cpp.

193  {
194  qDebug() << "getPwizSpectrumPtr error " << error.what()
195  << typeid(error).name();
196 
197  throw ExceptionNotFound(
198  QObject::tr("Pwiz spectrum index %1 not found in MS file :\n%2")
199  .arg(spectrum_index)
200  .arg(error.what()));
201  }
202 
203  if(native_pwiz_spectrum_sp.get() == nullptr)
204  {
205  throw ExceptionNotFound(
206  QObject::tr(
207  "Pwiz spectrum index %1 not found in MS file : null pointer")
208  .arg(spectrum_index));
209  }
210 
211  return native_pwiz_spectrum_sp;
212 }
213 
214 
215 QualifiedMassSpectrum
217  const MassSpectrumId &massSpectrumId,
218  pwiz::msdata::Spectrum *spectrum_p,
219  bool want_binary_data,
220  bool &ok) const
221 {
222  // qDebug();
223 
224  std::string env;
225  env = setlocale(LC_ALL, "");
226  setlocale(LC_ALL, "C");
227 
228  QualifiedMassSpectrum qualified_mass_spectrum(massSpectrumId);
229 
230  try
231  {

◆ 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 899 of file pwizmsrunreader.cpp.

◆ initialize()

void pappso::PwizMsRunReader::initialize ( )
overrideprotectedvirtual

Implements pappso::MsRunReader.

Definition at line 84 of file pwizmsrunreader.cpp.

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

◆ massSpectrumCstSPtr()

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

Implements pappso::MsRunReader.

Definition at line 733 of file pwizmsrunreader.cpp.

734  {
735  // spectrum = qualifiedMassSpectrumFromPwizMSData(scan_num - 1);
736  }
737  }

◆ 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 726 of file pwizmsrunreader.cpp.

◆ 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 740 of file pwizmsrunreader.cpp.

749 {
750 
751  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()";
752 
753  // We want to iterate in the pwiz-spectrum-list and for each pwiz-spectrum
754  // create a pappso-spectrum (QualifiedMassSpectrum). Once the pappso mass
755  // spectrum has been fully qualified (that is, the member data have been
756  // set), it is transferred to the handler passed as parameter to this
757  // function for the consumer to do what it wants with it.
758 
759  // Does the handler consuming the mass spectra read from file want these
760  // mass spectra to hold the binary data arrays (mz/i vectors)?
761 
762  const bool want_binary_data = handler.needPeakList();

◆ qualifiedMassSpectrumFromPwizMSData()

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

Definition at line 657 of file pwizmsrunreader.cpp.

667  {
668  setlocale(LC_ALL, env.c_str());
669  throw ExceptionNotFound(
670  QObject::tr("The spectrum index cannot be equal to the size of the "
671  "spectrum list."));
672  }
673 
674  // At this point we know the spectrum index might be sane, so store it in
675  // the mass spec id object.
676  massSpectrumId.setSpectrumIndex(spectrum_index);
677 
678  pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
679  getPwizSpectrumPtr(spectrum_list_p.get(), spectrum_index, want_binary_data);
680 
681  setlocale(LC_ALL, env.c_str());
682 
683  massSpectrumId.setNativeId(
684  QString::fromStdString(native_pwiz_spectrum_sp->id));
685 
687  massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
688 }
689 
690 
691 bool
692 PwizMsRunReader::accept(const QString &file_name) const
693 {
694  // We want to know if we can handle the file_name.
695  pwiz::msdata::ReaderList reader_list;
696 
697  std::string reader_type = reader_list.identify(file_name.toStdString());
698 
699  if(!reader_type.empty())
700  return true;
701 
702  return false;
703 }
704 
705 
707 PwizMsRunReader::massSpectrumSPtr(std::size_t spectrum_index)

◆ qualifiedMassSpectrumFromPwizSpectrumPtr()

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

Definition at line 235 of file pwizmsrunreader.cpp.

249  {
250  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
251  //<< "The spectrum has precursor(s).";
252 
253  // Sanity check
254  if(msLevel <= 1)
255  {
256  qDebug() << "Going to throw.";
257 
258  throw(ExceptionNotPossible(
259  "msLevel cannot be less than two for "
260  "a spectrum that has items in its Precursor list."));
261  }
262 
263  // See what is the first precursor in the list.
264 
265  // qDebug() << "Now tring to get the precursor.";
266 
267  pwiz::msdata::Precursor &precursor = spectrum_p->precursors.front();
268 
269  // Set this variable ready as we need that default value in certain
270  // circumstances.
271 
272  std::size_t precursor_spectrum_index =
273  std::numeric_limits<std::size_t>::max();
274 
275  // qDebug() << "First precursor:" << precursor.spectrumID.c_str();
276 
277  if(precursor.spectrumID.empty())
278  {
279  // qDebug() << "The precursor's spectrum ID is empty.";
280 
281  if(mcsp_msRunId.get()->getMzFormat() == MzFormat::MGF)
282  {
283  // qDebug()
284  //<< "Format is MGF, precursor's spectrum ID can be empty.";
285  }
286  else
287  {
288  // When performing Lumos Fusion fragmentation experiments in
289  // Tune mode and with recording, the first spectrum of the
290  // list is a fragmentation spectrum (ms level 2) that has no
291  // identity for the precursor spectrum because there is no
292  // full scan accquisition.
293 
294 #if 0
295  // Let's try to understand if we are in this configuration.
296 
297  if(!massSpectrumId.getSpectrumIndex())
298  {
299  qDebug() << "This MS2 sprectrum is at index 0."
300  "This might indicate a fragmentation "
301  "experiment performed in Tune mode.";
302 
303  // The precursor spectrum index is initialized to max().
304  // So, it is not going to be changed in the present
305  // situation.
306  }
307  else
308  {
309  qDebug() << "This MS2 spectrum has no precursor's "
310  "spectrum index.";
311  }
312  // else
313  //{
314  // throw(
315  // ExceptionNotPossible("Failed to get the id of the "
316  //"precursor ion's spectrum."));
317  //}
318 #endif
319  }
320  }
321  else
322  {
323  // We could get a native precursor spectrum id, so convert that
324  // native id to a spectrum index.
325 
326  qualified_mass_spectrum.setPrecursorNativeId(
327  QString::fromStdString(precursor.spectrumID));
328 
329  if(qualified_mass_spectrum.getPrecursorNativeId().isEmpty())
330  {
331  // qDebug()
332  //<< "The native id of the precursor spectrum is empty !!!";
333  }
334 
335  // Get the spectrum index of the spectrum that contained the
336  // precursor ion.
337 
338  precursor_spectrum_index =
339  msp_msData->run.spectrumListPtr->find(precursor.spectrumID);
340 
341  // Note that the Mascot MGF format has a peculiar handling of the
342  // precursor ion stuff so we cannot throw.
343  if(precursor_spectrum_index ==
344  msp_msData->run.spectrumListPtr->size())
345  {
346  if(mcsp_msRunId.get()->getMzFormat() != MzFormat::MGF)
347  {
348  throw(
349  ExceptionNotPossible("Failed to find the index of the "
350  "precursor ion's spectrum."));
351  }
352  }
353 
354  qualified_mass_spectrum.setPrecursorSpectrumIndex(
355  precursor_spectrum_index);
356 
357  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
358  //<< "Set the precursor spectrum index to:"
359  //<< qualified_mass_spectrum.getPrecursorSpectrumIndex()
360  //<< "for qualified mass spectrum:"
361  //<< &qualified_mass_spectrum;
362  }
363 
364  if(!precursor.selectedIons.size())
365  {
366  throw(
367  ExceptionNotPossible("The spectrum has msLevel > 1 but the "
368  "precursor ions's selected ions "
369  "list is empty."));
370  }
371 
372  pwiz::msdata::SelectedIon &ion = *(precursor.selectedIons.begin());
373 
374  // selected ion m/z
375 
376  pappso_double selected_ion_mz =
377  QString(ion.cvParam(pwiz::cv::MS_selected_ion_m_z).value.c_str())
378  .toDouble();
379 
380  qualified_mass_spectrum.setPrecursorMz(selected_ion_mz);
381 
382  // selected ion peak intensity
383 
384  pappso_double selected_ion_peak_intensity =
385  QString(ion.cvParam(pwiz::cv::MS_peak_intensity).value.c_str())
386  .toDouble();
387 
388  qualified_mass_spectrum.setPrecursorIntensity(
389  selected_ion_peak_intensity);
390 
391  // unsigned int test =
392  // QString(ion.cvParam(pwiz::cv::MS_1200_series_LC_MSD_SL).value.c_str()).toUInt();
393  // qDebug() << " test "<< test;
394 
395  // charge state
396 
397  unsigned int selected_ion_charge_state =
398  QString(ion.cvParam(pwiz::cv::MS_charge_state).value.c_str())
399  .toUInt();
400 
401  if(selected_ion_charge_state > 0)
402  {
403  qualified_mass_spectrum.setPrecursorCharge(
404  selected_ion_charge_state);
405  }
406 
407 
408  // General sum-up
409  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
410  //<< "precursor_scan_number:"
411  //<< "selected_ion_m_z:" << selected_ion_mz
412  //<< "selected_ion_peak_intensity:"
413  //<< selected_ion_peak_intensity << "selected_ion_charge_state"
414  //<< selected_ion_charge_state;
415  }
416  // End of
417  // if(spectrum_p->precursors.size() > 0)
418  else
419  {
420  // Sanity check
421  if(msLevel != 1)
422  {
423  throw(
424  ExceptionNotPossible("msLevel cannot be different than 1 if "
425  "there is not a single precursor ion."));
426  }
427  }
428 
429  // We now have to set the retention time at which this mass spectrum was
430  // acquired. This is the scan start time.
431 
432  if(!spectrum_p->scanList.scans[0].hasCVParam(
433  pwiz::msdata::MS_scan_start_time))
434  {
435  if(mcsp_msRunId.get()->getMzFormat() == MzFormat::MGF)
436  { // MGF could not have scan start time
437  qualified_mass_spectrum.setRtInSeconds(-1);
438  }
439  else
440  {
441  throw(ExceptionNotPossible(
442  "The spectrum has no scan start time value set."));
443  }
444  }
445  else
446  {
447  pwiz::data::CVParam retention_time_cv_param =
448  spectrum_p->scanList.scans[0].cvParam(
449  pwiz::msdata::MS_scan_start_time);
450 
451  // Try to get the units of the retention time value.
452 
453  std::string unit_name = retention_time_cv_param.unitsName();
454  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
455  //<< "Unit name for the retention time:"
456  //<< QString::fromStdString(unit_name);
457 
458  if(unit_name == "second")
459  {
460  qualified_mass_spectrum.setRtInSeconds(
461  retention_time_cv_param.valueAs<double>());
462  }
463  else if(unit_name == "minute")
464  {
465  qualified_mass_spectrum.setRtInSeconds(
466  retention_time_cv_param.valueAs<double>() * 60);
467  }
468  else
469  throw(ExceptionNotPossible(
470  "Could not determine the unit for the scan start time value."));
471  }
472 
473  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
474  //<< "Retention time for spectrum is:"
475  //<< qualified_mass_spectrum.getRtInSeconds();
476 
477  // Old version not checking unit (by default unit is minutes for RT,
478  // not seconds)
479  //
480  // pappso_double retentionTime =
481  // QString(spectrum_p->scanList.scans[0]
482  //.cvParam(pwiz::msdata::MS_scan_start_time)
483  //.value.c_str())
484  //.toDouble();
485  // qualified_mass_spectrum.setRtInSeconds(retentionTime);
486 
487  // Not all the acquisitions have ion mobility data. We need to test
488  // that:
489 
490  if(spectrum_p->scanList.scans[0].hasCVParam(
491  pwiz::msdata::MS_ion_mobility_drift_time))
492  {
493 
494  // qDebug() << "as strings:"
495  //<< QString::fromStdString(
496  // spectrum_p->scanList.scans[0]
497  //.cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
498  //.valueAs<std::string>());
499 
500  pappso_double driftTime =
501  spectrum_p->scanList.scans[0]
502  .cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
503  .valueAs<double>();
504 
505  // qDebug() << "driftTime:" << driftTime;
506 
507  // Old version requiring use of QString.
508  // pappso_double driftTime =
509  // QString(spectrum_p->scanList.scans[0]
510  //.cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
511  //.value.c_str())
512  //.toDouble();
513 
514  // Now make positively sure that the obtained value is correct.
515  // Note that I suffered a lot with Waters Synapt data that
516  // contained apparently correct drift time XML element that in
517  // fact contained either NaN or inf. When such mass spectra were
518  // encountered, the mz,i data were bogus and crashed the data loading
519  // functions. We just want to skip this kind of bogus mass spectrum by
520  // letting the caller know that the drift time was bogus ("I" is
521  // Filippo Rusconi).
522 
523  if(std::isnan(driftTime) || std::isinf(driftTime))
524  {
525  // qDebug() << "detected as nan or inf.";
526 
527  ok = false;
528 
529  return qualified_mass_spectrum;
530  }
531  else
532  {
533  // The mzML standard stipulates that drift times are in
534  // milliseconds.
535  qualified_mass_spectrum.setDtInMilliSeconds(driftTime);
536  }
537  }
538  // End of
539  // if(spectrum_p->scanList.scans[0].hasCVParam(
540  // pwiz::msdata::MS_ion_mobility_drift_time))
541  else
542  {
543  // Not a bogus mass spectrum but also not a drift spectrum, set -1 as
544  // the drift time value.
545  qualified_mass_spectrum.setDtInMilliSeconds(-1);
546  }
547 
548  // for(pwiz::data::CVParam cv_param : ion.cvParams)
549  //{
550  // pwiz::msdata::CVID param_id = cv_param.cvid;
551  // qDebug() << param_id;
552  // qDebug() << cv_param.cvid.c_str();
553  // qDebug() << cv_param.name().c_str();
554  // qDebug() << cv_param.value.c_str();
555  //}
556 
557  if(want_binary_data)
558  {
559 
560  // Fill-in MZIntensityPair vector for convenient access to binary
561  // data
562 
563  std::vector<pwiz::msdata::MZIntensityPair> pairs;
564  spectrum_p->getMZIntensityPairs(pairs);
565 
566  MassSpectrum spectrum;
567  double tic = 0;
568  // std::size_t iterCount = 0;
569 
570  // Iterate through the m/z-intensity pairs
571  for(std::vector<pwiz::msdata::MZIntensityPair>::const_iterator
572  it = pairs.begin(),
573  end = pairs.end();
574  it != end;
575  ++it)
576  {
577  //++iterCount;
578 
579  // qDebug() << "it->mz " << it->mz << " it->intensity" <<
580  // it->intensity;
581  if(it->intensity)
582  {
583  spectrum.push_back(DataPoint(it->mz, it->intensity));
584  tic += it->intensity;
585  }
586  }
587 
588  if(mcsp_msRunId.get()->getMzFormat() == MzFormat::MGF)
589  {
590  // Sort peaks by mz
591  spectrum.sortMz();
592  }
593 
594  // lc = localeconv ();
595  // qDebug() << " env=" << localeconv () << " lc->decimal_point "
596  // << lc->decimal_point;
597  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "() "<<
598  // spectrum.size();
599  MassSpectrumSPtr spectrum_sp = spectrum.makeMassSpectrumSPtr();
600  qualified_mass_spectrum.setMassSpectrumSPtr(spectrum_sp);
601 
602  // double sumY =
603  // qualified_mass_spectrum.getMassSpectrumSPtr()->sumY(); qDebug()
604  // <<
605  // __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
606  //<< "iterCount:" << iterCount << "Spectrum size "
607  //<< spectrum.size() << "with tic:" << tic
608  //<< "and sumY:" << sumY;
609  }
610  else
611  qualified_mass_spectrum.setMassSpectrumSPtr(nullptr);
612  }
613  catch(PappsoException &errorp)
614  {
615  qDebug() << "Going to throw";
616 
618  QObject::tr("Error reading data using the proteowizard library: %1")
619  .arg(errorp.qwhat()));
620  }
621  catch(std::exception &error)
622  {
623  qDebug() << "Going to throw";
624 
626  QObject::tr("Error reading data using the proteowizard library: %1")
627  .arg(error.what()));
628  }
629 
630  // setlocale(LC_ALL, env.c_str());
631 
632  ok = true;
633  return qualified_mass_spectrum;
634 }
635 
636 
637 QualifiedMassSpectrum
639  bool want_binary_data,
640  bool &ok) const
641 {
642 
643  std::string env;
644  env = setlocale(LC_ALL, "");
645  // struct lconv *lc = localeconv();
646 
647  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
648  //<< "env=" << env.c_str()
649  //<< "lc->decimal_point:" << lc->decimal_point;
650 
651  setlocale(LC_ALL, "C");
652 
653  MassSpectrumId massSpectrumId(mcsp_msRunId);

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 766 of file pwizmsrunreader.cpp.

788  {
789 
790  // If the user of this reader instance wants to stop reading the spectra,
791  // then break this loop.
792  if(handler.shouldStop())
793  {
794  qDebug() << "The operation was cancelled. Breaking the loop.";
795  break;
796  }
797 
798  // Get the native pwiz-spectrum from the spectrum list.
799  // Note that this pointer is a shared pointer from pwiz.
800 
801  pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
802  getPwizSpectrumPtr(spectrum_list_p.get(), iter, want_binary_data);
803 
804  /*
805  * we want to load metadata of the spectrum even if it does not contain
806  peaks
807 
808  * if(!native_pwiz_spectrum_sp->hasBinaryData())
809  {
810  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "
811  ()"
812  //<< "native pwiz spectrum is empty, continuing.";
813  continue;
814  }
815  */
816 
817  // Instantiate the mass spectrum id that will hold critical information
818  // like the the native id string and the spectrum index.
819 
820  MassSpectrumId massSpectrumId(mcsp_msRunId, iter /* spectrum index*/);
821 
822  // Get the spectrum native id as a QString to store it in the mass
823  // spectrum id class. This is will allow later to refer to the same
824  // spectrum starting back from the file.
825 
826  QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
827  massSpectrumId.setNativeId(native_id);
828 
829  // Finally, instantiate the qualified mass spectrum with its id. This
830  // function will continue performing pappso-spectrum detailed
831  // qualification.
832 
833  bool ok = false;
834 
835  QualifiedMassSpectrum qualified_mass_spectrum =
837  massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
838 
839  if(!ok)
840  {
841  // qDebug() << "Encountered a mass spectrum for which the returned "
842  //"status is bad.";
843  continue;
844  }
845 
846  // Before handing the mass spectrum out to the handler, see if the native
847  // mass spectrum was empty or not.
848 
849  // if(!native_pwiz_spectrum_sp->defaultArrayLength)
850  // qDebug() << "The mass spectrum has not defaultArrayLength";
851 
852  qualified_mass_spectrum.setEmptyMassSpectrum(
853  !native_pwiz_spectrum_sp->defaultArrayLength);
854 
855  // The handler will receive the index of the mass spectrum in the
856  // current run via the mass spectrum id member datum.
857  handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
858  }
859 
860  setlocale(LC_ALL, env.c_str());
861  // End of
862  // for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
863 
864  // Now let the loading handler know that the loading of the data has ended.
865  // The handler might need this "signal" to perform additional tasks or to
866  // cleanup cruft.
867 
868  // qDebug() << "Loading ended";
869  handler.loadingEnded();
870 }
871 
872 
873 std::size_t
875 {
876  return msp_msData->run.spectrumListPtr.get()->size();
877 }
878 
879 bool
881 {
882  return m_hasScanNumbers;
883 }
884 
885 
886 } // namespace pappso

◆ 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 893 of file pwizmsrunreader.cpp.

Friends And Related Function Documentation

◆ MsFileAccessor

friend class MsFileAccessor
friend

Definition at line 86 of file pwizmsrunreader.h.

Member Data Documentation

◆ m_hasScanNumbers

bool pappso::PwizMsRunReader::m_hasScanNumbers = false
private

Definition at line 129 of file pwizmsrunreader.h.

◆ msp_msData

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

Definition at line 109 of file pwizmsrunreader.h.

Referenced by qualifiedMassSpectrumFromPwizSpectrumPtr().


The documentation for this class was generated from the following files:
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:67
pappso::PwizMsRunReader::qualifiedMassSpectrumFromPwizMSData
QualifiedMassSpectrum qualifiedMassSpectrumFromPwizMSData(std::size_t spectrum_index, bool want_binary_data, bool &ok) const
Definition: pwizmsrunreader.cpp:657
pappso::PwizMsRunReader::m_hasScanNumbers
bool m_hasScanNumbers
Definition: pwizmsrunreader.h:129
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:899
pappso::PwizMsRunReader::massSpectrumSPtr
virtual MassSpectrumSPtr massSpectrumSPtr(std::size_t spectrum_index) override
get a MassSpectrumSPtr class given its spectrum index
Definition: pwizmsrunreader.cpp:726
pappso::PwizMsRunReader::qualifiedMassSpectrumFromPwizSpectrumPtr
QualifiedMassSpectrum qualifiedMassSpectrumFromPwizSpectrumPtr(const MassSpectrumId &massSpectrumId, pwiz::msdata::Spectrum *spectrum_p, bool want_binary_data, bool &ok) const
Definition: pwizmsrunreader.cpp:235
pappso::PwizMsRunReader::~PwizMsRunReader
virtual ~PwizMsRunReader()
Definition: pwizmsrunreader.cpp:184
pappso::MsRunReader::mcsp_msRunId
MsRunIdCstSPtr mcsp_msRunId
Definition: msrunreader.h:224
pappso::MzFormat::mzXML
mzXML
pappso::QualifiedMassSpectrum::getMassSpectrumCstSPtr
MassSpectrumCstSPtr getMassSpectrumCstSPtr() const
Get the MassSpectrumCstSPtr.
Definition: qualifiedmassspectrum.cpp:148
pappso::QualifiedMassSpectrum::setEmptyMassSpectrum
void setEmptyMassSpectrum(bool is_empty_mass_spectrum)
Definition: qualifiedmassspectrum.cpp:155
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:711
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:740
pappso::PwizMsRunReader::msp_msData
pwiz::msdata::MSDataPtr msp_msData
Definition: pwizmsrunreader.h:109
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:190
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:893
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:73
pappso::PappsoException
Definition: pappsoexception.h:60
pappso::MzFormat::MGF
Mascot format.