36#include <pwiz/data/msdata/DefaultReaderList.hpp>
67 std::string file_name_std =
73 pwiz::msdata::DefaultReaderList defaultReaderList;
75 std::vector<pwiz::msdata::MSDataPtr> msDataPtrVector;
79 defaultReaderList.read(file_name_std, msDataPtrVector);
81 catch(std::exception &error)
83 qDebug() << QString(
"Failed to read the data from file %1")
84 .arg(QString::fromStdString(file_name_std));
87 QString(
"Error reading file %1 in PwizMsRunReader, for msrun %2:\n%3")
105 if(msDataPtrVector.size() != 1)
107 "For the kind of file at hand there can only be "
108 "one run in the file."));
118 for(
const pwiz::msdata::MSDataPtr &msDataPtr : msDataPtrVector)
120 qDebug() <<
"msDataPtr->run.id=" << msDataPtr->run.id.c_str();
121 qDebug() <<
"mcsp_msRunId->getRunId()=" <<
mcsp_msRunId->getRunId();
122 qDebug() <<
"mcsp_msRunId->getXmlId()=" <<
mcsp_msRunId->getXmlId();
123 qDebug() <<
"mcsp_msRunId->getSampleName()="
125 if(msDataPtr->run.id ==
mcsp_msRunId->getRunId().toStdString())
141 "matching the requested run id : %1")
148 pwiz::cv::CVID native_id_format =
149 pwiz::msdata::id::getDefaultNativeIDFormat(*
msp_msData.get());
153 if(native_id_format == pwiz::cv::CVID::MS_Thermo_nativeID_format)
179 term.
m_name =
"no nativeID format";
181 "No nativeID format indicates that the file tagged with this term does "
183 "contain spectra that can have a nativeID format.";
186 pwiz::cv::CVID cvid =
187 pwiz::msdata::id::getDefaultNativeIDFormat(*(
msp_msData.get()));
191 case pwiz::cv::MS_Thermo_nativeID_format:
193 term.
m_name =
"Thermo nativeID format";
195 "Native format defined by controllerType=xsd:nonNegativeInteger "
196 "controllerNumber=xsd:positiveInteger scan=xsd:positiveInteger.";
205 pwiz::msdata::SpectrumList * p_spectrum_list,
206 std::size_t spectrum_index,
207 bool want_binary_data)
const
209 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp;
213 native_pwiz_spectrum_sp =
214 p_spectrum_list->spectrum(spectrum_index, want_binary_data);
216 catch(std::runtime_error &error)
218 qDebug() <<
"getPwizSpectrumPtr error " << error.what() <<
" "
219 <<
typeid(error).name();
222 QObject::tr(
"Pwiz spectrum index %1 not found in "
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;
251 pwiz::msdata::Spectrum * spectrum_p,
258 if(!spectrum_p->scanList.scans[0].hasCVParam(
259 pwiz::msdata::MS_scan_start_time))
268 "The spectrum has no scan start time value set."));
273 pwiz::data::CVParam retention_time_cv_param =
274 spectrum_p->scanList.scans[0].cvParam(
275 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 qualified_mass_spectrum)
const
325 if(spectrum_p->scanList.scans[0].hasCVParam(
326 pwiz::msdata::MS_ion_mobility_drift_time))
336 spectrum_p->scanList.scans[0]
337 .cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
358 if(std::isnan(driftTime) || std::isinf(driftTime))
388 pwiz::msdata::Spectrum *spectrum_p,
389 bool want_binary_data,
394 if(spectrum_p ==
nullptr)
395 qFatal(
"Spectrum pointer cannot be nullptr.");
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)
439 <<
"Going to throw: msLevel cannot be less than two for "
440 "a spectrum that has items in its Precursor list.";
443 "msLevel cannot be less than two for "
444 "a spectrum that has items in its Precursor list."));
449 for(
auto &precursor : spectrum_p->precursors)
455 std::size_t precursor_spectrum_index =
456 std::numeric_limits<std::size_t>::max();
460 if(precursor.spectrumID.empty())
489 QString::fromStdString(precursor.spectrumID));
500 precursor_spectrum_index =
502 precursor.spectrumID);
506 if(precursor_spectrum_index ==
513 "Failed to find the index of the "
514 "precursor ion's spectrum."));
519 precursor_spectrum_index);
530 if(!precursor.selectedIons.size())
533 <<
"Going to throw The spectrum has msLevel > 1 but the "
534 "precursor ions's selected ions list is empty..";
537 "The spectrum has msLevel > 1 but the "
538 "precursor ions's selected ions "
542 pwiz::msdata::SelectedIon &ion =
543 *(precursor.selectedIons.begin());
549 ion.cvParam(pwiz::cv::MS_selected_ion_m_z).value.c_str())
560 ion.cvParam(pwiz::cv::MS_peak_intensity).value.c_str())
565 unsigned int selected_ion_charge_state =
566 QString(ion.cvParam(pwiz::cv::MS_charge_state).value.c_str())
574 selected_ion_charge_state,
575 selected_ion_peak_intensity);
616 if(precursor_list_size !=
620 <<
"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;
702 qDebug() <<
"Going to throw";
705 QObject::tr(
"Error reading data using the proteowizard library: %1")
706 .arg(errorp.
qwhat()));
708 catch(std::exception &error)
710 qDebug() <<
"Going to throw";
713 QObject::tr(
"Error reading data using the proteowizard library: %1")
721 return qualified_mass_spectrum;
726 std::size_t spectrum_index,
bool want_binary_data,
bool &ok)
const
741 pwiz::msdata::SpectrumListPtr spectrum_list_p =
744 if(spectrum_index == spectrum_list_p.get()->size())
748 QObject::tr(
"The spectrum index cannot be equal to the size of the "
757 spectrum_list_p.get(), spectrum_index, want_binary_data);
762 QString::fromStdString(native_pwiz_spectrum_sp->id));
765 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
772 pwiz::msdata::ReaderList reader_list;
774 std::string reader_type = reader_list.identify(file_name.toStdString());
776 if(!reader_type.empty())
784 std::size_t spectrum_index)
791 std::size_t spectrum_index)
798 std::size_t spectrum_index,
bool want_binary_data)
const
829 catch(std::exception &error)
831 qDebug() <<
"Going to throw";
834 QObject::tr(
"Error reading data (spectrum collection) using the "
835 "proteowizard library: %1")
849 catch(std::exception &error)
851 qDebug() <<
"Going to throw";
854 QObject::tr(
"Error reading data (spectrum collection2) using the "
855 "proteowizard library: %1")
883 pwiz::msdata::SpectrumListPtr spectrum_list_p =
887 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
897 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
904 qDebug() <<
"The operation was cancelled. Breaking the loop.";
911 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
936 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
948 native_pwiz_spectrum_sp.get(),
966 !native_pwiz_spectrum_sp->defaultArrayLength);
976 if(qualified_mass_spectrum.
getMsLevel() == ms_level)
1019 pwiz::msdata::SpectrumListPtr spectrum_list_p =
1023 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
1034 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
1042 qDebug() <<
"The operation was cancelled. Breaking the loop.";
1050 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
1077 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
1089 native_pwiz_spectrum_sp.get(),
1108 !native_pwiz_spectrum_sp->defaultArrayLength);
1134 qDebug() <<
"Loading ended";
1140 return msp_msData->run.spectrumListPtr.get()->size();
1182 xic_coord.get()->mzRange =
1189 std::string env_backup;
1196 std::string env_backup = std::setlocale(LC_ALL,
nullptr);
1197 std::setlocale(LC_ALL,
"C");
1199 std::locale::global(std::locale(
"C"));
1202 catch(std::exception &error)
1205 QObject::tr(
"Error trying to set local to C : %1").arg(error.what()));
1211 const std::string &environment_locale)
1218 std::setlocale(LC_ALL, environment_locale.c_str());
1220 std::locale::global(
1224 catch(std::exception &error)
1228 "Error trying to set local to original system one %1 : %2")
1229 .arg(environment_locale.c_str())
1230 .arg(error.what()));
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
static std::string setGlobalLocaleToEnglish()
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)
static void setGlobalLocaleToCurrentOs(const std::string &environment_locale)
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.