OpenMS
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MSExperiment.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg $
6 // $Authors: Marc Sturm, Tom Waschischeck $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
19 
20 #include <vector>
21 
22 
23 namespace OpenMS
24 {
25  class Peak1D;
26  class ChromatogramPeak;
27 
29 
48  class OPENMS_DLLAPI MSExperiment final : public ExperimentalSettings
49  {
50 
51 public:
52  typedef Peak1D PeakT;
54 
56 
57  typedef PeakT PeakType;
67 
70 
78  typedef std::vector<SpectrumType> Base;
80 
82 
83  typedef std::vector<SpectrumType>::iterator Iterator;
86  typedef std::vector<SpectrumType>::const_iterator ConstIterator;
92 
94  // Attention: these refer to the spectra vector only!
96  typedef Base::value_type value_type;
97  typedef Base::iterator iterator;
98  typedef Base::const_iterator const_iterator;
99 
102 
104  MSExperiment(const MSExperiment & source);
105 
108 
111 
114 
117 
119  ~MSExperiment() override;
120 
122  bool operator==(const MSExperiment & rhs) const;
123 
125  bool operator!=(const MSExperiment & rhs) const;
126 
128  inline Size size() const noexcept
129  {
130  return spectra_.size();
131  }
132 
134  inline void resize(Size n)
135  {
136  spectra_.resize(n);
137  }
138 
140  inline bool empty() const noexcept
141  {
142  return spectra_.empty();
143  }
144 
146  inline void reserve(Size n)
147  {
148  spectra_.reserve(n);
149  }
150 
153  {
154  return spectra_[n];
155  }
156 
158  inline const SpectrumType& operator[](Size n) const
159  {
160  return spectra_[n];
161  }
162 
163  inline Iterator begin() noexcept
164  {
165  return spectra_.begin();
166  }
167 
168  inline ConstIterator begin() const noexcept
169  {
170  return spectra_.cbegin();
171  }
172 
173  inline ConstIterator cbegin() const noexcept
174  {
175  return spectra_.cbegin();
176  }
177 
178  inline Iterator end()
179  {
180  return spectra_.end();
181  }
182 
183  inline ConstIterator end() const noexcept
184  {
185  return spectra_.cend();
186  }
187 
188  inline ConstIterator cend() const noexcept
189  {
190  return spectra_.cend();
191  }
193 
194  // Aliases / chromatograms
197 
199 
200 
206  template <class Container>
207  void get2DData(Container& cont) const
208  {
209  for (typename Base::const_iterator spec = spectra_.begin(); spec != spectra_.end(); ++spec)
210  {
211  if (spec->getMSLevel() != 1)
212  {
213  continue;
214  }
215  typename Container::value_type s; // explicit object here, since instantiation within push_back() fails on VS<12
216  for (typename SpectrumType::const_iterator it = spec->begin(); it != spec->end(); ++it)
217  {
218  cont.push_back(s);
219  cont.back().setRT(spec->getRT());
220  cont.back().setMZ(it->getMZ());
221  cont.back().setIntensity(it->getIntensity());
222  }
223  }
224  }
225 
237  template <class Container>
238  void set2DData(const Container& container)
239  {
240  set2DData<false, Container>(container);
241  }
242 
257  template <class Container>
258  void set2DData(const Container& container, const StringList& store_metadata_names)
259  {
260  // clean up the container first
261  clear(true);
262  SpectrumType* spectrum = nullptr;
263  typename PeakType::CoordinateType current_rt = -std::numeric_limits<typename PeakType::CoordinateType>::max();
264  for (typename Container::const_iterator iter = container.begin(); iter != container.end(); ++iter)
265  {
266  // check if the retention time has changed
267  if (current_rt != iter->getRT() || spectrum == nullptr)
268  {
269  // append new spectrum
270  if (current_rt > iter->getRT())
271  {
272  throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Input container is not sorted!");
273  }
274  current_rt = iter->getRT();
275  spectrum = createSpec_(current_rt, store_metadata_names);
276  }
277 
278  // add either data point or mass traces (depending on template argument value)
279  ContainerAdd_<typename Container::value_type, false>::addData_(spectrum, &(*iter), store_metadata_names);
280  }
281  }
282 
301  template <bool add_mass_traces, class Container>
302  void set2DData(const Container& container)
303  {
304  // clean up the container first
305  clear(true);
306  SpectrumType* spectrum = nullptr;
307  typename PeakType::CoordinateType current_rt = -std::numeric_limits<typename PeakType::CoordinateType>::max();
308  for (typename Container::const_iterator iter = container.begin(); iter != container.end(); ++iter)
309  {
310  // check if the retention time has changed
311  if (current_rt != iter->getRT() || spectrum == nullptr)
312  {
313  // append new spectrum
314  if (current_rt > iter->getRT())
315  {
316  throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Input container is not sorted!");
317  }
318  current_rt = iter->getRT();
319  spectrum = createSpec_(current_rt);
320  }
321 
322  // add either data point or mass traces (depending on template argument value)
324  }
325  }
326 
328 
329 
331 
332  AreaIterator areaBegin(CoordinateType min_rt, CoordinateType max_rt,
334  CoordinateType min_mz, CoordinateType max_mz, UInt ms_level = 1);
335 
337  AreaIterator areaBegin(const RangeManagerType& range, UInt ms_level = 1);
338 
341 
344 
346  ConstAreaIterator areaBeginConst(const RangeManagerType& range, UInt ms_level = 1) const;
347 
350 
351  /* @brief Retrieves the peak data in the given mz-rt range and store data spectrum-wise in separate arrays.
352  *
353  * For fast pyOpenMS access to peak data in format: [rt, [mz, intensity]]
354  *
355  * @param min_rt The minimum retention time.
356  * @param max_rt The maximum retention time.
357  * @param min_mz The minimum m/z value.
358  * @param max_mz The maximum m/z value.
359  * @param ms_level The MS level of the spectra to consider.
360  * @param rt The vector to store the retention times in.
361  * @param mz The vector to store the m/z values in.
362  * @param intensity The vector to store the intensities in.
363  */
365  CoordinateType min_rt,
366  CoordinateType max_rt,
367  CoordinateType min_mz,
368  CoordinateType max_mz,
369  Size ms_level,
370  std::vector<float>& rt,
371  std::vector<std::vector<float>>& mz,
372  std::vector<std::vector<float>>& intensity) const
373  {
374  float t = -1.0;
375  for (auto it = areaBeginConst(min_rt, max_rt, min_mz, max_mz, ms_level); it != areaEndConst(); ++it)
376  {
377  if (it.getRT() != t)
378  {
379  t = (float)it.getRT();
380  rt.push_back(t);
381  mz.push_back(std::vector<float>());
382  intensity.push_back(std::vector<float>());
383  }
384  mz.back().push_back((float)it->getMZ());
385  intensity.back().push_back(it->getIntensity());
386  }
387  }
388 
389  /* @brief Retrieves the peak data in the given mz-rt range and store data spectrum-wise in separate arrays.
390  *
391  * For fast pyOpenMS access to MS1 peak data in format: [rt, [mz, intensity, ion mobility]]
392  *
393  * @param min_rt The minimum retention time.
394  * @param max_rt The maximum retention time.
395  * @param min_mz The minimum m/z value.
396  * @param max_mz The maximum m/z value.
397  * @param ms_level The MS level of the spectra to consider.
398  * @param rt The vector to store the retention times in.
399  * @param mz The vector to store the m/z values in.
400  * @param intensity The vector to store the intensities in.
401  * @param ion_mobility The vector to store the ion mobility values in.
402  */
404  CoordinateType min_rt,
405  CoordinateType max_rt,
406  CoordinateType min_mz,
407  CoordinateType max_mz,
408  Size ms_level,
409  std::vector<float>& rt,
410  std::vector<std::vector<float>>& mz,
411  std::vector<std::vector<float>>& intensity,
412  std::vector<std::vector<float>>& ion_mobility) const
413  {
414  DriftTimeUnit unit;
415  std::vector<float> im;
416  float t = -1.0;
417  for (auto it = areaBeginConst(min_rt, max_rt, min_mz, max_mz, ms_level); it != areaEndConst(); ++it)
418  {
419  if (it.getRT() != t)
420  {
421  t = (float)it.getRT();
422  rt.push_back(t);
423  std::tie(unit, im) = it.getSpectrum().maybeGetIMData();
424  mz.push_back(std::vector<float>());
425  intensity.push_back(std::vector<float>());
426  ion_mobility.push_back(std::vector<float>());
427  }
428 
429  if (unit != DriftTimeUnit::NONE)
430  {
431  const Size peak_index = it.getPeakIndex().peak;
432  ion_mobility.back().push_back(im[peak_index]);
433  }
434  else
435  {
436  ion_mobility.back().push_back(-1.0);
437  }
438  mz.back().push_back((float)it->getMZ());
439  intensity.back().push_back(it->getIntensity());
440  }
441  }
442 
443  /* @brief Retrieves the peak data in the given mz-rt range and store in separate arrays.
444  *
445  * For fast pyOpenMS access to MS1 peak data in format: [rt, mz, intensity]
446  *
447  * @param min_rt The minimum retention time.
448  * @param max_rt The maximum retention time.
449  * @param min_mz The minimum m/z value.
450  * @param max_mz The maximum m/z value.
451  * @param ms_level The MS level of the spectra to consider.
452  * @param rt The vector to store the retention times in.
453  * @param mz The vector to store the m/z values in.
454  * @param intensity The vector to store the intensities in.
455  */
457  CoordinateType min_rt,
458  CoordinateType max_rt,
459  CoordinateType min_mz,
460  CoordinateType max_mz,
461  Size ms_level,
462  std::vector<float>& rt,
463  std::vector<float>& mz,
464  std::vector<float>& intensity)
465  const
466  {
467  for (auto it = areaBeginConst(min_rt, max_rt, min_mz, max_mz, ms_level); it != areaEndConst(); ++it)
468  {
469  rt.push_back((float)it.getRT());
470  mz.push_back((float)it->getMZ());
471  intensity.push_back(it->getIntensity());
472  }
473  }
474 
475 
476  /* @brief Retrieves the peak data in the given mz-rt range and store in separate arrays.
477  *
478  * For fast pyOpenMS access to MS1 peak data in format: [rt, mz, intensity, ion mobility]
479  *
480  * @param min_rt The minimum retention time.
481  * @param max_rt The maximum retention time.
482  * @param min_mz The minimum m/z value.
483  * @param max_mz The maximum m/z value.
484  * @param ms_level The MS level of the spectra to consider.
485  * @param rt The vector to store the retention times in.
486  * @param mz The vector to store the m/z values in.
487  * @param intensity The vector to store the intensities in.
488  */
490  CoordinateType min_rt,
491  CoordinateType max_rt,
492  CoordinateType min_mz,
493  CoordinateType max_mz,
494  Size ms_level,
495  std::vector<float>& rt,
496  std::vector<float>& mz,
497  std::vector<float>& intensity,
498  std::vector<float>& ion_mobility) const
499  {
500  for (auto it = areaBeginConst(min_rt, max_rt, min_mz, max_mz, ms_level); it != areaEndConst(); ++it)
501  {
503  std::vector<float> im;
504  float t = -1.0;
505  if (it.getRT() != t)
506  {
507  t = (float)it.getRT();
508  std::tie(unit, im) = it.getSpectrum().maybeGetIMData();
509  }
510  rt.push_back((float)it.getRT());
511  mz.push_back((float)it->getMZ());
512  intensity.push_back(it->getIntensity());
513  if (unit != DriftTimeUnit::NONE)
514  {
515  const Size peak_index = it.getPeakIndex().peak;
516  ion_mobility.push_back(im[peak_index]);
517  }
518  else
519  {
520  ion_mobility.push_back(-1.0);
521  }
522  }
523  }
524 
536 
537  template <typename Iterator>
538  auto operator()(Iterator begin, Iterator end) const {
539  // Static assert to verify iterator type has intensity accessor
540  using ValueType = typename std::iterator_traits<Iterator>::value_type;
541  using IntensityType = decltype(std::declval<ValueType>().getIntensity());
542  static_assert(std::is_member_function_pointer_v<decltype(&ValueType::getIntensity)>,
543  "Iterator value type must have getIntensity() member function");
544 
545  IntensityType sum{};
546  for (auto it = begin; it != end; ++it) {
547  sum += it->getIntensity();
548  }
549  return sum;
550  }
551 };
552 
602 template<class MzReductionFunctionType>
603 std::vector<std::vector<MSExperiment::CoordinateType>> aggregate(
604  const std::vector<std::pair<RangeMZ, RangeRT>>& mz_rt_ranges,
605  unsigned int ms_level,
606  MzReductionFunctionType func_mz_reduction) const
607 {
608  // Early exit if there are no ranges
609  if (mz_rt_ranges.empty())
610  {
611  // likely an error, but we return an empty vector instead of throwing an exception for now
612  return {};
613  }
614 
615  // Create a view of the spectra with given MS level
616  std::vector<std::reference_wrapper<const MSSpectrum>> spectra_view;
617  spectra_view.reserve(spectra_.size());
618  std::copy_if(spectra_.begin(), spectra_.end(),
619  std::back_inserter(spectra_view),
620  [ms_level](const auto& spec) {
621  return spec.getMSLevel() == ms_level;
622  });
623 
624  // Early exit if there are no spectra with the given MS level
625  if (spectra_view.empty()) { // could be valid use or an error -> we return an empty vector
626  return {};
627  }
628 
629  // Get the indices of the spectra covered by the RT ranges by considering the MS level
630  // If start and stop are the same, the range is empty
631  auto getCoveredSpectra = [](
632  const std::vector<std::reference_wrapper<const MSSpectrum>>& spectra_view,
633  const std::vector<std::pair<RangeMZ, RangeRT>>& mz_rt_ranges)
634  -> std::vector<std::pair<size_t, size_t>>
635  {
636  std::vector<std::pair<size_t, size_t>> res;
637  res.reserve(mz_rt_ranges.size());
638 
639  for (const auto & mz_rt : mz_rt_ranges)
640  {
641  // std::cout << "rt range: " << mz_rt.second.getMin() << " - " << mz_rt.second.getMax() << std::endl;
642  // std::cout << "specs start:" << spectra_view[0].get().getRT() << " specs end:" << spectra_view[spectra_view.size() - 1].get().getRT() << std::endl;
643  auto start_it = std::lower_bound(spectra_view.begin(), spectra_view.end(), mz_rt.second.getMin(),
644  [](const auto& spec, double rt)
645  { return spec.get().getRT() < rt; });
646 
647  auto stop_it = std::upper_bound(spectra_view.begin(), spectra_view.end(), mz_rt.second.getMax(),
648  [](double rt, const auto& spec)
649  { return rt < spec.get().getRT(); });
650 
651  res.emplace_back(
652  std::distance(spectra_view.begin(), start_it),
653  std::distance(spectra_view.begin(), stop_it)
654  );
655  // std::cout << "start: " << std::distance(spectra_view.begin(), start_it) << " stop: " << std::distance(spectra_view.begin(), stop_it) << std::endl;
656  }
657  return res;
658  };
659 
660  // For each range, gets (spectrum start index, spectrum stop index). The spectra covered by each RT range.
661  const std::vector<std::pair<size_t, size_t>> rt_ranges_idcs = getCoveredSpectra(spectra_view, mz_rt_ranges);
662 
663  // Initialize result vector
664  std::vector<std::vector<MSExperiment::CoordinateType>> result(mz_rt_ranges.size());
665 
666  // Initialize counts per spectrum index and total mappings
667  std::vector<std::vector<size_t>> spec_idx_to_range_idx(spectra_view.size());
668 
669  // Build spectrum to range index mapping
670  for (size_t i = 0; i < rt_ranges_idcs.size(); ++i)
671  {
672  const auto& [start, stop] = rt_ranges_idcs[i];
673  result[i].resize(stop - start);
674  // std::cout << "start: " << start << " stop: " << stop << std::endl;
675  for (size_t j = start; j < stop; ++j)
676  {
677  spec_idx_to_range_idx[j].push_back(i);
678  }
679  }
680 
681  #pragma omp parallel for schedule(dynamic)
682  for (Int64 i = 0; i < (Int64)spec_idx_to_range_idx.size(); ++i) // OpenMP on windows still requires signed loop variable
683  {
684  if (spec_idx_to_range_idx[i].empty()) continue; // no ranges for this spectrum? skip it
685 
686  const auto& spec = spectra_view[i].get();
687  auto spec_begin = spec.cbegin();
688  auto spec_end = spec.cend();
689 
690  for (size_t range_idx : spec_idx_to_range_idx[i])
691  {
692  const auto& mz_range = mz_rt_ranges[range_idx].first;
693 
694  // Find data points within MZ range
695  auto start_it = spec.PosBegin(spec_begin, mz_range.getMinMZ(), spec_end);
696  auto end_it = start_it;
697 
698  while (end_it != spec_end && end_it->getPosition() <= mz_range.getMaxMZ())
699  {
700  ++end_it;
701  }
702 
703  // std::cout << "calculating reduction on range: " << range_idx << " for spectrum: " << i << " and peaks " << std::distance(spec.begin(), start_it) << " - " << std::distance(spec.begin(), end_it) << std::endl;
704 
705  // Calculate result using provided reduction function
706  result[range_idx][i - rt_ranges_idcs[range_idx].first] =
707  func_mz_reduction(start_it, end_it);
708  }
709  }
710  return result;
711  }
712 
713 // Overload without func_mz_reduction parameter (default to SumIntensityReduction). Needed because of template deduction issues
714 std::vector<std::vector<MSExperiment::CoordinateType>> aggregate(
715  const std::vector<std::pair<RangeMZ, RangeRT>>& mz_rt_ranges,
716  unsigned int ms_level) const
717 {
718  return aggregate(mz_rt_ranges, ms_level, SumIntensityReduction());
719 }
720 
733 template<class MzReductionFunctionType>
734 std::vector<MSChromatogram> extractXICs(
735  const std::vector<std::pair<RangeMZ, RangeRT>>& mz_rt_ranges,
736  unsigned int ms_level,
737  MzReductionFunctionType func_mz_reduction) const
738 {
739  // Early exit if there are no ranges
740  if (mz_rt_ranges.empty())
741  {
742  // likely an error, but we return an empty vector instead of throwing an exception for now
743  return {};
744  }
745 
746  // Create a view of the spectra with given MS level
747  std::vector<std::reference_wrapper<const MSSpectrum>> spectra_view;
748  spectra_view.reserve(spectra_.size());
749  std::copy_if(spectra_.begin(), spectra_.end(),
750  std::back_inserter(spectra_view),
751  [ms_level](const auto& spec) {
752  return spec.getMSLevel() == ms_level;
753  });
754 
755  // Early exit if there are no spectra with the given MS level
756  if (spectra_view.empty()) { // could be valid use or an error -> we return an empty vector
757  return {};
758  }
759 
760  // Get the indices of the spectra covered by the RT ranges by considering the MS level
761  // If start and stop are the same, the range is empty
762  auto getCoveredSpectra = [](
763  const std::vector<std::reference_wrapper<const MSSpectrum>>& spectra_view,
764  const std::vector<std::pair<RangeMZ, RangeRT>>& mz_rt_ranges)
765  -> std::vector<std::pair<size_t, size_t>>
766  {
767  std::vector<std::pair<size_t, size_t>> res;
768  res.reserve(mz_rt_ranges.size());
769 
770  for (const auto & mz_rt : mz_rt_ranges)
771  {
772  auto start_it = std::lower_bound(spectra_view.begin(), spectra_view.end(), mz_rt.second.getMin(),
773  [](const auto& spec, double rt)
774  { return spec.get().getRT() < rt; });
775 
776  auto stop_it = std::upper_bound(spectra_view.begin(), spectra_view.end(), mz_rt.second.getMax(),
777  [](double rt, const auto& spec)
778  { return rt < spec.get().getRT(); });
779 
780  res.emplace_back(
781  std::distance(spectra_view.begin(), start_it),
782  std::distance(spectra_view.begin(), stop_it)
783  );
784  }
785  return res;
786  };
787 
788  // For each range, gets (spectrum start index, spectrum stop index). The spectra covered by each RT range.
789  const std::vector<std::pair<size_t, size_t>> rt_ranges_idcs = getCoveredSpectra(spectra_view, mz_rt_ranges);
790 
791  // Initialize result vector
792  std::vector<MSChromatogram> result(mz_rt_ranges.size());
793 
794  // Initialize counts per spectrum index and total mappings
795  std::vector<std::vector<size_t>> spec_idx_to_range_idx(spectra_view.size());
796 
797  // Build spectrum to range index mapping
798  for (size_t i = 0; i < rt_ranges_idcs.size(); ++i)
799  {
800  const auto& [start, stop] = rt_ranges_idcs[i];
801  result[i].resize(stop - start);
802  result[i].getProduct().setMZ(
803  (mz_rt_ranges[i].first.getMinMZ() + mz_rt_ranges[i].first.getMaxMZ()) / 2.0);
804  for (size_t j = start; j < stop; ++j)
805  {
806  spec_idx_to_range_idx[j].push_back(i);
807  }
808  }
809 
810  #pragma omp parallel for schedule(dynamic)
811  for (Int64 i = 0; i < (Int64)spec_idx_to_range_idx.size(); ++i) // OpenMP on windows still requires signed loop variable
812  {
813  if (spec_idx_to_range_idx[i].empty()) continue; // no ranges for this spectrum? skip
814 
815  const auto& spec = spectra_view[i].get();
816  const double rt = spec.getRT();
817  auto spec_begin = spec.cbegin();
818  auto spec_end = spec.cend();
819 
820  for (size_t range_idx : spec_idx_to_range_idx[i])
821  {
822  const auto& mz_range = mz_rt_ranges[range_idx].first;
823 
824  // Find data points within MZ range
825  auto start_it = spec.PosBegin(spec_begin, mz_range.getMinMZ(), spec_end);
826  auto end_it = start_it;
827 
828  while (end_it != spec_end && end_it->getPosition() <= mz_range.getMaxMZ())
829  {
830  ++end_it;
831  }
832 
833  // Calculate result using provided reduction function
834  result[range_idx][i - rt_ranges_idcs[range_idx].first] =
835  ChromatogramPeak(rt, func_mz_reduction(start_it, end_it));
836  }
837  }
838 
839  for (auto& r : result) r.updateRanges(); // TODO: prob.. faster to look at first and last peaks as range is sorted
840 
841  return result;
842  }
843 
844 // Overload without func_mz_reduction parameter (needed because of template deduction issue)
845 std::vector<MSChromatogram> extractXICs(
846  const std::vector<std::pair<RangeMZ, RangeRT>>& mz_rt_ranges,
847  unsigned int ms_level) const
848 {
849  return extractXICs(mz_rt_ranges, ms_level, SumIntensityReduction());
850 }
851 
860  std::vector<std::vector<MSExperiment::CoordinateType>> aggregateFromMatrix(
861  const Matrix<double>& ranges,
862  unsigned int ms_level,
863  const std::string& mz_agg) const
864  {
865  // Check matrix dimensions
866  if (ranges.cols() != 4)
867  {
868  throw Exception::InvalidParameter(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
869  "Range matrix must have 4 columns [mz_min, mz_max, rt_min, rt_max]");
870  }
871 
872  // Convert matrix rows to vector of pairs
873  std::vector<std::pair<RangeMZ, RangeRT>> mz_rt_ranges;
874  mz_rt_ranges.reserve((Size)ranges.rows());
875 
876  for (Size i = 0; i < (Size)ranges.rows(); ++i)
877  {
878  mz_rt_ranges.emplace_back(
879  RangeMZ(ranges(i, 0), ranges(i, 1)), // min max mz
880  RangeRT(ranges(i, 2), ranges(i, 3)) // min max rt
881  );
882  // std::cout << "mz: " << ranges(i, 0) << " - " << ranges(i, 1) << " rt: " << ranges(i, 2) << " - " << ranges(i, 3) << std::endl;
883  }
884 
885  // Call appropriate aggregation function based on mz_agg parameter
886  if (mz_agg == "sum")
887  {
888  return aggregate(mz_rt_ranges, ms_level,
889  [](auto begin_it, auto end_it)
890  {
891  return std::accumulate(begin_it, end_it, 0.0,
892  [](double a, const Peak1D& b) { return a + b.getIntensity(); });
893  });
894  }
895  else if (mz_agg == "max")
896  {
897  return aggregate(mz_rt_ranges, ms_level,
898  [](auto begin_it, auto end_it)->double
899  {
900  if (begin_it == end_it) return 0.0;
901  return std::max_element(begin_it, end_it,
902  [](const Peak1D& a, const Peak1D& b) { return a.getIntensity() < b.getIntensity(); }
903  )->getIntensity();
904  });
905  }
906  else if (mz_agg == "min")
907  {
908  return aggregate(mz_rt_ranges, ms_level,
909  [](auto begin_it, auto end_it)->double
910  {
911  if (begin_it == end_it) return 0.0;
912  return std::min_element(begin_it, end_it,
913  [](const Peak1D& a, const Peak1D& b) { return a.getIntensity() < b.getIntensity(); }
914  )->getIntensity();
915  });
916  }
917  else if (mz_agg == "mean")
918  {
919  return aggregate(mz_rt_ranges, ms_level,
920  [](auto begin_it, auto end_it)
921  {
922  if (begin_it == end_it) return 0.0;
923  double sum = std::accumulate(begin_it, end_it, 0.0,
924  [](double a, const Peak1D& b) { return a + b.getIntensity(); });
925  return sum / static_cast<double>(std::distance(begin_it, end_it));
926  });
927  }
928  else
929  {
930  throw Exception::InvalidValue(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
931  "Invalid aggregation function", mz_agg);
932  }
933  }
934 
943  std::vector<MSChromatogram> extractXICsFromMatrix(
944  const Matrix<double>& ranges,
945  unsigned int ms_level,
946  const std::string& mz_agg) const
947  {
948  // Check matrix dimensions
949  if (ranges.cols() != 4)
950  {
951  throw Exception::InvalidParameter(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
952  "Range matrix must have 4 columns [mz_min, mz_max, rt_min, rt_max]");
953  }
954 
955  // Convert matrix rows to vector of pairs
956  std::vector<std::pair<RangeMZ, RangeRT>> mz_rt_ranges;
957  mz_rt_ranges.reserve((Size)ranges.rows());
958 
959  for (Size i = 0; i < (Size)ranges.rows(); ++i)
960  {
961  mz_rt_ranges.emplace_back(
962  RangeMZ(ranges(i, 0), ranges(i, 1)),
963  RangeRT(ranges(i, 2), ranges(i, 3))
964  );
965  }
966 
967  // Call appropriate extractXICs function based on mz_agg parameter
968  if (mz_agg == "sum")
969  {
970  return extractXICs(mz_rt_ranges, ms_level,
971  [](auto begin_it, auto end_it)
972  {
973  return std::accumulate(begin_it, end_it, 0.0,
974  [](double a, const Peak1D& b) { return a + b.getIntensity(); });
975  });
976  }
977  else if (mz_agg == "max")
978  {
979  return extractXICs(mz_rt_ranges, ms_level,
980  [](auto begin_it, auto end_it)->double
981  {
982  if (begin_it == end_it) return 0.0;
983  return std::max_element(begin_it, end_it,
984  [](const Peak1D& a, const Peak1D& b) { return a.getIntensity() < b.getIntensity(); }
985  )->getIntensity();
986  });
987  }
988  else if (mz_agg == "min")
989  {
990  return extractXICs(mz_rt_ranges, ms_level,
991  [](auto begin_it, auto end_it)->double
992  {
993  if (begin_it == end_it) return 0.0;
994  return std::min_element(begin_it, end_it,
995  [](const Peak1D& a, const Peak1D& b) { return a.getIntensity() < b.getIntensity(); }
996  )->getIntensity();
997  });
998  }
999  else if (mz_agg == "mean")
1000  {
1001  return extractXICs(mz_rt_ranges, ms_level,
1002  [](auto begin_it, auto end_it)
1003  {
1004  if (begin_it == end_it) return 0.0;
1005  double sum = std::accumulate(begin_it, end_it, 0.0,
1006  [](double a, const Peak1D& b) { return a + b.getIntensity(); });
1007  return sum / static_cast<double>(std::distance(begin_it, end_it));
1008  });
1009  }
1010  else
1011  {
1012  throw Exception::InvalidValue(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
1013  "Invalid aggregation function", mz_agg);
1014  }
1015  }
1016 
1025 
1034 
1041 
1048 
1049 
1058 
1068 
1076 
1084  {
1085  combined_ranges_.clearRanges();
1086  spectrum_ranges_.clearRanges();
1087  chromatogram_ranges_.clearRanges();
1088  }
1089 
1091  double getMinRT() const { return combined_ranges_.getMinRT(); }
1092 
1094  double getMaxRT() const { return combined_ranges_.getMaxRT(); }
1095 
1097  double getMinMZ() const { return combined_ranges_.getMinMZ(); }
1098 
1100  double getMaxMZ() const { return combined_ranges_.getMaxMZ(); }
1101 
1103  double getMinIntensity() const { return combined_ranges_.getMinIntensity(); }
1104 
1106  double getMaxIntensity() const { return combined_ranges_.getMaxIntensity(); }
1107 
1109  double getMinMobility() const { return combined_ranges_.getMinMobility(); }
1110 
1112  double getMaxMobility() const { return combined_ranges_.getMaxMobility(); }
1113 
1125 
1127  UInt64 getSize() const;
1128 
1130  std::vector<UInt> getMSLevels() const;
1131 
1133 
1137 
1140 
1143 
1148  void sortSpectra(bool sort_mz = true);
1149 
1155  void sortChromatograms(bool sort_rt = true);
1156 
1162  bool isSorted(bool check_mz = true) const;
1163 
1165 
1167  void reset();
1168 
1175 
1178 
1181 
1183  void getPrimaryMSRunPath(StringList& toFill) const;
1184 
1201 
1207  int getPrecursorSpectrum(int zero_based_index) const;
1208 
1234 
1242  int getFirstProductSpectrum(int zero_based_index) const;
1243 
1245  void swap(MSExperiment& from);
1246 
1248  void setSpectra(const std::vector<MSSpectrum>& spectra);
1249  void setSpectra(std::vector<MSSpectrum>&& spectra);
1250 
1252  void addSpectrum(const MSSpectrum& spectrum);
1253  void addSpectrum(MSSpectrum&& spectrum);
1254 
1256  const std::vector<MSSpectrum>& getSpectra() const;
1257 
1259  std::vector<MSSpectrum>& getSpectra();
1260 
1262  ConstIterator getClosestSpectrumInRT(const double RT) const;
1264 
1266  ConstIterator getClosestSpectrumInRT(const double RT, UInt ms_level) const;
1267  Iterator getClosestSpectrumInRT(const double RT, UInt ms_level);
1268 
1270  void setChromatograms(const std::vector<MSChromatogram>& chromatograms);
1271  void setChromatograms(std::vector<MSChromatogram>&& chromatograms);
1272 
1274  void addChromatogram(const MSChromatogram& chromatogram);
1276 
1278  const std::vector<MSChromatogram>& getChromatograms() const;
1279 
1281  std::vector<MSChromatogram>& getChromatograms();
1282 
1284 
1285  MSChromatogram& getChromatogram(Size id);
1287 
1290 
1293 
1297 
1308  const MSChromatogram calculateTIC(float rt_bin_size = 0, UInt ms_level = 1) const;
1309 
1315  void clear(bool clear_meta_data);
1316 
1318  bool containsScanOfLevel(size_t ms_level) const;
1319 
1321  bool hasZeroIntensities(size_t ms_level) const;
1322 
1324  bool isIMFrame() const;
1325 
1326  protected:
1328  std::vector<MSChromatogram > chromatograms_;
1330  std::vector<SpectrumType> spectra_;
1333 
1336 
1339 
1340  public:
1350  const SpectrumRangeManagerType& spectrumRanges() const { return spectrum_ranges_; }
1351 
1361  const ChromatogramRangeManagerType& chromatogramRanges() const { return chromatogram_ranges_; }
1362 
1371  const RangeManagerType& combinedRanges() const { return combined_ranges_; }
1372 
1373  private:
1374 
1376  template<typename ContainerValueType, bool addMassTraces>
1378  {
1379  static void addData_(SpectrumType* spectrum, const ContainerValueType* item);
1380  static void addData_(SpectrumType* spectrum, const ContainerValueType* item, const StringList& store_metadata_names);
1381  };
1382 
1383  template<typename ContainerValueType>
1384  struct ContainerAdd_<ContainerValueType, false>
1385  {
1387  static void addData_(SpectrumType* spectrum, const ContainerValueType* item)
1388  {
1389  // create temporary peak and insert it into spectrum
1390  spectrum->insert(spectrum->end(), PeakType());
1391  spectrum->back().setIntensity(item->getIntensity());
1392  spectrum->back().setPosition(item->getMZ());
1393  }
1395  static void addData_(SpectrumType* spectrum, const ContainerValueType* item, const StringList& store_metadata_names)
1396  {
1397  addData_(spectrum, item);
1398  for (StringList::const_iterator itm = store_metadata_names.begin(); itm != store_metadata_names.end(); ++itm)
1399  {
1400  float val = std::numeric_limits<float>::quiet_NaN();
1401  if (item->metaValueExists(*itm)) val = item->getMetaValue(*itm);
1402  spectrum->getFloatDataArrays()[itm - store_metadata_names.begin()].push_back(val);
1403  }
1404  }
1405  };
1406 
1407  template<typename ContainerValueType>
1408  struct ContainerAdd_<ContainerValueType, true>
1409  {
1411  static void addData_(SpectrumType* spectrum, const ContainerValueType* item)
1412  {
1413  if (item->metaValueExists("num_of_masstraces"))
1414  {
1415  Size mts = item->getMetaValue("num_of_masstraces");
1416  int charge = (item->getCharge()==0 ? 1 : item->getCharge()); // set to 1 if charge is 0, otherwise div/0 below
1417  for (Size i = 0; i < mts; ++i)
1418  {
1419  String meta_name = String("masstrace_intensity_") + i;
1420  if (!item->metaValueExists(meta_name))
1421  {
1422  throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, String("Meta value '") + meta_name + "' expected but not found in container.");
1423  }
1424  ContainerValueType p;
1425  p.setIntensity(item->getMetaValue(meta_name));
1426  p.setPosition(item->getMZ() + Constants::C13C12_MASSDIFF_U / charge * i);
1428  }
1429  }
1431  }
1432  };
1433 
1434 
1435  /*
1436  @brief Append a spectrum to current MSExperiment
1437 
1438  @param rt RT of new spectrum
1439  @return Pointer to newly created spectrum
1440  */
1442 
1443  /*
1444  @brief Append a spectrum including floatdata arrays to current MSExperiment
1445 
1446  @param rt RT of new spectrum
1447  @param metadata_names Names of floatdata arrays attached to this spectrum
1448  @return Pointer to newly created spectrum
1449  */
1451 
1452  };
1453 
1455  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const MSExperiment& exp);
1456 
1457 } // namespace OpenMS
1458 
1460 
1461 
A 1-dimensional raw data point or peak for chromatograms.
Definition: ChromatogramPeak.h:28
Range manager for chromatograms.
Definition: ChromatogramRangeManager.h:31
Exception indicating that an invalid parameter was handed over to an algorithm.
Definition: Exception.h:316
Invalid value exception.
Definition: Exception.h:305
Precondition failed exception.
Definition: Exception.h:128
Description of the experimental settings.
Definition: ExperimentalSettings.h:36
Forward iterator for an area of peaks in an experiment.
Definition: AreaIterator.h:36
The representation of a chromatogram.
Definition: MSChromatogram.h:30
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:49
const ExperimentalSettings & getExperimentalSettings() const
returns the meta information of this experiment (const access)
MSExperiment(MSExperiment &&)=default
Move constructor.
ConstIterator IMBegin(CoordinateType im) const
Fast search for spectrum range begin.
RangeManagerType combined_ranges_
Combined range manager that provides overall ranges across both spectra and chromatograms (maintained...
Definition: MSExperiment.h:1338
ConstIterator getClosestSpectrumInRT(const double RT, UInt ms_level) const
Returns the closest(=nearest) spectrum in retention time to the given RT of a certain MS level.
std::vector< SpectrumType > spectra_
spectra
Definition: MSExperiment.h:1330
const std::vector< MSChromatogram > & getChromatograms() const
returns the chromatogram list
std::vector< SpectrumType > Base
STL base class type.
Definition: MSExperiment.h:78
void setChromatograms(std::vector< MSChromatogram > &&chromatograms)
Base::iterator iterator
Definition: MSExperiment.h:97
bool containsScanOfLevel(size_t ms_level) const
returns true if at least one of the spectra has the specified level
ConstAreaIterator areaBeginConst(CoordinateType min_rt, CoordinateType max_rt, CoordinateType min_mz, CoordinateType max_mz, UInt ms_level=1) const
Returns a non-mutable area iterator for area.
double getMaxRT() const
Get the maximum RT value from the combined ranges (includes both chromatogram and spectra ranges)
Definition: MSExperiment.h:1094
~MSExperiment() override
D'tor.
PeakType::CoordinateType CoordinateType
Coordinate type of peak positions.
Definition: MSExperiment.h:62
void get2DData(Container &cont) const
Reads out a 2D Spectrum.
Definition: MSExperiment.h:207
void swap(MSExperiment &from)
Swaps the content of this map with the content of from.
MSChromatogram ChromatogramType
Chromatogram type.
Definition: MSExperiment.h:76
void addSpectrum(const MSSpectrum &spectrum)
adds a spectrum to the list
PeakType::IntensityType IntensityType
Intensity type of peaks.
Definition: MSExperiment.h:64
void set2DData(const Container &container, const StringList &store_metadata_names)
Assignment of a data container with RT and MZ to an MSExperiment.
Definition: MSExperiment.h:258
std::vector< SpectrumType >::iterator Iterator
Mutable iterator.
Definition: MSExperiment.h:84
bool clearMetaDataArrays()
Clears the meta data arrays of all contained spectra (float, integer and string arrays)
SpectrumType * createSpec_(PeakType::CoordinateType rt)
ConstAreaIterator areaBeginConst(const RangeManagerType &range, UInt ms_level=1) const
Returns a non-mutable area iterator for all peaks in range. If a dimension is empty(),...
ConstIterator RTBegin(CoordinateType rt) const
Fast search for spectrum range begin.
Size getNrSpectra() const
get the total number of spectra available
std::vector< MSChromatogram > extractXICs(const std::vector< std::pair< RangeMZ, RangeRT >> &mz_rt_ranges, unsigned int ms_level, MzReductionFunctionType func_mz_reduction) const
Extracts extracted ion chromatograms (XICs) from the MSExperiment.
Definition: MSExperiment.h:734
bool empty() const noexcept
Are there any spectra (does not consider chromatograms)
Definition: MSExperiment.h:140
UInt64 getSize() const
returns the total number of peaks (spectra and chromatograms included)
std::vector< MSChromatogram > extractXICs(const std::vector< std::pair< RangeMZ, RangeRT >> &mz_rt_ranges, unsigned int ms_level) const
Definition: MSExperiment.h:845
double getMaxMZ() const
Get the maximum m/z value from the combined ranges (includes both chromatogram and spectra ranges)
Definition: MSExperiment.h:1100
ConstIterator begin() const noexcept
Definition: MSExperiment.h:168
MSExperiment & operator=(MSExperiment &&) &=default
Move assignment operator.
ConstIterator cbegin() const noexcept
Definition: MSExperiment.h:173
ConstIterator RTEnd(CoordinateType rt) const
Fast search for spectrum range end (returns the past-the-end iterator)
void addChromatogram(MSChromatogram &&chrom)
ExperimentalSettings & getExperimentalSettings()
returns the meta information of this experiment (mutable access)
void reserveSpaceChromatograms(Size s)
Iterator getClosestSpectrumInRT(const double RT, UInt ms_level)
Iterator begin() noexcept
Definition: MSExperiment.h:163
double getMinMobility() const
Get the minimum mobility value from the combined ranges (includes both chromatogram and spectra range...
Definition: MSExperiment.h:1109
SpectrumRangeManager SpectrumRangeManagerType
Spectrum range manager type for tracking ranges with MS level separation.
Definition: MSExperiment.h:69
double getMinIntensity() const
Get the minimum intensity value from the combined ranges (includes both chromatogram and spectra rang...
Definition: MSExperiment.h:1103
SpectrumType * createSpec_(PeakType::CoordinateType rt, const StringList &metadata_names)
ChromatogramPeakT ChromatogramPeakType
Chromatogram peak type.
Definition: MSExperiment.h:60
MSSpectrum & getSpectrum(Size id)
returns a single spectrum
AreaIterator areaBegin(const RangeManagerType &range, UInt ms_level=1)
Returns an area iterator for all peaks in range. If a dimension is empty(), it is ignored (i....
Iterator RTEnd(CoordinateType rt)
Fast search for spectrum range end (returns the past-the-end iterator)
MSExperiment & operator=(const MSExperiment &source)
Assignment operator.
MSSpectrum SpectrumType
Spectrum Type.
Definition: MSExperiment.h:74
double getMinMZ() const
Get the minimum m/z value from the combined ranges (includes both chromatogram and spectra ranges)
Definition: MSExperiment.h:1097
Size getNrChromatograms() const
get the total number of chromatograms available
Iterator getClosestSpectrumInRT(const double RT)
Base::value_type value_type
Definition: MSExperiment.h:96
Size size() const noexcept
The number of spectra.
Definition: MSExperiment.h:128
MSExperiment()
Constructor.
bool operator!=(const MSExperiment &rhs) const
Equality operator.
Peak1D PeakT
Definition: MSExperiment.h:52
ConstAreaIterator areaEndConst() const
Returns a non-mutable invalid area iterator marking the end of an area.
const RangeManagerType & combinedRanges() const
Returns a const reference to the combined range manager.
Definition: MSExperiment.h:1371
void get2DPeakDataIMPerSpectrum(CoordinateType min_rt, CoordinateType max_rt, CoordinateType min_mz, CoordinateType max_mz, Size ms_level, std::vector< float > &rt, std::vector< std::vector< float >> &mz, std::vector< std::vector< float >> &intensity, std::vector< std::vector< float >> &ion_mobility) const
Definition: MSExperiment.h:403
void set2DData(const Container &container)
Assignment of a data container with RT and MZ to an MSExperiment.
Definition: MSExperiment.h:238
void setSpectra(std::vector< MSSpectrum > &&spectra)
void getPrimaryMSRunPath(StringList &toFill) const
get the file path to the first MS run
double getMaxMobility() const
Get the maximum mobility value from the combined ranges (includes both chromatogram and spectra range...
Definition: MSExperiment.h:1112
void resize(Size n)
Resize to n spectra.
Definition: MSExperiment.h:134
ConstIterator cend() const noexcept
Definition: MSExperiment.h:188
void get2DPeakData(CoordinateType min_rt, CoordinateType max_rt, CoordinateType min_mz, CoordinateType max_mz, Size ms_level, std::vector< float > &rt, std::vector< float > &mz, std::vector< float > &intensity) const
Definition: MSExperiment.h:456
std::vector< MSChromatogram > & getChromatograms()
returns the chromatogram list (mutable)
void setSpectra(const std::vector< MSSpectrum > &spectra)
sets the spectrum list
void get2DPeakDataIM(CoordinateType min_rt, CoordinateType max_rt, CoordinateType min_mz, CoordinateType max_mz, Size ms_level, std::vector< float > &rt, std::vector< float > &mz, std::vector< float > &intensity, std::vector< float > &ion_mobility) const
Definition: MSExperiment.h:489
void sortChromatograms(bool sort_rt=true)
Sorts the data points of the chromatograms by m/z.
double getMaxIntensity() const
Get the maximum intensity value from the combined ranges (includes both chromatogram and spectra rang...
Definition: MSExperiment.h:1106
int getFirstProductSpectrum(int zero_based_index) const
Returns the index of the first product spectrum given an index.
Iterator RTBegin(CoordinateType rt)
Fast search for spectrum range begin.
void clearRanges()
Clear all ranges in all range managers.
Definition: MSExperiment.h:1083
std::vector< std::vector< MSExperiment::CoordinateType > > aggregateFromMatrix(const Matrix< double > &ranges, unsigned int ms_level, const std::string &mz_agg) const
Wrapper for aggregate function that takes a matrix of m/z and RT ranges.
Definition: MSExperiment.h:860
Internal::AreaIterator< const PeakT, const PeakT &, const PeakT *, ConstIterator, SpectrumType::ConstIterator > ConstAreaIterator
Immutable area iterator type (for traversal of a rectangular subset of the peaks)
Definition: MSExperiment.h:90
void setChromatograms(const std::vector< MSChromatogram > &chromatograms)
sets the chromatogram list
Internal::AreaIterator< PeakT, PeakT &, PeakT *, Iterator, SpectrumType::Iterator > AreaIterator
Mutable area iterator type (for traversal of a rectangular subset of the peaks)
Definition: MSExperiment.h:88
const SpectrumType & operator[](Size n) const
Random access to n'th spectrum.
Definition: MSExperiment.h:158
double getMinRT() const
Get the minimum RT value from the combined ranges (includes both chromatogram and spectra ranges)
Definition: MSExperiment.h:1091
const MSChromatogram calculateTIC(float rt_bin_size=0, UInt ms_level=1) const
Computes the total ion chromatogram (TIC) for a given MS level (use ms_level = 0 for all levels).
const std::vector< MSSpectrum > & getSpectra() const
returns the spectrum list
std::vector< MSChromatogram > extractXICsFromMatrix(const Matrix< double > &ranges, unsigned int ms_level, const std::string &mz_agg) const
Wrapper for extractXICs function that takes a matrix of m/z and RT ranges.
Definition: MSExperiment.h:943
Iterator end()
Definition: MSExperiment.h:178
std::vector< std::vector< MSExperiment::CoordinateType > > aggregate(const std::vector< std::pair< RangeMZ, RangeRT >> &mz_rt_ranges, unsigned int ms_level) const
Definition: MSExperiment.h:714
bool isSorted(bool check_mz=true) const
Checks if all spectra are sorted with respect to ascending RT.
MSExperiment(const MSExperiment &source)
Copy constructor.
ConstIterator end() const noexcept
Definition: MSExperiment.h:183
RangeManager< RangeRT, RangeMZ, RangeIntensity, RangeMobility > RangeManagerType
Combined RangeManager type to store the overall range of all spectra and chromatograms (for backward ...
Definition: MSExperiment.h:66
std::vector< MSSpectrum > & getSpectra()
returns the spectrum list (mutable)
ConstIterator getClosestSpectrumInRT(const double RT) const
Returns the closest(=nearest) spectrum in retention time to the given RT.
ChromatogramRangeManager ChromatogramRangeManagerType
Chromatogram range manager type for tracking chromatogram-specific ranges.
Definition: MSExperiment.h:72
void set2DData(const Container &container)
Assignment of a data container with RT and MZ to an MSExperiment.
Definition: MSExperiment.h:302
ChromatogramPeak ChromatogramPeakT
Definition: MSExperiment.h:53
void sortSpectra(bool sort_mz=true)
Sorts the data points by retention time.
std::vector< UInt > getMSLevels() const
returns a sorted array of MS levels (calculated on demand)
void reset()
Clear all internal data (spectra, ranges, metadata)
const ChromatogramRangeManagerType & chromatogramRanges() const
Returns a const reference to the chromatogram range manager.
Definition: MSExperiment.h:1361
void addSpectrum(MSSpectrum &&spectrum)
void reserveSpaceSpectra(Size s)
void updateRanges()
Updates the m/z, intensity, mobility, and retention time ranges of all spectra and chromatograms.
bool hasZeroIntensities(size_t ms_level) const
returns true if any MS spectra of trthe specified level contain at least one peak with intensity of 0...
bool operator==(const MSExperiment &rhs) const
Equality operator.
ConstIterator IMEnd(CoordinateType im) const
Fast search for spectrum range end (returns the past-the-end iterator)
SpectrumRangeManagerType spectrum_ranges_
Spectrum range manager for tracking m/z, intensity, RT, and ion mobility ranges of spectra with MS le...
Definition: MSExperiment.h:1332
void get2DPeakDataPerSpectrum(CoordinateType min_rt, CoordinateType max_rt, CoordinateType min_mz, CoordinateType max_mz, Size ms_level, std::vector< float > &rt, std::vector< std::vector< float >> &mz, std::vector< std::vector< float >> &intensity) const
Definition: MSExperiment.h:364
ConstIterator getPrecursorSpectrum(ConstIterator iterator) const
Returns the precursor spectrum of the scan pointed to by iterator.
void reserve(Size n)
Reserve space for n spectra.
Definition: MSExperiment.h:146
Base::const_iterator const_iterator
Definition: MSExperiment.h:98
std::vector< std::vector< MSExperiment::CoordinateType > > aggregate(const std::vector< std::pair< RangeMZ, RangeRT >> &mz_rt_ranges, unsigned int ms_level, MzReductionFunctionType func_mz_reduction) const
Aggregates data over specified m/z and RT ranges at a given MS level using a custom reduction functio...
Definition: MSExperiment.h:603
void setSqlRunID(UInt64 id)
sets the run-ID which is used when storing an sqMass file
MSExperiment & operator=(const ExperimentalSettings &source)
Assignment operator.
UInt64 getSqlRunID() const
void addChromatogram(const MSChromatogram &chromatogram)
adds a chromatogram to the list
std::vector< SpectrumType >::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSExperiment.h:86
void clear(bool clear_meta_data)
Clears all data and meta data.
ConstIterator getFirstProductSpectrum(ConstIterator iterator) const
SpectrumType & operator[](Size n)
Random access to n'th spectrum.
Definition: MSExperiment.h:152
const SpectrumRangeManagerType & spectrumRanges() const
Returns a const reference to the spectrum range manager.
Definition: MSExperiment.h:1350
int getPrecursorSpectrum(int zero_based_index) const
Returns the index of the precursor spectrum for spectrum at index zero_based_index.
std::vector< MSChromatogram > chromatograms_
chromatograms
Definition: MSExperiment.h:1328
ChromatogramRangeManagerType chromatogram_ranges_
Chromatogram range manager for tracking RT, intensity, and m/z ranges of chromatograms.
Definition: MSExperiment.h:1335
AreaIterator areaEnd()
Returns an invalid area iterator marking the end of an area.
bool isIMFrame() const
Are all MSSpectra in this experiment part of an IM Frame? I.e. they all have the same RT,...
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
const FloatDataArrays & getFloatDataArrays() const
Returns a const reference to the float meta data arrays.
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:28
double CoordinateType
Coordinate type.
Definition: Peak1D.h:40
IntensityType getIntensity() const
Definition: Peak1D.h:82
float IntensityType
Intensity type.
Definition: Peak1D.h:36
Advanced range manager for MS spectra with separate ranges for each MS level.
Definition: SpectrumRangeManager.h:44
A more convenient string class.
Definition: String.h:34
int64_t Int64
Signed integer type (64bit)
Definition: Types.h:40
uint64_t UInt64
Unsigned integer type (64bit)
Definition: Types.h:47
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:44
static double sum(IteratorType begin, IteratorType end)
Calculates the sum of a range of values.
Definition: StatisticFunctions.h:81
const double C13C12_MASSDIFF_U
Definition: Constants.h:95
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Peak2D PeakType
Definition: MassTrace.h:21
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
DriftTimeUnit
Drift time unit for ion mobility.
Definition: IMTypes.h:23
static void addData_(SpectrumType *spectrum, const ContainerValueType *item)
general method for adding data points
Definition: MSExperiment.h:1387
static void addData_(SpectrumType *spectrum, const ContainerValueType *item, const StringList &store_metadata_names)
general method for adding data points, including metadata arrays (populated from metainfointerface)
Definition: MSExperiment.h:1395
static void addData_(SpectrumType *spectrum, const ContainerValueType *item)
specialization for adding feature mass traces (does not support metadata_names currently)
Definition: MSExperiment.h:1411
Helper class to add either general data points in set2DData or use mass traces from meta values.
Definition: MSExperiment.h:1378
static void addData_(SpectrumType *spectrum, const ContainerValueType *item)
static void addData_(SpectrumType *spectrum, const ContainerValueType *item, const StringList &store_metadata_names)
Calculates the sum of intensities for a range of elements.
Definition: MSExperiment.h:535
auto operator()(Iterator begin, Iterator end) const
Definition: MSExperiment.h:538
Definition: RangeManager.h:358
Definition: RangeManager.h:295