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"
68 std::string file_name_std =
72 std::string env_backup = setlocale(LC_ALL,
"");
81 pwiz::msdata::DefaultReaderList defaultReaderList;
83 std::vector<pwiz::msdata::MSDataPtr> msDataPtrVector;
87 defaultReaderList.read(file_name_std, msDataPtrVector);
89 catch(std::exception &error)
91 qDebug() << QString(
"Failed to read the data from file %1")
92 .arg(QString::fromStdString(file_name_std));
95 QString(
"Error reading file %1 in PwizMsRunReader, for msrun %2:\n%3")
113 if(msDataPtrVector.size() != 1)
116 "one run in the file."));
126 for(
const pwiz::msdata::MSDataPtr &msDataPtr : msDataPtrVector)
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()="
133 if(msDataPtr->run.id ==
mcsp_msRunId->getRunId().toStdString())
149 "Could not find a pwiz MSDataPtr matching the requested run id : %1")
156 pwiz::cv::CVID native_id_format =
157 pwiz::msdata::id::getDefaultNativeIDFormat(*
msp_msData.get());
161 if(native_id_format == pwiz::cv::CVID::MS_Thermo_nativeID_format)
188 term.
m_name =
"no nativeID format";
190 "No nativeID format indicates that the file tagged with this term does not "
191 "contain spectra that can have a nativeID format.";
194 pwiz::cv::CVID cvid =
195 pwiz::msdata::id::getDefaultNativeIDFormat(*(
msp_msData.get()));
199 case pwiz::cv::MS_Thermo_nativeID_format:
201 term.
m_name =
"Thermo nativeID format";
203 "Native format defined by controllerType=xsd:nonNegativeInteger "
204 "controllerNumber=xsd:positiveInteger scan=xsd:positiveInteger.";
212pwiz::msdata::SpectrumPtr
214 std::size_t spectrum_index,
215 bool want_binary_data)
const
217 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp;
221 native_pwiz_spectrum_sp =
222 p_spectrum_list->spectrum(spectrum_index, want_binary_data);
224 catch(std::runtime_error &error)
226 qDebug() <<
"getPwizSpectrumPtr error " << error.what() <<
" "
227 <<
typeid(error).name();
230 "MS file std::runtime_error :\n%2")
234 catch(std::exception &error)
236 qDebug() <<
"getPwizSpectrumPtr error " << error.what()
237 <<
typeid(error).name();
240 QObject::tr(
"Pwiz spectrum index %1 not found in MS file :\n%2")
245 if(native_pwiz_spectrum_sp.get() ==
nullptr)
249 "Pwiz spectrum index %1 not found in MS file : null pointer")
250 .arg(spectrum_index));
253 return native_pwiz_spectrum_sp;
259 pwiz::msdata::Spectrum *spectrum_p,
266 if(!spectrum_p->scanList.scans[0].hasCVParam(
267 pwiz::msdata::MS_scan_start_time))
276 "The spectrum has no scan start time value set."));
281 pwiz::data::CVParam retention_time_cv_param =
282 spectrum_p->scanList.scans[0].cvParam(pwiz::msdata::MS_scan_start_time);
286 std::string unit_name = retention_time_cv_param.unitsName();
291 if(unit_name ==
"second")
294 retention_time_cv_param.valueAs<
double>());
296 else if(unit_name ==
"minute")
299 retention_time_cv_param.valueAs<
double>() * 60);
304 "scan start time value."));
327 pwiz::msdata::Spectrum *spectrum_p,
333 if(spectrum_p->scanList.scans[0].hasCVParam(
334 pwiz::msdata::MS_ion_mobility_drift_time))
344 spectrum_p->scanList.scans[0]
345 .cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
366 if(std::isnan(driftTime) || std::isinf(driftTime))
396 pwiz::msdata::Spectrum *spectrum_p,
397 bool want_binary_data,
403 env = setlocale(LC_ALL,
"");
405 setlocale(LC_ALL,
"C");
415 (spectrum_p->cvParam(pwiz::msdata::MS_ms_level).valueAs<
int>());
419 if(!spectrum_p->scanList.scans[0].hasCVParam(
420 pwiz::msdata::MS_peak_list_scans))
427 spectrum_p->cvParam(pwiz::msdata::MS_peak_list_scans)
433 std::size_t precursor_list_size = spectrum_p->precursors.size();
440 if(precursor_list_size > 0)
446 qDebug() <<
"Going to throw: msLevel cannot be less than two for "
447 "a spectrum that has items in its Precursor list.";
450 "msLevel cannot be less than two for "
451 "a spectrum that has items in its Precursor list."));
456 for(
auto &precursor : spectrum_p->precursors)
462 std::size_t precursor_spectrum_index =
463 std::numeric_limits<std::size_t>::max();
467 if(precursor.spectrumID.empty())
494 QString::fromStdString(precursor.spectrumID));
505 precursor_spectrum_index =
506 msp_msData->run.spectrumListPtr->find(precursor.spectrumID);
510 if(precursor_spectrum_index ==
517 "Failed to find the index of the "
518 "precursor ion's spectrum."));
523 precursor_spectrum_index);
533 if(!precursor.selectedIons.size())
536 <<
"Going to throw The spectrum has msLevel > 1 but the "
537 "precursor ions's selected ions list is empty..";
541 "precursor ions's selected ions "
545 pwiz::msdata::SelectedIon &ion =
546 *(precursor.selectedIons.begin());
552 ion.cvParam(pwiz::cv::MS_selected_ion_m_z).value.c_str())
562 QString(ion.cvParam(pwiz::cv::MS_peak_intensity).value.c_str())
567 unsigned int selected_ion_charge_state =
568 QString(ion.cvParam(pwiz::cv::MS_charge_state).value.c_str())
575 selected_ion_charge_state,
576 selected_ion_peak_intensity);
617 if(precursor_list_size !=
620 qDebug() <<
"Going to throw The number of precursors in the file is "
621 "different from the number of precursors in memory.";
624 QObject::tr(
"The number of precursors in the file is different "
625 "from the number of precursors in memory."));
653 std::vector<pwiz::msdata::MZIntensityPair> pairs;
654 spectrum_p->getMZIntensityPairs(pairs);
661 for(std::vector<pwiz::msdata::MZIntensityPair>::const_iterator
673 spectrum.push_back(
DataPoint(it->mz, it->intensity));
674 tic += it->intensity;
705 qDebug() <<
"Going to throw";
708 QObject::tr(
"Error reading data using the proteowizard library: %1")
709 .arg(errorp.
qwhat()));
711 catch(std::exception &error)
713 qDebug() <<
"Going to throw";
716 QObject::tr(
"Error reading data using the proteowizard library: %1")
726 return qualified_mass_spectrum;
732 bool want_binary_data,
737 env = setlocale(LC_ALL,
"");
744 setlocale(LC_ALL,
"C");
750 setlocale(LC_ALL, env.c_str());
756 pwiz::msdata::SpectrumListPtr spectrum_list_p =
759 if(spectrum_index == spectrum_list_p.get()->size())
761 setlocale(LC_ALL, env.c_str());
763 QObject::tr(
"The spectrum index cannot be equal to the size of the "
771 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
774 setlocale(LC_ALL, env.c_str());
777 QString::fromStdString(native_pwiz_spectrum_sp->id));
780 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
788 pwiz::msdata::ReaderList reader_list;
790 std::string reader_type = reader_list.identify(file_name.toStdString());
792 if(!reader_type.empty())
815 bool want_binary_data)
const
877 env = setlocale(LC_ALL,
"");
878 setlocale(LC_ALL,
"C");
884 pwiz::msdata::SpectrumListPtr spectrum_list_p =
888 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
898 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
905 qDebug() <<
"The operation was cancelled. Breaking the loop.";
912 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
937 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
948 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
964 !native_pwiz_spectrum_sp->defaultArrayLength);
974 if(qualified_mass_spectrum.
getMsLevel() == ms_level)
981 setlocale(LC_ALL, env.c_str());
1018 env = setlocale(LC_ALL,
"");
1019 setlocale(LC_ALL,
"C");
1026 pwiz::msdata::SpectrumListPtr spectrum_list_p =
1030 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
1041 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
1049 qDebug() <<
"The operation was cancelled. Breaking the loop.";
1057 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
1084 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
1095 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
1112 !native_pwiz_spectrum_sp->defaultArrayLength);
1129 setlocale(LC_ALL, env.c_str());
1137 qDebug() <<
"Loading ended";
1144 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.