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."));
126 for(
auto &msDataPtr : msDataPtrVector)
128 if(msDataPtr->run.id ==
mcsp_msRunId->getRunId().toStdString())
143 QString(
"Could not find a MSDataPtr matching the requested run id : %1")
150 pwiz::cv::CVID native_id_format =
151 pwiz::msdata::id::getDefaultNativeIDFormat(*
msp_msData.get());
155 if(native_id_format == pwiz::cv::CVID::MS_Thermo_nativeID_format)
176 pwiz::msdata::SpectrumPtr
178 std::size_t spectrum_index,
179 bool want_binary_data)
const
181 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp;
185 native_pwiz_spectrum_sp =
186 p_spectrum_list->spectrum(spectrum_index, want_binary_data);
188 catch(std::runtime_error &error)
190 qDebug() <<
"getPwizSpectrumPtr error " << error.what() <<
" "
191 <<
typeid(error).name();
194 "MS file std::runtime_error :\n%2")
198 catch(std::exception &error)
200 qDebug() <<
"getPwizSpectrumPtr error " << error.what()
201 <<
typeid(error).name();
204 QObject::tr(
"Pwiz spectrum index %1 not found in MS file :\n%2")
209 if(native_pwiz_spectrum_sp.get() ==
nullptr)
213 "Pwiz spectrum index %1 not found in MS file : null pointer")
214 .arg(spectrum_index));
217 return native_pwiz_spectrum_sp;
223 pwiz::msdata::Spectrum *spectrum_p,
230 if(!spectrum_p->scanList.scans[0].hasCVParam(
231 pwiz::msdata::MS_scan_start_time))
240 "The spectrum has no scan start time value set."));
245 pwiz::data::CVParam retention_time_cv_param =
246 spectrum_p->scanList.scans[0].cvParam(pwiz::msdata::MS_scan_start_time);
250 std::string unit_name = retention_time_cv_param.unitsName();
255 if(unit_name ==
"second")
258 retention_time_cv_param.valueAs<
double>());
260 else if(unit_name ==
"minute")
263 retention_time_cv_param.valueAs<
double>() * 60);
268 "scan start time value."));
291 pwiz::msdata::Spectrum *spectrum_p,
297 if(spectrum_p->scanList.scans[0].hasCVParam(
298 pwiz::msdata::MS_ion_mobility_drift_time))
308 spectrum_p->scanList.scans[0]
309 .cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
330 if(std::isnan(driftTime) || std::isinf(driftTime))
360 pwiz::msdata::Spectrum *spectrum_p,
361 bool want_binary_data,
367 env = setlocale(LC_ALL,
"");
368 setlocale(LC_ALL,
"C");
378 (spectrum_p->cvParam(pwiz::msdata::MS_ms_level).valueAs<
int>());
385 std::size_t precursor_list_size = spectrum_p->precursors.size();
392 if(precursor_list_size > 0)
398 qDebug() <<
"Going to throw: msLevel cannot be less than two for "
399 "a spectrum that has items in its Precursor list.";
402 "msLevel cannot be less than two for "
403 "a spectrum that has items in its Precursor list."));
408 for(
auto &precursor : spectrum_p->precursors)
414 std::size_t precursor_spectrum_index =
415 std::numeric_limits<std::size_t>::max();
419 if(precursor.spectrumID.empty())
446 QString::fromStdString(precursor.spectrumID));
457 precursor_spectrum_index =
458 msp_msData->run.spectrumListPtr->find(precursor.spectrumID);
462 if(precursor_spectrum_index ==
468 "Failed to find the index of the "
469 "precursor ion's spectrum."));
474 precursor_spectrum_index);
484 if(!precursor.selectedIons.size())
487 <<
"Going to throw The spectrum has msLevel > 1 but the "
488 "precursor ions's selected ions list is empty..";
492 "precursor ions's selected ions "
496 pwiz::msdata::SelectedIon &ion =
497 *(precursor.selectedIons.begin());
503 ion.cvParam(pwiz::cv::MS_selected_ion_m_z).value.c_str())
509 QString(ion.cvParam(pwiz::cv::MS_peak_intensity).value.c_str())
514 unsigned int selected_ion_charge_state =
515 QString(ion.cvParam(pwiz::cv::MS_charge_state).value.c_str())
522 selected_ion_charge_state,
523 selected_ion_peak_intensity);
564 if(precursor_list_size !=
567 qDebug() <<
"Going to throw The number of precursors in the file is "
568 "different from the number of precursors in memory.";
571 QObject::tr(
"The number of precursors in the file is different "
572 "from the number of precursors in memory."));
600 std::vector<pwiz::msdata::MZIntensityPair> pairs;
601 spectrum_p->getMZIntensityPairs(pairs);
608 for(std::vector<pwiz::msdata::MZIntensityPair>::const_iterator
620 spectrum.push_back(
DataPoint(it->mz, it->intensity));
621 tic += it->intensity;
652 qDebug() <<
"Going to throw";
655 QObject::tr(
"Error reading data using the proteowizard library: %1")
656 .arg(errorp.
qwhat()));
658 catch(std::exception &error)
660 qDebug() <<
"Going to throw";
663 QObject::tr(
"Error reading data using the proteowizard library: %1")
673 return qualified_mass_spectrum;
679 bool want_binary_data,
684 env = setlocale(LC_ALL,
"");
691 setlocale(LC_ALL,
"C");
697 setlocale(LC_ALL, env.c_str());
703 pwiz::msdata::SpectrumListPtr spectrum_list_p =
706 if(spectrum_index == spectrum_list_p.get()->size())
708 setlocale(LC_ALL, env.c_str());
710 QObject::tr(
"The spectrum index cannot be equal to the size of the "
718 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
721 setlocale(LC_ALL, env.c_str());
724 QString::fromStdString(native_pwiz_spectrum_sp->id));
727 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
735 pwiz::msdata::ReaderList reader_list;
737 std::string reader_type = reader_list.identify(file_name.toStdString());
739 if(!reader_type.empty())
762 bool want_binary_data)
const
815 env = setlocale(LC_ALL,
"");
816 setlocale(LC_ALL,
"C");
822 pwiz::msdata::SpectrumListPtr spectrum_list_p =
826 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
836 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
843 qDebug() <<
"The operation was cancelled. Breaking the loop.";
850 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
876 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
887 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
903 !native_pwiz_spectrum_sp->defaultArrayLength);
913 if(qualified_mass_spectrum.
getMsLevel() == ms_level)
920 setlocale(LC_ALL, env.c_str());
935 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
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 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.
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
MSrun file reader base on proteowizard library.