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)
181 term.
m_name =
"no nativeID format";
183 "No nativeID format indicates that the file tagged with this term does not "
184 "contain spectra that can have a nativeID format.";
187 pwiz::cv::CVID cvid =
188 pwiz::msdata::id::getDefaultNativeIDFormat(*(
msp_msData.get()));
192 case pwiz::cv::MS_Thermo_nativeID_format:
194 term.
m_name =
"Thermo nativeID format";
196 "Native format defined by controllerType=xsd:nonNegativeInteger "
197 "controllerNumber=xsd:positiveInteger scan=xsd:positiveInteger.";
205pwiz::msdata::SpectrumPtr
207 std::size_t spectrum_index,
208 bool want_binary_data)
const
210 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp;
214 native_pwiz_spectrum_sp =
215 p_spectrum_list->spectrum(spectrum_index, want_binary_data);
217 catch(std::runtime_error &error)
219 qDebug() <<
"getPwizSpectrumPtr error " << error.what() <<
" "
220 <<
typeid(error).name();
223 "MS file std::runtime_error :\n%2")
227 catch(std::exception &error)
229 qDebug() <<
"getPwizSpectrumPtr error " << error.what()
230 <<
typeid(error).name();
233 QObject::tr(
"Pwiz spectrum index %1 not found in MS file :\n%2")
238 if(native_pwiz_spectrum_sp.get() ==
nullptr)
242 "Pwiz spectrum index %1 not found in MS file : null pointer")
243 .arg(spectrum_index));
246 return native_pwiz_spectrum_sp;
252 pwiz::msdata::Spectrum *spectrum_p,
259 if(!spectrum_p->scanList.scans[0].hasCVParam(
260 pwiz::msdata::MS_scan_start_time))
269 "The spectrum has no scan start time value set."));
274 pwiz::data::CVParam retention_time_cv_param =
275 spectrum_p->scanList.scans[0].cvParam(pwiz::msdata::MS_scan_start_time);
279 std::string unit_name = retention_time_cv_param.unitsName();
284 if(unit_name ==
"second")
287 retention_time_cv_param.valueAs<
double>());
289 else if(unit_name ==
"minute")
292 retention_time_cv_param.valueAs<
double>() * 60);
297 "scan start time value."));
320 pwiz::msdata::Spectrum *spectrum_p,
326 if(spectrum_p->scanList.scans[0].hasCVParam(
327 pwiz::msdata::MS_ion_mobility_drift_time))
337 spectrum_p->scanList.scans[0]
338 .cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
359 if(std::isnan(driftTime) || std::isinf(driftTime))
389 pwiz::msdata::Spectrum *spectrum_p,
390 bool want_binary_data,
396 env = setlocale(LC_ALL,
"");
397 setlocale(LC_ALL,
"C");
407 (spectrum_p->cvParam(pwiz::msdata::MS_ms_level).valueAs<
int>());
411 if(!spectrum_p->scanList.scans[0].hasCVParam(
412 pwiz::msdata::MS_peak_list_scans))
419 spectrum_p->cvParam(pwiz::msdata::MS_peak_list_scans)
425 std::size_t precursor_list_size = spectrum_p->precursors.size();
432 if(precursor_list_size > 0)
438 qDebug() <<
"Going to throw: msLevel cannot be less than two for "
439 "a spectrum that has items in its Precursor list.";
442 "msLevel cannot be less than two for "
443 "a spectrum that has items in its Precursor list."));
448 for(
auto &precursor : spectrum_p->precursors)
454 std::size_t precursor_spectrum_index =
455 std::numeric_limits<std::size_t>::max();
459 if(precursor.spectrumID.empty())
486 QString::fromStdString(precursor.spectrumID));
497 precursor_spectrum_index =
498 msp_msData->run.spectrumListPtr->find(precursor.spectrumID);
502 if(precursor_spectrum_index ==
509 "Failed to find the index of the "
510 "precursor ion's spectrum."));
515 precursor_spectrum_index);
525 if(!precursor.selectedIons.size())
528 <<
"Going to throw The spectrum has msLevel > 1 but the "
529 "precursor ions's selected ions list is empty..";
533 "precursor ions's selected ions "
537 pwiz::msdata::SelectedIon &ion =
538 *(precursor.selectedIons.begin());
544 ion.cvParam(pwiz::cv::MS_selected_ion_m_z).value.c_str())
554 QString(ion.cvParam(pwiz::cv::MS_peak_intensity).value.c_str())
559 unsigned int selected_ion_charge_state =
560 QString(ion.cvParam(pwiz::cv::MS_charge_state).value.c_str())
567 selected_ion_charge_state,
568 selected_ion_peak_intensity);
609 if(precursor_list_size !=
612 qDebug() <<
"Going to throw The number of precursors in the file is "
613 "different from the number of precursors in memory.";
616 QObject::tr(
"The number of precursors in the file is different "
617 "from the number of precursors in memory."));
645 std::vector<pwiz::msdata::MZIntensityPair> pairs;
646 spectrum_p->getMZIntensityPairs(pairs);
653 for(std::vector<pwiz::msdata::MZIntensityPair>::const_iterator
665 spectrum.push_back(
DataPoint(it->mz, it->intensity));
666 tic += it->intensity;
697 qDebug() <<
"Going to throw";
700 QObject::tr(
"Error reading data using the proteowizard library: %1")
701 .arg(errorp.
qwhat()));
703 catch(std::exception &error)
705 qDebug() <<
"Going to throw";
708 QObject::tr(
"Error reading data using the proteowizard library: %1")
718 return qualified_mass_spectrum;
724 bool want_binary_data,
729 env = setlocale(LC_ALL,
"");
736 setlocale(LC_ALL,
"C");
742 setlocale(LC_ALL, env.c_str());
748 pwiz::msdata::SpectrumListPtr spectrum_list_p =
751 if(spectrum_index == spectrum_list_p.get()->size())
753 setlocale(LC_ALL, env.c_str());
755 QObject::tr(
"The spectrum index cannot be equal to the size of the "
763 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
766 setlocale(LC_ALL, env.c_str());
769 QString::fromStdString(native_pwiz_spectrum_sp->id));
772 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
780 pwiz::msdata::ReaderList reader_list;
782 std::string reader_type = reader_list.identify(file_name.toStdString());
784 if(!reader_type.empty())
807 bool want_binary_data)
const
868 env = setlocale(LC_ALL,
"");
869 setlocale(LC_ALL,
"C");
875 pwiz::msdata::SpectrumListPtr spectrum_list_p =
879 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
889 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
896 qDebug() <<
"The operation was cancelled. Breaking the loop.";
903 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
929 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
940 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
956 !native_pwiz_spectrum_sp->defaultArrayLength);
966 if(qualified_mass_spectrum.
getMsLevel() == ms_level)
973 setlocale(LC_ALL, env.c_str());
1006 env = setlocale(LC_ALL,
"");
1007 setlocale(LC_ALL,
"C");
1013 pwiz::msdata::SpectrumListPtr spectrum_list_p =
1017 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
1027 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
1035 qDebug() <<
"The operation was cancelled. Breaking the loop.";
1042 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
1068 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
1079 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
1095 !native_pwiz_spectrum_sp->defaultArrayLength);
1110 setlocale(LC_ALL, env.c_str());
1125 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.