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 qDebug() <<
"msDataPtr->run.id=" << msDataPtr->run.id.c_str();
128 qDebug() <<
"mcsp_msRunId->getRunId()=" <<
mcsp_msRunId->getRunId();
129 qDebug() <<
"mcsp_msRunId->getXmlId()=" <<
mcsp_msRunId->getXmlId();
130 qDebug() <<
"mcsp_msRunId->getSampleName()=" <<
mcsp_msRunId->getSampleName();
131 if(msDataPtr->run.id ==
mcsp_msRunId->getRunId().toStdString())
146 QString(
"Could not find a pwiz MSDataPtr matching the requested run id : %1")
153 pwiz::cv::CVID native_id_format =
154 pwiz::msdata::id::getDefaultNativeIDFormat(*
msp_msData.get());
158 if(native_id_format == pwiz::cv::CVID::MS_Thermo_nativeID_format)
185 term.
m_name =
"no nativeID format";
187 "No nativeID format indicates that the file tagged with this term does not "
188 "contain spectra that can have a nativeID format.";
191 pwiz::cv::CVID cvid =
192 pwiz::msdata::id::getDefaultNativeIDFormat(*(
msp_msData.get()));
196 case pwiz::cv::MS_Thermo_nativeID_format:
198 term.
m_name =
"Thermo nativeID format";
200 "Native format defined by controllerType=xsd:nonNegativeInteger "
201 "controllerNumber=xsd:positiveInteger scan=xsd:positiveInteger.";
209pwiz::msdata::SpectrumPtr
211 std::size_t spectrum_index,
212 bool want_binary_data)
const
214 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp;
218 native_pwiz_spectrum_sp =
219 p_spectrum_list->spectrum(spectrum_index, want_binary_data);
221 catch(std::runtime_error &error)
223 qDebug() <<
"getPwizSpectrumPtr error " << error.what() <<
" "
224 <<
typeid(error).name();
227 "MS file std::runtime_error :\n%2")
231 catch(std::exception &error)
233 qDebug() <<
"getPwizSpectrumPtr error " << error.what()
234 <<
typeid(error).name();
237 QObject::tr(
"Pwiz spectrum index %1 not found in MS file :\n%2")
242 if(native_pwiz_spectrum_sp.get() ==
nullptr)
246 "Pwiz spectrum index %1 not found in MS file : null pointer")
247 .arg(spectrum_index));
250 return native_pwiz_spectrum_sp;
256 pwiz::msdata::Spectrum *spectrum_p,
263 if(!spectrum_p->scanList.scans[0].hasCVParam(
264 pwiz::msdata::MS_scan_start_time))
273 "The spectrum has no scan start time value set."));
278 pwiz::data::CVParam retention_time_cv_param =
279 spectrum_p->scanList.scans[0].cvParam(pwiz::msdata::MS_scan_start_time);
283 std::string unit_name = retention_time_cv_param.unitsName();
288 if(unit_name ==
"second")
291 retention_time_cv_param.valueAs<
double>());
293 else if(unit_name ==
"minute")
296 retention_time_cv_param.valueAs<
double>() * 60);
301 "scan start time value."));
324 pwiz::msdata::Spectrum *spectrum_p,
330 if(spectrum_p->scanList.scans[0].hasCVParam(
331 pwiz::msdata::MS_ion_mobility_drift_time))
341 spectrum_p->scanList.scans[0]
342 .cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
363 if(std::isnan(driftTime) || std::isinf(driftTime))
393 pwiz::msdata::Spectrum *spectrum_p,
394 bool want_binary_data,
400 env = setlocale(LC_ALL,
"");
401 setlocale(LC_ALL,
"C");
411 (spectrum_p->cvParam(pwiz::msdata::MS_ms_level).valueAs<
int>());
415 if(!spectrum_p->scanList.scans[0].hasCVParam(
416 pwiz::msdata::MS_peak_list_scans))
423 spectrum_p->cvParam(pwiz::msdata::MS_peak_list_scans)
429 std::size_t precursor_list_size = spectrum_p->precursors.size();
436 if(precursor_list_size > 0)
442 qDebug() <<
"Going to throw: msLevel cannot be less than two for "
443 "a spectrum that has items in its Precursor list.";
446 "msLevel cannot be less than two for "
447 "a spectrum that has items in its Precursor list."));
452 for(
auto &precursor : spectrum_p->precursors)
458 std::size_t precursor_spectrum_index =
459 std::numeric_limits<std::size_t>::max();
463 if(precursor.spectrumID.empty())
490 QString::fromStdString(precursor.spectrumID));
501 precursor_spectrum_index =
502 msp_msData->run.spectrumListPtr->find(precursor.spectrumID);
506 if(precursor_spectrum_index ==
513 "Failed to find the index of the "
514 "precursor ion's spectrum."));
519 precursor_spectrum_index);
529 if(!precursor.selectedIons.size())
532 <<
"Going to throw The spectrum has msLevel > 1 but the "
533 "precursor ions's selected ions list is empty..";
537 "precursor ions's selected ions "
541 pwiz::msdata::SelectedIon &ion =
542 *(precursor.selectedIons.begin());
548 ion.cvParam(pwiz::cv::MS_selected_ion_m_z).value.c_str())
558 QString(ion.cvParam(pwiz::cv::MS_peak_intensity).value.c_str())
563 unsigned int selected_ion_charge_state =
564 QString(ion.cvParam(pwiz::cv::MS_charge_state).value.c_str())
571 selected_ion_charge_state,
572 selected_ion_peak_intensity);
613 if(precursor_list_size !=
616 qDebug() <<
"Going to throw The number of precursors in the file is "
617 "different from the number of precursors in memory.";
620 QObject::tr(
"The number of precursors in the file is different "
621 "from the number of precursors in memory."));
649 std::vector<pwiz::msdata::MZIntensityPair> pairs;
650 spectrum_p->getMZIntensityPairs(pairs);
657 for(std::vector<pwiz::msdata::MZIntensityPair>::const_iterator
669 spectrum.push_back(
DataPoint(it->mz, it->intensity));
670 tic += it->intensity;
701 qDebug() <<
"Going to throw";
704 QObject::tr(
"Error reading data using the proteowizard library: %1")
705 .arg(errorp.
qwhat()));
707 catch(std::exception &error)
709 qDebug() <<
"Going to throw";
712 QObject::tr(
"Error reading data using the proteowizard library: %1")
722 return qualified_mass_spectrum;
728 bool want_binary_data,
733 env = setlocale(LC_ALL,
"");
740 setlocale(LC_ALL,
"C");
746 setlocale(LC_ALL, env.c_str());
752 pwiz::msdata::SpectrumListPtr spectrum_list_p =
755 if(spectrum_index == spectrum_list_p.get()->size())
757 setlocale(LC_ALL, env.c_str());
759 QObject::tr(
"The spectrum index cannot be equal to the size of the "
767 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
770 setlocale(LC_ALL, env.c_str());
773 QString::fromStdString(native_pwiz_spectrum_sp->id));
776 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
784 pwiz::msdata::ReaderList reader_list;
786 std::string reader_type = reader_list.identify(file_name.toStdString());
788 if(!reader_type.empty())
811 bool want_binary_data)
const
872 env = setlocale(LC_ALL,
"");
873 setlocale(LC_ALL,
"C");
879 pwiz::msdata::SpectrumListPtr spectrum_list_p =
883 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
893 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
900 qDebug() <<
"The operation was cancelled. Breaking the loop.";
907 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
933 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
944 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
960 !native_pwiz_spectrum_sp->defaultArrayLength);
970 if(qualified_mass_spectrum.
getMsLevel() == ms_level)
977 setlocale(LC_ALL, env.c_str());
1010 env = setlocale(LC_ALL,
"");
1011 setlocale(LC_ALL,
"C");
1017 pwiz::msdata::SpectrumListPtr spectrum_list_p =
1021 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
1031 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
1039 qDebug() <<
"The operation was cancelled. Breaking the loop.";
1046 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
1072 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
1083 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
1099 !native_pwiz_spectrum_sp->defaultArrayLength);
1114 setlocale(LC_ALL, env.c_str());
1129 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
bool needPeakList() const
bool acceptMsLevel(std::size_t ms_level) const
bool acceptRetentionTimeInSeconds(double retention_time_in_seconds) 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
virtual void readSpectrumCollectionWithMsrunReadConfig(const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler)
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 void readSpectrumCollection2(const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler) 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 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
const OboPsiModTerm getOboPsiModTermNativeIDFormat() const
get OboPsiModTerm corresponding to the nativeID format format of mz data
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 precursor mz
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.
void setParameterValue(QualifiedMassSpectrumParameter parameter, const QVariant &value)
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.