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));
106 if(msDataPtrVector.size() != 1)
109 "one run in the file."));
120 for(
auto &msDataPtr : msDataPtrVector)
122 if(msDataPtr->run.id ==
mcsp_msRunId->getRunId().toStdString())
137 "Could not find a MSDataPtr matching the requested run id."));
143 pwiz::cv::CVID native_id_format =
144 pwiz::msdata::id::getDefaultNativeIDFormat(*
msp_msData.get());
148 if(native_id_format == pwiz::cv::CVID::MS_Thermo_nativeID_format)
157 if(
mcsp_msRunId.get()->getMzFormat() == MzFormat::mzXML)
169 pwiz::msdata::SpectrumPtr
171 std::size_t spectrum_index,
172 bool want_binary_data)
const
174 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp;
178 native_pwiz_spectrum_sp =
179 p_spectrum_list->spectrum(spectrum_index, want_binary_data);
181 catch(std::runtime_error &error)
183 qDebug() <<
"getPwizSpectrumPtr error " << error.what() <<
" "
184 <<
typeid(error).name();
187 "MS file std::runtime_error :\n%2")
191 catch(std::exception &error)
193 qDebug() <<
"getPwizSpectrumPtr error " << error.what()
194 <<
typeid(error).name();
197 QObject::tr(
"Pwiz spectrum index %1 not found in MS file :\n%2")
202 if(native_pwiz_spectrum_sp.get() ==
nullptr)
206 "Pwiz spectrum index %1 not found in MS file : null pointer")
207 .arg(spectrum_index));
210 return native_pwiz_spectrum_sp;
216 pwiz::msdata::Spectrum *spectrum_p,
223 if(!spectrum_p->scanList.scans[0].hasCVParam(
224 pwiz::msdata::MS_scan_start_time))
233 "The spectrum has no scan start time value set."));
238 pwiz::data::CVParam retention_time_cv_param =
239 spectrum_p->scanList.scans[0].cvParam(pwiz::msdata::MS_scan_start_time);
243 std::string unit_name = retention_time_cv_param.unitsName();
248 if(unit_name ==
"second")
251 retention_time_cv_param.valueAs<
double>());
253 else if(unit_name ==
"minute")
256 retention_time_cv_param.valueAs<
double>() * 60);
261 "scan start time value."));
284 pwiz::msdata::Spectrum *spectrum_p,
290 if(spectrum_p->scanList.scans[0].hasCVParam(
291 pwiz::msdata::MS_ion_mobility_drift_time))
301 spectrum_p->scanList.scans[0]
302 .cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
323 if(std::isnan(driftTime) || std::isinf(driftTime))
353 pwiz::msdata::Spectrum *spectrum_p,
354 bool want_binary_data,
360 env = setlocale(LC_ALL,
"");
361 setlocale(LC_ALL,
"C");
371 (spectrum_p->cvParam(pwiz::msdata::MS_ms_level).valueAs<
int>());
378 std::size_t precursor_list_size = spectrum_p->precursors.size();
385 if(precursor_list_size > 0)
391 qDebug() <<
"Going to throw: msLevel cannot be less than two for "
392 "a spectrum that has items in its Precursor list.";
395 "msLevel cannot be less than two for "
396 "a spectrum that has items in its Precursor list."));
401 for(
auto &precursor : spectrum_p->precursors)
407 std::size_t precursor_spectrum_index =
408 std::numeric_limits<std::size_t>::max();
412 if(precursor.spectrumID.empty())
439 QString::fromStdString(precursor.spectrumID));
450 precursor_spectrum_index =
451 msp_msData->run.spectrumListPtr->find(precursor.spectrumID);
455 if(precursor_spectrum_index ==
461 "Failed to find the index of the "
462 "precursor ion's spectrum."));
467 precursor_spectrum_index);
477 if(!precursor.selectedIons.size())
480 <<
"Going to throw The spectrum has msLevel > 1 but the "
481 "precursor ions's selected ions list is empty..";
485 "precursor ions's selected ions "
489 pwiz::msdata::SelectedIon &ion =
490 *(precursor.selectedIons.begin());
496 ion.cvParam(pwiz::cv::MS_selected_ion_m_z).value.c_str())
502 QString(ion.cvParam(pwiz::cv::MS_peak_intensity).value.c_str())
507 unsigned int selected_ion_charge_state =
508 QString(ion.cvParam(pwiz::cv::MS_charge_state).value.c_str())
515 selected_ion_charge_state,
516 selected_ion_peak_intensity);
557 if(precursor_list_size !=
560 qDebug() <<
"Going to throw The number of precursors in the file is "
561 "different from the number of precursors in memory.";
564 QObject::tr(
"The number of precursors in the file is different "
565 "from the number of precursors in memory."));
593 std::vector<pwiz::msdata::MZIntensityPair> pairs;
594 spectrum_p->getMZIntensityPairs(pairs);
601 for(std::vector<pwiz::msdata::MZIntensityPair>::const_iterator
613 spectrum.push_back(
DataPoint(it->mz, it->intensity));
614 tic += it->intensity;
645 qDebug() <<
"Going to throw";
648 QObject::tr(
"Error reading data using the proteowizard library: %1")
649 .arg(errorp.
qwhat()));
651 catch(std::exception &error)
653 qDebug() <<
"Going to throw";
656 QObject::tr(
"Error reading data using the proteowizard library: %1")
666 return qualified_mass_spectrum;
672 bool want_binary_data,
677 env = setlocale(LC_ALL,
"");
684 setlocale(LC_ALL,
"C");
690 setlocale(LC_ALL, env.c_str());
696 pwiz::msdata::SpectrumListPtr spectrum_list_p =
699 if(spectrum_index == spectrum_list_p.get()->size())
701 setlocale(LC_ALL, env.c_str());
703 QObject::tr(
"The spectrum index cannot be equal to the size of the "
711 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
714 setlocale(LC_ALL, env.c_str());
717 QString::fromStdString(native_pwiz_spectrum_sp->id));
720 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
728 pwiz::msdata::ReaderList reader_list;
730 std::string reader_type = reader_list.identify(file_name.toStdString());
732 if(!reader_type.empty())
755 bool want_binary_data)
const
764 if(
mcsp_msRunId->getMzFormat() == pappso::MzFormat::MGF)
799 env = setlocale(LC_ALL,
"");
800 setlocale(LC_ALL,
"C");
806 pwiz::msdata::SpectrumListPtr spectrum_list_p =
810 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
820 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
827 qDebug() <<
"The operation was cancelled. Breaking the loop.";
834 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
860 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
871 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
887 !native_pwiz_spectrum_sp->defaultArrayLength);
894 setlocale(LC_ALL, env.c_str());
910 return msp_msData->run.spectrumListPtr.get()->size();