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();
384 if(precursor_list_size > 0)
390 qDebug() <<
"Going to throw: msLevel cannot be less than two for "
391 "a spectrum that has items in its Precursor list.";
394 "msLevel cannot be less than two for "
395 "a spectrum that has items in its Precursor list."));
400 for(
auto &precursor : spectrum_p->precursors)
406 std::size_t precursor_spectrum_index =
407 std::numeric_limits<std::size_t>::max();
411 if(precursor.spectrumID.empty())
438 QString::fromStdString(precursor.spectrumID));
449 precursor_spectrum_index =
450 msp_msData->run.spectrumListPtr->find(precursor.spectrumID);
454 if(precursor_spectrum_index ==
460 "Failed to find the index of the "
461 "precursor ion's spectrum."));
466 precursor_spectrum_index);
476 if(!precursor.selectedIons.size())
479 <<
"Going to throw The spectrum has msLevel > 1 but the "
480 "precursor ions's selected ions list is empty..";
484 "precursor ions's selected ions "
488 pwiz::msdata::SelectedIon &ion =
489 *(precursor.selectedIons.begin());
495 ion.cvParam(pwiz::cv::MS_selected_ion_m_z).value.c_str())
501 QString(ion.cvParam(pwiz::cv::MS_peak_intensity).value.c_str())
506 unsigned int selected_ion_charge_state =
507 QString(ion.cvParam(pwiz::cv::MS_charge_state).value.c_str())
514 selected_ion_charge_state,
515 selected_ion_peak_intensity);
558 if(precursor_list_size !=
561 qDebug() <<
"Going to throw The number of precursors in the file is "
562 "different from the number of precursors in memory.";
565 QObject::tr(
"The number of precursors in the file is different "
566 "from the number of precursors in memory."));
594 std::vector<pwiz::msdata::MZIntensityPair> pairs;
595 spectrum_p->getMZIntensityPairs(pairs);
602 for(std::vector<pwiz::msdata::MZIntensityPair>::const_iterator
614 spectrum.push_back(
DataPoint(it->mz, it->intensity));
615 tic += it->intensity;
646 qDebug() <<
"Going to throw";
649 QObject::tr(
"Error reading data using the proteowizard library: %1")
650 .arg(errorp.
qwhat()));
652 catch(std::exception &error)
654 qDebug() <<
"Going to throw";
657 QObject::tr(
"Error reading data using the proteowizard library: %1")
667 return qualified_mass_spectrum;
673 bool want_binary_data,
678 env = setlocale(LC_ALL,
"");
685 setlocale(LC_ALL,
"C");
691 setlocale(LC_ALL, env.c_str());
697 pwiz::msdata::SpectrumListPtr spectrum_list_p =
700 if(spectrum_index == spectrum_list_p.get()->size())
702 setlocale(LC_ALL, env.c_str());
704 QObject::tr(
"The spectrum index cannot be equal to the size of the "
712 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
715 setlocale(LC_ALL, env.c_str());
718 QString::fromStdString(native_pwiz_spectrum_sp->id));
721 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
729 pwiz::msdata::ReaderList reader_list;
731 std::string reader_type = reader_list.identify(file_name.toStdString());
733 if(!reader_type.empty())
756 bool want_binary_data)
const
765 if(
mcsp_msRunId->getMzFormat() == pappso::MzFormat::MGF)
800 env = setlocale(LC_ALL,
"");
801 setlocale(LC_ALL,
"C");
807 pwiz::msdata::SpectrumListPtr spectrum_list_p =
811 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
821 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
828 qDebug() <<
"The operation was cancelled. Breaking the loop.";
835 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
861 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
872 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
888 !native_pwiz_spectrum_sp->defaultArrayLength);
895 setlocale(LC_ALL, env.c_str());
911 return msp_msData->run.spectrumListPtr.get()->size();