Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
MSExperiment.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-2017.
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: Timo Sachsenberg$
32 // $Authors: Marc Sturm $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_KERNEL_MSEXPERIMENT_H
36 #define OPENMS_KERNEL_MSEXPERIMENT_H
37 
45 #include <OpenMS/KERNEL/Peak1D.h>
48 #include <OpenMS/SYSTEM/File.h>
49 
50 #include <vector>
51 #include <algorithm>
52 #include <limits>
53 
54 namespace OpenMS
55 {
56  class Peak1D;
57 
82  class MSExperiment :
83  public RangeManager<2>,
85  {
86 
87 public:
88  typedef Peak1D PeakT;
90 
92 
93  typedef PeakT PeakType;
96  typedef ChromatogramPeakT ChromatogramPeakType;
110  typedef std::vector<SpectrumType> Base;
112 
114 
115  typedef std::vector<SpectrumType>::iterator Iterator;
118  typedef std::vector<SpectrumType>::const_iterator ConstIterator;
124 
126  // Attention: these refer to the spectra vector only!
128  typedef Base::value_type value_type;
129  typedef Base::iterator iterator;
130  typedef Base::const_iterator const_iterator;
131 
132  inline Size size() const
133  {
134  return spectra_.size();
135  }
136 
137  inline void resize(Size s)
138  {
139  spectra_.resize(s);
140  }
141 
142  inline bool empty() const
143  {
144  return spectra_.empty();
145  }
146 
147  inline void reserve(Size s)
148  {
149  spectra_.reserve(s);
150  }
151 
152  inline SpectrumType& operator[] (Size n)
153  {
154  return spectra_[n];
155  }
156 
157  inline const SpectrumType& operator[] (Size n) const
158  {
159  return spectra_[n];
160  }
161 
162  inline Iterator begin()
163  {
164  return spectra_.begin();
165  }
166 
167  inline ConstIterator begin() const
168  {
169  return spectra_.begin();
170  }
171 
172  inline Iterator end()
173  {
174  return spectra_.end();
175  }
176 
177  inline ConstIterator end() const
178  {
179  return spectra_.end();
180  }
182 
183  // Aliases / chromatograms
184  inline void reserveSpaceSpectra(Size s)
185  {
186  spectra_.reserve(s);
187  }
189  {
190  chromatograms_.reserve(s);
191  }
192 
195  RangeManagerType(),
197  ms_levels_(),
198  total_size_(0)
199  {}
200 
202  MSExperiment(const MSExperiment & source) :
203  RangeManagerType(source),
204  ExperimentalSettings(source),
205  ms_levels_(source.ms_levels_),
206  total_size_(source.total_size_),
208  spectra_(source.spectra_)
209  {}
210 
213  {
214  if (&source == this) return *this;
215 
218 
219  ms_levels_ = source.ms_levels_;
220  total_size_ = source.total_size_;
222  spectra_ = source.spectra_;
223 
224  //no need to copy the alloc?!
225  //alloc_
226 
227  return *this;
228  }
229 
232  {
234  return *this;
235  }
236 
238  bool operator==(const MSExperiment & rhs) const
239  {
240  return ExperimentalSettings::operator==(rhs) &&
241  chromatograms_ == rhs.chromatograms_ &&
242  spectra_ == rhs.spectra_;
243  }
244 
246  bool operator!=(const MSExperiment & rhs) const
247  {
248  return !(operator==(rhs));
249  }
250 
252 
253 
259  template <class Container>
260  void get2DData(Container & cont) const
261  {
262  for (typename Base::const_iterator spec = spectra_.begin(); spec != spectra_.end(); ++spec)
263  {
264  if (spec->getMSLevel() != 1)
265  {
266  continue;
267  }
268  typename Container::value_type s; // explicit object here, since instantiation within push_back() fails on VS<12
269  for (typename SpectrumType::const_iterator it = spec->begin(); it != spec->end(); ++it)
270  {
271  cont.push_back(s);
272  cont.back().setRT(spec->getRT());
273  cont.back().setMZ(it->getMZ());
274  cont.back().setIntensity(it->getIntensity());
275  }
276  }
277  }
278 
290  template <class Container>
291  void set2DData(const Container& container)
292  {
293  set2DData<false, Container>(container);
294  }
295 
310  template <class Container>
311  void set2DData(const Container& container, const StringList& store_metadata_names)
312  {
313  // clean up the container first
314  clear(true);
315  SpectrumType* spectrum = 0;
316  typename PeakType::CoordinateType current_rt = -std::numeric_limits<typename PeakType::CoordinateType>::max();
317  for (typename Container::const_iterator iter = container.begin(); iter != container.end(); ++iter)
318  {
319  // check if the retention time has changed
320  if (current_rt != iter->getRT() || spectrum == 0)
321  {
322  // append new spectrum
323  if (current_rt > iter->getRT())
324  {
325  throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Input container is not sorted!");
326  }
327  current_rt = iter->getRT();
328  spectrum = createSpec_(current_rt, store_metadata_names);
329  }
330 
331  // add either data point or mass traces (depending on template argument value)
332  ContainerAdd_<typename Container::value_type, false>::addData_(spectrum, &(*iter), store_metadata_names);
333  }
334  }
335 
353  template <bool add_mass_traces, class Container>
354  void set2DData(const Container& container)
355  {
356  // clean up the container first
357  clear(true);
358  SpectrumType* spectrum = 0;
359  typename PeakType::CoordinateType current_rt = -std::numeric_limits<typename PeakType::CoordinateType>::max();
360  for (typename Container::const_iterator iter = container.begin(); iter != container.end(); ++iter)
361  {
362  // check if the retention time has changed
363  if (current_rt != iter->getRT() || spectrum == 0)
364  {
365  // append new spectrum
366  if (current_rt > iter->getRT())
367  {
368  throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Input container is not sorted!");
369  }
370  current_rt = iter->getRT();
371  spectrum = createSpec_(current_rt);
372  }
373 
374  // add either data point or mass traces (depending on template argument value)
376  }
377  }
378 
380 
381 
383 
384  AreaIterator areaBegin(CoordinateType min_rt, CoordinateType max_rt, CoordinateType min_mz, CoordinateType max_mz)
386  {
387  OPENMS_PRECONDITION(min_rt <= max_rt, "Swapped RT range boundaries!")
388  OPENMS_PRECONDITION(min_mz <= max_mz, "Swapped MZ range boundaries!")
389  OPENMS_PRECONDITION(this->isSorted(true), "Experiment is not sorted by RT and m/z! Using AreaIterator will give invalid results!")
390  //std::cout << "areaBegin: " << min_rt << " " << max_rt << " " << min_mz << " " << max_mz << std::endl;
391  return AreaIterator(spectra_.begin(), RTBegin(min_rt), RTEnd(max_rt), min_mz, max_mz);
392  }
393 
395  AreaIterator areaEnd()
396  {
397  return AreaIterator();
398  }
399 
401  ConstAreaIterator areaBeginConst(CoordinateType min_rt, CoordinateType max_rt, CoordinateType min_mz, CoordinateType max_mz) const
402  {
403  OPENMS_PRECONDITION(min_rt <= max_rt, "Swapped RT range boundaries!")
404  OPENMS_PRECONDITION(min_mz <= max_mz, "Swapped MZ range boundaries!")
405  OPENMS_PRECONDITION(this->isSorted(true), "Experiment is not sorted by RT and m/z! Using ConstAreaIterator will give invalid results!")
406  //std::cout << "areaBeginConst: " << min_rt << " " << max_rt << " " << min_mz << " " << max_mz << std::endl;
407  return ConstAreaIterator(spectra_.begin(), RTBegin(min_rt), RTEnd(max_rt), min_mz, max_mz);
408  }
409 
411  ConstAreaIterator areaEndConst() const
412  {
413  return ConstAreaIterator();
414  }
415 
423  ConstIterator RTBegin(CoordinateType rt) const
424  {
425  SpectrumType s;
426  s.setRT(rt);
427  return lower_bound(spectra_.begin(), spectra_.end(), s, SpectrumType::RTLess());
428  }
429 
437  ConstIterator RTEnd(CoordinateType rt) const
438  {
439  SpectrumType s;
440  s.setRT(rt);
441  return upper_bound(spectra_.begin(), spectra_.end(), s, SpectrumType::RTLess());
442  }
443 
449  Iterator RTBegin(CoordinateType rt)
450  {
451  SpectrumType s;
452  s.setRT(rt);
453  return lower_bound(spectra_.begin(), spectra_.end(), s, SpectrumType::RTLess());
454  }
455 
461  Iterator RTEnd(CoordinateType rt)
462  {
463  SpectrumType s;
464  s.setRT(rt);
465  return upper_bound(spectra_.begin(), spectra_.end(), s, SpectrumType::RTLess());
466  }
467 
469 
475  // Docu in base class
477  virtual void updateRanges()
478  {
479  updateRanges(-1);
480  }
481 
487  void updateRanges(Int ms_level)
488  {
489  //clear MS levels
490  ms_levels_.clear();
491 
492  //reset mz/rt/int range
493  this->clearRanges();
494  //reset point count
495  total_size_ = 0;
496 
497  //empty
498  if (spectra_.empty() && chromatograms_.empty())
499  {
500  return;
501  }
502 
503  //update
504  for (Base::iterator it = spectra_.begin(); it != spectra_.end(); ++it)
505  {
506  if (ms_level < Int(0) || Int(it->getMSLevel()) == ms_level)
507  {
508  //ms levels
509  if (std::find(ms_levels_.begin(), ms_levels_.end(), it->getMSLevel()) == ms_levels_.end())
510  {
511  ms_levels_.push_back(it->getMSLevel());
512  }
513 
514  // calculate size
515  total_size_ += it->size();
516 
517  //rt
518  if (it->getRT() < RangeManagerType::pos_range_.minX()) RangeManagerType::pos_range_.setMinX(it->getRT());
519  if (it->getRT() > RangeManagerType::pos_range_.maxX()) RangeManagerType::pos_range_.setMaxX(it->getRT());
520 
521  //do not update mz and int when the spectrum is empty
522  if (it->size() == 0) continue;
523 
524  it->updateRanges();
525 
526  //mz
527  if (it->getMin()[0] < RangeManagerType::pos_range_.minY()) RangeManagerType::pos_range_.setMinY(it->getMin()[0]);
528  if (it->getMax()[0] > RangeManagerType::pos_range_.maxY()) RangeManagerType::pos_range_.setMaxY(it->getMax()[0]);
529 
530  //int
531  if (it->getMinInt() < RangeManagerType::int_range_.minX()) RangeManagerType::int_range_.setMinX(it->getMinInt());
532  if (it->getMaxInt() > RangeManagerType::int_range_.maxX()) RangeManagerType::int_range_.setMaxX(it->getMaxInt());
533 
534  }
535  // for MS level = 1 we extend the range for all the MS2 precursors
536  if (ms_level == 1 && it->getMSLevel() == 2)
537  {
538  if (!it->getPrecursors().empty())
539  {
540  double pc_rt = it->getRT();
541  if (pc_rt < RangeManagerType::pos_range_.minX()) RangeManagerType::pos_range_.setMinX(pc_rt);
542  if (pc_rt > RangeManagerType::pos_range_.maxX()) RangeManagerType::pos_range_.setMaxX(pc_rt);
543  double pc_mz = it->getPrecursors()[0].getMZ();
544  if (pc_mz < RangeManagerType::pos_range_.minY()) RangeManagerType::pos_range_.setMinY(pc_mz);
545  if (pc_mz > RangeManagerType::pos_range_.maxY()) RangeManagerType::pos_range_.setMaxY(pc_mz);
546  }
547 
548  }
549 
550  }
551  std::sort(ms_levels_.begin(), ms_levels_.end());
552 
553 
554 
555 
556  if (this->chromatograms_.empty())
557  {
558  return;
559  }
560 
561  //TODO CHROM update intensity, m/z and RT according to chromatograms as well! (done????)
562 
563  for (std::vector<ChromatogramType>::iterator it = chromatograms_.begin(); it != chromatograms_.end(); ++it)
564  {
565 
566  // ignore TICs and ECs (as these are usually positioned at 0 and therefor lead to a large white margin in plots if included)
567  if (it->getChromatogramType() == ChromatogramSettings::TOTAL_ION_CURRENT_CHROMATOGRAM ||
568  it->getChromatogramType() == ChromatogramSettings::EMISSION_CHROMATOGRAM)
569  {
570  continue;
571  }
572 
573  // update MZ
574  if (it->getMZ() < RangeManagerType::pos_range_.minY()) RangeManagerType::pos_range_.setMinY(it->getMZ());
575  if (it->getMZ() > RangeManagerType::pos_range_.maxY()) RangeManagerType::pos_range_.setMaxY(it->getMZ());
576 
577  // do not update RT and in if the spectrum is empty
578  if (it->size() == 0) continue;
579 
580  total_size_ += it->size();
581 
582  it->updateRanges();
583 
584  // RT
585  if (it->getMin()[0] < RangeManagerType::pos_range_.minX()) RangeManagerType::pos_range_.setMinX(it->getMin()[0]);
586  if (it->getMax()[0] > RangeManagerType::pos_range_.maxX()) RangeManagerType::pos_range_.setMaxX(it->getMax()[0]);
587 
588  // int
589  if (it->getMinInt() < RangeManagerType::int_range_.minX()) RangeManagerType::int_range_.setMinX(it->getMinInt());
590  if (it->getMaxInt() > RangeManagerType::int_range_.maxX()) RangeManagerType::int_range_.setMaxX(it->getMaxInt());
591  }
592  }
593 
595  CoordinateType getMinMZ() const
596  {
597  return RangeManagerType::pos_range_.minPosition()[1];
598  }
599 
601  CoordinateType getMaxMZ() const
602  {
603  return RangeManagerType::pos_range_.maxPosition()[1];
604  }
605 
607  CoordinateType getMinRT() const
608  {
609  return RangeManagerType::pos_range_.minPosition()[0];
610  }
611 
613  CoordinateType getMaxRT() const
614  {
615  return RangeManagerType::pos_range_.maxPosition()[0];
616  }
617 
623  const AreaType & getDataRange() const
624  {
626  }
627 
629  UInt64 getSize() const
630  {
631  return total_size_;
632  }
633 
635  const std::vector<UInt> & getMSLevels() const
636  {
637  return ms_levels_;
638  }
639 
641 
644 
649  void sortSpectra(bool sort_mz = true)
650  {
651  std::sort(spectra_.begin(), spectra_.end(), SpectrumType::RTLess());
652 
653  if (sort_mz)
654  {
655  // sort each spectrum by m/z
656  for (Iterator iter = spectra_.begin(); iter != spectra_.end(); ++iter)
657  {
658  iter->sortByPosition();
659  }
660  }
661  }
662 
668  void sortChromatograms(bool sort_rt = true)
669  {
670  // sort the chromatograms according to their product m/z
671  std::sort(chromatograms_.begin(), chromatograms_.end(), ChromatogramType::MZLess());
672 
673  if (sort_rt)
674  {
675  for (std::vector<ChromatogramType>::iterator it = chromatograms_.begin(); it != chromatograms_.end(); ++it)
676  {
677  it->sortByPosition();
678  }
679  }
680  }
681 
687  bool isSorted(bool check_mz = true) const
688  {
689  //check RT positions
690  for (Size i = 1; i < spectra_.size(); ++i)
691  {
692  if (spectra_[i - 1].getRT() > spectra_[i].getRT()) return false;
693  }
694  //check spectra
695  if (check_mz)
696  {
697  for (Size i = 0; i < spectra_.size(); ++i)
698  {
699  if (!spectra_[i].isSorted()) return false;
700  }
701  }
702  // TODO CHROM
703  return true;
704  }
705 
707 
709  void reset()
710  {
711  spectra_.clear(); //remove data
712  RangeManagerType::clearRanges(); //reset range manager
714  }
715 
722  {
723  bool meta_present = false;
724  for (Size i = 0; i < spectra_.size(); ++i)
725  {
726  if (spectra_[i].getFloatDataArrays().size() != 0 || spectra_[i].getIntegerDataArrays().size() != 0 || spectra_[i].getStringDataArrays().size() != 0)
727  {
728  meta_present = true;
729  }
730  spectra_[i].getStringDataArrays().clear();
731  spectra_[i].getIntegerDataArrays().clear();
732  spectra_[i].getFloatDataArrays().clear();
733  }
734  return meta_present;
735  }
736 
739  {
740  return *this;
741  }
742 
745  {
746  return *this;
747  }
748 
750  void getPrimaryMSRunPath(StringList& toFill) const
751  {
752  std::vector<SourceFile> sfs(this->getSourceFiles());
753  for (std::vector<SourceFile>::const_iterator it = sfs.begin(); it != sfs.end(); ++it)
754  {
755  // assemble a single location string from the URI (path to file) and file name
756  String path = it->getPathToFile();
757  String filename = it->getNameOfFile();
758 
759  if (path.empty() || filename.empty())
760  {
761  LOG_WARN << "Path or file name of primary MS run is empty. "
762  << "This might be the result of incomplete conversion. "
763  << "Not that tracing back e.g. identification results to the original file might more difficult." << std::endl;
764  }
765  else
766  {
767  String ms_run_location = path + "/" + filename;
768  toFill.push_back(ms_run_location);
769  }
770  }
771  }
772 
778  ConstIterator getPrecursorSpectrum(ConstIterator iterator) const
779  {
780  if (iterator == spectra_.end() || iterator == spectra_.begin())
781  {
782  return spectra_.end();
783  }
784  UInt ms_level = iterator->getMSLevel();
785  do
786  {
787  --iterator;
788  if (iterator->getMSLevel() < ms_level)
789  {
790  return iterator;
791  }
792  }
793  while (iterator != spectra_.begin());
794 
795  return spectra_.end();
796  }
797 
799  void swap(MSExperiment & from)
800  {
801  MSExperiment tmp;
802 
803  //swap range information
804  tmp.RangeManagerType::operator=(* this);
805  this->RangeManagerType::operator=(from);
806  from.RangeManagerType::operator=(tmp);
807 
808  //swap experimental settings
809  tmp.ExperimentalSettings::operator=(* this);
811  from.ExperimentalSettings::operator=(tmp);
812 
813  // swap chromatograms
814  std::swap(chromatograms_, from.chromatograms_);
815 
816  //swap peaks
817  spectra_.swap(from.getSpectra());
818 
819  //swap remaining members
820  ms_levels_.swap(from.ms_levels_);
821  std::swap(total_size_, from.total_size_);
822  }
823 
825  void setSpectra(const std::vector<MSSpectrum> & spectra)
826  {
827  spectra_ = spectra;
828  }
829 
831  void addSpectrum(const MSSpectrum & spectrum)
832  {
833  spectra_.push_back(spectrum);
834  }
835 
837  const std::vector<MSSpectrum> & getSpectra() const
838  {
839  return spectra_;
840  }
841 
843  std::vector<MSSpectrum> & getSpectra()
844  {
845  return spectra_;
846  }
847 
849  void setChromatograms(const std::vector<MSChromatogram > & chromatograms)
850  {
851  chromatograms_ = chromatograms;
852  }
853 
855  void addChromatogram(const MSChromatogram & chromatogram)
856  {
857  chromatograms_.push_back(chromatogram);
858  }
859 
861  const std::vector<MSChromatogram > & getChromatograms() const
862  {
863  return chromatograms_;
864  }
865 
867  std::vector<MSChromatogram > & getChromatograms()
868  {
869  return chromatograms_;
870  }
871 
873 
876  {
877  return chromatograms_[id];
878  }
879 
882  {
883  return spectra_[id];
884  }
885 
887  inline Size getNrSpectra() const
888  {
889  return spectra_.size();
890  }
891 
893  inline Size getNrChromatograms() const
894  {
895  return chromatograms_.size();
896  }
898 
900  const MSChromatogram getTIC() const
901  {
902  // The TIC is (re)calculated from the MS1 spectra. Even if MSExperiment does not contain a TIC chromatogram explicitly, it can be reported.
903  MSChromatogram TIC;
904  for (Base::const_iterator spec_it = spectra_.begin(); spec_it != spectra_.end(); ++spec_it)
905  {
906  if (spec_it->getMSLevel() == 1)
907  {
908  double totalIntensity = 0;
909  // sum intensities of a spectrum
910  for (SpectrumType::const_iterator peak_it = spec_it->begin(); peak_it != spec_it->end(); ++peak_it)
911  {
912  totalIntensity += static_cast<double>(peak_it->getIntensity());
913  }
914  // fill chromatogram
915  ChromatogramPeakType peak;
916  peak.setRT(spec_it->getRT());
917  peak.setIntensity(totalIntensity);
918  TIC.push_back(peak);
919  }
920  }
921  return TIC;
922  }
923 
929  void clear(bool clear_meta_data)
930  {
931  spectra_.clear();
932 
933  if (clear_meta_data)
934  {
935  clearRanges();
936  this->ExperimentalSettings::operator=(ExperimentalSettings()); // no "clear" method
937  chromatograms_.clear();
938  ms_levels_.clear();
939  total_size_ = 0;
940  }
941  }
942 
943 protected:
944 
945 
947  std::vector<UInt> ms_levels_;
950 
952  std::vector<MSChromatogram > chromatograms_;
953 
955  std::vector<SpectrumType> spectra_;
956 
957 private:
958 
960  template<typename ContainerValueType, bool addMassTraces>
962  {
963  static void addData_(SpectrumType* spectrum, const ContainerValueType* item);
964  static void addData_(SpectrumType* spectrum, const ContainerValueType* item, const StringList& store_metadata_names);
965  };
966 
967  template<typename ContainerValueType>
968  struct ContainerAdd_<ContainerValueType, false>
969  {
971  static void addData_(SpectrumType* spectrum, const ContainerValueType* item)
972  {
973  // create temporary peak and insert it into spectrum
974  spectrum->insert(spectrum->end(), PeakType());
975  spectrum->back().setIntensity(item->getIntensity());
976  spectrum->back().setPosition(item->getMZ());
977  }
979  static void addData_(SpectrumType* spectrum, const ContainerValueType* item, const StringList& store_metadata_names)
980  {
981  addData_(spectrum, item);
982  for (StringList::const_iterator itm = store_metadata_names.begin(); itm != store_metadata_names.end(); ++itm)
983  {
984  float val = std::numeric_limits<float>::quiet_NaN();
985  if (item->metaValueExists(*itm)) val = item->getMetaValue(*itm);
986  spectrum->getFloatDataArrays()[itm - store_metadata_names.begin()].push_back(val);
987  }
988  }
989  };
990 
991  template<typename ContainerValueType>
992  struct ContainerAdd_<ContainerValueType, true>
993  {
995  static void addData_(SpectrumType* spectrum, const ContainerValueType* item)
996  {
997  if (item->metaValueExists("num_of_masstraces"))
998  {
999  Size mts = item->getMetaValue("num_of_masstraces");
1000  int charge = (item->getCharge()==0 ? 1 : item->getCharge()); // set to 1 if charge is 0, otherwise div/0 below
1001  for (Size i = 0; i < mts; ++i)
1002  {
1003  String meta_name = String("masstrace_intensity_") + i;
1004  if (!item->metaValueExists(meta_name))
1005  {
1006  throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, String("Meta value '") + meta_name + "' expected but not found in container.");
1007  }
1008  ContainerValueType p;
1009  p.setIntensity(item->getMetaValue(meta_name));
1010  p.setPosition(item->getMZ() + Constants::C13C12_MASSDIFF_U / charge * i);
1012  }
1013  }
1015  }
1016  };
1017 
1018  /*
1019  @brief Append a spectrum to current MSExperiment
1020 
1021  @param rt RT of new spectrum
1022  @return Pointer to newly created spectrum
1023  */
1025  {
1026  SpectrumType* spectrum = 0;
1027  spectra_.insert(spectra_.end(), SpectrumType());
1028  spectrum = &(spectra_.back());
1029  spectrum->setRT(rt);
1030  spectrum->setMSLevel(1);
1031  return spectrum;
1032  }
1033 
1034  /*
1035  @brief Append a spectrum including floatdata arrays to current MSExperiment
1036 
1037  @param rt RT of new spectrum
1038  @param metadata_names Names of floatdata arrays attached to this spectrum
1039  @return Pointer to newly created spectrum
1040  */
1041  SpectrumType* createSpec_(PeakType::CoordinateType rt, const StringList& metadata_names)
1042  {
1043  SpectrumType* spectrum = createSpec_(rt);
1044  // create metadata arrays
1045  spectrum->getFloatDataArrays().reserve(metadata_names.size());
1046  StringList::const_iterator itm = metadata_names.begin();
1047  for (; itm != metadata_names.end(); ++itm)
1048  {
1049  spectrum->getFloatDataArrays().push_back(MSSpectrum::FloatDataArray());
1050  spectrum->getFloatDataArrays().back().setName(*itm);
1051  }
1052  return spectrum;
1053  }
1054 
1055  };
1056 
1058  inline std::ostream & operator<<(std::ostream & os, const MSExperiment & exp)
1059  {
1060  os << "-- MSEXPERIMENT BEGIN --" << std::endl;
1061 
1062  //experimental settings
1063  os << static_cast<const ExperimentalSettings &>(exp);
1064 
1065  //spectra
1066  for (std::vector<MSSpectrum>::const_iterator it = exp.getSpectra().begin(); it != exp.getSpectra().end(); ++it)
1067  {
1068  os << *it;
1069  }
1070 
1071  //chromatograms
1072  for (std::vector<MSChromatogram >::const_iterator it = exp.getChromatograms().begin(); it != exp.getChromatograms().end(); ++it)
1073  {
1074  os << *it;
1075  }
1076 
1077  os << "-- MSEXPERIMENT END --" << std::endl;
1078 
1079  return os;
1080  }
1081 
1082 } // namespace OpenMS
1083 
1085 
1086 #endif // OPENMS_KERNEL_MSEXPERIMENT_H
1087 
void setRT(CoordinateType rt)
Mutable access to RT.
Definition: ChromatogramPeak.h:117
ConstIterator RTBegin(CoordinateType rt) const
Fast search for spectrum range begin.
Definition: MSExperiment.h:423
CoordinateType getMaxRT() const
returns the maximal retention time value
Definition: MSExperiment.h:613
bool operator==(const ExperimentalSettings &rhs) const
Equality operator.
const double C13C12_MASSDIFF_U
const std::vector< MSChromatogram > & getChromatograms() const
returns the chromatogram list
Definition: MSExperiment.h:861
A more convenient string class.
Definition: String.h:57
void reserveSpaceChromatograms(Size s)
Definition: MSExperiment.h:188
void set2DData(const Container &container)
Assignment of a data container with RT and MZ to an MSExperiment.
Definition: MSExperiment.h:354
static void addData_(SpectrumType *spectrum, const ContainerValueType *item)
general method for adding data points
Definition: MSExperiment.h:971
void reset()
Resets all internal values.
Definition: MSExperiment.h:709
PositionRangeType pos_range_
Position range (D-dimensional)
Definition: RangeManager.h:151
std::vector< SpectrumType >::iterator Iterator
Mutable iterator.
Definition: MSExperiment.h:116
Peak1D PeakT
Definition: MSExperiment.h:88
void addSpectrum(const MSSpectrum &spectrum)
adds a spectrum to the list
Definition: MSExperiment.h:831
The representation of a chromatogram.
Definition: MSChromatogram.h:55
CoordinateType maxX() const
Accessor for min_ coordinate maximum.
Definition: DIntervalBase.h:253
Base::value_type value_type
Definition: MSExperiment.h:128
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:107
Comparator for the retention time.
Definition: MSSpectrum.h:75
Iterator RTEnd(CoordinateType rt)
Fast search for spectrum range end (returns the past-the-end iterator)
Definition: MSExperiment.h:461
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
ConstAreaIterator areaEndConst() const
Returns an non-mutable invalid area iterator marking the end of an area.
Definition: MSExperiment.h:411
bool clearMetaDataArrays()
Clears the meta data arrays of all contained spectra (float, integer and string arrays) ...
Definition: MSExperiment.h:721
MSExperiment()
Constructor.
Definition: MSExperiment.h:194
ChromatogramPeakT ChromatogramPeakType
Chromatogram peak type.
Definition: MSExperiment.h:96
Forward iterator for an area of peaks in an experiment.
Definition: AreaIterator.h:58
ConstIterator end() const
Definition: MSExperiment.h:177
std::vector< MSChromatogram > chromatograms_
chromatograms
Definition: MSExperiment.h:952
SpectrumType * createSpec_(PeakType::CoordinateType rt)
Definition: MSExperiment.h:1024
Iterator begin()
Definition: MSExperiment.h:162
SpectrumType * createSpec_(PeakType::CoordinateType rt, const StringList &metadata_names)
Definition: MSExperiment.h:1041
void sortSpectra(bool sort_mz=true)
Sorts the data points by retention time.
Definition: MSExperiment.h:649
Base::const_iterator const_iterator
Definition: MSExperiment.h:130
const std::vector< UInt > & getMSLevels() const
returns an array of MS levels
Definition: MSExperiment.h:635
void setChromatograms(const std::vector< MSChromatogram > &chromatograms)
sets the chromatogram list
Definition: MSExperiment.h:849
void resize(Size s)
Definition: MSExperiment.h:137
std::vector< MSSpectrum > & getSpectra()
returns the spectrum list (mutable)
Definition: MSExperiment.h:843
PeakType::IntensityType IntensityType
Intensity type of peaks.
Definition: MSExperiment.h:102
void swap(MSExperiment &from)
Swaps the content of this map with the content of from.
Definition: MSExperiment.h:799
void addChromatogram(const MSChromatogram &chromatogram)
adds a chromatogram to the list
Definition: MSExperiment.h:855
Size size() const
Definition: MSExperiment.h:132
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Precondition failed exception.
Definition: Exception.h:167
MSSpectrum & getSpectrum(Size id)
returns a single spectrum
Definition: MSExperiment.h:881
bool isSorted(bool check_mz=true) const
Checks if all spectra are sorted with respect to ascending RT.
Definition: MSExperiment.h:687
const FloatDataArrays & getFloatDataArrays() const
Returns a const reference to the float meta data arrays.
MSSpectrum SpectrumType
Spectrum Type.
Definition: MSExperiment.h:106
Float data array class.
Definition: DataArrays.h:46
SpectrumType & operator[](Size n)
Definition: MSExperiment.h:152
RangeManager< 2 > RangeManagerType
RangeManager type.
Definition: MSExperiment.h:104
std::vector< MSChromatogram > & getChromatograms()
returns the chromatogram list (mutable)
Definition: MSExperiment.h:867
#define LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged...
Definition: LogStream.h:451
Iterator end()
Definition: MSExperiment.h:172
static void addData_(SpectrumType *spectrum, const ContainerValueType *item)
Base::iterator iterator
Definition: MSExperiment.h:129
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
void sortChromatograms(bool sort_rt=true)
Sorts the data points of the chromatograms by m/z.
Definition: MSExperiment.h:668
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:120
void updateRanges(Int ms_level)
Updates the m/z, intensity, retention time and MS level ranges of all spectra with a certain ms level...
Definition: MSExperiment.h:487
bool operator!=(const MSExperiment &rhs) const
Equality operator.
Definition: MSExperiment.h:246
const std::vector< SourceFile > & getSourceFiles() const
returns a const reference to the source data file
Comparator for the retention time.
Definition: MSChromatogram.h:64
void reserve(Size s)
Definition: MSExperiment.h:147
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:311
Size getNrChromatograms() const
get the total number of chromatograms available
Definition: MSExperiment.h:893
RangeManager & operator=(const RangeManager &rhs)
Assignment operator.
Definition: RangeManager.h:77
void getPrimaryMSRunPath(StringList &toFill) const
get the file path to the first MS run
Definition: MSExperiment.h:750
Helper class to add either general data points in set2DData or use mass traces from meta values...
Definition: MSExperiment.h:961
Size getNrSpectra() const
get the total number of spectra available
Definition: MSExperiment.h:887
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:55
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
void clearRanges()
Resets the ranges.
Definition: RangeManager.h:140
void setMSLevel(UInt ms_level)
Sets the MS level.
ChromatogramPeak ChromatogramPeakT
Definition: MSExperiment.h:89
Definition: ChromatogramSettings.h:77
AreaIterator areaBegin(CoordinateType min_rt, CoordinateType max_rt, CoordinateType min_mz, CoordinateType max_mz)
Returns an area iterator for area.
Definition: MSExperiment.h:385
PeakType::CoordinateType CoordinateType
Coordinate type of peak positions.
Definition: MSExperiment.h:100
bool empty() const
Definition: MSExperiment.h:142
IntensityRangeType int_range_
Intensity range (1-dimensional)
Definition: RangeManager.h:149
PeakT PeakType
Peak type.
Definition: MSExperiment.h:94
void reserveSpaceSpectra(Size s)
Definition: MSExperiment.h:184
OPENMS_UINT64_TYPE UInt64
Unsigned integer type (64bit)
Definition: Types.h:78
std::vector< SpectrumType > spectra_
spectra
Definition: MSExperiment.h:955
DRange< 2 > AreaType
Area type.
Definition: MSExperiment.h:98
ExperimentalSettings & getExperimentalSettings()
returns the meta information of this experiment (mutable access)
Definition: MSExperiment.h:744
void setRT(double rt)
Sets the absolute retention time (in seconds)
ConstAreaIterator areaBeginConst(CoordinateType min_rt, CoordinateType max_rt, CoordinateType min_mz, CoordinateType max_mz) const
Returns a non-mutable area iterator for area.
Definition: MSExperiment.h:401
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:74
MSExperiment(const MSExperiment &source)
Copy constructor.
Definition: MSExperiment.h:202
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:82
const MSChromatogram getTIC() const
returns the total ion chromatogram (TIC)
Definition: MSExperiment.h:900
ExperimentalSettings & operator=(const ExperimentalSettings &source)
Assignment operator.
UInt64 getSize() const
returns the total number of peaks
Definition: MSExperiment.h:629
MSChromatogram ChromatogramType
Chromatogram type.
Definition: MSExperiment.h:108
MSExperiment & operator=(const ExperimentalSettings &source)
Assignment operator.
Definition: MSExperiment.h:231
ConstIterator getPrecursorSpectrum(ConstIterator iterator) const
Returns the precursor spectrum of the scan pointed to by iterator.
Definition: MSExperiment.h:778
ConstIterator RTEnd(CoordinateType rt) const
Fast search for spectrum range end (returns the past-the-end iterator)
Definition: MSExperiment.h:437
std::vector< SpectrumType >::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSExperiment.h:118
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: ChromatogramPeak.h:108
AreaIterator areaEnd()
Returns an invalid area iterator marking the end of an area.
Definition: MSExperiment.h:395
static void addData_(SpectrumType *spectrum, const ContainerValueType *item)
specialization for adding feature mass traces (does not support metadata_names currently) ...
Definition: MSExperiment.h:995
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
CoordinateType minX() const
Accessor for min_ coordinate minimum.
Definition: DIntervalBase.h:241
CoordinateType getMaxMZ() const
returns the maximal m/z value
Definition: MSExperiment.h:601
void clear(bool clear_meta_data)
Clears all data and meta data.
Definition: MSExperiment.h:929
const ExperimentalSettings & getExperimentalSettings() const
returns the meta information of this experiment (const access)
Definition: MSExperiment.h:738
MSExperiment & operator=(const MSExperiment &source)
Assignment operator.
Definition: MSExperiment.h:212
Iterator RTBegin(CoordinateType rt)
Fast search for spectrum range begin.
Definition: MSExperiment.h:449
void get2DData(Container &cont) const
Reads out a 2D Spectrum.
Definition: MSExperiment.h:260
std::vector< SpectrumType > Base
STL base class type.
Definition: MSExperiment.h:110
A 1-dimensional raw data point or peak for chromatograms.
Definition: ChromatogramPeak.h:55
const std::vector< MSSpectrum > & getSpectra() const
returns the spectrum list
Definition: MSExperiment.h:837
Handles the management of a position and intensity range.
Definition: RangeManager.h:48
MSChromatogram & getChromatogram(Size id)
returns a single chromatogram
Definition: MSExperiment.h:875
CoordinateType getMinMZ() const
returns the minimal m/z value
Definition: MSExperiment.h:595
void set2DData(const Container &container)
Assignment of a data container with RT and MZ to an MSExperiment.
Definition: MSExperiment.h:291
virtual void updateRanges()
Updates minimum and maximum position/intensity.
Definition: MSExperiment.h:477
ConstIterator begin() const
Definition: MSExperiment.h:167
UInt64 total_size_
Number of all data points.
Definition: MSExperiment.h:949
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:979
int Int
Signed integer type.
Definition: Types.h:103
void setSpectra(const std::vector< MSSpectrum > &spectra)
sets the spectrum list
Definition: MSExperiment.h:825
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:122
Description of the experimental settings.
Definition: ExperimentalSettings.h:59
CoordinateType getMinRT() const
returns the minimal retention time value
Definition: MSExperiment.h:607
const AreaType & getDataRange() const
Returns RT and m/z range the data lies in.
Definition: MSExperiment.h:623
std::vector< UInt > ms_levels_
MS levels of the data.
Definition: MSExperiment.h:947
bool operator==(const MSExperiment &rhs) const
Equality operator.
Definition: MSExperiment.h:238
ExperimentalSettings()
Constructor.

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:02 using doxygen 1.8.13