36 #include <pwiz/data/msdata/DefaultReaderList.hpp>
39 #include "../../utils.h"
40 #include "../../pappsoexception.h"
41 #include "../../exception/exceptionnotfound.h"
42 #include "../../exception/exceptionnotpossible.h"
67 std::string file_name_std =
71 std::string env_backup = setlocale(LC_ALL,
"");
80 pwiz::msdata::DefaultReaderList defaultReaderList;
82 std::vector<pwiz::msdata::MSDataPtr> msDataPtrVector;
86 defaultReaderList.read(file_name_std, msDataPtrVector);
88 catch(std::exception &error)
90 qDebug() << QString(
"Failed to read the data from file %1")
91 .arg(QString::fromStdString(file_name_std));
94 QString(
"Error reading file %1 in PwizMsRunReader, for msrun %2:\n%3")
112 if(msDataPtrVector.size() != 1)
115 "one run in the file."));
125 for(
auto &msDataPtr : msDataPtrVector)
127 if(msDataPtr->run.id ==
mcsp_msRunId->getRunId().toStdString())
142 QString(
"Could not find a MSDataPtr matching the requested run id : %1")
149 pwiz::cv::CVID native_id_format =
150 pwiz::msdata::id::getDefaultNativeIDFormat(*
msp_msData.get());
154 if(native_id_format == pwiz::cv::CVID::MS_Thermo_nativeID_format)
175 pwiz::msdata::SpectrumPtr
177 std::size_t spectrum_index,
178 bool want_binary_data)
const
180 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp;
184 native_pwiz_spectrum_sp =
185 p_spectrum_list->spectrum(spectrum_index, want_binary_data);
187 catch(std::runtime_error &error)
189 qDebug() <<
"getPwizSpectrumPtr error " << error.what() <<
" "
190 <<
typeid(error).name();
193 "MS file std::runtime_error :\n%2")
197 catch(std::exception &error)
199 qDebug() <<
"getPwizSpectrumPtr error " << error.what()
200 <<
typeid(error).name();
203 QObject::tr(
"Pwiz spectrum index %1 not found in MS file :\n%2")
208 if(native_pwiz_spectrum_sp.get() ==
nullptr)
212 "Pwiz spectrum index %1 not found in MS file : null pointer")
213 .arg(spectrum_index));
216 return native_pwiz_spectrum_sp;
222 pwiz::msdata::Spectrum *spectrum_p,
229 if(!spectrum_p->scanList.scans[0].hasCVParam(
230 pwiz::msdata::MS_scan_start_time))
239 "The spectrum has no scan start time value set."));
244 pwiz::data::CVParam retention_time_cv_param =
245 spectrum_p->scanList.scans[0].cvParam(pwiz::msdata::MS_scan_start_time);
249 std::string unit_name = retention_time_cv_param.unitsName();
254 if(unit_name ==
"second")
257 retention_time_cv_param.valueAs<
double>());
259 else if(unit_name ==
"minute")
262 retention_time_cv_param.valueAs<
double>() * 60);
267 "scan start time value."));
290 pwiz::msdata::Spectrum *spectrum_p,
296 if(spectrum_p->scanList.scans[0].hasCVParam(
297 pwiz::msdata::MS_ion_mobility_drift_time))
307 spectrum_p->scanList.scans[0]
308 .cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
329 if(std::isnan(driftTime) || std::isinf(driftTime))
359 pwiz::msdata::Spectrum *spectrum_p,
360 bool want_binary_data,
366 env = setlocale(LC_ALL,
"");
367 setlocale(LC_ALL,
"C");
377 (spectrum_p->cvParam(pwiz::msdata::MS_ms_level).valueAs<
int>());
384 std::size_t precursor_list_size = spectrum_p->precursors.size();
391 if(precursor_list_size > 0)
397 qDebug() <<
"Going to throw: msLevel cannot be less than two for "
398 "a spectrum that has items in its Precursor list.";
401 "msLevel cannot be less than two for "
402 "a spectrum that has items in its Precursor list."));
407 for(
auto &precursor : spectrum_p->precursors)
413 std::size_t precursor_spectrum_index =
414 std::numeric_limits<std::size_t>::max();
418 if(precursor.spectrumID.empty())
445 QString::fromStdString(precursor.spectrumID));
456 precursor_spectrum_index =
457 msp_msData->run.spectrumListPtr->find(precursor.spectrumID);
461 if(precursor_spectrum_index ==
467 "Failed to find the index of the "
468 "precursor ion's spectrum."));
473 precursor_spectrum_index);
483 if(!precursor.selectedIons.size())
486 <<
"Going to throw The spectrum has msLevel > 1 but the "
487 "precursor ions's selected ions list is empty..";
491 "precursor ions's selected ions "
495 pwiz::msdata::SelectedIon &ion =
496 *(precursor.selectedIons.begin());
502 ion.cvParam(pwiz::cv::MS_selected_ion_m_z).value.c_str())
508 QString(ion.cvParam(pwiz::cv::MS_peak_intensity).value.c_str())
513 unsigned int selected_ion_charge_state =
514 QString(ion.cvParam(pwiz::cv::MS_charge_state).value.c_str())
521 selected_ion_charge_state,
522 selected_ion_peak_intensity);
563 if(precursor_list_size !=
566 qDebug() <<
"Going to throw The number of precursors in the file is "
567 "different from the number of precursors in memory.";
570 QObject::tr(
"The number of precursors in the file is different "
571 "from the number of precursors in memory."));
599 std::vector<pwiz::msdata::MZIntensityPair> pairs;
600 spectrum_p->getMZIntensityPairs(pairs);
607 for(std::vector<pwiz::msdata::MZIntensityPair>::const_iterator
619 spectrum.push_back(
DataPoint(it->mz, it->intensity));
620 tic += it->intensity;
651 qDebug() <<
"Going to throw";
654 QObject::tr(
"Error reading data using the proteowizard library: %1")
655 .arg(errorp.
qwhat()));
657 catch(std::exception &error)
659 qDebug() <<
"Going to throw";
662 QObject::tr(
"Error reading data using the proteowizard library: %1")
672 return qualified_mass_spectrum;
678 bool want_binary_data,
683 env = setlocale(LC_ALL,
"");
690 setlocale(LC_ALL,
"C");
696 setlocale(LC_ALL, env.c_str());
702 pwiz::msdata::SpectrumListPtr spectrum_list_p =
705 if(spectrum_index == spectrum_list_p.get()->size())
707 setlocale(LC_ALL, env.c_str());
709 QObject::tr(
"The spectrum index cannot be equal to the size of the "
717 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
720 setlocale(LC_ALL, env.c_str());
723 QString::fromStdString(native_pwiz_spectrum_sp->id));
726 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
734 pwiz::msdata::ReaderList reader_list;
736 std::string reader_type = reader_list.identify(file_name.toStdString());
738 if(!reader_type.empty())
761 bool want_binary_data)
const
814 env = setlocale(LC_ALL,
"");
815 setlocale(LC_ALL,
"C");
821 pwiz::msdata::SpectrumListPtr spectrum_list_p =
825 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
835 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
842 qDebug() <<
"The operation was cancelled. Breaking the loop.";
849 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
875 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
886 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
902 !native_pwiz_spectrum_sp->defaultArrayLength);
912 if(qualified_mass_spectrum.
getMsLevel() == ms_level)
919 setlocale(LC_ALL, env.c_str());
934 return msp_msData->run.spectrumListPtr.get()->size();
void setNativeId(const QString &native_id)
void setSpectrumIndex(std::size_t index)
Class to represent a mass spectrum.
void sortMz()
Sort the DataPoint instances of this spectrum.
MassSpectrumSPtr makeMassSpectrumSPtr() const
base class to read MSrun the only way to build a MsRunReader object is to use the MsRunReaderFactory
MsRunIdCstSPtr mcsp_msRunId
virtual const QString & qwhat() const
virtual pappso::XicCoordSPtr newXicCoordSPtrFromSpectrumIndex(std::size_t spectrum_index, pappso::PrecisionPtr precision) const override
get a xic coordinate object from a given spectrum index
pwiz::msdata::MSDataPtr msp_msData
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
bool processDriftTime(pwiz::msdata::Spectrum *spectrum_p, QualifiedMassSpectrum &qualified_mass_spectrum) const
virtual MassSpectrumCstSPtr massSpectrumCstSPtr(std::size_t spectrum_index) override
QualifiedMassSpectrum qualifiedMassSpectrumFromPwizMSData(std::size_t spectrum_index, bool want_binary_data, bool &ok) const
PwizMsRunReader(MsRunIdCstSPtr &msrun_id_csp)
QualifiedMassSpectrum qualifiedMassSpectrumFromPwizSpectrumPtr(const MassSpectrumId &massSpectrumId, pwiz::msdata::Spectrum *spectrum_p, bool want_binary_data, bool &ok) const
virtual QualifiedMassSpectrum qualifiedMassSpectrum(std::size_t spectrum_index, bool want_binary_data=true) const override
get a QualifiedMassSpectrum class given its scan number
virtual bool hasScanNumbers() const override
tells if spectra can be accessed using scan numbers by default, it returns false. Only overrided func...
bool processRetentionTime(pwiz::msdata::Spectrum *spectrum_p, QualifiedMassSpectrum &qualified_mass_spectrum) const
virtual bool acquireDevice() override
acquire data back end device
virtual ~PwizMsRunReader()
virtual void initialize() override
virtual void readSpectrumCollection(SpectrumCollectionHandlerInterface &handler) override
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
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,...
virtual std::size_t spectrumListSize() const override
get the totat number of spectrum conained in the MSrun data file
pwiz::msdata::SpectrumPtr getPwizSpectrumPtr(pwiz::msdata::SpectrumList *p_spectrum_list, std::size_t spectrum_index, bool want_binary_data) const
virtual bool releaseDevice() override
release data back end device if a the data back end is released, the developper has to use acquireDev...
virtual pappso::XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum(const pappso::QualifiedMassSpectrum &mass_spectrum, pappso::PrecisionPtr precision) const override
get a xic coordinate object from a given spectrum
virtual MassSpectrumSPtr massSpectrumSPtr(std::size_t spectrum_index) override
get a MassSpectrumSPtr class given its spectrum index
Class representing a fully specified mass spectrum.
uint getMsLevel() const
Get the mass spectrum level.
MassSpectrumCstSPtr getMassSpectrumCstSPtr() const
Get the MassSpectrumCstSPtr.
void setPrecursorNativeId(const QString &native_id)
Set the scan native id of the precursor ion.
const std::vector< PrecursorIonData > & getPrecursorIonData() const
void setDtInMilliSeconds(pappso_double rt)
Set the drift time in milliseconds.
const QString & getPrecursorNativeId() const
void appendPrecursorIonData(const PrecursorIonData &precursor_ion_data)
void setMsLevel(uint ms_level)
Set the mass spectrum level.
void setPrecursorSpectrumIndex(std::size_t precursor_scan_num)
Set the scan number of the precursor ion.
pappso_double getPrecursorMz(bool *ok=nullptr) const
Get the precursor m/z ratio.
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.
void setMassSpectrumSPtr(MassSpectrumSPtr massSpectrum)
Set the MassSpectrumSPtr.
void setRtInSeconds(pappso_double rt)
Set the retention time in seconds.
pappso_double getRtInSeconds() const
Get the retention time in seconds.
void setEmptyMassSpectrum(bool is_empty_mass_spectrum)
interface to collect spectrums from the MsRunReader class
virtual bool shouldStop()
virtual bool needPeakList() const =0
tells if we need the peak list (if we want the binary data) for each spectrum
virtual void loadingEnded()
virtual void spectrumListHasSize(std::size_t size)
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum)=0
static std::string toUtf8StandardString(const QString &text)
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
double pappso_double
A type definition for doubles.
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
std::shared_ptr< XicCoord > XicCoordSPtr
MSrun file reader base on proteowizard library.