libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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
 
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
 
virtual void readSpectrumCollection (SpectrumCollectionHandlerInterface &handler) override
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
 
virtual void readSpectrumCollection2 (const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler) override
 
virtual pappso::XicCoordSPtr newXicCoordSPtrFromSpectrumIndex (std::size_t spectrum_index, pappso::PrecisionPtr precision) const override
 get a xic coordinate object from a given spectrum index
 
virtual pappso::XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum (const pappso::QualifiedMassSpectrum &mass_spectrum, pappso::PrecisionPtr precision) const override
 get a xic coordinate object from a given spectrum
 
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
 
virtual std::size_t spectrumListSize () const override
 get the totat number of spectrum conained in the MSrun data file
 
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
 
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
 
virtual bool acquireDevice () override
 acquire data back end device
 
const OboPsiModTerm getOboPsiModTermNativeIDFormat () const
 get OboPsiModTerm corresponding to the nativeID format format of mz data
 
- 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.
 
virtual std::vector< double > getRetentionTimeLine ()
 retention timeline get retention times along the MSrun in seconds
 
virtual Trace getTicChromatogram ()
 get a TIC chromatogram
 
void setMonoThread (bool is_mono_thread)
 set only one is_mono_thread to true
 
bool isMonoThread () const
 

Protected Member Functions

virtual void readSpectrumCollectionWithMsrunReadConfig (const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler)
 
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
 
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
 

Static Protected Attributes

static QMutex m_mutex
 

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

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

References initialize().

◆ ~PwizMsRunReader()

pappso::PwizMsRunReader::~PwizMsRunReader ( )
virtual

Definition at line 176 of file pwizmsrunreader.cpp.

177{
178}

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

786{
787 // We want to know if we can handle the file_name.
788 pwiz::msdata::ReaderList reader_list;
789
790 std::string reader_type = reader_list.identify(file_name.toStdString());
791
792 if(!reader_type.empty())
793 return true;
794
795 return false;
796}

◆ acquireDevice()

bool pappso::PwizMsRunReader::acquireDevice ( )
overridevirtual

acquire data back end device

Returns
bool true if done

Implements pappso::MsRunReader.

Definition at line 1161 of file pwizmsrunreader.cpp.

1162{
1163 if(msp_msData == nullptr)
1164 {
1165 initialize();
1166 }
1167 return true;
1168}
pwiz::msdata::MSDataPtr msp_msData

References initialize(), and msp_msData.

Referenced by readSpectrumCollectionByMsLevel(), and readSpectrumCollectionWithMsrunReadConfig().

◆ getOboPsiModTermNativeIDFormat()

const OboPsiModTerm pappso::PwizMsRunReader::getOboPsiModTermNativeIDFormat ( ) const

get OboPsiModTerm corresponding to the nativeID format format of mz data

Definition at line 182 of file pwizmsrunreader.cpp.

183{
184
185 OboPsiModTerm term;
186
187 term.m_accession = "MS:1000824";
188 term.m_name = "no nativeID format";
189 term.m_definition =
190 "No nativeID format indicates that the file tagged with this term does not "
191 "contain spectra that can have a nativeID format.";
192
193
194 pwiz::cv::CVID cvid =
195 pwiz::msdata::id::getDefaultNativeIDFormat(*(msp_msData.get()));
196
197 switch(cvid)
198 {
199 case pwiz::cv::MS_Thermo_nativeID_format:
200 term.m_accession = "MS:1000768";
201 term.m_name = "Thermo nativeID format";
202 term.m_definition =
203 "Native format defined by controllerType=xsd:nonNegativeInteger "
204 "controllerNumber=xsd:positiveInteger scan=xsd:positiveInteger.";
205 break;
206 default:
207 break;
208 }
209 return term;
210}

References pappso::OboPsiModTerm::m_accession, pappso::OboPsiModTerm::m_definition, pappso::OboPsiModTerm::m_name, and msp_msData.

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

216{
217 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp;
218
219 try
220 {
221 native_pwiz_spectrum_sp =
222 p_spectrum_list->spectrum(spectrum_index, want_binary_data);
223 }
224 catch(std::runtime_error &error)
225 {
226 qDebug() << "getPwizSpectrumPtr error " << error.what() << " "
227 << typeid(error).name();
228
229 throw ExceptionNotFound(QObject::tr("Pwiz spectrum index %1 not found in "
230 "MS file std::runtime_error :\n%2")
231 .arg(spectrum_index)
232 .arg(error.what()));
233 }
234 catch(std::exception &error)
235 {
236 qDebug() << "getPwizSpectrumPtr error " << error.what()
237 << typeid(error).name();
238
239 throw ExceptionNotFound(
240 QObject::tr("Pwiz spectrum index %1 not found in MS file :\n%2")
241 .arg(spectrum_index)
242 .arg(error.what()));
243 }
244
245 if(native_pwiz_spectrum_sp.get() == nullptr)
246 {
247 throw ExceptionNotFound(
248 QObject::tr(
249 "Pwiz spectrum index %1 not found in MS file : null pointer")
250 .arg(spectrum_index));
251 }
252
253 return native_pwiz_spectrum_sp;
254}

Referenced by qualifiedMassSpectrumFromPwizMSData(), readSpectrumCollectionByMsLevel(), and readSpectrumCollectionWithMsrunReadConfig().

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

1149{
1150 return m_hasScanNumbers;
1151}

References m_hasScanNumbers.

◆ initialize()

void pappso::PwizMsRunReader::initialize ( )
overrideprotectedvirtual

Implements pappso::MsRunReader.

Definition at line 66 of file pwizmsrunreader.cpp.

67{
68 std::string file_name_std =
70
71 // Make a backup of the current locale
72 std::string env_backup = setlocale(LC_ALL, "");
73 // struct lconv *lc = localeconv();
74
75 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
76 //<< "env_backup=" << env_backup.c_str() << "lc->decimal_point"
77 //<< lc->decimal_point;
78
79 // Now actually search the useful MSDataPtr to the member variable.
80
81 pwiz::msdata::DefaultReaderList defaultReaderList;
82
83 std::vector<pwiz::msdata::MSDataPtr> msDataPtrVector;
84
85 try
86 {
87 defaultReaderList.read(file_name_std, msDataPtrVector);
88 }
89 catch(std::exception &error)
90 {
91 qDebug() << QString("Failed to read the data from file %1")
92 .arg(QString::fromStdString(file_name_std));
93
94 throw(PappsoException(
95 QString("Error reading file %1 in PwizMsRunReader, for msrun %2:\n%3")
96 .arg(mcsp_msRunId->getFileName())
97 .arg(mcsp_msRunId.get()->toString())
98 .arg(error.what())));
99 }
100
101 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
102 //<< "The number of runs is:" << msDataPtrVector.size()
103 //<< "The number of spectra in first run is:"
104 //<< msDataPtrVector.at(0)->run.spectrumListPtr->size();
105
106 // Single-run file handling here.
107
108 // Specific case of the MGF data format: we do not have a run id for that kind
109 // of data. In this case there must be a single run!
110
111 if(mcsp_msRunId->getRunId().isEmpty())
112 {
113 if(msDataPtrVector.size() != 1)
114 throw(
115 ExceptionNotPossible("For the kind of file at hand there can only be "
116 "one run in the file."));
117
118 // At this point we know the single msDataPtr is the one we are looking
119 // for.
120
121 msp_msData = msDataPtrVector.front();
122 }
123 else
124 {
125 // Multi-run file handling here.
126 for(const pwiz::msdata::MSDataPtr &msDataPtr : msDataPtrVector)
127 {
128 qDebug() << "msDataPtr->run.id=" << msDataPtr->run.id.c_str();
129 qDebug() << "mcsp_msRunId->getRunId()=" << mcsp_msRunId->getRunId();
130 qDebug() << "mcsp_msRunId->getXmlId()=" << mcsp_msRunId->getXmlId();
131 qDebug() << "mcsp_msRunId->getSampleName()="
132 << mcsp_msRunId->getSampleName();
133 if(msDataPtr->run.id == mcsp_msRunId->getRunId().toStdString())
134 {
135 msp_msData = msDataPtr;
136
137 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
138 //<< "Found the right MSDataPtr for run id.";
139
140 break;
141 }
142 }
143 }
144
145 if(msp_msData == nullptr)
146 {
147 throw(ExceptionNotPossible(
148 QString(
149 "Could not find a pwiz MSDataPtr matching the requested run id : %1")
150 .arg(mcsp_msRunId.get()->toString())));
151 }
152
153
154 // check if this MS run can be used with scan numbers
155 // MS:1000490 Agilent instrument model
156 pwiz::cv::CVID native_id_format =
157 pwiz::msdata::id::getDefaultNativeIDFormat(*msp_msData.get());
158
159 // msp_msData.get()->getDefaultNativeIDFormat();
160
161 if(native_id_format == pwiz::cv::CVID::MS_Thermo_nativeID_format)
162 {
163 m_hasScanNumbers = true;
164 }
165 else
166 {
167 m_hasScanNumbers = false;
168 }
169
170 if(mcsp_msRunId.get()->getMsDataFormat() == MsDataFormat::mzXML)
171 {
172 m_hasScanNumbers = true;
173 }
174}
MsRunIdCstSPtr mcsp_msRunId
static std::string toUtf8StandardString(const QString &text)
Definition utils.cpp:164

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

808{
809 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
810 return qualifiedMassSpectrum(spectrum_index, true).getMassSpectrumCstSPtr();
811}
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 800 of file pwizmsrunreader.cpp.

801{
802 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
803 return qualifiedMassSpectrum(spectrum_index, true).getMassSpectrumSPtr();
804}
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 1183 of file pwizmsrunreader.cpp.

1186{
1187 XicCoordSPtr xic_coord = std::make_shared<XicCoord>();
1188
1189 xic_coord.get()->rtTarget = mass_spectrum.getRtInSeconds();
1190
1191 xic_coord.get()->mzRange = MzRange(mass_spectrum.getPrecursorMz(), precision);
1192
1193 return xic_coord;
1194}
pappso_double getPrecursorMz(bool *ok=nullptr) const
get precursor mz
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 1172 of file pwizmsrunreader.cpp.

1174{
1175
1176 QualifiedMassSpectrum mass_spectrum =
1177 qualifiedMassSpectrum(spectrum_index, false);
1178
1179 return newXicCoordSPtrFromQualifiedMassSpectrum(mass_spectrum, precision);
1180}
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 326 of file pwizmsrunreader.cpp.

329{
330 // Not all the acquisitions have ion mobility data. We need to test
331 // that:
332
333 if(spectrum_p->scanList.scans[0].hasCVParam(
334 pwiz::msdata::MS_ion_mobility_drift_time))
335 {
336
337 // qDebug() << "as strings:"
338 //<< QString::fromStdString(
339 // spectrum_p->scanList.scans[0]
340 //.cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
341 //.valueAs<std::string>());
342
343 pappso_double driftTime =
344 spectrum_p->scanList.scans[0]
345 .cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
346 .valueAs<double>();
347
348 // qDebug() << "driftTime:" << driftTime;
349
350 // Old version requiring use of QString.
351 // pappso_double driftTime =
352 // QString(spectrum_p->scanList.scans[0]
353 //.cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
354 //.value.c_str())
355 //.toDouble();
356
357 // Now make positively sure that the obtained value is correct.
358 // Note that I suffered a lot with Waters Synapt data that
359 // contained apparently correct drift time XML element that in
360 // fact contained either NaN or inf. When such mass spectra were
361 // encountered, the mz,i data were bogus and crashed the data
362 // loading functions. We just want to skip this kind of bogus mass
363 // spectrum by letting the caller know that the drift time was
364 // bogus ("I" is Filippo Rusconi).
365
366 if(std::isnan(driftTime) || std::isinf(driftTime))
367 {
368 // qDebug() << "detected as nan or inf.";
369
370 return false;
371 }
372 else
373 {
374 // The mzML standard stipulates that drift times are in
375 // milliseconds.
376 qualified_mass_spectrum.setDtInMilliSeconds(driftTime);
377 }
378 }
379 // End of
380 // if(spectrum_p->scanList.scans[0].hasCVParam(
381 // pwiz::msdata::MS_ion_mobility_drift_time))
382 else
383 {
384 // Not a bogus mass spectrum but also not a drift spectrum, set -1
385 // as the drift time value.
386 qualified_mass_spectrum.setDtInMilliSeconds(-1);
387 }
388
389 return true;
390}
double pappso_double
A type definition for doubles.
Definition types.h:50

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

261{
262
263 // We now have to set the retention time at which this mass spectrum
264 // was acquired. This is the scan start time.
265
266 if(!spectrum_p->scanList.scans[0].hasCVParam(
267 pwiz::msdata::MS_scan_start_time))
268 {
269 if(mcsp_msRunId.get()->getMsDataFormat() == MsDataFormat::MGF)
270 { // MGF could not have scan start time
271 qualified_mass_spectrum.setRtInSeconds(-1);
272 }
273 else
274 {
275 throw(ExceptionNotPossible(
276 "The spectrum has no scan start time value set."));
277 }
278 }
279 else
280 {
281 pwiz::data::CVParam retention_time_cv_param =
282 spectrum_p->scanList.scans[0].cvParam(pwiz::msdata::MS_scan_start_time);
283
284 // Try to get the units of the retention time value.
285
286 std::string unit_name = retention_time_cv_param.unitsName();
287 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
288 //<< "Unit name for the retention time:"
289 //<< QString::fromStdString(unit_name);
290
291 if(unit_name == "second")
292 {
293 qualified_mass_spectrum.setRtInSeconds(
294 retention_time_cv_param.valueAs<double>());
295 }
296 else if(unit_name == "minute")
297 {
298 qualified_mass_spectrum.setRtInSeconds(
299 retention_time_cv_param.valueAs<double>() * 60);
300 }
301 else
302 throw(
303 ExceptionNotPossible("Could not determine the unit for the "
304 "scan start time value."));
305 }
306
307 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
308 //<< "Retention time for spectrum is:"
309 //<< qualified_mass_spectrum.getRtInSeconds();
310
311 // Old version not checking unit (by default unit is minutes for RT,
312 // not seconds)
313 //
314 // pappso_double retentionTime =
315 // QString(spectrum_p->scanList.scans[0]
316 //.cvParam(pwiz::msdata::MS_scan_start_time)
317 //.value.c_str())
318 //.toDouble();
319 // qualified_mass_spectrum.setRtInSeconds(retentionTime);
320
321 return true;
322}
@ 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 814 of file pwizmsrunreader.cpp.

816{
817
818 QualifiedMassSpectrum spectrum;
819 bool ok = false;
820
821 spectrum =
822 qualifiedMassSpectrumFromPwizMSData(spectrum_index, want_binary_data, ok);
823
824 if(mcsp_msRunId->getMsDataFormat() == pappso::MsDataFormat::MGF)
825 {
826 if(spectrum.getRtInSeconds() == 0)
827 {
828 // spectrum = qualifiedMassSpectrumFromPwizMSData(scan_num - 1);
829 }
830 }
831
832 // if(!ok)
833 // qDebug() << "Encountered a mass spectrum for which the status is bad.";
834
835 return spectrum;
836}
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 731 of file pwizmsrunreader.cpp.

734{
735
736 std::string env;
737 env = setlocale(LC_ALL, "");
738 // struct lconv *lc = localeconv();
739
740 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
741 //<< "env=" << env.c_str()
742 //<< "lc->decimal_point:" << lc->decimal_point;
743
744 setlocale(LC_ALL, "C");
745
746 MassSpectrumId massSpectrumId(mcsp_msRunId);
747
748 if(msp_msData == nullptr)
749 {
750 setlocale(LC_ALL, env.c_str());
751 return (QualifiedMassSpectrum(massSpectrumId));
752 }
753
754 // const bool want_binary_data = true;
755
756 pwiz::msdata::SpectrumListPtr spectrum_list_p =
757 msp_msData->run.spectrumListPtr;
758
759 if(spectrum_index == spectrum_list_p.get()->size())
760 {
761 setlocale(LC_ALL, env.c_str());
762 throw ExceptionNotFound(
763 QObject::tr("The spectrum index cannot be equal to the size of the "
764 "spectrum list."));
765 }
766
767 // At this point we know the spectrum index might be sane, so store it in
768 // the mass spec id object.
769 massSpectrumId.setSpectrumIndex(spectrum_index);
770
771 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
772 getPwizSpectrumPtr(spectrum_list_p.get(), spectrum_index, want_binary_data);
773
774 setlocale(LC_ALL, env.c_str());
775
776 massSpectrumId.setNativeId(
777 QString::fromStdString(native_pwiz_spectrum_sp->id));
778
780 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
781}
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 394 of file pwizmsrunreader.cpp.

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

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::ScanNumber, pappso::QualifiedMassSpectrum::setMassSpectrumSPtr(), pappso::QualifiedMassSpectrum::setMsLevel(), pappso::QualifiedMassSpectrum::setParameterValue(), pappso::QualifiedMassSpectrum::setPrecursorNativeId(), pappso::QualifiedMassSpectrum::setPrecursorSpectrumIndex(), and pappso::MassSpectrum::sortMz().

Referenced by qualifiedMassSpectrumFromPwizMSData(), readSpectrumCollectionByMsLevel(), and readSpectrumCollectionWithMsrunReadConfig().

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

842{
844}
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().

◆ readSpectrumCollection2()

void pappso::PwizMsRunReader::readSpectrumCollection2 ( const MsRunReadConfig config,
SpectrumCollectionHandlerInterface handler 
)
overridevirtual

Implements pappso::MsRunReader.

Definition at line 847 of file pwizmsrunreader.cpp.

850{
851 qDebug();
852
854}
virtual void readSpectrumCollectionWithMsrunReadConfig(const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler)

References readSpectrumCollectionWithMsrunReadConfig().

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

859{
860
862 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()";
863
864 // We want to iterate in the pwiz-spectrum-list and for each pwiz-spectrum
865 // create a pappso-spectrum (QualifiedMassSpectrum). Once the pappso mass
866 // spectrum has been fully qualified (that is, the member data have been
867 // set), it is transferred to the handler passed as parameter to this
868 // function for the consumer to do what it wants with it.
869
870 // Does the handler consuming the mass spectra read from file want these
871 // mass spectra to hold the binary data arrays (mz/i vectors)?
872
873 const bool want_binary_data = handler.needPeakList();
874
875
876 std::string env;
877 env = setlocale(LC_ALL, "");
878 setlocale(LC_ALL, "C");
879
880
881 // We access the pwiz-mass-spectra via the spectrumListPtr that sits in the
882 // run member of msp_msData.
883
884 pwiz::msdata::SpectrumListPtr spectrum_list_p =
885 msp_msData->run.spectrumListPtr;
886
887 // We'll need it to perform the looping in the spectrum list.
888 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
889
890 // qDebug() << "The spectrum list has size:" << spectrum_list_size;
891
892 // Inform the handler of the spectrum list so that it can handle feedback to
893 // the user.
894 handler.spectrumListHasSize(spectrum_list_size);
895
896 // Iterate in the full list of spectra.
897
898 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
899 {
900
901 // If the user of this reader instance wants to stop reading the
902 // spectra, then break this loop.
903 if(handler.shouldStop())
904 {
905 qDebug() << "The operation was cancelled. Breaking the loop.";
906 break;
907 }
908
909 // Get the native pwiz-spectrum from the spectrum list.
910 // Note that this pointer is a shared pointer from pwiz.
911
912 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
913 getPwizSpectrumPtr(spectrum_list_p.get(), iter, want_binary_data);
914 /*
915 * we want to load metadata of the spectrum even if it does not contain
916 peaks
917
918 * if(!native_pwiz_spectrum_sp->hasBinaryData())
919 {
920 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ <<
921 "
922 ()"
923 //<< "native pwiz spectrum is empty, continuing.";
924 continue;
925 }
926 */
927
928 // Instantiate the mass spectrum id that will hold critical information
929 // like the the native id string and the spectrum index.
930
931 MassSpectrumId massSpectrumId(mcsp_msRunId, iter /* spectrum index*/);
932
933 // Get the spectrum native id as a QString to store it in the mass
934 // spectrum id class. This is will allow later to refer to the same
935 // spectrum starting back from the file.
936
937 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
938 massSpectrumId.setNativeId(native_id);
939
940 // Finally, instantiate the qualified mass spectrum with its id. This
941 // function will continue performing pappso-spectrum detailed
942 // qualification.
943
944 bool ok = false;
945
946 QualifiedMassSpectrum qualified_mass_spectrum =
948 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
949
950 if(!ok)
951 {
952 // qDebug() << "Encountered a mass spectrum for which the returned "
953 //"status is bad.";
954 continue;
955 }
956
957 // Before handing the mass spectrum out to the handler, see if the
958 // native mass spectrum was empty or not.
959
960 // if(!native_pwiz_spectrum_sp->defaultArrayLength)
961 // qDebug() << "The mass spectrum has not defaultArrayLength";
962
963 qualified_mass_spectrum.setEmptyMassSpectrum(
964 !native_pwiz_spectrum_sp->defaultArrayLength);
965
966 // The handler will receive the index of the mass spectrum in the
967 // current run via the mass spectrum id member datum.
968 if(ms_level == 0)
969 {
970 handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
971 }
972 else
973 {
974 if(qualified_mass_spectrum.getMsLevel() == ms_level)
975 {
976 handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
977 }
978 }
979 }
980
981 setlocale(LC_ALL, env.c_str());
982 // End of
983 // for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
984
985 // Now let the loading handler know that the loading of the data has ended.
986 // The handler might need this "signal" to perform additional tasks or to
987 // cleanup cruft.
988
989 // qDebug() << "Loading ended";
990 handler.loadingEnded();
991}
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().

◆ readSpectrumCollectionWithMsrunReadConfig()

void pappso::PwizMsRunReader::readSpectrumCollectionWithMsrunReadConfig ( const MsRunReadConfig config,
SpectrumCollectionHandlerInterface handler 
)
protectedvirtual

Definition at line 994 of file pwizmsrunreader.cpp.

996{
997 // pwiz library is not thread safe under MXE
998 QMutexLocker lock(&m_mutex);
999
1000 qDebug();
1001 acquireDevice();
1002 qDebug();
1003 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()";
1004
1005 // We want to iterate in the pwiz-spectrum-list and for each pwiz-spectrum
1006 // create a pappso-spectrum (QualifiedMassSpectrum). Once the pappso mass
1007 // spectrum has been fully qualified (that is, the member data have been
1008 // set), it is transferred to the handler passed as parameter to this
1009 // function for the consumer to do what it wants with it.
1010
1011 // Does the handler consuming the mass spectra read from file want these
1012 // mass spectra to hold the binary data arrays (mz/i vectors)?
1013
1014 const bool want_binary_data = config.needPeakList();
1015
1016
1017 std::string env;
1018 env = setlocale(LC_ALL, "");
1019 setlocale(LC_ALL, "C");
1020
1021
1022 qDebug();
1023 // We access the pwiz-mass-spectra via the spectrumListPtr that sits in the
1024 // run member of msp_msData.
1025
1026 pwiz::msdata::SpectrumListPtr spectrum_list_p =
1027 msp_msData->run.spectrumListPtr;
1028
1029 // We'll need it to perform the looping in the spectrum list.
1030 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
1031
1032 // qDebug() << "The spectrum list has size:" << spectrum_list_size;
1033
1034 // Inform the handler of the spectrum list so that it can handle feedback to
1035 // the user.
1036 handler.spectrumListHasSize(spectrum_list_size);
1037
1038 // Iterate in the full list of spectra.
1039
1040 qDebug();
1041 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
1042 {
1043
1044
1045 // If the user of this reader instance wants to stop reading the
1046 // spectra, then break this loop.
1047 if(handler.shouldStop())
1048 {
1049 qDebug() << "The operation was cancelled. Breaking the loop.";
1050 break;
1051 }
1052
1053 qDebug();
1054 // Get the native pwiz-spectrum from the spectrum list.
1055 // Note that this pointer is a shared pointer from pwiz.
1056
1057 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
1058 getPwizSpectrumPtr(spectrum_list_p.get(), iter, want_binary_data);
1059 qDebug();
1060 /*
1061 * we want to load metadata of the spectrum even if it does not contain
1062 peaks
1063
1064 * if(!native_pwiz_spectrum_sp->hasBinaryData())
1065 {
1066 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ <<
1067 "
1068 ()"
1069 //<< "native pwiz spectrum is empty, continuing.";
1070 continue;
1071 }
1072 */
1073
1074 // Instantiate the mass spectrum id that will hold critical information
1075 // like the the native id string and the spectrum index.
1076
1077 MassSpectrumId massSpectrumId(mcsp_msRunId, iter /* spectrum index*/);
1078
1079 qDebug();
1080 // Get the spectrum native id as a QString to store it in the mass
1081 // spectrum id class. This is will allow later to refer to the same
1082 // spectrum starting back from the file.
1083
1084 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
1085 massSpectrumId.setNativeId(native_id);
1086
1087 // Finally, instantiate the qualified mass spectrum with its id. This
1088 // function will continue performing pappso-spectrum detailed
1089 // qualification.
1090
1091 bool ok = false;
1092
1093 QualifiedMassSpectrum qualified_mass_spectrum =
1095 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
1096
1097 if(!ok)
1098 {
1099 // qDebug() << "Encountered a mass spectrum for which the returned "
1100 //"status is bad.";
1101 continue;
1102 }
1103
1104 qDebug();
1105 // Before handing the mass spectrum out to the handler, see if the
1106 // native mass spectrum was empty or not.
1107
1108 // if(!native_pwiz_spectrum_sp->defaultArrayLength)
1109 // qDebug() << "The mass spectrum has not defaultArrayLength";
1110
1111 qualified_mass_spectrum.setEmptyMassSpectrum(
1112 !native_pwiz_spectrum_sp->defaultArrayLength);
1113
1114 // The handler will receive the index of the mass spectrum in the
1115 // current run via the mass spectrum id member datum.
1116
1117 qDebug();
1118 if(config.acceptMsLevel(qualified_mass_spectrum.getMsLevel()))
1119 {
1120 if(config.acceptRetentionTimeInSeconds(
1121 qualified_mass_spectrum.getRtInSeconds()))
1122 {
1123 handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
1124 }
1125 }
1126 }
1127
1128 qDebug();
1129 setlocale(LC_ALL, env.c_str());
1130 // End of
1131 // for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
1132
1133 // Now let the loading handler know that the loading of the data has ended.
1134 // The handler might need this "signal" to perform additional tasks or to
1135 // cleanup cruft.
1136
1137 qDebug() << "Loading ended";
1138 handler.loadingEnded();
1139}

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

Referenced by readSpectrumCollection2().

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

1155{
1156 msp_msData = nullptr;
1157 return true;
1158}

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

1143{
1144 return msp_msData->run.spectrumListPtr.get()->size();
1145}

References msp_msData.

Friends And Related Symbol 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 129 of file pwizmsrunreader.h.

Referenced by hasScanNumbers(), and initialize().

◆ m_mutex

QMutex pappso::PwizMsRunReader::m_mutex
staticprotected

Definition at line 124 of file pwizmsrunreader.h.

Referenced by readSpectrumCollectionWithMsrunReadConfig().

◆ msp_msData


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