libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pwizmsrunreader.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/msrun/private/pwizmsrunreader.cpp
3 * \date 29/05/2018
4 * \author Olivier Langella
5 * \brief MSrun file reader base on proteowizard library
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2018 Olivier Langella <Olivier.Langella@u-psud.fr>.
10 *
11 * This file is part of the PAPPSOms++ library.
12 *
13 * PAPPSOms++ is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * PAPPSOms++ is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
25 *
26 * Contributors:
27 * Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and
28 *implementation
29 ******************************************************************************/
30
31
32#include <QDebug>
33
34#include "pwizmsrunreader.h"
35
36#include <pwiz/data/common/cv.hpp>
37#include <pwiz/data/msdata/DefaultReaderList.hpp>
38#include <qlogging.h>
39#include "../../obo/obopsims.h"
41
42
47
48// int pwizMsRunReaderMetaTypeId =
49// qRegisterMetaType<pappso::PwizMsRunReader>("pappso::PwizMsRunReader");
50
51
52namespace pappso
53{
54
56
58{
59 // The initialization needs to be done immediately so that we get the pwiz
60 // MsDataPtr corresponding to the right ms_run_id in the parameter. That
61 // pointer will be set to msp_msData.
62
63 initialize();
64}
65
66
67void
69{
70 std::string file_name_std = Utils::toUtf8StandardString(mcsp_msRunId->getFileName());
71
72
73 // Now actually search the useful MSDataPtr to the member variable.
74
75 pwiz::msdata::DefaultReaderList defaultReaderList;
76
77 std::vector<pwiz::msdata::MSDataPtr> msDataPtrVector;
78
79 try
80 {
81 defaultReaderList.read(file_name_std, msDataPtrVector);
82 }
83 catch(std::exception &error)
84 {
85 // qDebug() << QString("Failed to read the data from file %1")
86 //.arg(QString::fromStdString(file_name_std));
87
88 throw(PappsoException(QString("Error reading file %1 in PwizMsRunReader, for msrun %2:\n%3")
89 .arg(mcsp_msRunId->getFileName())
90 .arg(mcsp_msRunId.get()->toString())
91 .arg(error.what())));
92 }
93
94 // qDebug() << "The number of runs is:" << msDataPtrVector.size()
95 //<< "The number of spectra in first run is:"
96 //<< msDataPtrVector.at(0)->run.spectrumListPtr->size();
97
98 // Single-run file handling here.
99
100 // Specific case of the MGF data format: we do not have a run id for that
101 // kind of data. In this case there must be a single run!
102
103 if(mcsp_msRunId->getRunId().isEmpty())
104 {
105 if(msDataPtrVector.size() != 1)
106 throw(
107 ExceptionNotPossible("For the kind of file at hand there can only be "
108 "one run in the file."));
109
110 // At this point we know the single msDataPtr is the one we are looking
111 // for.
112
113 msp_msData = msDataPtrVector.front();
114 }
115 else
116 {
117 // Multi-run file handling here.
118 for(const pwiz::msdata::MSDataPtr &msDataPtr : msDataPtrVector)
119 {
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()=" << mcsp_msRunId->getSampleName();
124
125 if(msDataPtr->run.id == mcsp_msRunId->getRunId().toStdString())
126 {
127 msp_msData = msDataPtr;
128
129 // qDebug() << "Found the right MSDataPtr for run id.";
130
131 break;
132 }
133 }
134 }
135
136 if(msp_msData == nullptr)
137 {
138 throw(ExceptionNotPossible(QString("Could not find a pwiz MSDataPtr "
139 "matching the requested run id : %1")
140 .arg(mcsp_msRunId.get()->toString())));
141 }
142
143
144 // check if this MS run can be used with scan numbers
145 // MS:1000490 Agilent instrument model
146 pwiz::cv::CVID native_id_format = pwiz::msdata::id::getDefaultNativeIDFormat(*msp_msData.get());
147
148 // msp_msData.get()->getDefaultNativeIDFormat();
149
150 if(native_id_format == pwiz::cv::CVID::MS_Thermo_nativeID_format)
151 {
152 m_hasScanNumbers = true;
153 }
154 else
155 {
156 m_hasScanNumbers = false;
157 }
158
159 if(mcsp_msRunId.get()->getMsDataFormat() == Enums::MsDataFormat::mzXML)
160 {
161 m_hasScanNumbers = true;
162 }
163}
164
168
169const pwiz::msdata::MSDataPtr
170
172{
173 return msp_msData;
174}
175
176const OboPsiModTerm
178{
179
180 OboPsiModTerm term;
181
182 term.setAccession("MS:1000824");
183 term.m_name = "no nativeID format";
184 term.m_definition =
185 "No nativeID format indicates that the file tagged with this term does "
186 "not "
187 "contain spectra that can have a nativeID format.";
188
189
190 pwiz::cv::CVID cvid = pwiz::msdata::id::getDefaultNativeIDFormat(*(msp_msData.get()));
191
192 switch(cvid)
193 {
194 case pwiz::cv::MS_Thermo_nativeID_format:
195 term.setAccession("MS:1000768");
196 term.m_name = "Thermo nativeID format";
197 term.m_definition =
198 "Native format defined by controllerType=xsd:nonNegativeInteger "
199 "controllerNumber=xsd:positiveInteger scan=xsd:positiveInteger.";
200 break;
201 default:
202 break;
203 }
204 return term;
205}
206
207pwiz::msdata::SpectrumPtr
208PwizMsRunReader::getPwizSpectrumPtr(pwiz::msdata::SpectrumList *p_spectrum_list,
209 std::size_t spectrum_index,
210 bool want_binary_data) const
211{
212 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp;
213
214 try
215 {
216 native_pwiz_spectrum_sp = p_spectrum_list->spectrum(spectrum_index, want_binary_data);
217 }
218 catch(std::runtime_error &error)
219 {
220 // qDebug() << "getPwizSpectrumPtr error " << error.what() << " " << typeid(error).name();
221
222 throw ExceptionNotFound(QObject::tr("Pwiz spectrum index %1 not found in "
223 "MS file std::runtime_error :\n%2")
224 .arg(spectrum_index)
225 .arg(error.what()));
226 }
227 catch(std::exception &error)
228 {
229 // qDebug() << "getPwizSpectrumPtr error " << error.what() << typeid(error).name();
230
231 throw ExceptionNotFound(QObject::tr("Pwiz spectrum index %1 not found in MS file :\n%2")
232 .arg(spectrum_index)
233 .arg(error.what()));
234 }
235
236 if(native_pwiz_spectrum_sp.get() == nullptr)
237 {
238 throw ExceptionNotFound(
239 QObject::tr("Pwiz spectrum index %1 not found in MS file : null pointer")
240 .arg(spectrum_index));
241 }
242
243 return native_pwiz_spectrum_sp;
244}
245
246
247bool
248PwizMsRunReader::processRetentionTime(pwiz::msdata::Spectrum *spectrum_p,
249 QualifiedMassSpectrum &qualified_mass_spectrum) const
250{
251
252 // We now have to set the retention time at which this mass spectrum
253 // was acquired. This is the scan start time.
254
255 if(!spectrum_p->scanList.scans[0].hasCVParam(pwiz::msdata::MS_scan_start_time))
256 {
257 if(mcsp_msRunId.get()->getMsDataFormat() == Enums::MsDataFormat::MGF)
258 { // MGF could not have scan start time
259 qualified_mass_spectrum.setRtInSeconds(-1);
260 }
261 else
262 {
263 throw(ExceptionNotPossible("The spectrum has no scan start time value set."));
264 }
265 }
266 else
267 {
268 pwiz::data::CVParam retention_time_cv_param =
269 spectrum_p->scanList.scans[0].cvParam(pwiz::msdata::MS_scan_start_time);
270
271 // Try to get the units of the retention time value.
272
273 std::string unit_name = retention_time_cv_param.unitsName();
274 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
275 //<< "Unit name for the retention time:"
276 //<< QString::fromStdString(unit_name);
277
278 if(unit_name == "second")
279 {
280 qualified_mass_spectrum.setRtInSeconds(retention_time_cv_param.valueAs<double>());
281 }
282 else if(unit_name == "minute")
283 {
284 qualified_mass_spectrum.setRtInSeconds(retention_time_cv_param.valueAs<double>() * 60);
285 }
286 else
287 throw(
288 ExceptionNotPossible("Could not determine the unit for the "
289 "scan start time value."));
290 }
291
292 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
293 //<< "Retention time for spectrum is:"
294 //<< qualified_mass_spectrum.getRtInSeconds();
295
296 // Old version not checking unit (by default unit is minutes for RT,
297 // not seconds)
298 //
299 // pappso_double retentionTime =
300 // QString(spectrum_p->scanList.scans[0]
301 //.cvParam(pwiz::msdata::MS_scan_start_time)
302 //.value.c_str())
303 //.toDouble();
304 // qualified_mass_spectrum.setRtInSeconds(retentionTime);
305
306 return true;
307}
308
309
310bool
311PwizMsRunReader::processDriftTime(pwiz::msdata::Spectrum *spectrum_p,
312 QualifiedMassSpectrum &qualified_mass_spectrum) const
313{
314 // Not all the acquisitions have ion mobility data. We need to test
315 // that:
316
317 if(spectrum_p->scanList.scans[0].hasCVParam(pwiz::msdata::MS_ion_mobility_drift_time))
318 {
319
320 // qDebug() << "as strings:"
321 //<< QString::fromStdString(
322 // spectrum_p->scanList.scans[0]
323 //.cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
324 //.valueAs<std::string>());
325
326 pappso_double driftTime = spectrum_p->scanList.scans[0]
327 .cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
328 .valueAs<double>();
329
330 // qDebug() << "driftTime:" << driftTime;
331
332 // Old version requiring use of QString.
333 // pappso_double driftTime =
334 // QString(spectrum_p->scanList.scans[0]
335 //.cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
336 //.value.c_str())
337 //.toDouble();
338
339 // Now make positively sure that the obtained value is correct.
340 // Note that I suffered a lot with Waters Synapt data that
341 // contained apparently correct drift time XML element that in
342 // fact contained either NaN or inf. When such mass spectra were
343 // encountered, the mz,i data were bogus and crashed the data
344 // loading functions. We just want to skip this kind of bogus mass
345 // spectrum by letting the caller know that the drift time was
346 // bogus ("I" is Filippo Rusconi).
347
348 if(std::isnan(driftTime) || std::isinf(driftTime))
349 {
350 // qDebug() << "detected as nan or inf.";
351
352 return false;
353 }
354 else
355 {
356 // The mzML standard stipulates that drift times are in
357 // milliseconds.
358 qualified_mass_spectrum.setDtInMilliSeconds(driftTime);
359 }
360 }
361 // End of
362 // if(spectrum_p->scanList.scans[0].hasCVParam(
363 // pwiz::msdata::MS_ion_mobility_drift_time))
364 else
365 {
366 // Not a bogus mass spectrum but also not a drift spectrum, set -1
367 // as the drift time value.
368 qualified_mass_spectrum.setDtInMilliSeconds(-1);
369 }
370
371 return true;
372}
373
374
377 pwiz::msdata::Spectrum *spectrum_p,
378 bool want_binary_data,
379 bool &ok) const
380{
381 // qDebug();
382
383 if(spectrum_p == nullptr)
384 qFatal("Spectrum pointer cannot be nullptr.");
385
386 std::string backup_env = setGlobalLocaleToEnglish();
387
388 QualifiedMassSpectrum qualified_mass_spectrum(massSpectrumId);
389
390 try
391 {
392
393 // We want to store the ms level for this spectrum
394
395 int msLevel = (spectrum_p->cvParam(pwiz::msdata::MS_ms_level).valueAs<int>());
396
397 qualified_mass_spectrum.setMsLevel(msLevel);
398
399 if(!spectrum_p->scanList.scans[0].hasCVParam(pwiz::msdata::MS_peak_list_scans))
400 {
401
402 // qDebug() << spectrum_p->cvParam(pwiz::msdata::MS_peak_list_scans)
403 // .valueAs<double>();
404 qualified_mass_spectrum.setParameterValue(
406 spectrum_p->cvParam(pwiz::msdata::MS_peak_list_scans).valueAs<double>());
407 }
408 // We want to know if this spectrum is a fragmentation spectrum obtained
409 // from a selected precursor ion.
410
411 std::size_t precursor_list_size = spectrum_p->precursors.size();
412
413 // qDebug() << "For spectrum at index:" <<
414 // massSpectrumId.getSpectrumIndex()
415 //<< "msLevel:" << msLevel
416 //<< "with number of precursors:" << precursor_list_size;
417
418 if(precursor_list_size > 0)
419 {
420
421 // Sanity check
422 if(msLevel < 2)
423 {
424 // qDebug() << "Going to throw: msLevel cannot be less than two for "
425 //"a spectrum that has items in its Precursor list.";
426
427 throw(
428 ExceptionNotPossible("msLevel cannot be less than two for "
429 "a spectrum that has items in its Precursor list."));
430 }
431
432 // See what is the first precursor in the list.
433
434 for(auto &precursor : spectrum_p->precursors)
435 {
436
437 // Set this variable ready as we need that default value in
438 // certain circumstances.
439
440 std::size_t precursor_spectrum_index = std::numeric_limits<std::size_t>::max();
441
442 // The spectrum ID of the precursor might be empty.
443
444 if(precursor.spectrumID.empty())
445 {
446 // qDebug() << "The precursor's spectrum ID is empty.";
447
448 if(mcsp_msRunId.get()->getMsDataFormat() == Enums::MsDataFormat::MGF)
449 {
450 // qDebug()
451 //<< "Format is MGF, precursor's spectrum ID can be
452 // empty.";
453 }
454 else
455 {
456 // When performing Lumos Fusion fragmentation
457 // experiments in Tune mode and with recording, the
458 // first spectrum of the list is a fragmentation
459 // spectrum (ms level 2) that has no identity for the
460 // precursor spectrum because there is no full scan
461 // accquisition.
462 }
463 }
464 // End of
465 // if(precursor.spectrumID.empty())
466 else
467 {
468 // We could get a native precursor spectrum id, so convert
469 // that native id to a spectrum index.
470
471 qualified_mass_spectrum.setPrecursorNativeId(
472 QString::fromStdString(precursor.spectrumID));
473
474 if(qualified_mass_spectrum.getPrecursorNativeId().isEmpty())
475 {
476 // qDebug() << "The native id of the precursor spectrum
477 // is empty.";
478 }
479
480 // Get the spectrum index of the spectrum that contained
481 // the precursor ion.
482
483 precursor_spectrum_index =
484 msp_msData->run.spectrumListPtr->find(precursor.spectrumID);
485
486 // Note that the Mascot MGF format has a peculiar handling
487 // of the precursor ion stuff so we cannot throw.
488 if(precursor_spectrum_index == msp_msData->run.spectrumListPtr->size())
489 {
490 if(mcsp_msRunId.get()->getMsDataFormat() != Enums::MsDataFormat::MGF)
491 {
492 throw(
493 ExceptionNotPossible("Failed to find the index of the "
494 "precursor ion's spectrum."));
495 }
496 }
497
498 qualified_mass_spectrum.setPrecursorSpectrumIndex(precursor_spectrum_index);
499
500 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__
501 // <<
502 // "()"
503 //<< "Set the precursor spectrum index to:"
504 //<< qualified_mass_spectrum.getPrecursorSpectrumIndex()
505 //<< "for qualified mass spectrum:"
506 //<< &qualified_mass_spectrum;
507 }
508
509 // *****************************************************
510 // get isolation window (very simplified)
511 // *****************************************************
512 auto pwiz_cv_param =
513 precursor.isolationWindow.cvParam(pwiz::cv::MS_isolation_window_target_m_z);
514 if(pwiz_cv_param != pwiz::cv::CVID_Unknown)
515 {
516 double isolation_mz = QString(pwiz_cv_param.value.c_str()).toDouble();
517
518 qualified_mass_spectrum.setParameterValue(
520
521 double isolation_mz_width =
522 QString(
523 precursor.isolationWindow.cvParam(pwiz::cv::MS_isolation_window_lower_offset)
524 .value.c_str())
525 .toDouble();
526 qualified_mass_spectrum.setParameterValue(
528 isolation_mz_width =
529 QString(
530 precursor.isolationWindow.cvParam(pwiz::cv::MS_isolation_window_upper_offset)
531 .value.c_str())
532 .toDouble();
533 qualified_mass_spectrum.setParameterValue(
535
536 // /// isolation window target m/z: The primary or reference m/z about which the
537 // isolation window is defined. MS_isolation_window_target_m_z = 1000827,
538
539 // /// isolation window lower offset: The extent of the isolation window in m/z
540 // below the isolation window target m/z. The lower and upper offsets may be
541 // asymmetric about the target m/z. MS_isolation_window_lower_offset = 1000828,
542
543 // /// isolation window upper offset: The extent of the isolation window in m/z
544 // above the isolation window target m/z. The lower and upper offsets may be
545 // asymmetric about the target m/z. MS_isolation_window_upper_offset = 1000829,
546 }
547 // *****************************************************
548 // end get isolation window (very simplified)
549 // *****************************************************
550
551 if(!precursor.selectedIons.size())
552 {
553 // qDebug() << "Going to throw The spectrum has msLevel > 1 but the "
554 //"precursor ions's selected ions list is empty..";
555
556 throw(
557 ExceptionNotPossible("The spectrum has msLevel > 1 but the "
558 "precursor ions's selected ions "
559 "list is empty."));
560 }
561
562 pwiz::msdata::SelectedIon &ion = *(precursor.selectedIons.begin());
563
564 // selected ion m/z
565
566 pappso_double selected_ion_mz =
567 QString(ion.cvParam(pwiz::cv::MS_selected_ion_m_z).value.c_str()).toDouble();
568
569 // selected ion peak intensity
570 //<cvParam cvRef="MS" accession="MS:1000042"
571 // value="910663.949707031" name="peak intensity"
572 // unitAccession="MS:1000131" unitName="number of detector
573 // counts" unitCvRef="MS" />
574
575 pappso_double selected_ion_peak_intensity =
576 QString(ion.cvParam(pwiz::cv::MS_peak_intensity).value.c_str()).toDouble();
577
578 // charge state
579
580 unsigned int selected_ion_charge_state =
581 QString(ion.cvParam(pwiz::cv::MS_charge_state).value.c_str()).toUInt();
582
583 // At this point we can craft a new PrecursorIonData instance
584 // and push it back to the vector.
585
586 PrecursorIonData precursor_ion_data(
587 selected_ion_mz, selected_ion_charge_state, selected_ion_peak_intensity);
588
589 qualified_mass_spectrum.appendPrecursorIonData(precursor_ion_data);
590
591 // General sum-up
592
593 // qDebug()
594 //<< "Appended new PrecursorIonData:"
595 //<< "mz:"
596 //<< qualified_mass_spectrum.getPrecursorIonData().back().mz
597 //<< "charge:"
598 //<< qualified_mass_spectrum.getPrecursorIonData().back().charge
599 //<< "intensity:"
600 //<< qualified_mass_spectrum.getPrecursorIonData()
601 //.back()
602 //.intensity;
603 }
604 // End of
605 // for(auto &precursor : spectrum_p->precursors)
606 }
607 // End of
608 // if(precursor_list_size > 0)
609 else
610 {
611 // Sanity check
612
613 // Unfortunately, logic here is defeated by some vendors that have
614 // files with MS2 spectra without <precursorList>. Thus we have
615 // spectrum_p->precursors.size() == 0 and msLevel > 1.
616
617 // if(msLevel != 1)
618 //{
619 // throw(
620 // ExceptionNotPossible("msLevel cannot be different than 1 if "
621 //"there is not a single precursor ion."));
622 //}
623 }
624
625 // Sanity check.
626
627 if(precursor_list_size != qualified_mass_spectrum.getPrecursorIonData().size())
628 {
629 // qDebug() << "Going to throw The number of precursors in the file is "
630 //"different from the number of precursors in memory.";
631
633 QObject::tr("The number of precursors in the file is different "
634 "from the number of precursors in memory."));
635 }
636
637 // if(precursor_list_size == 1)
638 //{
639 // qDebug() << "Trying to get the mz value of the unique precursor ion:"
640 //<< qualified_mass_spectrum.getPrecursorMz();
641 //}
642
643 processRetentionTime(spectrum_p, qualified_mass_spectrum);
644
645 processDriftTime(spectrum_p, qualified_mass_spectrum);
646
647 // for(pwiz::data::CVParam cv_param : ion.cvParams)
648 //{
649 // pwiz::msdata::CVID param_id = cv_param.cvid;
650 // qDebug() << param_id;
651 // qDebug() << cv_param.cvid.c_str();
652 // qDebug() << cv_param.name().c_str();
653 // qDebug() << cv_param.value.c_str();
654 //}
655
656 if(want_binary_data)
657 {
658
659 // Fill-in MZIntensityPair vector for convenient access to binary
660 // data
661
662 std::vector<pwiz::msdata::MZIntensityPair> pairs;
663 spectrum_p->getMZIntensityPairs(pairs);
664
665 MassSpectrum spectrum;
666 // double tic = 0;
667 // std::size_t iterCount = 0;
668
669 // Iterate through the m/z-intensity pairs
670 for(std::vector<pwiz::msdata::MZIntensityPair>::const_iterator it = pairs.begin(),
671 end = pairs.end();
672 it != end;
673 ++it)
674 {
675 //++iterCount;
676
677 // qDebug() << "it->mz " << it->mz << " it->intensity" <<
678 // it->intensity;
679 if(it->intensity)
680 {
681 spectrum.push_back(DataPoint(it->mz, it->intensity));
682 // tic += it->intensity;
683 }
684 }
685
686 if(mcsp_msRunId.get()->getMsDataFormat() == Enums::MsDataFormat::MGF)
687 {
688 // Sort peaks by mz
689 spectrum.sortMz();
690 }
691
692 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()
693 // "<< spectrum.size();
694 MassSpectrumSPtr spectrum_sp = spectrum.makeMassSpectrumSPtr();
695 qualified_mass_spectrum.setMassSpectrumSPtr(spectrum_sp);
696
697 // double sumY =
698 // qualified_mass_spectrum.getMassSpectrumSPtr()->sumY(); qDebug()
699 // <<
700 // __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
701 //<< "iterCount:" << iterCount << "Spectrum size "
702 //<< spectrum.size() << "with tic:" << tic
703 //<< "and sumY:" << sumY;
704 }
705 else
706 qualified_mass_spectrum.setMassSpectrumSPtr(nullptr);
707 }
708 catch(PappsoException &errorp)
709 {
710 // qDebug() << "Going to throw";
711
713 QObject::tr("Error reading data using the proteowizard library: %1").arg(errorp.qwhat()));
714 }
715 catch(std::exception &error)
716 {
717 // qDebug() << "Going to throw";
718
720 QObject::tr("Error reading data using the proteowizard library: %1").arg(error.what()));
721 }
722
723 ok = true;
724
725 // qDebug() << "QualifiedMassSpectrum: " <<
726 // qualified_mass_spectrum.toString();
727 return qualified_mass_spectrum;
728}
729
730
733 bool want_binary_data,
734 bool &ok) const
735{
736
737 std::string backup_env = setGlobalLocaleToEnglish();
738
739 MassSpectrumId massSpectrumId(mcsp_msRunId);
740
741 if(msp_msData == nullptr)
742 {
743 setGlobalLocaleToCurrentOs(backup_env);
744 return (QualifiedMassSpectrum(massSpectrumId));
745 }
746
747 // const bool want_binary_data = true;
748
749 pwiz::msdata::SpectrumListPtr spectrum_list_p = msp_msData->run.spectrumListPtr;
750
751 if(spectrum_index == spectrum_list_p.get()->size())
752 {
753 setGlobalLocaleToCurrentOs(backup_env);
754 throw ExceptionNotFound(
755 QObject::tr("The spectrum index cannot be equal to the size of the "
756 "spectrum list."));
757 }
758
759 // At this point we know the spectrum index might be sane, so store it in
760 // the mass spec id object.
761 massSpectrumId.setSpectrumIndex(spectrum_index);
762
763 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
764 getPwizSpectrumPtr(spectrum_list_p.get(), spectrum_index, want_binary_data);
765
766 setGlobalLocaleToCurrentOs(backup_env);
767
768 checkNativeId(native_pwiz_spectrum_sp.get(), massSpectrumId);
769
770
772 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
773}
774
775
776bool
777PwizMsRunReader::accept(const QString &file_name) const
778{
779 // We want to know if we can handle the file_name.
780 pwiz::msdata::ReaderList reader_list;
781
782 std::string reader_type = reader_list.identify(file_name.toStdString());
783
784 if(!reader_type.empty())
785 return true;
786
787 return false;
788}
789
790
792PwizMsRunReader::massSpectrumSPtr(std::size_t spectrum_index)
793{
794 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
795 return qualifiedMassSpectrum(spectrum_index, true).getMassSpectrumSPtr();
796}
797
799PwizMsRunReader::massSpectrumCstSPtr(std::size_t spectrum_index)
800{
801 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
802 return qualifiedMassSpectrum(spectrum_index, true).getMassSpectrumCstSPtr();
803}
804
806PwizMsRunReader::qualifiedMassSpectrum(std::size_t spectrum_index, bool want_binary_data) const
807{
808
809 QualifiedMassSpectrum spectrum;
810 bool ok = false;
811
812 spectrum = qualifiedMassSpectrumFromPwizMSData(spectrum_index, want_binary_data, ok);
813
814 if(mcsp_msRunId->getMsDataFormat() == Enums::MsDataFormat::MGF)
815 {
816 if(spectrum.getRtInSeconds() == 0)
817 {
818 // spectrum = qualifiedMassSpectrumFromPwizMSData(scan_num - 1);
819 }
820 }
821
822 // if(!ok)
823 // qDebug() << "Encountered a mass spectrum for which the status is bad.";
824
825 return spectrum;
826}
827
828
829void
831{
832 try
833 {
835 }
836 catch(std::exception &error)
837 {
838 // qDebug() << "Going to throw";
839
841 QObject::tr("Error reading data (spectrum collection) using the "
842 "proteowizard library: %1")
843 .arg(error.what()));
844 }
845}
846
847void
850{
851 // qDebug();
852 try
853 {
855 }
856 catch(std::exception &error)
857 {
858 // qDebug() << "Going to throw";
859
861 QObject::tr("Error reading data (spectrum collection2) using the "
862 "proteowizard library: %1")
863 .arg(error.what()));
864 }
865}
866
867void
869 unsigned int ms_level)
870{
871
873 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()";
874
875 // We want to iterate in the pwiz-spectrum-list and for each pwiz-spectrum
876 // create a pappso-spectrum (QualifiedMassSpectrum). Once the pappso mass
877 // spectrum has been fully qualified (that is, the member data have been
878 // set), it is transferred to the handler passed as parameter to this
879 // function for the consumer to do what it wants with it.
880
881 // Does the handler consuming the mass spectra read from file want these
882 // mass spectra to hold the binary data arrays (mz/i vectors)?
883
884 const bool want_binary_data = handler.needPeakList();
885
886 std::string backup_env = setGlobalLocaleToEnglish();
887
888 // We access the pwiz-mass-spectra via the spectrumListPtr that sits in the
889 // run member of msp_msData.
890
891 pwiz::msdata::SpectrumListPtr spectrum_list_p = msp_msData->run.spectrumListPtr;
892
893 // We'll need it to perform the looping in the spectrum list.
894 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
895
896 // qDebug() << "The spectrum list has size:" << spectrum_list_size;
897
898 // Inform the handler of the spectrum list so that it can handle feedback to
899 // the user.
900 handler.spectrumListHasSize(spectrum_list_size);
901
902 // Iterate in the full list of spectra.
903
904 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
905 {
906
907 // If the user of this reader instance wants to stop reading the
908 // spectra, then break this loop.
909 if(handler.shouldStop())
910 {
911 // qDebug() << "The operation was cancelled. Breaking the loop.";
912 break;
913 }
914
915 // Get the native pwiz-spectrum from the spectrum list.
916 // Note that this pointer is a shared pointer from pwiz.
917
918 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
919 getPwizSpectrumPtr(spectrum_list_p.get(), iter, want_binary_data);
920 /*
921 * we want to load metadata of the spectrum even if it does not contain
922 peaks
923
924 * if(!native_pwiz_spectrum_sp->hasBinaryData())
925 {
926 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ <<
927 "
928 ()"
929 //<< "native pwiz spectrum is empty, continuing.";
930 continue;
931 }
932 */
933
934 // Instantiate the mass spectrum id that will hold critical information
935 // like the the native id string and the spectrum index.
936
937 MassSpectrumId massSpectrumId(mcsp_msRunId, iter /* spectrum index*/);
938
939 // Get the spectrum native id as a QString to store it in the mass
940 // spectrum id class. This is will allow later to refer to the same
941 // spectrum starting back from the file.
942
943 checkNativeId(native_pwiz_spectrum_sp.get(), massSpectrumId);
944
945 // Finally, instantiate the qualified mass spectrum with its id. This
946 // function will continue performing pappso-spectrum detailed
947 // qualification.
948
949 bool ok = false;
950
952 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
953
954 if(!ok)
955 {
956 // qDebug() << "Encountered a mass spectrum for which the returned "
957 //"status is bad.";
958 continue;
959 }
960
961 // Before handing the mass spectrum out to the handler, see if the
962 // native mass spectrum was empty or not.
963
964 // if(!native_pwiz_spectrum_sp->defaultArrayLength)
965 // qDebug() << "The mass spectrum has not defaultArrayLength";
966
967 qualified_mass_spectrum.setEmptyMassSpectrum(!native_pwiz_spectrum_sp->defaultArrayLength);
968
969 // The handler will receive the index of the mass spectrum in the
970 // current run via the mass spectrum id member datum.
971 if(ms_level == 0)
972 {
973 handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
974 }
975 else
976 {
977 if(qualified_mass_spectrum.getMsLevel() == ms_level)
978 {
979 handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
980 }
981 }
982 }
983
984 setGlobalLocaleToCurrentOs(backup_env);
985 // End of
986 // for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
987
988 // Now let the loading handler know that the loading of the data has ended.
989 // The handler might need this "signal" to perform additional tasks or to
990 // cleanup cruft.
991
992 // qDebug() << "Loading ended";
993 handler.loadingEnded();
994}
995
996
997void
998PwizMsRunReader::checkNativeId(const pwiz::msdata::Spectrum *pwiz_spectrum_ptr,
999 MassSpectrumId &mass_spectrum_id) const
1000{
1001 QString native_id = QString::fromStdString(pwiz_spectrum_ptr->id);
1002 mass_spectrum_id.setNativeId(native_id);
1003
1004
1005 // qWarning() << "native_id";
1006 if(mcsp_msRunId->getMsDataFormat() == Enums::MsDataFormat::MGF)
1007 {
1008 std::vector<pwiz::data::CVParam>::const_iterator it =
1009 find_if(pwiz_spectrum_ptr->cvParams.cbegin(),
1010 pwiz_spectrum_ptr->cvParams.cend(),
1011 pwiz::data::CVParamIs(pwiz::cv::MS_spectrum_title));
1012 if(it != pwiz_spectrum_ptr->cvParams.cend())
1013 {
1014 mass_spectrum_id.setNativeId(QString::fromStdString(it->value));
1015 // qWarning() << QString::fromStdString(it->value);
1016 }
1017 }
1018}
1019
1020void
1023{
1024 acquireDevice();
1025 // qDebug();
1026
1027 // We want to iterate in the pwiz-spectrum-list and for each pwiz-spectrum
1028 // create a pappso-spectrum (QualifiedMassSpectrum). Once the pappso mass
1029 // spectrum has been fully qualified (that is, the member data have been
1030 // set), it is transferred to the handler passed as parameter to this
1031 // function for the consumer to do what it wants with it.
1032
1033 // Does the handler consuming the mass spectra read from file want these
1034 // mass spectra to hold the binary data arrays (mz/i vectors)?
1035
1036 const bool want_binary_data = config.needPeakList();
1037
1038
1039 std::string backup_env = setGlobalLocaleToEnglish();
1040
1041 // qDebug();
1042 // We access the pwiz-mass-spectra via the spectrumListPtr that sits in the
1043 // run member of msp_msData.
1044
1045 pwiz::msdata::SpectrumListPtr spectrum_list_p = msp_msData->run.spectrumListPtr;
1046
1047 // We'll need it to perform the looping in the spectrum list.
1048 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
1049
1050 // qDebug() << "The spectrum list has size:" << spectrum_list_size;
1051
1052 // Inform the handler of the spectrum list so that it can handle feedback to
1053 // the user.
1054 handler.spectrumListHasSize(spectrum_list_size);
1055
1056 // Iterate in the full list of spectra.
1057
1058 // qDebug();
1059 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
1060 {
1061
1062
1063 // If the user of this reader instance wants to stop reading the
1064 // spectra, then break this loop.
1065 if(handler.shouldStop())
1066 {
1067 // qDebug() << "The operation was cancelled. Breaking the loop.";
1068 break;
1069 }
1070
1071 // qDebug();
1072 // Get the native pwiz-spectrum from the spectrum list.
1073 // Note that this pointer is a shared pointer from pwiz.
1074
1075 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
1076 getPwizSpectrumPtr(spectrum_list_p.get(), iter, want_binary_data);
1077 // qDebug();
1078 /*
1079 * we want to load metadata of the spectrum even if it does not contain
1080 peaks
1081
1082 * if(!native_pwiz_spectrum_sp->hasBinaryData())
1083 {
1084 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ <<
1085 "
1086 ()"
1087 //<< "native pwiz spectrum is empty, continuing.";
1088 continue;
1089 }
1090 */
1091
1092 // Instantiate the mass spectrum id that will hold critical information
1093 // like the the native id string and the spectrum index.
1094
1095 MassSpectrumId massSpectrumId(mcsp_msRunId, iter /* spectrum index*/);
1096
1097 // qDebug();
1098 // Get the spectrum native id as a QString to store it in the mass
1099 // spectrum id class. This is will allow later to refer to the same
1100 // spectrum starting back from the file.
1101
1102
1103 checkNativeId(native_pwiz_spectrum_sp.get(), massSpectrumId);
1104
1105 // Finally, instantiate the qualified mass spectrum with its id. This
1106 // function will continue performing pappso-spectrum detailed
1107 // qualification.
1108
1109 bool ok = false;
1110
1112 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
1113
1114 if(!ok)
1115 {
1116 // qDebug() << "Encountered a mass spectrum for which the returned "
1117 //"status is bad.";
1118 continue;
1119 }
1120
1121 // qDebug();
1122 // Before handing the mass spectrum out to the handler, see if the
1123 // native mass spectrum was empty or not.
1124
1125 // if(!native_pwiz_spectrum_sp->defaultArrayLength)
1126 // qDebug() << "The mass spectrum has not defaultArrayLength";
1127
1128 qualified_mass_spectrum.setEmptyMassSpectrum(!native_pwiz_spectrum_sp->defaultArrayLength);
1129
1130 // The handler will receive the index of the mass spectrum in the
1131 // current run via the mass spectrum id member datum.
1132
1133 // qDebug();
1134 if(config.acceptMsLevel(qualified_mass_spectrum.getMsLevel()))
1135 {
1136 if(config.acceptRetentionTimeInSeconds(qualified_mass_spectrum.getRtInSeconds()))
1137 {
1138 handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
1139 }
1140 }
1141 }
1142
1143
1144 // qDebug();
1145 setGlobalLocaleToCurrentOs(backup_env);
1146 // End of
1147 // for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
1148
1149 // Now let the loading handler know that the loading of the data has ended.
1150 // The handler might need this "signal" to perform additional tasks or to
1151 // cleanup cruft.
1152
1153 // qDebug() << "Loading ended";
1154 handler.loadingEnded();
1155}
1156
1157std::size_t
1159{
1160 return msp_msData->run.spectrumListPtr.get()->size();
1161}
1162
1163bool
1165{
1166 return m_hasScanNumbers;
1167}
1168
1169bool
1171{
1172 msp_msData = nullptr;
1173 return true;
1174}
1175
1176bool
1178{
1179 if(msp_msData == nullptr)
1180 {
1181 initialize();
1182 }
1183 return true;
1184}
1185
1186
1189 pappso::PrecisionPtr precision) const
1190{
1191
1192 QualifiedMassSpectrum mass_spectrum = qualifiedMassSpectrum(spectrum_index, false);
1193
1194 return newXicCoordSPtrFromQualifiedMassSpectrum(mass_spectrum, precision);
1195}
1196
1199 const pappso::QualifiedMassSpectrum &mass_spectrum, pappso::PrecisionPtr precision) const
1200{
1201 XicCoordSPtr xic_coord = std::make_shared<XicCoord>();
1202
1203 xic_coord.get()->rtTarget = mass_spectrum.getRtInSeconds();
1204
1205 xic_coord.get()->mzRange = MzRange(mass_spectrum.getPrecursorMz(), precision);
1206
1207 return xic_coord;
1208}
1209std::string
1211{
1212 std::string env_backup;
1213 try
1214 {
1215#ifdef MXE
1216 // std::locale::global(std::locale("C")); // set locale to default
1217 // locale
1218
1219 std::string env_backup = std::setlocale(LC_ALL, nullptr);
1220 std::setlocale(LC_ALL, "C");
1221#else
1222 std::locale::global(std::locale("C")); // set locale to default locale
1223#endif
1224 }
1225 catch(std::exception &error)
1226 {
1228 QObject::tr("Error trying to set local to C : %1").arg(error.what()));
1229 }
1230 return env_backup;
1231}
1232
1233void
1234PwizMsRunReader::setGlobalLocaleToCurrentOs(const std::string &environment_locale)
1235{
1236 try
1237 {
1238#ifdef MXE
1239 // std::locale::global(std::locale("C")); // set locale to default
1240 // locale
1241 std::setlocale(LC_ALL, environment_locale.c_str());
1242#else
1243 std::locale::global(std::locale("")); // sets locale according to OS environment
1244#endif
1245 }
1246 catch(std::exception &error)
1247 {
1249 QObject::tr("Error trying to set local to original system one %1 : %2")
1250 .arg(environment_locale.c_str())
1251 .arg(error.what()));
1252 }
1253}
1254
1255std::size_t
1257{
1258 acquireDevice();
1259 std::size_t spectrum_id =
1260 msp_msData->run.spectrumListPtr->find(spectrum_identifier.toStdString());
1261 if(spectrum_id == msp_msData->run.spectrumListPtr->size())
1262 {
1264 QObject::tr("Spectrum identifier %1 not found").arg(spectrum_identifier));
1265 }
1266 return spectrum_id;
1267}
1268
1269} // namespace pappso
1270
1271
1274{
1275
1276
1278
1279 if(getOboPsiModTermNativeIDFormat().getAccession() == "MS:1000768")
1280 {
1281
1283
1284 pappso::OboPsiMs psims_file(psims_map);
1285 // it should be a Thermo instrument
1286 /*
1287 * [Term]
1288 id: MS:1000494
1289 name: Thermo Scientific instrument model
1290 def: "Thermo Scientific instrument model." [PSI:MS]
1291 is_a: MS:1000483 ! Thermo Fisher Scientific instrument model
1292
1293 */
1294 term = psims_map.getOboPsiModTermWithAccession("MS:1000494");
1295
1296 for(auto &param_group : msp_msData.get()->paramGroupPtrs)
1297 {
1298 for(const auto &cv_param : param_group.get()->cvParams)
1299 {
1300 if(cv_param.cvid == pwiz::cv::CVID::MS_Q_Exactive)
1301 {
1302 term = psims_map.getOboPsiModTermWithAccession("MS:1001911");
1303 }
1304 else if(cv_param.cvid == pwiz::cv::CVID::MS_Velos_Plus)
1305 {
1306 /// Velos Plus: Thermo Scientific second generation Velos.
1307 term = psims_map.getOboPsiModTermWithAccession("MS:1001909");
1308 }
1309 else if(cv_param.cvid == pwiz::cv::CVID::MS_LTQ_Orbitrap_Elite)
1310 {
1311 /// LTQ Orbitrap Elite: Thermo Scientific LTQ Orbitrap Elite, often just referred
1312 /// to as the Orbitrap Elite.
1313
1314 term = psims_map.getOboPsiModTermWithAccession("MS:1001910");
1315 }
1316
1317 /// Orbitrap Fusion: Thermo Scientific Orbitrap Fusion.
1318 else if(cv_param.cvid == pwiz::cv::CVID::MS_Orbitrap_Fusion)
1319 {
1320 /// LTQ Orbitrap Elite: Thermo Scientific LTQ Orbitrap Elite, often just referred
1321 /// to as the Orbitrap Elite.
1322
1323 term = psims_map.getOboPsiModTermWithAccession("MS:1002416");
1324 }
1325 /// Q Exactive HF: Thermo Scientific Q Exactive.
1326 // MS_Q_Exactive_HF = 1002523,
1327 else if(cv_param.cvid == pwiz::cv::CVID::MS_Q_Exactive_HF)
1328 {
1329 /// LTQ Orbitrap Elite: Thermo Scientific LTQ Orbitrap Elite, often just referred
1330 /// to as the Orbitrap Elite.
1331
1332 term = psims_map.getOboPsiModTermWithAccession("MS:1002523");
1333 }
1334 //
1335 /// Exactive Plus: Thermo Scientific Exactive Plus MS.
1336 else if(cv_param.cvid == pwiz::cv::CVID::MS_Exactive_Plus)
1337 {
1338 term = psims_map.getOboPsiModTermWithAccession("MS:1002526");
1339 }
1340 /// Q Exactive Plus: Thermo Scientific Q Exactive Plus.
1341 else if(cv_param.cvid == pwiz::cv::CVID::MS_Q_Exactive_Plus)
1342 {
1343 term = psims_map.getOboPsiModTermWithAccession("MS:1002634");
1344 }
1345 /// Orbitrap Fusion Lumos: Thermo Scientific Orbitrap Fusion Lumos mass spectrometer
1346 /// with Tribrid architecture consisting of quadrupole mass filter, linear ion trap
1347 /// and Orbitrap mass analyzers.
1348 else if(cv_param.cvid == pwiz::cv::CVID::MS_Orbitrap_Fusion_Lumos)
1349 {
1350 term = psims_map.getOboPsiModTermWithAccession("MS:1002732");
1351 }
1352 /// Q Exactive HF-X: Thermo Scientific Q Exactive HF-X Hybrid Quadrupole Orbitrap MS.
1353 else if(cv_param.cvid == pwiz::cv::CVID::MS_Q_Exactive_HF_X)
1354 {
1355 term = psims_map.getOboPsiModTermWithAccession("MS:1002877");
1356 }
1357 /// Orbitrap Exploris 480: Thermo Scientific Orbitrap Exploris 480 Quadrupole Orbitrap
1358 /// MS.
1359
1360 else if(cv_param.cvid == pwiz::cv::CVID::MS_Orbitrap_Exploris_480)
1361 {
1362 term = psims_map.getOboPsiModTermWithAccession("MS:1003028");
1363 }
1364 /// Orbitrap Eclipse: Thermo Scientific Orbitrap Eclipse mass spectrometer with
1365 /// Tribrid architecture consisting of quadrupole mass filter, linear ion trap and
1366 /// Orbitrap mass analyzers.
1367 else if(cv_param.cvid == pwiz::cv::CVID::MS_Orbitrap_Eclipse)
1368 {
1369 term = psims_map.getOboPsiModTermWithAccession("MS:1003029");
1370 }
1371 /// Orbitrap Exploris 240: Thermo Scientific Orbitrap Exploris 240 Quadrupole Orbitrap
1372 /// MS.
1373
1374 else if(cv_param.cvid == pwiz::cv::CVID::MS_Orbitrap_Exploris_240)
1375 {
1376 term = psims_map.getOboPsiModTermWithAccession("MS:1003094");
1377 }
1378 /// Orbitrap Exploris 120: Thermo Scientific Orbitrap Exploris 120 Quadrupole Orbitrap
1379 /// MS.
1380
1381 else if(cv_param.cvid == pwiz::cv::CVID::MS_Orbitrap_Exploris_120)
1382 {
1383 term = psims_map.getOboPsiModTermWithAccession("MS:1003095");
1384 }
1385 /// LTQ Orbitrap Velos Pro: Thermo Scientific LTQ Orbitrap Velos Pro, often just
1386 /// referred to as the Orbitrap Velos Pro.
1387 else if(cv_param.cvid == pwiz::cv::CVID::MS_LTQ_Orbitrap_Velos_Pro)
1388 {
1389 term = psims_map.getOboPsiModTermWithAccession("MS:1003096");
1390 }
1391 /// Q Exactive UHMR: Thermo Scientific Q Exactive UHMR (Ultra High Mass Range) Hybrid
1392 /// Quadrupole Orbitrap MS.
1393 else if(cv_param.cvid == pwiz::cv::CVID::MS_Q_Exactive_UHMR)
1394 {
1395 term = psims_map.getOboPsiModTermWithAccession("MS:1003245");
1396 }
1397 /// TSQ Altis Plus: Thermo Scientific TSQ Altis Plus Triple Quadrupole MS.
1398 else if(cv_param.cvid == pwiz::cv::CVID::MS_TSQ_Altis_Plus)
1399 {
1400 term = psims_map.getOboPsiModTermWithAccession("MS:1003292");
1401 }
1402 /// Orbitrap Ascend: Thermo Scientific Orbitrap Ascend mass spectrometer with Tribrid
1403 /// architecture consisting of quadrupole mass filter, linear ion trap and Orbitrap
1404 /// mass analyzers.
1405 else if(cv_param.cvid == pwiz::cv::CVID::MS_Orbitrap_Ascend)
1406 {
1407 term = psims_map.getOboPsiModTermWithAccession("MS:1003356");
1408 }
1409 /// Orbitrap Astral: Thermo Scientific Orbitrap Astral mass spectrometer contains
1410 /// three mass analyzers: a quadrupole analyzer, an Orbitrap analyzer, and the Astral
1411 /// analyzer.
1412 else if(cv_param.cvid == pwiz::cv::CVID::MS_Orbitrap_Astral)
1413 {
1414 term = psims_map.getOboPsiModTermWithAccession("MS:1003378");
1415 }
1416 }
1417 }
1418 }
1419 else
1420 {
1421
1422 throw ExceptionNotFound(QObject::tr("instrument model name not found in %1")
1423 .arg(mcsp_msRunId.get()->getFileName()));
1424 }
1425
1426 return term;
1427}
const OboPsiModTerm & getOboPsiModTermWithAccession(const QString &accession) const
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 acceptMsLevel(std::size_t ms_level) const
bool acceptRetentionTimeInSeconds(double retention_time_in_seconds) const
MsRunIdCstSPtr mcsp_msRunId
MsRunReader(const MsRunIdCstSPtr &ms_run_id)
void setAccession(const QString &accession)
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
const pwiz::msdata::MSDataPtr getMsDataPtr() const
QualifiedMassSpectrum qualifiedMassSpectrumFromPwizMSData(std::size_t spectrum_index, bool want_binary_data, bool &ok) const
PwizMsRunReader(MsRunIdCstSPtr &msrun_id_csp)
void checkNativeId(const pwiz::msdata::Spectrum *pwiz_spectrum_ptr, MassSpectrumId &mass_spectrum_id) const
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
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
virtual std::size_t spectrumStringIdentifier2SpectrumIndex(const QString &spectrum_identifier) override
if possible, get the spectrum index given a string identifier throw a not found exception if spectrum...
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 const OboPsiModTerm getOboPsiModTermInstrumentModelName() const override
get OboPsiModTerm corresponding to the instrument model name child of : [Term] id: MS:1000031 name: i...
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 needPeakList() const =0
tells if we need the peak list (if we want the binary data) for each spectrum
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum)=0
static std::string toUtf8StandardString(const QString &text)
Definition utils.cpp:166
@ MGF
Mascot format.
Definition types.h:145
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition msrunid.h:46
double pappso_double
A type definition for doubles.
Definition types.h:60
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
@ IsolationWindowTargetMz
Isolation m/z value isolation window target m/z (thomson).
@ IsolationWindowUpperOffset
isolation window upper offset (thomson)
@ IsolationWindowLowerOffset
isolation window lower offset (thomson)
const PrecisionBase * PrecisionPtr
Definition precision.h:122
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
std::shared_ptr< XicCoord > XicCoordSPtr
Definition xiccoord.h:44