OpenMS
DimMapper.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2023.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Chris Bielow $
32 // $Authors: Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 
47 #include <OpenMS/KERNEL/Peak1D.h>
48 #include <OpenMS/KERNEL/Peak2D.h>
50 
51 #include <array>
52 #include <memory>
53 
54 
55 namespace OpenMS
56 {
66  class OPENMS_DLLAPI DimBase
67  {
68  public:
69  using ValueType = double;
70  using ValueTypes = std::vector<ValueType>;
71 
73  DimBase() = delete;
74 
76  DimBase(DIM_UNIT unit) :
77  unit_(unit)
78  {}
79 
81  DimBase& operator=(const DimBase& rhs) = default;
82 
84  virtual ~DimBase() noexcept = default;
85 
87  bool operator==(const DimBase& rhs) const
88  {
89  return unit_ == rhs.unit_;
90  }
91 
93  virtual std::unique_ptr<DimBase> clone() const = 0;
94 
95  virtual ValueType map(const Peak1D& p) const = 0;
96  virtual ValueType map(const Peak2D& p) const = 0;
97  virtual ValueType map(const ChromatogramPeak& p) const = 0;
98  virtual ValueType map(const MSExperiment::ConstAreaIterator& it) const = 0;
99  virtual ValueType map(const MobilityPeak1D& p) const = 0;
100  virtual ValueType map(const MobilityPeak2D& p) const = 0;
101 
103  virtual ValueType map(const MSSpectrum& spec, const Size index) const = 0;
105  virtual ValueType map(const MSChromatogram& chrom, const Size index) const = 0;
107  virtual ValueType map(const Mobilogram& mb, const Size index) const = 0;
108 
111  virtual ValueTypes map(const MSSpectrum& spec) const = 0;
112 
115  virtual ValueTypes map(const MSChromatogram& chrom) const = 0;
116 
117  virtual ValueType map(const BaseFeature& bf) const = 0;
118 
119  virtual ValueType map(const PeptideIdentification& pi) const = 0;
120 
122  virtual RangeBase map(const RangeAllType& rm) const = 0;
123 
125  virtual RangeBase& map(RangeAllType& rm) const = 0;
126 
128  virtual void setRange(const RangeBase& in, RangeAllType& out) const = 0;
129 
130 
131  // from XY to a type
132 
134  virtual void fromXY(const ValueType in, Peak1D& p) const = 0;
136  virtual void fromXY(const ValueType in, ChromatogramPeak& p) const = 0;
138  virtual void fromXY(const ValueType in, MobilityPeak1D& p) const = 0;
140  virtual void fromXY(const ValueType in, MobilityPeak2D& p) const = 0;
141 
143  std::string_view getDimName() const
144  {
145  return DIM_NAMES[(int)unit_];
146  }
147 
149  std::string_view getDimNameShort() const
150  {
151  return DIM_NAMES_SHORT[(int)unit_];
152  }
153 
156  {
157  return unit_;
158  }
159 
165  String formattedValue(const ValueType value) const;
166 
169 
171  int valuePrecision() const;
172 
173  protected:
175  };
176 
177 
178 
179  class OPENMS_DLLAPI DimRT final : public DimBase
180  {
181  public:
183 
184  std::unique_ptr<DimBase> clone() const override
185  {
186  return std::make_unique<DimRT>();
187  }
188 
189  ValueType map(const Peak1D&) const override
190  {
191  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
192  }
193  ValueType map(const Peak2D& p) const override
194  {
195  return p.getRT();
196  }
197  ValueType map(const ChromatogramPeak& p) const override
198  {
199  return p.getRT();
200  }
201  ValueType map(const MSSpectrum& spec, const Size /*index*/) const override
202  {
203  return spec.getRT();
204  }
205  ValueType map(const MSChromatogram& chrom, const Size index) const override
206  {
207  return chrom[index].getRT();
208  }
209  ValueType map(const Mobilogram& mb, const Size /*index*/) const override
210  {
211  return mb.getRT();
212  }
213 
214  ValueTypes map(const MSSpectrum&) const override
215  {
216  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
217  }
218  ValueTypes map(const MSChromatogram& chrom) const override
219  {
220  ValueTypes res;
221  res.reserve(chrom.size());
222  for (const auto& p : chrom)
223  {
224  res.push_back(p.getRT());
225  }
226  return res;
227  }
228 
230  {
231  return it.getRT();
232  }
233  ValueType map(const MobilityPeak1D&) const override
234  {
235  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
236  }
237  ValueType map(const MobilityPeak2D&) const override
238  {
239  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
240  }
241 
242  ValueType map(const BaseFeature& bf) const override
243  {
244  return bf.getRT();
245  }
246 
247  ValueType map(const PeptideIdentification& pi) const override
248  {
249  return pi.getRT();
250  }
251 
252  RangeBase map(const RangeAllType& rm) const override
253  {
254  return rm.getRangeForDim(MSDim::RT);
255  }
256  RangeBase& map(RangeAllType& rm) const override
257  {
258  return rm.getRangeForDim(MSDim::RT);
259  }
260 
261  void setRange(const RangeBase& in, RangeAllType& out) const override
262  {
263  out.RangeRT::operator=(in);
264  }
265 
267  void fromXY(const ValueType, Peak1D&) const override
268  {
269  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
270  }
271 
273  void fromXY(const ValueType in, ChromatogramPeak& p) const override
274  {
275  p.setRT(in);
276  }
278  void fromXY(const ValueType, MobilityPeak1D&) const override
279  {
280  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
281  }
283  void fromXY(const ValueType, MobilityPeak2D&) const override
284  {
285  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
286  }
287  };
288 
289  class OPENMS_DLLAPI DimMZ final : public DimBase
290  {
291  public:
293 
294  std::unique_ptr<DimBase> clone() const override
295  {
296  return std::make_unique<DimMZ>();
297  }
298 
299  ValueType map(const Peak1D& p) const override
300  {
301  return p.getMZ();
302  }
303  ValueType map(const Peak2D& p) const override
304  {
305  return p.getMZ();
306  }
307  ValueType map(const ChromatogramPeak&) const override
308  {
309  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
310  }
312  {
313  return it->getMZ();
314  }
315  ValueType map(const MobilityPeak1D&) const override
316  {
317  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
318  }
319  ValueType map(const MobilityPeak2D& p) const override
320  {
321  return p.getMZ();
322  }
323 
324  ValueType map(const MSSpectrum& spec, const Size index) const override
325  {
326  return spec[index].getMZ();
327  }
328  ValueType map(const MSChromatogram& chrom, const Size /*index*/) const override
329  {
330  return chrom.getPrecursor().getMZ();
331  }
332  ValueType map(const Mobilogram& /*mb*/, const Size /*index*/) const override
333  {
334  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
335  }
336 
337  ValueTypes map(const MSSpectrum& spec) const override
338  {
339  ValueTypes res;
340  res.reserve(spec.size());
341  for (const auto& p : spec)
342  {
343  res.push_back(p.getMZ());
344  }
345  return res;
346  }
347  ValueTypes map(const MSChromatogram&) const override
348  {
349  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
350  }
351 
352  ValueType map(const BaseFeature& bf) const override
353  {
354  return bf.getMZ();
355  }
356 
357  ValueType map(const PeptideIdentification& pi) const override
358  {
359  return pi.getMZ();
360  }
361 
362  RangeBase map(const RangeAllType& rm) const override
363  {
364  return rm.getRangeForDim(MSDim::MZ);
365  }
366  RangeBase& map(RangeAllType& rm) const override
367  {
368  return rm.getRangeForDim(MSDim::MZ);
369  }
370 
371  void setRange(const RangeBase& in, RangeAllType& out) const override
372  {
373  out.RangeMZ::operator=(in);
374  }
375 
377  void fromXY(const ValueType in, Peak1D& p) const override
378  {
379  p.setMZ(in);
380  }
381 
383  void fromXY(const ValueType, ChromatogramPeak&) const override
384  {
385  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
386  }
387 
389  void fromXY(const ValueType, MobilityPeak1D&) const override
390  {
391  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
392  }
394  void fromXY(const ValueType in, MobilityPeak2D& p) const override
395  {
396  p.setMZ(in);
397  }
398  };
399 
400  class OPENMS_DLLAPI DimINT final : public DimBase
401  {
402  public:
404 
405  std::unique_ptr<DimBase> clone() const override
406  {
407  return std::make_unique<DimINT>();
408  }
409 
410  ValueType map(const Peak1D& p) const override
411  {
412  return p.getIntensity();
413  }
414  ValueType map(const Peak2D& p) const override
415  {
416  return p.getIntensity();
417  }
418  ValueType map(const ChromatogramPeak& p) const override
419  {
420  return p.getIntensity();
421  }
423  {
424  return it->getIntensity();
425  }
426  ValueType map(const MobilityPeak1D& p) const override
427  {
428  return p.getIntensity();
429  }
430  ValueType map(const MobilityPeak2D& p) const override
431  {
432  return p.getIntensity();
433  }
434 
435  ValueType map(const MSSpectrum& spec, const Size index) const override
436  {
437  return spec[index].getIntensity();
438  }
439  ValueType map(const MSChromatogram& chrom, const Size index) const override
440  {
441  return chrom[index].getIntensity();
442  }
443  ValueType map(const Mobilogram& mb, const Size index) const override
444  {
445  return mb[index].getIntensity();
446  }
447 
448  ValueTypes map(const MSSpectrum& spec) const override
449  {
450  ValueTypes res;
451  res.reserve(spec.size());
452  for (const auto& p : spec)
453  {
454  res.push_back(p.getIntensity());
455  }
456  return res;
457  }
458 
459  ValueTypes map(const MSChromatogram& chrom) const override
460  {
461  ValueTypes res;
462  res.reserve(chrom.size());
463  for (const auto& p : chrom)
464  {
465  res.push_back(p.getIntensity());
466  }
467  return res;
468  }
469 
470  ValueType map(const BaseFeature& bf) const override
471  {
472  return bf.getIntensity();
473  }
474 
475  ValueType map(const PeptideIdentification&) const override
476  {
477  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
478  }
479 
480  RangeBase map(const RangeAllType& rm) const override
481  {
482  return rm.getRangeForDim(MSDim::INT);
483  }
484  RangeBase& map(RangeAllType& rm) const override
485  {
486  return rm.getRangeForDim(MSDim::INT);
487  }
488 
489  void setRange(const RangeBase& in, RangeAllType& out) const override
490  {
491  out.RangeIntensity::operator=(in);
492  }
493 
495  void fromXY(const ValueType in, Peak1D& p) const override
496  {
498  }
499 
501  void fromXY(const ValueType in, ChromatogramPeak& p) const override
502  {
504  }
506  void fromXY(const ValueType in, MobilityPeak1D& p) const override
507  {
509  }
511  void fromXY(const ValueType in, MobilityPeak2D& p) const override
512  {
514  }
515  };
516 
517  class OPENMS_DLLAPI DimIM final : public DimBase
518  {
519  public:
520  DimIM(const DIM_UNIT im_unit) : DimBase(im_unit) {}
521 
522  std::unique_ptr<DimBase> clone() const override
523  {
524  return std::make_unique<DimIM>(*this);
525  }
526 
527  ValueType map(const Peak1D&) const override
528  {
529  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
530  }
531  ValueType map(const Peak2D&) const override
532  {
533  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
534  }
535  ValueType map(const ChromatogramPeak&) const override
536  {
537  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
538  }
539  ValueTypes map(const MSSpectrum&) const override
540  {
541  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
542  }
543  ValueTypes map(const MSChromatogram&) const override
544  {
545  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
546  }
547 
549  {
550  return it.getDriftTime();
551  }
552 
553  ValueType map(const MobilityPeak1D& p) const override
554  {
555  return p.getMobility();
556  }
557  ValueType map(const MobilityPeak2D& p) const override
558  {
559  return p.getMobility();
560  }
561 
562  ValueType map(const MSSpectrum& spec, const Size /*index*/) const override
563  {
564  return spec.getDriftTime();
565  }
566  ValueType map(const MSChromatogram&, const Size) const override
567  {
568  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
569  }
570  ValueType map(const Mobilogram& mb, const Size index) const override
571  {
572  return mb[index].getMobility();
573  }
574 
575  ValueType map(const BaseFeature&) const override
576  {
577  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
578  }
579 
580  ValueType map(const PeptideIdentification&) const override
581  {
582  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
583  }
584 
585  RangeBase map(const RangeAllType& rm) const override
586  {
587  return rm.getRangeForDim(MSDim::IM);
588  }
589  RangeBase& map(RangeAllType& rm) const override
590  {
591  return rm.getRangeForDim(MSDim::IM);
592  }
593 
594  void setRange(const RangeBase& in, RangeAllType& out) const override
595  {
596  out.RangeMobility::operator=(in);
597  }
598 
600  void fromXY(const ValueType, Peak1D&) const override
601  {
602  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
603  }
604 
606  void fromXY(const ValueType, ChromatogramPeak&) const override
607  {
608  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
609  }
610 
612  void fromXY(const ValueType in, MobilityPeak1D& p) const override
613  {
614  p.setMobility(in);
615  }
617  void fromXY(const ValueType in, MobilityPeak2D& p) const override
618  {
619  p.setMobility(in);
620  }
621  };
622 
626  enum class DIM
627  {
628  X = 0,
629  Y = 1,
630  Z = 2
631  };
632 
643  template<int N_DIM>
644  class DimMapper
645  {
646  public:
648 
650  DimMapper() = delete;
651 
653  DimMapper(const DIM_UNIT (&units)[N_DIM])
654  :dims_([&]() {
655  std::array<std::unique_ptr<const DimBase>, N_DIM> dims_tmp;
656  for (int i = 0; i < N_DIM; ++i)
657  {
658  dims_tmp[i] = create_(units[i]);
659  }
660  return dims_tmp;
661  }()) // immediately evaluated lambda to enable 'dims_' to be const
662  {
663  static_assert(N_DIM >= 1); // at least one dimension (X)
664  static_assert(N_DIM <= 3); // at most three (X, Y, Z)
665  }
666 
668  DimMapper(const DimMapper& rhs) // cannot be defaulted due to unique_ptr
669  {
670  *this = rhs;
671  };
672 
674  DimMapper& operator=(const DimMapper& rhs) // cannot be defaulted due to unique_ptr
675  {
676  for (int i = 0; i < N_DIM; ++i) dims_[i] = rhs.dims_[i]->clone();
677  return *this;
678  };
679 
681  bool operator==(const DimMapper& rhs) const
682  {
683  bool res {true};
684  for (int i = 0; i < N_DIM; ++i)
685  {
686  res &= (*dims_[i] == *rhs.dims_[i]);
687  }
688  return res;
689  }
690 
692  bool operator!=(const DimMapper& rhs) const
693  {
694  return !operator==(rhs);
695  }
696 
698  template <typename T>
699  Point map(const T& data) const
700  {
701  Point pr;
702  for (int i = 0; i < N_DIM; ++i) pr[i] = dims_[i]->map(data);
703  return pr;
704  }
706  template<typename Container>
707  Point map(const Container& data, const Size index) const
708  {
709  Point pr;
710  for (int i = 0; i < N_DIM; ++i)
711  pr[i] = dims_[i]->map(data, index);
712  return pr;
713  }
714 
716  template<typename ...Ranges>
718  {
719  DRange<N_DIM> res;
720  RangeAllType all;
721  all.assign(ranges);
722  for (int i = 0; i < N_DIM; ++i)
723  {
724  RangeBase mm = dims_[i]->map(all);
725  if (mm.isEmpty()) continue;
726  res.setDimMinMax(i, {mm.getMin(), mm.getMax()});
727  }
728  return res;
729  }
730 
734  template<typename... Ranges>
735  void fromXY(const DRange<N_DIM>& in, RangeManager<Ranges...>& output) const
736  {
737  for (int i = 0; i < N_DIM; ++i)
738  {
739  if (in.isEmpty(i))
740  dims_[i]->setRange(RangeBase(), output);
741  else
742  dims_[i]->setRange({in.minPosition()[i], in.maxPosition()[i]}, output);
743  }
744  }
745 
749  template<typename... Ranges>
750  void fromXY(const Point& in, RangeManager<Ranges...>& output) const
751  {
752  for (int i = 0; i < N_DIM; ++i)
753  {
754  dims_[i]->setRange({in[i], in[i]}, output);
755  }
756  }
757 
761  template<typename T>
762  void fromXY(const Point& in, T& out) const
763  {
764  for (int i = 0; i < N_DIM; ++i)
765  {
766  dims_[i]->fromXY(in[i], out);
767  }
768  }
769 
773  RangeAllType fromXY(const Point& in) const
774  {
775  RangeAllType output;
776  for (int i = 0; i < N_DIM; ++i)
777  {
778  dims_[i]->setRange({in[i], in[i]}, output);
779  }
780  return output;
781  }
782 
784  const DimBase& getDim(DIM d) const
785  {
786  assert((int)d <= N_DIM);
787  return *dims_[(int)d];
788  }
789 
790  protected:
792  static std::unique_ptr<const DimBase> create_(DIM_UNIT u)
793  {
794  switch (u)
795  {
796  case DIM_UNIT::RT:
797  return std::make_unique<DimRT>();
798  case DIM_UNIT::MZ:
799  return std::make_unique<DimMZ>();
800  case DIM_UNIT::INT:
801  return std::make_unique<DimINT>();
802  case DIM_UNIT::FAIMS_CV:
803  case DIM_UNIT::IM_MS:
804  case DIM_UNIT::IM_VSSC:
805  return std::make_unique<DimIM>(u);
806  default:
807  throw Exception::NotImplemented(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
808  }
809  }
810 
811  std::array<std::unique_ptr<const DimBase>, N_DIM> dims_;
812  };
813 
814 
817  template <int N_DIM>
818  class Area
819  {
820  public:
823 
825  Area() = delete;
826 
828  Area(const DimMapper<N_DIM>* const dims)
829  : mapper_(dims)
830  {
831  }
832 
834  Area(const Area& range) = default;
835 
837  Area& operator=(const Area& rhs)
838  {
839  // check that Dims are identical, otherwise this is very dangerous (the user probably only wanted to update the area, not change its mapping).
840  if (mapper_ != rhs.mapper_ && *mapper_ != *rhs.mapper_)
841  {
842  throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Assignment of Areas using different mappers!");
843  }
844  data_range_ = rhs.data_range_;
846  return *this;
847  }
848 
849  bool operator==(const Area& rhs) const
850  {
851  return data_range_ == rhs.data_range_
852  && visible_area_ == rhs.visible_area_
853  && (*mapper_ == *rhs.mapper_);
854  }
855  bool operator!=(const Area& rhs) const
856  {
857  return !operator==(rhs);
858  }
859 
865  const Area& setArea(const RangeAllType& data)
866  {
867  data_range_ = data;
868  // update axis view using dims
869  visible_area_ = mapper_->mapRange(data);
870  return *this;
871  }
872 
878  const Area& setArea(const AreaXYType& data)
879  {
880  visible_area_ = data;
881  // update range view from XY area using dims
883  return *this;
884  }
885 
886  const AreaXYType& getAreaXY() const
887  {
888  return visible_area_;
889  }
890 
891  const RangeAllType& getAreaUnit() const
892  {
893  return data_range_;
894  }
895 
901  Area cloneWith(const AreaXYType& data) const
902  {
903  Area clone(*this);
904  clone.setArea(data);
905  return clone;
906  }
907 
913  Area cloneWith(const RangeAllType& data) const
914  {
915  Area clone(*this);
916  clone.setArea(data);
917  return clone;
918  }
919 
924  void pushInto(const RangeAllType& sandbox)
925  {
926  auto a = data_range_;
927  a.pushInto(sandbox);
928  setArea(a);
929  }
930 
932  void clear()
933  {
935  }
936 
937  private:
938  /* two sides of the same coin... */
943  };
944 
945 } // namespace OpenMS
Definition: DimMapper.h:819
bool operator!=(const Area &rhs) const
Definition: DimMapper.h:855
const Area & setArea(const RangeAllType &data)
Set the area using unit data (RT, m/z, ...)
Definition: DimMapper.h:865
Area()=delete
No default C'tor.
bool operator==(const Area &rhs) const
Definition: DimMapper.h:849
RangeAllType data_range_
range in units
Definition: DimMapper.h:939
const Area & setArea(const AreaXYType &data)
Set the area using axis data (X and Y)
Definition: DimMapper.h:878
void pushInto(const RangeAllType &sandbox)
Push the area into a sandbox (if its outside the sandbox). See UnitRange::pushInto()
Definition: DimMapper.h:924
AreaXYType visible_area_
Definition: DimMapper.h:940
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:913
const DimMapper< N_DIM > * mapper_
and a mapper (non-owning pointer) to translate between the two
Definition: DimMapper.h:942
Area & operator=(const Area &rhs)
Assignment operator - which checks for identical DimMappers and throws otherwise.
Definition: DimMapper.h:837
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:901
Area(const DimMapper< N_DIM > *const dims)
Custom C'tor with a mapper (non owning pointer)
Definition: DimMapper.h:828
const RangeAllType & getAreaUnit() const
Definition: DimMapper.h:891
Area(const Area &range)=default
Copy C'tor.
void clear()
empty all dimensions
Definition: DimMapper.h:932
const AreaXYType & getAreaXY() const
Definition: DimMapper.h:886
A basic LC-MS feature.
Definition: BaseFeature.h:59
A 1-dimensional raw data point or peak for chromatograms.
Definition: ChromatogramPeak.h:54
IntensityType getIntensity() const
Non-mutable access to the data point intensity (height)
Definition: ChromatogramPeak.h:110
void setRT(CoordinateType rt)
Mutable access to RT.
Definition: ChromatogramPeak.h:121
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: ChromatogramPeak.h:112
double IntensityType
Intensity type.
Definition: ChromatogramPeak.h:63
CoordinateType getRT() const
Non-mutable access to RT.
Definition: ChromatogramPeak.h:115
const Precursor & getPrecursor() const
returns a const reference to the precursors
Representation of a coordinate in D-dimensional space.
Definition: DPosition.h:55
A base class for a dimension which represents a certain unit (e.g. RT or m/z). Derived classes implem...
Definition: DimMapper.h:67
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:69
std::string_view getDimNameShort() const
Name of the dimension, e.g. 'RT'.
Definition: DimMapper.h:149
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:76
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:174
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:70
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:143
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:155
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:518
ValueType map(const MSChromatogram &, const Size) const override
obtain value from a certain point in a chromatogram
Definition: DimMapper.h:566
ValueType map(const Peak2D &) const override
Definition: DimMapper.h:531
ValueType map(const BaseFeature &) const override
Definition: DimMapper.h:575
void setRange(const RangeBase &in, RangeAllType &out) const override
Set the min/max (range) in out for a certain dimension.
Definition: DimMapper.h:594
ValueType map(const PeptideIdentification &) const override
Definition: DimMapper.h:580
void fromXY(const ValueType, Peak1D &) const override
set the IM of a Peak1D (throws)
Definition: DimMapper.h:600
std::unique_ptr< DimBase > clone() const override
Copy derived objects to avoid slicing when dealing with pointers to DimBase.
Definition: DimMapper.h:522
ValueTypes map(const MSSpectrum &) const override
Definition: DimMapper.h:539
ValueType map(const MSSpectrum &spec, const Size) const override
obtain value from a certain point in a spectrum
Definition: DimMapper.h:562
ValueType map(const MSExperiment::ConstAreaIterator &it) const override
Definition: DimMapper.h:548
ValueType map(const ChromatogramPeak &) const override
Definition: DimMapper.h:535
void fromXY(const ValueType, ChromatogramPeak &) const override
set the IM of a ChromatogramPeak (throws)
Definition: DimMapper.h:606
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:589
ValueType map(const Mobilogram &mb, const Size index) const override
obtain value from a certain point in a mobilogram
Definition: DimMapper.h:570
RangeBase map(const RangeAllType &rm) const override
Return the min/max (range) for a certain dimension.
Definition: DimMapper.h:585
void fromXY(const ValueType in, MobilityPeak2D &p) const override
set the IM of a MobilityPeak2D
Definition: DimMapper.h:617
ValueType map(const MobilityPeak2D &p) const override
Definition: DimMapper.h:557
ValueType map(const MobilityPeak1D &p) const override
Definition: DimMapper.h:553
DimIM(const DIM_UNIT im_unit)
Definition: DimMapper.h:520
ValueTypes map(const MSChromatogram &) const override
Definition: DimMapper.h:543
ValueType map(const Peak1D &) const override
Definition: DimMapper.h:527
void fromXY(const ValueType in, MobilityPeak1D &p) const override
set the IM of a MobilityPeak1D
Definition: DimMapper.h:612
Definition: DimMapper.h:401
ValueType map(const Peak1D &p) const override
Definition: DimMapper.h:410
void setRange(const RangeBase &in, RangeAllType &out) const override
Set the min/max (range) in out for a certain dimension.
Definition: DimMapper.h:489
ValueType map(const Peak2D &p) const override
Definition: DimMapper.h:414
ValueType map(const PeptideIdentification &) const override
Definition: DimMapper.h:475
std::unique_ptr< DimBase > clone() const override
Copy derived objects to avoid slicing when dealing with pointers to DimBase.
Definition: DimMapper.h:405
ValueTypes map(const MSChromatogram &chrom) const override
Definition: DimMapper.h:459
ValueType map(const MSSpectrum &spec, const Size index) const override
obtain value from a certain point in a spectrum
Definition: DimMapper.h:435
ValueType map(const MSExperiment::ConstAreaIterator &it) const override
Definition: DimMapper.h:422
ValueType map(const ChromatogramPeak &p) const override
Definition: DimMapper.h:418
DimINT()
Definition: DimMapper.h:403
ValueTypes map(const MSSpectrum &spec) const override
Definition: DimMapper.h:448
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:484
ValueType map(const BaseFeature &bf) const override
Definition: DimMapper.h:470
ValueType map(const Mobilogram &mb, const Size index) const override
obtain value from a certain point in a mobilogram
Definition: DimMapper.h:443
RangeBase map(const RangeAllType &rm) const override
Return the min/max (range) for a certain dimension.
Definition: DimMapper.h:480
void fromXY(const ValueType in, MobilityPeak2D &p) const override
set the intensity of a MobilityPeak2D
Definition: DimMapper.h:511
ValueType map(const MobilityPeak2D &p) const override
Definition: DimMapper.h:430
ValueType map(const MobilityPeak1D &p) const override
Definition: DimMapper.h:426
void fromXY(const ValueType in, Peak1D &p) const override
set the intensity of a Peak1D
Definition: DimMapper.h:495
void fromXY(const ValueType in, ChromatogramPeak &p) const override
set the intensity of a ChromatogramPeak
Definition: DimMapper.h:501
ValueType map(const MSChromatogram &chrom, const Size index) const override
obtain value from a certain point in a chromatogram
Definition: DimMapper.h:439
void fromXY(const ValueType in, MobilityPeak1D &p) const override
set the intensity of a MobilityPeak1D
Definition: DimMapper.h:506
Definition: DimMapper.h:290
ValueType map(const Peak1D &p) const override
Definition: DimMapper.h:299
ValueType map(const Mobilogram &, const Size) const override
obtain value from a certain point in a mobilogram
Definition: DimMapper.h:332
void setRange(const RangeBase &in, RangeAllType &out) const override
Set the min/max (range) in out for a certain dimension.
Definition: DimMapper.h:371
DimMZ()
Definition: DimMapper.h:292
ValueType map(const MSChromatogram &chrom, const Size) const override
obtain value from a certain point in a chromatogram
Definition: DimMapper.h:328
ValueType map(const Peak2D &p) const override
Definition: DimMapper.h:303
std::unique_ptr< DimBase > clone() const override
Copy derived objects to avoid slicing when dealing with pointers to DimBase.
Definition: DimMapper.h:294
ValueType map(const MSSpectrum &spec, const Size index) const override
obtain value from a certain point in a spectrum
Definition: DimMapper.h:324
ValueType map(const MSExperiment::ConstAreaIterator &it) const override
Definition: DimMapper.h:311
ValueTypes map(const MSSpectrum &spec) const override
Definition: DimMapper.h:337
ValueType map(const ChromatogramPeak &) const override
Definition: DimMapper.h:307
void fromXY(const ValueType, ChromatogramPeak &) const override
set the MZ of a ChromatogramPeak (throws)
Definition: DimMapper.h:383
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:366
ValueType map(const BaseFeature &bf) const override
Definition: DimMapper.h:352
ValueType map(const PeptideIdentification &pi) const override
Definition: DimMapper.h:357
void fromXY(const ValueType, MobilityPeak1D &) const override
set the MZ of a MobilityPeak1D (throws)
Definition: DimMapper.h:389
RangeBase map(const RangeAllType &rm) const override
Return the min/max (range) for a certain dimension.
Definition: DimMapper.h:362
void fromXY(const ValueType in, MobilityPeak2D &p) const override
set the MZ of a MobilityPeak2D (throws)
Definition: DimMapper.h:394
ValueType map(const MobilityPeak2D &p) const override
Definition: DimMapper.h:319
ValueTypes map(const MSChromatogram &) const override
Definition: DimMapper.h:347
void fromXY(const ValueType in, Peak1D &p) const override
set the MZ of a Peak1D
Definition: DimMapper.h:377
ValueType map(const MobilityPeak1D &) const override
Definition: DimMapper.h:315
Allows dynamical switching (at runtime) between a dimension (RT, m/z, int, IM, etc) and X,...
Definition: DimMapper.h:645
static std::unique_ptr< const DimBase > create_(DIM_UNIT u)
a minimal factory
Definition: DimMapper.h:792
bool operator!=(const DimMapper &rhs) const
Inequality.
Definition: DimMapper.h:692
std::array< std::unique_ptr< const DimBase >, N_DIM > dims_
mappers for the X,Y,Z... dimension
Definition: DimMapper.h:811
bool operator==(const DimMapper &rhs) const
Equality.
Definition: DimMapper.h:681
void fromXY(const DRange< N_DIM > &in, RangeManager< Ranges... > &output) const
Definition: DimMapper.h:735
DimMapper & operator=(const DimMapper &rhs)
Assignment operator.
Definition: DimMapper.h:674
void fromXY(const Point &in, RangeManager< Ranges... > &output) const
Definition: DimMapper.h:750
DimMapper(const DimMapper &rhs)
Copy C'tor.
Definition: DimMapper.h:668
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:717
Point map(const T &data) const
convert an OpenMS datatype (such as Feature) to an N_DIM-dimensional point
Definition: DimMapper.h:699
const DimBase & getDim(DIM d) const
obtain unit/name for X/Y/Z dimension.
Definition: DimMapper.h:784
RangeAllType fromXY(const Point &in) const
Definition: DimMapper.h:773
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:653
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:707
void fromXY(const Point &in, T &out) const
Definition: DimMapper.h:762
Definition: DimMapper.h:180
void setRange(const RangeBase &in, RangeAllType &out) const override
Set the min/max (range) in out for a certain dimension.
Definition: DimMapper.h:261
ValueType map(const MobilityPeak2D &) const override
Definition: DimMapper.h:237
ValueType map(const Peak2D &p) const override
Definition: DimMapper.h:193
void fromXY(const ValueType, MobilityPeak2D &) const override
set the RT of a MobilityPeak2D (throws)
Definition: DimMapper.h:283
void fromXY(const ValueType, Peak1D &) const override
set the RT of a Peak1D (throws)
Definition: DimMapper.h:267
std::unique_ptr< DimBase > clone() const override
Copy derived objects to avoid slicing when dealing with pointers to DimBase.
Definition: DimMapper.h:184
ValueTypes map(const MSChromatogram &chrom) const override
Definition: DimMapper.h:218
ValueTypes map(const MSSpectrum &) const override
Definition: DimMapper.h:214
ValueType map(const MSSpectrum &spec, const Size) const override
obtain value from a certain point in a spectrum
Definition: DimMapper.h:201
ValueType map(const MSExperiment::ConstAreaIterator &it) const override
Definition: DimMapper.h:229
ValueType map(const ChromatogramPeak &p) const override
Definition: DimMapper.h:197
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:256
ValueType map(const BaseFeature &bf) const override
Definition: DimMapper.h:242
ValueType map(const PeptideIdentification &pi) const override
Definition: DimMapper.h:247
void fromXY(const ValueType, MobilityPeak1D &) const override
set the RT of a MobilityPeak1D (throws)
Definition: DimMapper.h:278
RangeBase map(const RangeAllType &rm) const override
Return the min/max (range) for a certain dimension.
Definition: DimMapper.h:252
DimRT()
Definition: DimMapper.h:182
ValueType map(const Mobilogram &mb, const Size) const override
obtain value from a certain point in a mobilogram
Definition: DimMapper.h:209
ValueType map(const Peak1D &) const override
Definition: DimMapper.h:189
void fromXY(const ValueType in, ChromatogramPeak &p) const override
set the RT of a ChromatogramPeak
Definition: DimMapper.h:273
ValueType map(const MobilityPeak1D &) const override
Definition: DimMapper.h:233
ValueType map(const MSChromatogram &chrom, const Size index) const override
obtain value from a certain point in a chromatogram
Definition: DimMapper.h:205
Invalid range exception.
Definition: Exception.h:278
Not implemented exception.
Definition: Exception.h:430
Precondition failed exception.
Definition: Exception.h:159
Forward iterator for an area of peaks in an experiment.
Definition: AreaIterator.h:62
CoordinateType getDriftTime() const
returns the ion mobility time of the current scan
Definition: AreaIterator.h:274
CoordinateType getRT() const
returns the retention time of the current scan
Definition: AreaIterator.h:268
void setDimMinMax(UInt dim, const DIntervalBase< 1 > &min_max)
only set interval for a single dimension
Definition: DIntervalBase.h:254
PositionType const & maxPosition() const
Accessor to maximum position.
Definition: DIntervalBase.h:130
bool isEmpty() const
Definition: DIntervalBase.h:242
static DIntervalBase const empty
empty instance
Definition: DIntervalBase.h:284
PositionType const & minPosition() const
Accessor to minimum position.
Definition: DIntervalBase.h:124
The representation of a chromatogram.
Definition: MSChromatogram.h:57
The representation of a 1D spectrum.
Definition: MSSpectrum.h:70
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:51
IntensityType getIntensity() const
Definition: MobilityPeak1D.h:105
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: MobilityPeak1D.h:110
void setMobility(CoordinateType mobility)
Mutable access to mobility.
Definition: MobilityPeak1D.h:122
CoordinateType getMobility() const
Non-mutable access to m/z.
Definition: MobilityPeak1D.h:116
float IntensityType
Intensity type.
Definition: MobilityPeak1D.h:58
A 2-dimensional raw data point or peak.
Definition: MobilityPeak2D.h:55
CoordinateType getMZ() const
Returns the m/z coordinate (index 1)
Definition: MobilityPeak2D.h:194
void setMZ(CoordinateType coordinate)
Mutable access to the m/z coordinate (index 1)
Definition: MobilityPeak2D.h:200
void setMobility(CoordinateType coordinate)
Mutable access to the IM coordinate (index 0)
Definition: MobilityPeak2D.h:212
float IntensityType
Intensity type.
Definition: MobilityPeak2D.h:61
IntensityType getIntensity() const
Definition: MobilityPeak2D.h:164
void setIntensity(IntensityType intensity)
Sets data point intensity (height)
Definition: MobilityPeak2D.h:170
CoordinateType getMobility() const
Returns the IM coordinate (index 0)
Definition: MobilityPeak2D.h:206
The representation of a 1D ion mobilogram.
Definition: Mobilogram.h:55
double getRT() const noexcept
Definition: Mobilogram.h:262
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:54
CoordinateType getMZ() const
Non-mutable access to m/z.
Definition: Peak1D.h:113
IntensityType getIntensity() const
Definition: Peak1D.h:108
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: Peak1D.h:110
void setMZ(CoordinateType mz)
Mutable access to m/z.
Definition: Peak1D.h:119
float IntensityType
Intensity type.
Definition: Peak1D.h:62
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:55
CoordinateType getMZ() const
Returns the m/z coordinate (index 1)
Definition: Peak2D.h:198
IntensityType getIntensity() const
Definition: Peak2D.h:168
CoordinateType getRT() const
Returns the RT coordinate (index 0)
Definition: Peak2D.h:210
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:65
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:704
const RangeBase & getRangeForDim(MSDim dim) const
obtain a range dimension at runtime using dim
Definition: RangeManager.h:748
auto & assign(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:612
A more convenient string class.
Definition: String.h:60
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
static String prefix(const String &this_s, size_t length)
Definition: StringUtilsSimple.h:147
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
DIM
Definition: DimMapper.h:627
RangeManager< RangeRT, RangeMZ, RangeIntensity, RangeMobility > RangeAllType
Range which contains all known dimensions.
Definition: RangeManager.h:923
DIM_UNIT
Definition: CommonEnums.h:46
@ 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:55
std::string_view DIM_NAMES_SHORT[(int) DIM_UNIT::SIZE_OF_DIM_UNITS]
Definition: CommonEnums.h:56
Base class for a simple range with minimum and maximum.
Definition: RangeManager.h:64
double getMin() const
only useful if isEmpty() returns false
Definition: RangeManager.h:148
bool isEmpty() const
is the range empty (i.e. min > max)?
Definition: RangeManager.h:108
double getMax() const
only useful if isEmpty() returns false
Definition: RangeManager.h:154