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)
164 if(
mcsp_msRunId.get()->getMzFormat() == MzFormat::mzXML)
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
771 if(
mcsp_msRunId->getMzFormat() == pappso::MzFormat::MGF)
807 env = setlocale(LC_ALL,
"");
808 setlocale(LC_ALL,
"C");
814 pwiz::msdata::SpectrumListPtr spectrum_list_p =
818 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
828 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
835 qDebug() <<
"The operation was cancelled. Breaking the loop.";
842 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
868 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
879 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
895 !native_pwiz_spectrum_sp->defaultArrayLength);
902 setlocale(LC_ALL, env.c_str());
918 return msp_msData->run.spectrumListPtr.get()->size();