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 pappso::XicCoordSPtr newXicCoordSPtrFromSpectrumIndex (std::size_t spectrum_index, pappso::PrecisionPtr precision) const override
 get a xic coordinate object from a given spectrum index More...
 
virtual pappso::XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum (const pappso::QualifiedMassSpectrum &mass_spectrum, pappso::PrecisionPtr precision) const override
 get a xic coordinate object from a given spectrum More...
 
virtual void readSpectrumCollectionByMsLevel (SpectrumCollectionHandlerInterface &handler, unsigned int ms_level) override
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels 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 MassSpectrumSPtr massSpectrumSPtr (std::size_t spectrum_index)=0
 get a MassSpectrumSPtr class given its spectrum index More...
 
virtual MassSpectrumCstSPtr massSpectrumCstSPtr (std::size_t spectrum_index)=0
 
virtual QualifiedMassSpectrum qualifiedMassSpectrum (std::size_t spectrum_index, bool want_binary_data=true) const =0
 get a QualifiedMassSpectrum class given its scan number More...
 
virtual XicCoordSPtr newXicCoordSPtrFromSpectrumIndex (std::size_t spectrum_index, PrecisionPtr precision) const =0
 get a xic coordinate object from a given spectrum index More...
 
virtual XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum (const QualifiedMassSpectrum &mass_spectrum, PrecisionPtr precision) const =0
 get a xic coordinate object from a given spectrum More...
 
virtual std::size_t spectrumListSize () const =0
 get the totat number of spectrum conained in the MSrun data file More...
 
virtual void readSpectrumCollection (SpectrumCollectionHandlerInterface &handler)=0
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler More...
 
virtual void readSpectrumCollectionByMsLevel (SpectrumCollectionHandlerInterface &handler, unsigned int ms_level)=0
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels More...
 
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...
 
virtual bool hasScanNumbers () const
 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 ()=0
 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 ()=0
 acquire data back end device More...
 
virtual std::vector< double > getRetentionTimeLine ()
 retention timeline get retention times along the MSrun in seconds More...
 
virtual Trace getTicChromatogram ()
 
void setMonoThread (bool is_mono_thread)
 set only one is_mono_thread to true More...
 
bool isMonoThread () const
 

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
 
virtual void initialize ()=0
 
virtual bool accept (const QString &file_name) const =0
 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...
 

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

Constructor & Destructor Documentation

◆ PwizMsRunReader()

pappso::PwizMsRunReader::PwizMsRunReader ( MsRunIdCstSPtr msrun_id_csp)

Definition at line 53 of file pwizmsrunreader.cpp.

54 : MsRunReader(msrun_id_csp)
55{
56 // The initialization needs to be done immediately so that we get the pwiz
57 // MsDataPtr corresponding to the right ms_run_id in the parameter. That
58 // pointer will be set to msp_msData.
59
60 initialize();
61}
MsRunReader(MsRunIdCstSPtr &ms_run_id)
virtual void initialize() override

References initialize().

◆ ~PwizMsRunReader()

pappso::PwizMsRunReader::~PwizMsRunReader ( )
virtual

Definition at line 171 of file pwizmsrunreader.cpp.

172{
173}

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

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}

◆ acquireDevice()

bool pappso::PwizMsRunReader::acquireDevice ( )
overridevirtual

acquire data back end device

Returns
bool true if done

Implements pappso::MsRunReader.

Definition at line 952 of file pwizmsrunreader.cpp.

953{
954 if(msp_msData == nullptr)
955 {
956 initialize();
957 }
958 return true;
959}
pwiz::msdata::MSDataPtr msp_msData

References initialize(), and msp_msData.

Referenced by readSpectrumCollectionByMsLevel().

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

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 {
190 qDebug() << "getPwizSpectrumPtr error " << error.what() << " "
191 << typeid(error).name();
192
193 throw ExceptionNotFound(QObject::tr("Pwiz spectrum index %1 not found in "
194 "MS file std::runtime_error :\n%2")
195 .arg(spectrum_index)
196 .arg(error.what()));
197 }
198 catch(std::exception &error)
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}

Referenced by qualifiedMassSpectrumFromPwizMSData(), and readSpectrumCollectionByMsLevel().

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

940{
941 return m_hasScanNumbers;
942}

References m_hasScanNumbers.

◆ initialize()

void pappso::PwizMsRunReader::initialize ( )
overrideprotectedvirtual

Implements pappso::MsRunReader.

Definition at line 65 of file pwizmsrunreader.cpp.

66{
67 std::string file_name_std =
69
70 // Make a backup of the current locale
71 std::string env_backup = setlocale(LC_ALL, "");
72 // struct lconv *lc = localeconv();
73
74 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
75 //<< "env_backup=" << env_backup.c_str() << "lc->decimal_point"
76 //<< lc->decimal_point;
77
78 // Now actually search the useful MSDataPtr to the member variable.
79
80 pwiz::msdata::DefaultReaderList defaultReaderList;
81
82 std::vector<pwiz::msdata::MSDataPtr> msDataPtrVector;
83
84 try
85 {
86 defaultReaderList.read(file_name_std, msDataPtrVector);
87 }
88 catch(std::exception &error)
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}
MsRunIdCstSPtr mcsp_msRunId
Definition: msrunreader.h:291
static std::string toUtf8StandardString(const QString &text)
Definition: utils.cpp:142

References m_hasScanNumbers, pappso::MsRunReader::mcsp_msRunId, msp_msData, pappso::mzXML, and pappso::Utils::toUtf8StandardString().

Referenced by PwizMsRunReader(), and acquireDevice().

◆ massSpectrumCstSPtr()

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

Implements pappso::MsRunReader.

Definition at line 754 of file pwizmsrunreader.cpp.

755{
756 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
757 return qualifiedMassSpectrum(spectrum_index, true).getMassSpectrumCstSPtr();
758}
virtual QualifiedMassSpectrum qualifiedMassSpectrum(std::size_t spectrum_index, bool want_binary_data=true) const override
get a QualifiedMassSpectrum class given its scan number
MassSpectrumCstSPtr getMassSpectrumCstSPtr() const
Get the MassSpectrumCstSPtr.

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

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

748{
749 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
750 return qualifiedMassSpectrum(spectrum_index, true).getMassSpectrumSPtr();
751}
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.

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

◆ newXicCoordSPtrFromQualifiedMassSpectrum()

XicCoordSPtr pappso::PwizMsRunReader::newXicCoordSPtrFromQualifiedMassSpectrum ( const pappso::QualifiedMassSpectrum mass_spectrum,
pappso::PrecisionPtr  precision 
) const
overridevirtual

get a xic coordinate object from a given spectrum

Implements pappso::MsRunReader.

Definition at line 974 of file pwizmsrunreader.cpp.

977{
978 XicCoordSPtr xic_coord = std::make_shared<XicCoord>();
979
980 xic_coord.get()->rtTarget = mass_spectrum.getRtInSeconds();
981
982 xic_coord.get()->mzRange = MzRange(mass_spectrum.getPrecursorMz(), precision);
983
984 return xic_coord;
985}
pappso_double getPrecursorMz(bool *ok=nullptr) const
Get the precursor m/z ratio.
pappso_double getRtInSeconds() const
Get the retention time in seconds.
std::shared_ptr< XicCoord > XicCoordSPtr
Definition: xiccoord.h:43

References pappso::QualifiedMassSpectrum::getPrecursorMz(), and pappso::QualifiedMassSpectrum::getRtInSeconds().

Referenced by newXicCoordSPtrFromSpectrumIndex().

◆ newXicCoordSPtrFromSpectrumIndex()

XicCoordSPtr pappso::PwizMsRunReader::newXicCoordSPtrFromSpectrumIndex ( std::size_t  spectrum_index,
pappso::PrecisionPtr  precision 
) const
overridevirtual

get a xic coordinate object from a given spectrum index

Implements pappso::MsRunReader.

Definition at line 963 of file pwizmsrunreader.cpp.

965{
966
967 QualifiedMassSpectrum mass_spectrum =
968 qualifiedMassSpectrum(spectrum_index, false);
969
970 return newXicCoordSPtrFromQualifiedMassSpectrum(mass_spectrum, precision);
971}
virtual pappso::XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum(const pappso::QualifiedMassSpectrum &mass_spectrum, pappso::PrecisionPtr precision) const override
get a xic coordinate object from a given spectrum

References newXicCoordSPtrFromQualifiedMassSpectrum(), and qualifiedMassSpectrum().

◆ processDriftTime()

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

Definition at line 290 of file pwizmsrunreader.cpp.

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 =
308 spectrum_p->scanList.scans[0]
309 .cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
310 .valueAs<double>();
311
312 // qDebug() << "driftTime:" << driftTime;
313
314 // Old version requiring use of QString.
315 // pappso_double driftTime =
316 // QString(spectrum_p->scanList.scans[0]
317 //.cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
318 //.value.c_str())
319 //.toDouble();
320
321 // Now make positively sure that the obtained value is correct.
322 // Note that I suffered a lot with Waters Synapt data that
323 // contained apparently correct drift time XML element that in
324 // fact contained either NaN or inf. When such mass spectra were
325 // encountered, the mz,i data were bogus and crashed the data
326 // loading functions. We just want to skip this kind of bogus mass
327 // spectrum by letting the caller know that the drift time was
328 // bogus ("I" is Filippo Rusconi).
329
330 if(std::isnan(driftTime) || std::isinf(driftTime))
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}
double pappso_double
A type definition for doubles.
Definition: types.h:48

References pappso::QualifiedMassSpectrum::setDtInMilliSeconds().

Referenced by qualifiedMassSpectrumFromPwizSpectrumPtr().

◆ processRetentionTime()

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

Definition at line 222 of file pwizmsrunreader.cpp.

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(
240 "The spectrum has no scan start time value set."));
241 }
242 }
243 else
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}
@ MGF
Mascot format.

References pappso::MsRunReader::mcsp_msRunId, pappso::MGF, and pappso::QualifiedMassSpectrum::setRtInSeconds().

Referenced by qualifiedMassSpectrumFromPwizSpectrumPtr().

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

763{
764
765 QualifiedMassSpectrum spectrum;
766 bool ok = false;
767
768 spectrum =
769 qualifiedMassSpectrumFromPwizMSData(spectrum_index, want_binary_data, ok);
770
771 if(mcsp_msRunId->getMzFormat() == pappso::MzFormat::MGF)
772 {
773 if(spectrum.getRtInSeconds() == 0)
774 {
775 // spectrum = qualifiedMassSpectrumFromPwizMSData(scan_num - 1);
776 }
777 }
778
779 // if(!ok)
780 // qDebug() << "Encountered a mass spectrum for which the status is bad.";
781
782 return spectrum;
783}
QualifiedMassSpectrum qualifiedMassSpectrumFromPwizMSData(std::size_t spectrum_index, bool want_binary_data, bool &ok) const

References pappso::QualifiedMassSpectrum::getRtInSeconds(), pappso::MsRunReader::mcsp_msRunId, pappso::MGF, and qualifiedMassSpectrumFromPwizMSData().

Referenced by massSpectrumCstSPtr(), massSpectrumSPtr(), and newXicCoordSPtrFromSpectrumIndex().

◆ qualifiedMassSpectrumFromPwizMSData()

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

Definition at line 678 of file pwizmsrunreader.cpp.

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)
696 {
697 setlocale(LC_ALL, env.c_str());
698 return (QualifiedMassSpectrum(massSpectrumId));
699 }
700
701 // const bool want_binary_data = true;
702
703 pwiz::msdata::SpectrumListPtr spectrum_list_p =
704 msp_msData->run.spectrumListPtr;
705
706 if(spectrum_index == spectrum_list_p.get()->size())
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}
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

References getPwizSpectrumPtr(), pappso::MsRunReader::mcsp_msRunId, msp_msData, qualifiedMassSpectrumFromPwizSpectrumPtr(), pappso::MassSpectrumId::setNativeId(), and pappso::MassSpectrumId::setSpectrumIndex().

Referenced by qualifiedMassSpectrum().

◆ qualifiedMassSpectrumFromPwizSpectrumPtr()

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

Definition at line 358 of file pwizmsrunreader.cpp.

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
376
377 int msLevel =
378 (spectrum_p->cvParam(pwiz::msdata::MS_ms_level).valueAs<int>());
379
380 qualified_mass_spectrum.setMsLevel(msLevel);
381
382 // We want to know if this spectrum is a fragmentation spectrum obtained
383 // from a selected precursor ion.
384
385 std::size_t precursor_list_size = spectrum_p->precursors.size();
386
387 // qDebug() << "For spectrum at index:" <<
388 // massSpectrumId.getSpectrumIndex()
389 //<< "msLevel:" << msLevel
390 //<< "with number of precursors:" << precursor_list_size;
391
392 if(precursor_list_size > 0)
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}
bool processDriftTime(pwiz::msdata::Spectrum *spectrum_p, QualifiedMassSpectrum &qualified_mass_spectrum) const
bool processRetentionTime(pwiz::msdata::Spectrum *spectrum_p, QualifiedMassSpectrum &qualified_mass_spectrum) const
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:54

References pappso::QualifiedMassSpectrum::appendPrecursorIonData(), pappso::QualifiedMassSpectrum::getPrecursorIonData(), pappso::QualifiedMassSpectrum::getPrecursorNativeId(), pappso::MassSpectrum::makeMassSpectrumSPtr(), pappso::MsRunReader::mcsp_msRunId, pappso::MGF, msp_msData, processDriftTime(), processRetentionTime(), pappso::PappsoException::qwhat(), pappso::QualifiedMassSpectrum::setMassSpectrumSPtr(), pappso::QualifiedMassSpectrum::setMsLevel(), pappso::QualifiedMassSpectrum::setPrecursorNativeId(), pappso::QualifiedMassSpectrum::setPrecursorSpectrumIndex(), and pappso::MassSpectrum::sortMz().

Referenced by qualifiedMassSpectrumFromPwizMSData(), and readSpectrumCollectionByMsLevel().

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

789{
791}
virtual void readSpectrumCollectionByMsLevel(SpectrumCollectionHandlerInterface &handler, unsigned int ms_level) override
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels

References readSpectrumCollectionByMsLevel().

◆ readSpectrumCollectionByMsLevel()

void pappso::PwizMsRunReader::readSpectrumCollectionByMsLevel ( SpectrumCollectionHandlerInterface handler,
unsigned int  ms_level 
)
overridevirtual

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

Implements pappso::MsRunReader.

Definition at line 795 of file pwizmsrunreader.cpp.

797{
798
800 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()";
801
802 // We want to iterate in the pwiz-spectrum-list and for each pwiz-spectrum
803 // create a pappso-spectrum (QualifiedMassSpectrum). Once the pappso mass
804 // spectrum has been fully qualified (that is, the member data have been
805 // set), it is transferred to the handler passed as parameter to this
806 // function for the consumer to do what it wants with it.
807
808 // Does the handler consuming the mass spectra read from file want these
809 // mass spectra to hold the binary data arrays (mz/i vectors)?
810
811 const bool want_binary_data = handler.needPeakList();
812
813
814 std::string env;
815 env = setlocale(LC_ALL, "");
816 setlocale(LC_ALL, "C");
817
818
819 // We access the pwiz-mass-spectra via the spectrumListPtr that sits in the
820 // run member of msp_msData.
821
822 pwiz::msdata::SpectrumListPtr spectrum_list_p =
823 msp_msData->run.spectrumListPtr;
824
825 // We'll need it to perform the looping in the spectrum list.
826 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
827
828 // qDebug() << "The spectrum list has size:" << spectrum_list_size;
829
830 // Inform the handler of the spectrum list so that it can handle feedback to
831 // the user.
832 handler.spectrumListHasSize(spectrum_list_size);
833
834 // Iterate in the full list of spectra.
835
836 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
837 {
838
839 // If the user of this reader instance wants to stop reading the
840 // spectra, then break this loop.
841 if(handler.shouldStop())
842 {
843 qDebug() << "The operation was cancelled. Breaking the loop.";
844 break;
845 }
846
847 // Get the native pwiz-spectrum from the spectrum list.
848 // Note that this pointer is a shared pointer from pwiz.
849
850 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
851 getPwizSpectrumPtr(spectrum_list_p.get(), iter, want_binary_data);
852
853 /*
854 * we want to load metadata of the spectrum even if it does not contain
855 peaks
856
857 * if(!native_pwiz_spectrum_sp->hasBinaryData())
858 {
859 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ <<
860 "
861 ()"
862 //<< "native pwiz spectrum is empty, continuing.";
863 continue;
864 }
865 */
866
867 // Instantiate the mass spectrum id that will hold critical information
868 // like the the native id string and the spectrum index.
869
870 MassSpectrumId massSpectrumId(mcsp_msRunId, iter /* spectrum index*/);
871
872 // Get the spectrum native id as a QString to store it in the mass
873 // spectrum id class. This is will allow later to refer to the same
874 // spectrum starting back from the file.
875
876 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
877 massSpectrumId.setNativeId(native_id);
878
879 // Finally, instantiate the qualified mass spectrum with its id. This
880 // function will continue performing pappso-spectrum detailed
881 // qualification.
882
883 bool ok = false;
884
885 QualifiedMassSpectrum qualified_mass_spectrum =
887 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
888
889 if(!ok)
890 {
891 // qDebug() << "Encountered a mass spectrum for which the returned "
892 //"status is bad.";
893 continue;
894 }
895
896 // Before handing the mass spectrum out to the handler, see if the
897 // native mass spectrum was empty or not.
898
899 // if(!native_pwiz_spectrum_sp->defaultArrayLength)
900 // qDebug() << "The mass spectrum has not defaultArrayLength";
901
902 qualified_mass_spectrum.setEmptyMassSpectrum(
903 !native_pwiz_spectrum_sp->defaultArrayLength);
904
905 // The handler will receive the index of the mass spectrum in the
906 // current run via the mass spectrum id member datum.
907 if(ms_level == 0)
908 {
909 handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
910 }
911 else
912 {
913 if(qualified_mass_spectrum.getMsLevel() == ms_level)
914 {
915 handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
916 }
917 }
918 }
919
920 setlocale(LC_ALL, env.c_str());
921 // End of
922 // for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
923
924 // Now let the loading handler know that the loading of the data has ended.
925 // The handler might need this "signal" to perform additional tasks or to
926 // cleanup cruft.
927
928 // qDebug() << "Loading ended";
929 handler.loadingEnded();
930}
virtual bool acquireDevice() override
acquire data back end device

References acquireDevice(), pappso::QualifiedMassSpectrum::getMsLevel(), getPwizSpectrumPtr(), pappso::SpectrumCollectionHandlerInterface::loadingEnded(), pappso::MsRunReader::mcsp_msRunId, msp_msData, pappso::SpectrumCollectionHandlerInterface::needPeakList(), qualifiedMassSpectrumFromPwizSpectrumPtr(), pappso::QualifiedMassSpectrum::setEmptyMassSpectrum(), pappso::MassSpectrumId::setNativeId(), pappso::SpectrumCollectionHandlerInterface::setQualifiedMassSpectrum(), pappso::SpectrumCollectionHandlerInterface::shouldStop(), and pappso::SpectrumCollectionHandlerInterface::spectrumListHasSize().

Referenced by readSpectrumCollection().

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

946{
947 msp_msData = nullptr;
948 return true;
949}

References msp_msData.

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

934{
935 return msp_msData->run.spectrumListPtr.get()->size();
936}

References msp_msData.

Friends And Related Function Documentation

◆ MsFileAccessor

friend class MsFileAccessor
friend

Definition at line 47 of file pwizmsrunreader.h.

Member Data Documentation

◆ m_hasScanNumbers

bool pappso::PwizMsRunReader::m_hasScanNumbers = false
private

Definition at line 113 of file pwizmsrunreader.h.

Referenced by hasScanNumbers(), and initialize().

◆ msp_msData

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

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