OpenMS
DimMapper.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Chris Bielow $
6 // $Authors: Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 
21 #include <OpenMS/KERNEL/Peak1D.h>
22 #include <OpenMS/KERNEL/Peak2D.h>
24 
25 #include <array>
26 #include <memory>
27 
28 
29 namespace OpenMS
30 {
40  class OPENMS_DLLAPI DimBase
41  {
42  public:
43  using ValueType = double;
44  using ValueTypes = std::vector<ValueType>;
45 
47  DimBase() = delete;
48 
50  DimBase(DIM_UNIT unit) :
51  unit_(unit)
52  {}
53 
55  DimBase& operator=(const DimBase& rhs) = default;
56 
58  virtual ~DimBase() noexcept = default;
59 
61  bool operator==(const DimBase& rhs) const
62  {
63  return unit_ == rhs.unit_;
64  }
65 
67  virtual std::unique_ptr<DimBase> clone() const = 0;
68 
69  virtual ValueType map(const Peak1D& p) const = 0;
70  virtual ValueType map(const Peak2D& p) const = 0;
71  virtual ValueType map(const ChromatogramPeak& p) const = 0;
72  virtual ValueType map(const MSExperiment::ConstAreaIterator& it) const = 0;
73  virtual ValueType map(const MobilityPeak1D& p) const = 0;
74  virtual ValueType map(const MobilityPeak2D& p) const = 0;
75 
77  virtual ValueType map(const MSSpectrum& spec, const Size index) const = 0;
79  virtual ValueType map(const MSChromatogram& chrom, const Size index) const = 0;
81  virtual ValueType map(const Mobilogram& mb, const Size index) const = 0;
82 
85  virtual ValueTypes map(const MSSpectrum& spec) const = 0;
86 
89  virtual ValueTypes map(const MSChromatogram& chrom) const = 0;
90 
91  virtual ValueType map(const BaseFeature& bf) const = 0;
92 
93  virtual ValueType map(const PeptideIdentification& pi) const = 0;
94 
96  virtual RangeBase map(const RangeAllType& rm) const = 0;
97 
99  virtual RangeBase& map(RangeAllType& rm) const = 0;
100 
102  virtual void setRange(const RangeBase& in, RangeAllType& out) const = 0;
103 
104 
105  // from XY to a type
106 
108  virtual void fromXY(const ValueType in, Peak1D& p) const = 0;
110  virtual void fromXY(const ValueType in, ChromatogramPeak& p) const = 0;
112  virtual void fromXY(const ValueType in, MobilityPeak1D& p) const = 0;
114  virtual void fromXY(const ValueType in, MobilityPeak2D& p) const = 0;
115 
117  std::string_view getDimName() const
118  {
119  return DIM_NAMES[(int)unit_];
120  }
121 
123  std::string_view getDimNameShort() const
124  {
125  return DIM_NAMES_SHORT[(int)unit_];
126  }
127 
130  {
131  return unit_;
132  }
133 
139  String formattedValue(const ValueType value) const;
140 
143 
145  int valuePrecision() const;
146 
147  protected:
149  };
150 
151 
152 
153  class OPENMS_DLLAPI DimRT final : public DimBase
154  {
155  public:
157 
158  std::unique_ptr<DimBase> clone() const override
159  {
160  return std::make_unique<DimRT>();
161  }
162 
163  ValueType map(const Peak1D&) const override
164  {
165  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
166  }
167  ValueType map(const Peak2D& p) const override
168  {
169  return p.getRT();
170  }
171  ValueType map(const ChromatogramPeak& p) const override
172  {
173  return p.getRT();
174  }
175  ValueType map(const MSSpectrum& spec, const Size /*index*/) const override
176  {
177  return spec.getRT();
178  }
179  ValueType map(const MSChromatogram& chrom, const Size index) const override
180  {
181  return chrom[index].getRT();
182  }
183  ValueType map(const Mobilogram& mb, const Size /*index*/) const override
184  {
185  return mb.getRT();
186  }
187 
188  ValueTypes map(const MSSpectrum&) const override
189  {
190  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
191  }
192  ValueTypes map(const MSChromatogram& chrom) const override
193  {
194  ValueTypes res;
195  res.reserve(chrom.size());
196  for (const auto& p : chrom)
197  {
198  res.push_back(p.getRT());
199  }
200  return res;
201  }
202 
204  {
205  return it.getRT();
206  }
207  ValueType map(const MobilityPeak1D&) const override
208  {
209  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
210  }
211  ValueType map(const MobilityPeak2D&) const override
212  {
213  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
214  }
215 
216  ValueType map(const BaseFeature& bf) const override
217  {
218  return bf.getRT();
219  }
220 
221  ValueType map(const PeptideIdentification& pi) const override
222  {
223  return pi.getRT();
224  }
225 
226  RangeBase map(const RangeAllType& rm) const override
227  {
228  return rm.getRangeForDim(MSDim::RT);
229  }
230  RangeBase& map(RangeAllType& rm) const override
231  {
232  return rm.getRangeForDim(MSDim::RT);
233  }
234 
235  void setRange(const RangeBase& in, RangeAllType& out) const override
236  {
237  out.RangeRT::operator=(in);
238  }
239 
241  void fromXY(const ValueType, Peak1D&) const override
242  {
243  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
244  }
245 
247  void fromXY(const ValueType in, ChromatogramPeak& p) const override
248  {
249  p.setRT(in);
250  }
252  void fromXY(const ValueType, MobilityPeak1D&) const override
253  {
254  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
255  }
257  void fromXY(const ValueType, MobilityPeak2D&) const override
258  {
259  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
260  }
261  };
262 
263  class OPENMS_DLLAPI DimMZ final : public DimBase
264  {
265  public:
267 
268  std::unique_ptr<DimBase> clone() const override
269  {
270  return std::make_unique<DimMZ>();
271  }
272 
273  ValueType map(const Peak1D& p) const override
274  {
275  return p.getMZ();
276  }
277  ValueType map(const Peak2D& p) const override
278  {
279  return p.getMZ();
280  }
281  ValueType map(const ChromatogramPeak&) const override
282  {
283  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
284  }
286  {
287  return it->getMZ();
288  }
289  ValueType map(const MobilityPeak1D&) const override
290  {
291  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
292  }
293  ValueType map(const MobilityPeak2D& p) const override
294  {
295  return p.getMZ();
296  }
297 
298  ValueType map(const MSSpectrum& spec, const Size index) const override
299  {
300  return spec[index].getMZ();
301  }
302  ValueType map(const MSChromatogram& chrom, const Size /*index*/) const override
303  {
304  return chrom.getPrecursor().getMZ();
305  }
306  ValueType map(const Mobilogram& /*mb*/, const Size /*index*/) const override
307  {
308  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
309  }
310 
311  ValueTypes map(const MSSpectrum& spec) const override
312  {
313  ValueTypes res;
314  res.reserve(spec.size());
315  for (const auto& p : spec)
316  {
317  res.push_back(p.getMZ());
318  }
319  return res;
320  }
321  ValueTypes map(const MSChromatogram&) const override
322  {
323  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
324  }
325 
326  ValueType map(const BaseFeature& bf) const override
327  {
328  return bf.getMZ();
329  }
330 
331  ValueType map(const PeptideIdentification& pi) const override
332  {
333  return pi.getMZ();
334  }
335 
336  RangeBase map(const RangeAllType& rm) const override
337  {
338  return rm.getRangeForDim(MSDim::MZ);
339  }
340  RangeBase& map(RangeAllType& rm) const override
341  {
342  return rm.getRangeForDim(MSDim::MZ);
343  }
344 
345  void setRange(const RangeBase& in, RangeAllType& out) const override
346  {
347  out.RangeMZ::operator=(in);
348  }
349 
351  void fromXY(const ValueType in, Peak1D& p) const override
352  {
353  p.setMZ(in);
354  }
355 
357  void fromXY(const ValueType, ChromatogramPeak&) const override
358  {
359  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
360  }
361 
363  void fromXY(const ValueType, MobilityPeak1D&) const override
364  {
365  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
366  }
368  void fromXY(const ValueType in, MobilityPeak2D& p) const override
369  {
370  p.setMZ(in);
371  }
372  };
373 
374  class OPENMS_DLLAPI DimINT final : public DimBase
375  {
376  public:
378 
379  std::unique_ptr<DimBase> clone() const override
380  {
381  return std::make_unique<DimINT>();
382  }
383 
384  ValueType map(const Peak1D& p) const override
385  {
386  return p.getIntensity();
387  }
388  ValueType map(const Peak2D& p) const override
389  {
390  return p.getIntensity();
391  }
392  ValueType map(const ChromatogramPeak& p) const override
393  {
394  return p.getIntensity();
395  }
397  {
398  return it->getIntensity();
399  }
400  ValueType map(const MobilityPeak1D& p) const override
401  {
402  return p.getIntensity();
403  }
404  ValueType map(const MobilityPeak2D& p) const override
405  {
406  return p.getIntensity();
407  }
408 
409  ValueType map(const MSSpectrum& spec, const Size index) const override
410  {
411  return spec[index].getIntensity();
412  }
413  ValueType map(const MSChromatogram& chrom, const Size index) const override
414  {
415  return chrom[index].getIntensity();
416  }
417  ValueType map(const Mobilogram& mb, const Size index) const override
418  {
419  return mb[index].getIntensity();
420  }
421 
422  ValueTypes map(const MSSpectrum& spec) const override
423  {
424  ValueTypes res;
425  res.reserve(spec.size());
426  for (const auto& p : spec)
427  {
428  res.push_back(p.getIntensity());
429  }
430  return res;
431  }
432 
433  ValueTypes map(const MSChromatogram& chrom) const override
434  {
435  ValueTypes res;
436  res.reserve(chrom.size());
437  for (const auto& p : chrom)
438  {
439  res.push_back(p.getIntensity());
440  }
441  return res;
442  }
443 
444  ValueType map(const BaseFeature& bf) const override
445  {
446  return bf.getIntensity();
447  }
448 
449  ValueType map(const PeptideIdentification&) const override
450  {
451  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
452  }
453 
454  RangeBase map(const RangeAllType& rm) const override
455  {
456  return rm.getRangeForDim(MSDim::INT);
457  }
458  RangeBase& map(RangeAllType& rm) const override
459  {
460  return rm.getRangeForDim(MSDim::INT);
461  }
462 
463  void setRange(const RangeBase& in, RangeAllType& out) const override
464  {
465  out.RangeIntensity::operator=(in);
466  }
467 
469  void fromXY(const ValueType in, Peak1D& p) const override
470  {
472  }
473 
475  void fromXY(const ValueType in, ChromatogramPeak& p) const override
476  {
478  }
480  void fromXY(const ValueType in, MobilityPeak1D& p) const override
481  {
483  }
485  void fromXY(const ValueType in, MobilityPeak2D& p) const override
486  {
488  }
489  };
490 
491  class OPENMS_DLLAPI DimIM final : public DimBase
492  {
493  public:
494  DimIM(const DIM_UNIT im_unit) : DimBase(im_unit) {}
495 
496  std::unique_ptr<DimBase> clone() const override
497  {
498  return std::make_unique<DimIM>(*this);
499  }
500 
501  ValueType map(const Peak1D&) const override
502  {
503  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
504  }
505  ValueType map(const Peak2D&) const override
506  {
507  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
508  }
509  ValueType map(const ChromatogramPeak&) const override
510  {
511  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
512  }
513  ValueTypes map(const MSSpectrum&) const override
514  {
515  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
516  }
517  ValueTypes map(const MSChromatogram&) const override
518  {
519  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
520  }
521 
523  {
524  return it.getDriftTime();
525  }
526 
527  ValueType map(const MobilityPeak1D& p) const override
528  {
529  return p.getMobility();
530  }
531  ValueType map(const MobilityPeak2D& p) const override
532  {
533  return p.getMobility();
534  }
535 
536  ValueType map(const MSSpectrum& spec, const Size /*index*/) const override
537  {
538  return spec.getDriftTime();
539  }
540  ValueType map(const MSChromatogram&, const Size) const override
541  {
542  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
543  }
544  ValueType map(const Mobilogram& mb, const Size index) const override
545  {
546  return mb[index].getMobility();
547  }
548 
549  ValueType map(const BaseFeature&) const override
550  {
551  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
552  }
553 
554  ValueType map(const PeptideIdentification&) const override
555  {
556  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
557  }
558 
559  RangeBase map(const RangeAllType& rm) const override
560  {
561  return rm.getRangeForDim(MSDim::IM);
562  }
563  RangeBase& map(RangeAllType& rm) const override
564  {
565  return rm.getRangeForDim(MSDim::IM);
566  }
567 
568  void setRange(const RangeBase& in, RangeAllType& out) const override
569  {
570  out.RangeMobility::operator=(in);
571  }
572 
574  void fromXY(const ValueType, Peak1D&) const override
575  {
576  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
577  }
578 
580  void fromXY(const ValueType, ChromatogramPeak&) const override
581  {
582  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
583  }
584 
586  void fromXY(const ValueType in, MobilityPeak1D& p) const override
587  {
588  p.setMobility(in);
589  }
591  void fromXY(const ValueType in, MobilityPeak2D& p) const override
592  {
593  p.setMobility(in);
594  }
595  };
596 
600  enum class DIM
601  {
602  X = 0,
603  Y = 1,
604  Z = 2
605  };
606 
617  template<int N_DIM>
618  class DimMapper
619  {
620  public:
622 
624  DimMapper() = delete;
625 
627  DimMapper(const DIM_UNIT (&units)[N_DIM])
628  :dims_([&]() {
629  std::array<std::unique_ptr<const DimBase>, N_DIM> dims_tmp;
630  for (int i = 0; i < N_DIM; ++i)
631  {
632  dims_tmp[i] = create_(units[i]);
633  }
634  return dims_tmp;
635  }()) // immediately evaluated lambda to enable 'dims_' to be const
636  {
637  static_assert(N_DIM >= 1); // at least one dimension (X)
638  static_assert(N_DIM <= 3); // at most three (X, Y, Z)
639  }
640 
642  DimMapper(const DimMapper& rhs) // cannot be defaulted due to unique_ptr
643  {
644  *this = rhs;
645  };
646 
648  DimMapper& operator=(const DimMapper& rhs) // cannot be defaulted due to unique_ptr
649  {
650  for (int i = 0; i < N_DIM; ++i) dims_[i] = rhs.dims_[i]->clone();
651  return *this;
652  };
653 
655  bool operator==(const DimMapper& rhs) const
656  {
657  bool res {true};
658  for (int i = 0; i < N_DIM; ++i)
659  {
660  res &= (*dims_[i] == *rhs.dims_[i]);
661  }
662  return res;
663  }
664 
666  bool operator!=(const DimMapper& rhs) const
667  {
668  return !operator==(rhs);
669  }
670 
672  template <typename T>
673  Point map(const T& data) const
674  {
675  Point pr;
676  for (int i = 0; i < N_DIM; ++i) pr[i] = dims_[i]->map(data);
677  return pr;
678  }
680  template<typename Container>
681  Point map(const Container& data, const Size index) const
682  {
683  Point pr;
684  for (int i = 0; i < N_DIM; ++i)
685  pr[i] = dims_[i]->map(data, index);
686  return pr;
687  }
688 
690  template<typename ...Ranges>
692  {
693  DRange<N_DIM> res;
694  RangeAllType all;
695  all.assign(ranges);
696  for (int i = 0; i < N_DIM; ++i)
697  {
698  RangeBase mm = dims_[i]->map(all);
699  if (mm.isEmpty()) continue;
700  res.setDimMinMax(i, {mm.getMin(), mm.getMax()});
701  }
702  return res;
703  }
704 
708  template<typename... Ranges>
709  void fromXY(const DRange<N_DIM>& in, RangeManager<Ranges...>& output) const
710  {
711  for (int i = 0; i < N_DIM; ++i)
712  {
713  if (in.isEmpty(i))
714  dims_[i]->setRange(RangeBase(), output);
715  else
716  dims_[i]->setRange({in.minPosition()[i], in.maxPosition()[i]}, output);
717  }
718  }
719 
723  template<typename... Ranges>
724  void fromXY(const Point& in, RangeManager<Ranges...>& output) const
725  {
726  for (int i = 0; i < N_DIM; ++i)
727  {
728  dims_[i]->setRange({in[i], in[i]}, output);
729  }
730  }
731 
735  template<typename T>
736  void fromXY(const Point& in, T& out) const
737  {
738  for (int i = 0; i < N_DIM; ++i)
739  {
740  dims_[i]->fromXY(in[i], out);
741  }
742  }
743 
747  RangeAllType fromXY(const Point& in) const
748  {
749  RangeAllType output;
750  for (int i = 0; i < N_DIM; ++i)
751  {
752  dims_[i]->setRange({in[i], in[i]}, output);
753  }
754  return output;
755  }
756 
758  const DimBase& getDim(DIM d) const
759  {
760  assert((int)d <= N_DIM);
761  return *dims_[(int)d];
762  }
763 
764  protected:
766  static std::unique_ptr<const DimBase> create_(DIM_UNIT u)
767  {
768  switch (u)
769  {
770  case DIM_UNIT::RT:
771  return std::make_unique<DimRT>();
772  case DIM_UNIT::MZ:
773  return std::make_unique<DimMZ>();
774  case DIM_UNIT::INT:
775  return std::make_unique<DimINT>();
776  case DIM_UNIT::FAIMS_CV:
777  case DIM_UNIT::IM_MS:
778  case DIM_UNIT::IM_VSSC:
779  return std::make_unique<DimIM>(u);
780  default:
781  throw Exception::NotImplemented(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
782  }
783  }
784 
785  std::array<std::unique_ptr<const DimBase>, N_DIM> dims_;
786  };
787 
788 
791  template <int N_DIM>
792  class Area
793  {
794  public:
797 
799  Area() = delete;
800 
802  Area(const DimMapper<N_DIM>* const dims)
803  : mapper_(dims)
804  {
805  }
806 
808  Area(const Area& range) = default;
809 
811  Area& operator=(const Area& rhs)
812  {
813  // check that Dims are identical, otherwise this is very dangerous (the user probably only wanted to update the area, not change its mapping).
814  if (mapper_ != rhs.mapper_ && *mapper_ != *rhs.mapper_)
815  {
816  throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Assignment of Areas using different mappers!");
817  }
818  data_range_ = rhs.data_range_;
820  return *this;
821  }
822 
823  bool operator==(const Area& rhs) const
824  {
825  return data_range_ == rhs.data_range_
826  && visible_area_ == rhs.visible_area_
827  && (*mapper_ == *rhs.mapper_);
828  }
829  bool operator!=(const Area& rhs) const
830  {
831  return !operator==(rhs);
832  }
833 
839  const Area& setArea(const RangeAllType& data)
840  {
841  data_range_ = data;
842  // update axis view using dims
843  visible_area_ = mapper_->mapRange(data);
844  return *this;
845  }
846 
852  const Area& setArea(const AreaXYType& data)
853  {
854  visible_area_ = data;
855  // update range view from XY area using dims
857  return *this;
858  }
859 
860  const AreaXYType& getAreaXY() const
861  {
862  return visible_area_;
863  }
864 
865  const RangeAllType& getAreaUnit() const
866  {
867  return data_range_;
868  }
869 
875  Area cloneWith(const AreaXYType& data) const
876  {
877  Area clone(*this);
878  clone.setArea(data);
879  return clone;
880  }
881 
887  Area cloneWith(const RangeAllType& data) const
888  {
889  Area clone(*this);
890  clone.setArea(data);
891  return clone;
892  }
893 
898  void pushInto(const RangeAllType& sandbox)
899  {
900  auto a = data_range_;
901  a.pushInto(sandbox);
902  setArea(a);
903  }
904 
906  void clear()
907  {
909  }
910 
911  private:
912  /* two sides of the same coin... */
917  };
918 
919 } // namespace OpenMS
Definition: DimMapper.h:793
bool operator!=(const Area &rhs) const
Definition: DimMapper.h:829
const Area & setArea(const RangeAllType &data)
Set the area using unit data (RT, m/z, ...)
Definition: DimMapper.h:839
Area()=delete
No default C'tor.
bool operator==(const Area &rhs) const
Definition: DimMapper.h:823
RangeAllType data_range_
range in units
Definition: DimMapper.h:913
const Area & setArea(const AreaXYType &data)
Set the area using axis data (X and Y)
Definition: DimMapper.h:852
void pushInto(const RangeAllType &sandbox)
Push the area into a sandbox (if its outside the sandbox). See UnitRange::pushInto()
Definition: DimMapper.h:898
AreaXYType visible_area_
Definition: DimMapper.h:914
Area cloneWith(const RangeAllType &data) const
Clone the current object, set the area of the clone using unit data (RT, m/z, ...) and return the clo...
Definition: DimMapper.h:887
const DimMapper< N_DIM > * mapper_
and a mapper (non-owning pointer) to translate between the two
Definition: DimMapper.h:916
Area & operator=(const Area &rhs)
Assignment operator - which checks for identical DimMappers and throws otherwise.
Definition: DimMapper.h:811
Area cloneWith(const AreaXYType &data) const
Clone the current object, set the area of the clone using axis data (X and Y) and return the clone.
Definition: DimMapper.h:875
Area(const DimMapper< N_DIM > *const dims)
Custom C'tor with a mapper (non owning pointer)
Definition: DimMapper.h:802
const RangeAllType & getAreaUnit() const
Definition: DimMapper.h:865
Area(const Area &range)=default
Copy C'tor.
void clear()
empty all dimensions
Definition: DimMapper.h:906
const AreaXYType & getAreaXY() const
Definition: DimMapper.h:860
A basic LC-MS feature.
Definition: BaseFeature.h:33
A 1-dimensional raw data point or peak for chromatograms.
Definition: ChromatogramPeak.h:28
IntensityType getIntensity() const
Non-mutable access to the data point intensity (height)
Definition: ChromatogramPeak.h:84
void setRT(CoordinateType rt)
Mutable access to RT.
Definition: ChromatogramPeak.h:95
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: ChromatogramPeak.h:86
double IntensityType
Intensity type.
Definition: ChromatogramPeak.h:37
CoordinateType getRT() const
Non-mutable access to RT.
Definition: ChromatogramPeak.h:89
const Precursor & getPrecursor() const
returns a const reference to the precursors
Representation of a coordinate in D-dimensional space.
Definition: DPosition.h:29
A base class for a dimension which represents a certain unit (e.g. RT or m/z). Derived classes implem...
Definition: DimMapper.h:41
virtual ValueType map(const MSChromatogram &chrom, const Size index) const =0
obtain value from a certain point in a chromatogram
virtual ValueType map(const Peak1D &p) const =0
virtual ~DimBase() noexcept=default
D'tor (needs to be virtual; we are holding pointers to base in DimMapper)
virtual void fromXY(const ValueType in, Peak1D &p) const =0
set the dimension of a Peak1D
virtual RangeBase & map(RangeAllType &rm) const =0
Return the min/max (range) for a certain dimension (i.e. a reference to the base class of rm)
virtual ValueType map(const PeptideIdentification &pi) const =0
double ValueType
Definition: DimMapper.h:43
std::string_view getDimNameShort() const
Name of the dimension, e.g. 'RT'.
Definition: DimMapper.h:123
virtual ValueType map(const MobilityPeak2D &p) const =0
virtual ValueType map(const MSExperiment::ConstAreaIterator &it) const =0
virtual ValueType map(const ChromatogramPeak &p) const =0
int valuePrecision() const
return the recommended precision for the current unit (2 digits for RT, 8 for m/z,...
DimBase(DIM_UNIT unit)
Custom c'tor with unit.
Definition: DimMapper.h:50
virtual ValueType map(const Mobilogram &mb, const Size index) const =0
obtain value from a certain point in a mobilogram
virtual void fromXY(const ValueType in, ChromatogramPeak &p) const =0
set the dimension of a ChromatogramPeak
DIM_UNIT unit_
the unit of this dimension
Definition: DimMapper.h:148
String formattedValue(const ValueType value) const
Creates a short string representation with "UNIT: value", where value has a predefined precision (see...
DimBase & operator=(const DimBase &rhs)=default
Assignment operator.
virtual ValueTypes map(const MSChromatogram &chrom) const =0
virtual ValueType map(const BaseFeature &bf) const =0
virtual void setRange(const RangeBase &in, RangeAllType &out) const =0
Set the min/max (range) in out for a certain dimension.
virtual ValueType map(const MSSpectrum &spec, const Size index) const =0
obtain value from a certain point in a spectrum
std::vector< ValueType > ValueTypes
Definition: DimMapper.h:44
String formattedValue(ValueType value, const String &prefix) const
like formattedValue() but with a custom unit prefix instead of the default one for the dim,...
std::string_view getDimName() const
Name of the dimension, e.g. 'RT [s]'.
Definition: DimMapper.h:117
virtual void fromXY(const ValueType in, MobilityPeak2D &p) const =0
set the dimension of a MobilityPeak2D
virtual RangeBase map(const RangeAllType &rm) const =0
Return the min/max (range) for a certain dimension.
virtual ValueType map(const MobilityPeak1D &p) const =0
virtual ValueTypes map(const MSSpectrum &spec) const =0
virtual void fromXY(const ValueType in, MobilityPeak1D &p) const =0
set the dimension of a MobilityPeak1D
virtual ValueType map(const Peak2D &p) const =0
DIM_UNIT getUnit() const
The unit of the dimension.
Definition: DimMapper.h:129
DimBase()=delete
No default c'tor.
virtual std::unique_ptr< DimBase > clone() const =0
Copy derived objects to avoid slicing when dealing with pointers to DimBase.
Definition: DimMapper.h:492
ValueType map(const MSChromatogram &, const Size) const override
obtain value from a certain point in a chromatogram
Definition: DimMapper.h:540
ValueType map(const Peak2D &) const override
Definition: DimMapper.h:505
ValueType map(const BaseFeature &) const override
Definition: DimMapper.h:549
void setRange(const RangeBase &in, RangeAllType &out) const override
Set the min/max (range) in out for a certain dimension.
Definition: DimMapper.h:568
ValueType map(const PeptideIdentification &) const override
Definition: DimMapper.h:554
void fromXY(const ValueType, Peak1D &) const override
set the IM of a Peak1D (throws)
Definition: DimMapper.h:574
std::unique_ptr< DimBase > clone() const override
Copy derived objects to avoid slicing when dealing with pointers to DimBase.
Definition: DimMapper.h:496
ValueTypes map(const MSSpectrum &) const override
Definition: DimMapper.h:513
ValueType map(const MSSpectrum &spec, const Size) const override
obtain value from a certain point in a spectrum
Definition: DimMapper.h:536
ValueType map(const MSExperiment::ConstAreaIterator &it) const override
Definition: DimMapper.h:522
ValueType map(const ChromatogramPeak &) const override
Definition: DimMapper.h:509
void fromXY(const ValueType, ChromatogramPeak &) const override
set the IM of a ChromatogramPeak (throws)
Definition: DimMapper.h:580
RangeBase & map(RangeAllType &rm) const override
Return the min/max (range) for a certain dimension (i.e. a reference to the base class of rm)
Definition: DimMapper.h:563
ValueType map(const Mobilogram &mb, const Size index) const override
obtain value from a certain point in a mobilogram
Definition: DimMapper.h:544
RangeBase map(const RangeAllType &rm) const override
Return the min/max (range) for a certain dimension.
Definition: DimMapper.h:559
void fromXY(const ValueType in, MobilityPeak2D &p) const override
set the IM of a MobilityPeak2D
Definition: DimMapper.h:591
ValueType map(const MobilityPeak2D &p) const override
Definition: DimMapper.h:531
ValueType map(const MobilityPeak1D &p) const override
Definition: DimMapper.h:527
DimIM(const DIM_UNIT im_unit)
Definition: DimMapper.h:494
ValueTypes map(const MSChromatogram &) const override
Definition: DimMapper.h:517
ValueType map(const Peak1D &) const override
Definition: DimMapper.h:501
void fromXY(const ValueType in, MobilityPeak1D &p) const override
set the IM of a MobilityPeak1D
Definition: DimMapper.h:586
Definition: DimMapper.h:375
ValueType map(const Peak1D &p) const override
Definition: DimMapper.h:384
void setRange(const RangeBase &in, RangeAllType &out) const override
Set the min/max (range) in out for a certain dimension.
Definition: DimMapper.h:463
ValueType map(const Peak2D &p) const override
Definition: DimMapper.h:388
ValueType map(const PeptideIdentification &) const override
Definition: DimMapper.h:449
std::unique_ptr< DimBase > clone() const override
Copy derived objects to avoid slicing when dealing with pointers to DimBase.
Definition: DimMapper.h:379
ValueTypes map(const MSChromatogram &chrom) const override
Definition: DimMapper.h:433
ValueType map(const MSSpectrum &spec, const Size index) const override
obtain value from a certain point in a spectrum
Definition: DimMapper.h:409
ValueType map(const MSExperiment::ConstAreaIterator &it) const override
Definition: DimMapper.h:396
ValueType map(const ChromatogramPeak &p) const override
Definition: DimMapper.h:392
DimINT()
Definition: DimMapper.h:377
ValueTypes map(const MSSpectrum &spec) const override
Definition: DimMapper.h:422
RangeBase & map(RangeAllType &rm) const override
Return the min/max (range) for a certain dimension (i.e. a reference to the base class of rm)
Definition: DimMapper.h:458
ValueType map(const BaseFeature &bf) const override
Definition: DimMapper.h:444
ValueType map(const Mobilogram &mb, const Size index) const override
obtain value from a certain point in a mobilogram
Definition: DimMapper.h:417
RangeBase map(const RangeAllType &rm) const override
Return the min/max (range) for a certain dimension.
Definition: DimMapper.h:454
void fromXY(const ValueType in, MobilityPeak2D &p) const override
set the intensity of a MobilityPeak2D
Definition: DimMapper.h:485
ValueType map(const MobilityPeak2D &p) const override
Definition: DimMapper.h:404
ValueType map(const MobilityPeak1D &p) const override
Definition: DimMapper.h:400
void fromXY(const ValueType in, Peak1D &p) const override
set the intensity of a Peak1D
Definition: DimMapper.h:469
void fromXY(const ValueType in, ChromatogramPeak &p) const override
set the intensity of a ChromatogramPeak
Definition: DimMapper.h:475
ValueType map(const MSChromatogram &chrom, const Size index) const override
obtain value from a certain point in a chromatogram
Definition: DimMapper.h:413
void fromXY(const ValueType in, MobilityPeak1D &p) const override
set the intensity of a MobilityPeak1D
Definition: DimMapper.h:480
Definition: DimMapper.h:264
ValueType map(const Peak1D &p) const override
Definition: DimMapper.h:273
ValueType map(const Mobilogram &, const Size) const override
obtain value from a certain point in a mobilogram
Definition: DimMapper.h:306
void setRange(const RangeBase &in, RangeAllType &out) const override
Set the min/max (range) in out for a certain dimension.
Definition: DimMapper.h:345
DimMZ()
Definition: DimMapper.h:266
ValueType map(const MSChromatogram &chrom, const Size) const override
obtain value from a certain point in a chromatogram
Definition: DimMapper.h:302
ValueType map(const Peak2D &p) const override
Definition: DimMapper.h:277
std::unique_ptr< DimBase > clone() const override
Copy derived objects to avoid slicing when dealing with pointers to DimBase.
Definition: DimMapper.h:268
ValueType map(const MSSpectrum &spec, const Size index) const override
obtain value from a certain point in a spectrum
Definition: DimMapper.h:298
ValueType map(const MSExperiment::ConstAreaIterator &it) const override
Definition: DimMapper.h:285
ValueTypes map(const MSSpectrum &spec) const override
Definition: DimMapper.h:311
ValueType map(const ChromatogramPeak &) const override
Definition: DimMapper.h:281
void fromXY(const ValueType, ChromatogramPeak &) const override
set the MZ of a ChromatogramPeak (throws)
Definition: DimMapper.h:357
RangeBase & map(RangeAllType &rm) const override
Return the min/max (range) for a certain dimension (i.e. a reference to the base class of rm)
Definition: DimMapper.h:340
ValueType map(const BaseFeature &bf) const override
Definition: DimMapper.h:326
ValueType map(const PeptideIdentification &pi) const override
Definition: DimMapper.h:331
void fromXY(const ValueType, MobilityPeak1D &) const override
set the MZ of a MobilityPeak1D (throws)
Definition: DimMapper.h:363
RangeBase map(const RangeAllType &rm) const override
Return the min/max (range) for a certain dimension.
Definition: DimMapper.h:336
void fromXY(const ValueType in, MobilityPeak2D &p) const override
set the MZ of a MobilityPeak2D (throws)
Definition: DimMapper.h:368
ValueType map(const MobilityPeak2D &p) const override
Definition: DimMapper.h:293
ValueTypes map(const MSChromatogram &) const override
Definition: DimMapper.h:321
void fromXY(const ValueType in, Peak1D &p) const override
set the MZ of a Peak1D
Definition: DimMapper.h:351
ValueType map(const MobilityPeak1D &) const override
Definition: DimMapper.h:289
Allows dynamical switching (at runtime) between a dimension (RT, m/z, int, IM, etc) and X,...
Definition: DimMapper.h:619
static std::unique_ptr< const DimBase > create_(DIM_UNIT u)
a minimal factory
Definition: DimMapper.h:766
bool operator!=(const DimMapper &rhs) const
Inequality.
Definition: DimMapper.h:666
std::array< std::unique_ptr< const DimBase >, N_DIM > dims_
mappers for the X,Y,Z... dimension
Definition: DimMapper.h:785
bool operator==(const DimMapper &rhs) const
Equality.
Definition: DimMapper.h:655
void fromXY(const DRange< N_DIM > &in, RangeManager< Ranges... > &output) const
Definition: DimMapper.h:709
DimMapper & operator=(const DimMapper &rhs)
Assignment operator.
Definition: DimMapper.h:648
void fromXY(const Point &in, RangeManager< Ranges... > &output) const
Definition: DimMapper.h:724
DimMapper(const DimMapper &rhs)
Copy C'tor.
Definition: DimMapper.h:642
DRange< N_DIM > mapRange(const RangeManager< Ranges... > &ranges) const
Convert Range to an N_DIM-dimensional area (min and max for each dimension)
Definition: DimMapper.h:691
Point map(const T &data) const
convert an OpenMS datatype (such as Feature) to an N_DIM-dimensional point
Definition: DimMapper.h:673
const DimBase & getDim(DIM d) const
obtain unit/name for X/Y/Z dimension.
Definition: DimMapper.h:758
RangeAllType fromXY(const Point &in) const
Definition: DimMapper.h:747
DimMapper(const DIM_UNIT(&units)[N_DIM])
Custom C'tor with given dimensions to map to (the order is assumed to be X, Y, Z, ....
Definition: DimMapper.h:627
DimMapper()=delete
No default c'tor (we need dimensions)
Point map(const Container &data, const Size index) const
convert an OpenMS datapoint in a container (such as MSSpectrum) to an N_DIM-dimensional point
Definition: DimMapper.h:681
void fromXY(const Point &in, T &out) const
Definition: DimMapper.h:736
Definition: DimMapper.h:154
void setRange(const RangeBase &in, RangeAllType &out) const override
Set the min/max (range) in out for a certain dimension.
Definition: DimMapper.h:235
ValueType map(const MobilityPeak2D &) const override
Definition: DimMapper.h:211
ValueType map(const Peak2D &p) const override
Definition: DimMapper.h:167
void fromXY(const ValueType, MobilityPeak2D &) const override
set the RT of a MobilityPeak2D (throws)
Definition: DimMapper.h:257
void fromXY(const ValueType, Peak1D &) const override
set the RT of a Peak1D (throws)
Definition: DimMapper.h:241
std::unique_ptr< DimBase > clone() const override
Copy derived objects to avoid slicing when dealing with pointers to DimBase.
Definition: DimMapper.h:158
ValueTypes map(const MSChromatogram &chrom) const override
Definition: DimMapper.h:192
ValueTypes map(const MSSpectrum &) const override
Definition: DimMapper.h:188
ValueType map(const MSSpectrum &spec, const Size) const override
obtain value from a certain point in a spectrum
Definition: DimMapper.h:175
ValueType map(const MSExperiment::ConstAreaIterator &it) const override
Definition: DimMapper.h:203
ValueType map(const ChromatogramPeak &p) const override
Definition: DimMapper.h:171
RangeBase & map(RangeAllType &rm) const override
Return the min/max (range) for a certain dimension (i.e. a reference to the base class of rm)
Definition: DimMapper.h:230
ValueType map(const BaseFeature &bf) const override
Definition: DimMapper.h:216
ValueType map(const PeptideIdentification &pi) const override
Definition: DimMapper.h:221
void fromXY(const ValueType, MobilityPeak1D &) const override
set the RT of a MobilityPeak1D (throws)
Definition: DimMapper.h:252
RangeBase map(const RangeAllType &rm) const override
Return the min/max (range) for a certain dimension.
Definition: DimMapper.h:226
DimRT()
Definition: DimMapper.h:156
ValueType map(const Mobilogram &mb, const Size) const override
obtain value from a certain point in a mobilogram
Definition: DimMapper.h:183
ValueType map(const Peak1D &) const override
Definition: DimMapper.h:163
void fromXY(const ValueType in, ChromatogramPeak &p) const override
set the RT of a ChromatogramPeak
Definition: DimMapper.h:247
ValueType map(const MobilityPeak1D &) const override
Definition: DimMapper.h:207
ValueType map(const MSChromatogram &chrom, const Size index) const override
obtain value from a certain point in a chromatogram
Definition: DimMapper.h:179
Invalid range exception.
Definition: Exception.h:252
Not implemented exception.
Definition: Exception.h:404
Precondition failed exception.
Definition: Exception.h:133
Forward iterator for an area of peaks in an experiment.
Definition: AreaIterator.h:36
CoordinateType getDriftTime() const
returns the ion mobility time of the current scan
Definition: AreaIterator.h:248
CoordinateType getRT() const
returns the retention time of the current scan
Definition: AreaIterator.h:242
void setDimMinMax(UInt dim, const DIntervalBase< 1 > &min_max)
only set interval for a single dimension
Definition: DIntervalBase.h:228
PositionType const & maxPosition() const
Accessor to maximum position.
Definition: DIntervalBase.h:104
bool isEmpty() const
Definition: DIntervalBase.h:216
static DIntervalBase const empty
empty instance
Definition: DIntervalBase.h:258
PositionType const & minPosition() const
Accessor to minimum position.
Definition: DIntervalBase.h:98
The representation of a chromatogram.
Definition: MSChromatogram.h:31
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
double getRT() const
double getDriftTime() const
Returns the ion mobility drift time (MSSpectrum::DRIFTTIME_NOT_SET means it is not set)
A 1-dimensional raw data mobility point or peak. The unit (ms, 1/K_0, etc) is implicit.
Definition: MobilityPeak1D.h:25
IntensityType getIntensity() const
Definition: MobilityPeak1D.h:79
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: MobilityPeak1D.h:84
void setMobility(CoordinateType mobility)
Mutable access to mobility.
Definition: MobilityPeak1D.h:96
CoordinateType getMobility() const
Non-mutable access to m/z.
Definition: MobilityPeak1D.h:90
float IntensityType
Intensity type.
Definition: MobilityPeak1D.h:32
A 2-dimensional raw data point or peak.
Definition: MobilityPeak2D.h:29
CoordinateType getMZ() const
Returns the m/z coordinate (index 1)
Definition: MobilityPeak2D.h:168
void setMZ(CoordinateType coordinate)
Mutable access to the m/z coordinate (index 1)
Definition: MobilityPeak2D.h:174
void setMobility(CoordinateType coordinate)
Mutable access to the IM coordinate (index 0)
Definition: MobilityPeak2D.h:186
float IntensityType
Intensity type.
Definition: MobilityPeak2D.h:35
IntensityType getIntensity() const
Definition: MobilityPeak2D.h:138
void setIntensity(IntensityType intensity)
Sets data point intensity (height)
Definition: MobilityPeak2D.h:144
CoordinateType getMobility() const
Returns the IM coordinate (index 0)
Definition: MobilityPeak2D.h:180
The representation of a 1D ion mobilogram.
Definition: Mobilogram.h:29
double getRT() const noexcept
Definition: Mobilogram.h:236
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:28
CoordinateType getMZ() const
Non-mutable access to m/z.
Definition: Peak1D.h:87
IntensityType getIntensity() const
Definition: Peak1D.h:82
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: Peak1D.h:84
void setMZ(CoordinateType mz)
Mutable access to m/z.
Definition: Peak1D.h:93
float IntensityType
Intensity type.
Definition: Peak1D.h:36
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:29
CoordinateType getMZ() const
Returns the m/z coordinate (index 1)
Definition: Peak2D.h:172
IntensityType getIntensity() const
Definition: Peak2D.h:142
CoordinateType getRT() const
Returns the RT coordinate (index 0)
Definition: Peak2D.h:184
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:39
double getRT() const
returns the RT of the MS2 spectrum where the identification occurred
double getMZ() const
returns the MZ of the MS2 spectrum
void pushInto(const RangeManager< RangeBasesOther... > &sandbox)
Definition: RangeManager.h:678
const RangeBase & getRangeForDim(MSDim dim) const
obtain a range dimension at runtime using dim
Definition: RangeManager.h:722
auto & assign(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:586
A more convenient string class.
Definition: String.h:34
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
static String prefix(const String &this_s, size_t length)
Definition: StringUtilsSimple.h:122
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
DIM
Definition: DimMapper.h:601
RangeManager< RangeRT, RangeMZ, RangeIntensity, RangeMobility > RangeAllType
Range which contains all known dimensions.
Definition: RangeManager.h:897
DIM_UNIT
Definition: CommonEnums.h:20
@ IM_VSSC
volt-second per square centimeter (i.e. 1/K_0)
@ INT
intensity
@ FAIMS_CV
FAIMS compensation voltage.
@ RT
RT in seconds.
@ IM_MS
ion mobility milliseconds
std::string_view DIM_NAMES[(int) DIM_UNIT::SIZE_OF_DIM_UNITS]
Definition: CommonEnums.h:29
std::string_view DIM_NAMES_SHORT[(int) DIM_UNIT::SIZE_OF_DIM_UNITS]
Definition: CommonEnums.h:30
Base class for a simple range with minimum and maximum.
Definition: RangeManager.h:38
double getMin() const
only useful if isEmpty() returns false
Definition: RangeManager.h:122
bool isEmpty() const
is the range empty (i.e. min > max)?
Definition: RangeManager.h:82
double getMax() const
only useful if isEmpty() returns false
Definition: RangeManager.h:128