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-2016.
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: Stephan Aiche$
32 // $Authors: Marc Sturm $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_KERNEL_MSEXPERIMENT_H
36 #define OPENMS_KERNEL_MSEXPERIMENT_H
37 
45 #include <OpenMS/SYSTEM/File.h>
46 
47 #include <vector>
48 #include <algorithm>
49 #include <limits>
50 
51 namespace OpenMS
52 {
53  class Peak1D;
54 
70  template <typename PeakT = Peak1D, typename ChromatogramPeakT = ChromatogramPeak>
71  class MSExperiment :
72  public RangeManager<2>,
74  {
75 
76 public:
77 
79 
80  typedef PeakT PeakType;
83  typedef ChromatogramPeakT ChromatogramPeakType;
97  typedef std::vector<SpectrumType> Base;
99 
101 
102  typedef typename std::vector<SpectrumType>::iterator Iterator;
105  typedef typename std::vector<SpectrumType>::const_iterator ConstIterator;
111 
113  // Attention: these refer to the spectra vector only!
115  typedef typename Base::value_type value_type;
116  typedef typename Base::iterator iterator;
117  typedef typename Base::const_iterator const_iterator;
118 
119  inline Size size() const
120  {
121  return spectra_.size();
122  }
123 
124  inline void resize(Size s)
125  {
126  spectra_.resize(s);
127  }
128 
129  inline bool empty() const
130  {
131  return spectra_.empty();
132  }
133 
134  inline void reserve(Size s)
135  {
136  spectra_.reserve(s);
137  }
138 
139  inline SpectrumType& operator[] (Size n)
140  {
141  return spectra_[n];
142  }
143 
144  inline const SpectrumType& operator[] (Size n) const
145  {
146  return spectra_[n];
147  }
148 
149  inline Iterator begin()
150  {
151  return spectra_.begin();
152  }
153 
154  inline ConstIterator begin() const
155  {
156  return spectra_.begin();
157  }
158 
159  inline Iterator end()
160  {
161  return spectra_.end();
162  }
163 
164  inline ConstIterator end() const
165  {
166  return spectra_.end();
167  }
169 
170  // Aliases / chromatograms
171  inline void reserveSpaceSpectra(Size s)
172  {
173  spectra_.reserve(s);
174  }
176  {
177  chromatograms_.reserve(s);
178  }
179 
182  RangeManagerType(),
184  ms_levels_(),
185  total_size_(0)
186  {}
187 
189  MSExperiment(const MSExperiment & source) :
190  RangeManagerType(source),
191  ExperimentalSettings(source),
192  ms_levels_(source.ms_levels_),
193  total_size_(source.total_size_),
195  spectra_(source.spectra_)
196  {}
197 
200  {
201  if (&source == this) return *this;
202 
205 
206  ms_levels_ = source.ms_levels_;
207  total_size_ = source.total_size_;
209  spectra_ = source.spectra_;
210 
211  //no need to copy the alloc?!
212  //alloc_
213 
214  return *this;
215  }
216 
219  {
221  return *this;
222  }
223 
225  bool operator==(const MSExperiment & rhs) const
226  {
227  return ExperimentalSettings::operator==(rhs) &&
228  chromatograms_ == rhs.chromatograms_ &&
229  spectra_ == rhs.spectra_;
230  }
231 
233  bool operator!=(const MSExperiment & rhs) const
234  {
235  return !(operator==(rhs));
236  }
237 
239 
240 
246  template <class Container>
247  void get2DData(Container & cont) const
248  {
249  for (typename Base::const_iterator spec = spectra_.begin(); spec != spectra_.end(); ++spec)
250  {
251  if (spec->getMSLevel() != 1)
252  {
253  continue;
254  }
255  typename Container::value_type s; // explicit object here, since instantiation within push_back() fails on VS<12
256  for (typename SpectrumType::const_iterator it = spec->begin(); it != spec->end(); ++it)
257  {
258  cont.push_back(s);
259  cont.back().setRT(spec->getRT());
260  cont.back().setMZ(it->getMZ());
261  cont.back().setIntensity(it->getIntensity());
262  }
263  }
264  }
265 
277  template <class Container>
278  void set2DData(const Container& container)
279  {
280  set2DData<false, Container>(container);
281  }
282 
297  template <class Container>
298  void set2DData(const Container& container, const StringList& store_metadata_names)
299  {
300  // clean up the container first
301  clear(true);
302  SpectrumType* spectrum = 0;
303  typename PeakType::CoordinateType current_rt = -std::numeric_limits<typename PeakType::CoordinateType>::max();
304  for (typename Container::const_iterator iter = container.begin(); iter != container.end(); ++iter)
305  {
306  // check if the retention time has changed
307  if (current_rt != iter->getRT() || spectrum == 0)
308  {
309  // append new spectrum
310  if (current_rt > iter->getRT())
311  {
312  throw Exception::Precondition(__FILE__, __LINE__, __PRETTY_FUNCTION__, "Input container is not sorted!");
313  }
314  current_rt = iter->getRT();
315  spectrum = createSpec_(current_rt, store_metadata_names);
316  }
317 
318  // add either data point or mass traces (depending on template argument value)
319  ContainerAdd_<typename Container::value_type, false>::addData_(spectrum, &(*iter), store_metadata_names);
320  }
321  }
322 
340  template <bool add_mass_traces, class Container>
341  void set2DData(const Container& container)
342  {
343  // clean up the container first
344  clear(true);
345  SpectrumType* spectrum = 0;
346  typename PeakType::CoordinateType current_rt = -std::numeric_limits<typename PeakType::CoordinateType>::max();
347  for (typename Container::const_iterator iter = container.begin(); iter != container.end(); ++iter)
348  {
349  // check if the retention time has changed
350  if (current_rt != iter->getRT() || spectrum == 0)
351  {
352  // append new spectrum
353  if (current_rt > iter->getRT())
354  {
355  throw Exception::Precondition(__FILE__, __LINE__, __PRETTY_FUNCTION__, "Input container is not sorted!");
356  }
357  current_rt = iter->getRT();
358  spectrum = createSpec_(current_rt);
359  }
360 
361  // add either data point or mass traces (depending on template argument value)
363  }
364  }
365 
367 
368 
370 
371  AreaIterator areaBegin(CoordinateType min_rt, CoordinateType max_rt, CoordinateType min_mz, CoordinateType max_mz)
373  {
374  OPENMS_PRECONDITION(min_rt <= max_rt, "Swapped RT range boundaries!")
375  OPENMS_PRECONDITION(min_mz <= max_mz, "Swapped MZ range boundaries!")
376  OPENMS_PRECONDITION(this->isSorted(true), "Experiment is not sorted by RT and m/z! Using AreaIterator will give invalid results!")
377  //std::cout << "areaBegin: " << min_rt << " " << max_rt << " " << min_mz << " " << max_mz << std::endl;
378  return AreaIterator(spectra_.begin(), RTBegin(min_rt), RTEnd(max_rt), min_mz, max_mz);
379  }
380 
382  AreaIterator areaEnd()
383  {
384  return AreaIterator();
385  }
386 
388  ConstAreaIterator areaBeginConst(CoordinateType min_rt, CoordinateType max_rt, CoordinateType min_mz, CoordinateType max_mz) const
389  {
390  OPENMS_PRECONDITION(min_rt <= max_rt, "Swapped RT range boundaries!")
391  OPENMS_PRECONDITION(min_mz <= max_mz, "Swapped MZ range boundaries!")
392  OPENMS_PRECONDITION(this->isSorted(true), "Experiment is not sorted by RT and m/z! Using ConstAreaIterator will give invalid results!")
393  //std::cout << "areaBeginConst: " << min_rt << " " << max_rt << " " << min_mz << " " << max_mz << std::endl;
394  return ConstAreaIterator(spectra_.begin(), RTBegin(min_rt), RTEnd(max_rt), min_mz, max_mz);
395  }
396 
398  ConstAreaIterator areaEndConst() const
399  {
400  return ConstAreaIterator();
401  }
402 
410  ConstIterator RTBegin(CoordinateType rt) const
411  {
412  SpectrumType s;
413  s.setRT(rt);
414  return lower_bound(spectra_.begin(), spectra_.end(), s, typename SpectrumType::RTLess());
415  }
416 
424  ConstIterator RTEnd(CoordinateType rt) const
425  {
426  SpectrumType s;
427  s.setRT(rt);
428  return upper_bound(spectra_.begin(), spectra_.end(), s, typename SpectrumType::RTLess());
429  }
430 
436  Iterator RTBegin(CoordinateType rt)
437  {
438  SpectrumType s;
439  s.setRT(rt);
440  return lower_bound(spectra_.begin(), spectra_.end(), s, typename SpectrumType::RTLess());
441  }
442 
448  Iterator RTEnd(CoordinateType rt)
449  {
450  SpectrumType s;
451  s.setRT(rt);
452  return upper_bound(spectra_.begin(), spectra_.end(), s, typename SpectrumType::RTLess());
453  }
454 
456 
462  // Docu in base class
464  virtual void updateRanges()
465  {
466  updateRanges(-1);
467  }
468 
474  void updateRanges(Int ms_level)
475  {
476  //clear MS levels
477  ms_levels_.clear();
478 
479  //reset mz/rt/int range
480  this->clearRanges();
481  //reset point count
482  total_size_ = 0;
483 
484  //empty
485  if (spectra_.empty() && chromatograms_.empty())
486  {
487  return;
488  }
489 
490  //update
491  for (typename Base::iterator it = spectra_.begin(); it != spectra_.end(); ++it)
492  {
493  if (ms_level < Int(0) || Int(it->getMSLevel()) == ms_level)
494  {
495  //ms levels
496  if (std::find(ms_levels_.begin(), ms_levels_.end(), it->getMSLevel()) == ms_levels_.end())
497  {
498  ms_levels_.push_back(it->getMSLevel());
499  }
500 
501  // calculate size
502  total_size_ += it->size();
503 
504  //rt
505  if (it->getRT() < RangeManagerType::pos_range_.minX()) RangeManagerType::pos_range_.setMinX(it->getRT());
506  if (it->getRT() > RangeManagerType::pos_range_.maxX()) RangeManagerType::pos_range_.setMaxX(it->getRT());
507 
508  //do not update mz and int when the spectrum is empty
509  if (it->size() == 0) continue;
510 
511  it->updateRanges();
512 
513  //mz
514  if (it->getMin()[0] < RangeManagerType::pos_range_.minY()) RangeManagerType::pos_range_.setMinY(it->getMin()[0]);
515  if (it->getMax()[0] > RangeManagerType::pos_range_.maxY()) RangeManagerType::pos_range_.setMaxY(it->getMax()[0]);
516 
517  //int
518  if (it->getMinInt() < RangeManagerType::int_range_.minX()) RangeManagerType::int_range_.setMinX(it->getMinInt());
519  if (it->getMaxInt() > RangeManagerType::int_range_.maxX()) RangeManagerType::int_range_.setMaxX(it->getMaxInt());
520 
521  }
522  // for MS level = 1 we extend the range for all the MS2 precursors
523  if (ms_level == 1 && it->getMSLevel() == 2)
524  {
525  if (!it->getPrecursors().empty())
526  {
527  double pc_rt = it->getRT();
528  if (pc_rt < RangeManagerType::pos_range_.minX()) RangeManagerType::pos_range_.setMinX(pc_rt);
529  if (pc_rt > RangeManagerType::pos_range_.maxX()) RangeManagerType::pos_range_.setMaxX(pc_rt);
530  double pc_mz = it->getPrecursors()[0].getMZ();
531  if (pc_mz < RangeManagerType::pos_range_.minY()) RangeManagerType::pos_range_.setMinY(pc_mz);
532  if (pc_mz > RangeManagerType::pos_range_.maxY()) RangeManagerType::pos_range_.setMaxY(pc_mz);
533  }
534 
535  }
536 
537  }
538  std::sort(ms_levels_.begin(), ms_levels_.end());
539 
540 
541 
542 
543  if (this->chromatograms_.empty())
544  {
545  return;
546  }
547 
548  //TODO CHROM update intensity, m/z and RT according to chromatograms as well! (done????)
549 
550  for (typename std::vector<ChromatogramType>::iterator it = chromatograms_.begin(); it != chromatograms_.end(); ++it)
551  {
552 
553  // ignore TICs and ECs (as these are usually positioned at 0 and therefor lead to a large white margin in plots if included)
554  if (it->getChromatogramType() == ChromatogramSettings::TOTAL_ION_CURRENT_CHROMATOGRAM ||
555  it->getChromatogramType() == ChromatogramSettings::EMISSION_CHROMATOGRAM)
556  {
557  continue;
558  }
559 
560  // update MZ
561  if (it->getMZ() < RangeManagerType::pos_range_.minY()) RangeManagerType::pos_range_.setMinY(it->getMZ());
562  if (it->getMZ() > RangeManagerType::pos_range_.maxY()) RangeManagerType::pos_range_.setMaxY(it->getMZ());
563 
564  // do not update RT and in if the spectrum is empty
565  if (it->size() == 0) continue;
566 
567  total_size_ += it->size();
568 
569  it->updateRanges();
570 
571  // RT
572  if (it->getMin()[0] < RangeManagerType::pos_range_.minX()) RangeManagerType::pos_range_.setMinX(it->getMin()[0]);
573  if (it->getMax()[0] > RangeManagerType::pos_range_.maxX()) RangeManagerType::pos_range_.setMaxX(it->getMax()[0]);
574 
575  // int
576  if (it->getMinInt() < RangeManagerType::int_range_.minX()) RangeManagerType::int_range_.setMinX(it->getMinInt());
577  if (it->getMaxInt() > RangeManagerType::int_range_.maxX()) RangeManagerType::int_range_.setMaxX(it->getMaxInt());
578  }
579  }
580 
582  CoordinateType getMinMZ() const
583  {
584  return RangeManagerType::pos_range_.minPosition()[1];
585  }
586 
588  CoordinateType getMaxMZ() const
589  {
590  return RangeManagerType::pos_range_.maxPosition()[1];
591  }
592 
594  CoordinateType getMinRT() const
595  {
596  return RangeManagerType::pos_range_.minPosition()[0];
597  }
598 
600  CoordinateType getMaxRT() const
601  {
602  return RangeManagerType::pos_range_.maxPosition()[0];
603  }
604 
610  const AreaType & getDataRange() const
611  {
613  }
614 
616  UInt64 getSize() const
617  {
618  return total_size_;
619  }
620 
622  const std::vector<UInt> & getMSLevels() const
623  {
624  return ms_levels_;
625  }
626 
628 
631 
636  void sortSpectra(bool sort_mz = true)
637  {
638  std::sort(spectra_.begin(), spectra_.end(), typename SpectrumType::RTLess());
639 
640  if (sort_mz)
641  {
642  // sort each spectrum by m/z
643  for (Iterator iter = spectra_.begin(); iter != spectra_.end(); ++iter)
644  {
645  iter->sortByPosition();
646  }
647  }
648  }
649 
655  void sortChromatograms(bool sort_rt = true)
656  {
657  // sort the chromatograms according to their product m/z
658  std::sort(chromatograms_.begin(), chromatograms_.end(), typename ChromatogramType::MZLess());
659 
660  if (sort_rt)
661  {
662  for (typename std::vector<ChromatogramType>::iterator it = chromatograms_.begin(); it != chromatograms_.end(); ++it)
663  {
664  it->sortByPosition();
665  }
666  }
667  }
668 
674  bool isSorted(bool check_mz = true) const
675  {
676  //check RT positions
677  for (Size i = 1; i < spectra_.size(); ++i)
678  {
679  if (spectra_[i - 1].getRT() > spectra_[i].getRT()) return false;
680  }
681  //check spectra
682  if (check_mz)
683  {
684  for (Size i = 0; i < spectra_.size(); ++i)
685  {
686  if (!spectra_[i].isSorted()) return false;
687  }
688  }
689  // TODO CHROM
690  return true;
691  }
692 
694 
696  void reset()
697  {
698  spectra_.clear(); //remove data
699  RangeManagerType::clearRanges(); //reset range manager
701  }
702 
709  {
710  bool meta_present = false;
711  for (Size i = 0; i < spectra_.size(); ++i)
712  {
713  if (spectra_[i].getFloatDataArrays().size() != 0 || spectra_[i].getIntegerDataArrays().size() != 0 || spectra_[i].getStringDataArrays().size() != 0)
714  {
715  meta_present = true;
716  }
717  spectra_[i].getStringDataArrays().clear();
718  spectra_[i].getIntegerDataArrays().clear();
719  spectra_[i].getFloatDataArrays().clear();
720  }
721  return meta_present;
722  }
723 
726  {
727  return *this;
728  }
729 
732  {
733  return *this;
734  }
735 
738  {
739  StringList ms_run_paths;
740  std::vector<SourceFile> sfs(this->getSourceFiles());
741  for (std::vector<SourceFile>::const_iterator it = sfs.begin(); it != sfs.end(); ++it)
742  {
743  // assemble a single location string from the URI (path to file) and file name
744  String path = it->getPathToFile();
745  String filename = it->getNameOfFile();
746 
747  if (path.empty() || filename.empty())
748  {
749  LOG_WARN << "Path or file name of primary MS run is empty. "
750  << "This might be the result of incomplete conversion. "
751  << "Not that tracing back e.g. identification results to the original file might more difficult." << std::endl;
752  }
753  else
754  {
755  String ms_run_location = path + "/" + filename;
756  ms_run_paths.push_back(ms_run_location);
757  }
758  }
759  return ms_run_paths;
760  }
761 
767  ConstIterator getPrecursorSpectrum(ConstIterator iterator) const
768  {
769  if (iterator == spectra_.end() || iterator == spectra_.begin())
770  {
771  return spectra_.end();
772  }
773  UInt ms_level = iterator->getMSLevel();
774  do
775  {
776  --iterator;
777  if (iterator->getMSLevel() < ms_level)
778  {
779  return iterator;
780  }
781  }
782  while (iterator != spectra_.begin());
783 
784  return spectra_.end();
785  }
786 
788  void swap(MSExperiment & from)
789  {
790  MSExperiment tmp;
791 
792  //swap range information
793  tmp.RangeManagerType::operator=(* this);
794  this->RangeManagerType::operator=(from);
795  from.RangeManagerType::operator=(tmp);
796 
797  //swap experimental settings
798  tmp.ExperimentalSettings::operator=(* this);
800  from.ExperimentalSettings::operator=(tmp);
801 
802  // swap chromatograms
803  std::swap(chromatograms_, from.chromatograms_);
804 
805  //swap peaks
806  spectra_.swap(from.getSpectra());
807 
808  //swap remaining members
809  ms_levels_.swap(from.ms_levels_);
810  std::swap(total_size_, from.total_size_);
811  }
812 
814  void setSpectra(const std::vector<MSSpectrum<PeakT> > & spectra)
815  {
816  spectra_ = spectra;
817  }
818 
820  void addSpectrum(const MSSpectrum<PeakT> & spectrum)
821  {
822  spectra_.push_back(spectrum);
823  }
824 
826  const std::vector<MSSpectrum<PeakT> > & getSpectra() const
827  {
828  return spectra_;
829  }
830 
832  std::vector<MSSpectrum<PeakT> > & getSpectra()
833  {
834  return spectra_;
835  }
836 
838  void setChromatograms(const std::vector<MSChromatogram<ChromatogramPeakType> > & chromatograms)
839  {
840  chromatograms_ = chromatograms;
841  }
842 
845  {
846  chromatograms_.push_back(chromatogram);
847  }
848 
850  const std::vector<MSChromatogram<ChromatogramPeakType> > & getChromatograms() const
851  {
852  return chromatograms_;
853  }
854 
856  std::vector<MSChromatogram<ChromatogramPeakType> > & getChromatograms()
857  {
858  return chromatograms_;
859  }
860 
862 
865  {
866  return chromatograms_[id];
867  }
868 
871  {
872  return spectra_[id];
873  }
874 
876  inline Size getNrSpectra() const
877  {
878  return spectra_.size();
879  }
880 
882  inline Size getNrChromatograms() const
883  {
884  return chromatograms_.size();
885  }
887 
890  {
891  // The TIC is (re)calculated from the MS1 spectra. Even if MSExperiment does not contain a TIC chromatogram explicitly, it can be reported.
893  for (typename Base::const_iterator spec_it = spectra_.begin(); spec_it != spectra_.end(); ++spec_it)
894  {
895  if (spec_it->getMSLevel() == 1)
896  {
897  double totalIntensity = 0;
898  // sum intensities of a spectrum
899  for (typename SpectrumType::const_iterator peak_it = spec_it->begin(); peak_it != spec_it->end(); ++peak_it)
900  {
901  totalIntensity += peak_it->getIntensity();
902  }
903  // fill chromatogram
904  ChromatogramPeakType peak;
905  peak.setRT(spec_it->getRT());
906  peak.setIntensity(totalIntensity);
907  TIC.push_back(peak);
908  }
909  }
910  return TIC;
911  }
912 
918  void clear(bool clear_meta_data)
919  {
920  spectra_.clear();
921 
922  if (clear_meta_data)
923  {
924  clearRanges();
925  this->ExperimentalSettings::operator=(ExperimentalSettings()); // no "clear" method
926  chromatograms_.clear();
927  ms_levels_.clear();
928  total_size_ = 0;
929  }
930  }
931 
932 protected:
933 
934 
936  std::vector<UInt> ms_levels_;
939 
941  std::vector<MSChromatogram<ChromatogramPeakType> > chromatograms_;
942 
944  std::vector<SpectrumType> spectra_;
945 
946 private:
947 
949  template<typename ContainerValueType, bool addMassTraces>
951  {
952  static void addData_(SpectrumType* spectrum, const ContainerValueType* item);
953  static void addData_(SpectrumType* spectrum, const ContainerValueType* item, const StringList& store_metadata_names);
954  };
955 
956  template<typename ContainerValueType>
957  struct ContainerAdd_<ContainerValueType, false>
958  {
960  static void addData_(SpectrumType* spectrum, const ContainerValueType* item)
961  {
962  // create temporary peak and insert it into spectrum
963  spectrum->insert(spectrum->end(), PeakType());
964  spectrum->back().setIntensity(item->getIntensity());
965  spectrum->back().setPosition(item->getMZ());
966  }
968  static void addData_(SpectrumType* spectrum, const ContainerValueType* item, const StringList& store_metadata_names)
969  {
970  addData_(spectrum, item);
971  for (StringList::const_iterator itm = store_metadata_names.begin(); itm != store_metadata_names.end(); ++itm)
972  {
973  float val = std::numeric_limits<float>::quiet_NaN();
974  if (item->metaValueExists(*itm)) val = item->getMetaValue(*itm);
975  spectrum->getFloatDataArrays()[itm - store_metadata_names.begin()].push_back(val);
976  }
977  }
978  };
979 
980  template<typename ContainerValueType>
981  struct ContainerAdd_<ContainerValueType, true>
982  {
984  static void addData_(SpectrumType* spectrum, const ContainerValueType* item)
985  {
986  if (item->metaValueExists("num_of_masstraces"))
987  {
988  Size mts = item->getMetaValue("num_of_masstraces");
989  int charge = (item->getCharge()==0 ? 1 : item->getCharge()); // set to 1 if charge is 0, otherwise div/0 below
990  for (Size i = 0; i < mts; ++i)
991  {
992  String meta_name = String("masstrace_intensity_") + i;
993  if (!item->metaValueExists(meta_name))
994  {
995  throw Exception::Precondition(__FILE__, __LINE__, __PRETTY_FUNCTION__, String("Meta value '") + meta_name + "' expected but not found in container.");
996  }
997  ContainerValueType p;
998  p.setIntensity(item->getMetaValue(meta_name));
999  p.setPosition(item->getMZ() + Constants::C13C12_MASSDIFF_U / charge * i);
1001  }
1002  }
1004  }
1005  };
1006 
1007  /*
1008  @brief Append a spectrum to current MSExperiment
1009 
1010  @param rt RT of new spectrum
1011  @return Pointer to newly created spectrum
1012  */
1013  SpectrumType* createSpec_(typename PeakType::CoordinateType rt)
1014  {
1015  SpectrumType* spectrum = 0;
1016  spectra_.insert(spectra_.end(), SpectrumType());
1017  spectrum = &(spectra_.back());
1018  spectrum->setRT(rt);
1019  spectrum->setMSLevel(1);
1020  return spectrum;
1021  }
1022 
1023  /*
1024  @brief Append a spectrum including floatdata arrays to current MSExperiment
1025 
1026  @param rt RT of new spectrum
1027  @param metadata_names Names of floatdata arrays attached to this spectrum
1028  @return Pointer to newly created spectrum
1029  */
1030  SpectrumType* createSpec_(typename PeakType::CoordinateType rt, const StringList& metadata_names)
1031  {
1032  SpectrumType* spectrum = createSpec_(rt);
1033  // create metadata arrays
1034  spectrum->getFloatDataArrays().reserve(metadata_names.size());
1035  StringList::const_iterator itm = metadata_names.begin();
1036  for (; itm != metadata_names.end(); ++itm)
1037  {
1038  spectrum->getFloatDataArrays().push_back(MSSpectrum<>::FloatDataArray());
1039  spectrum->getFloatDataArrays().back().setName(*itm);
1040  }
1041  return spectrum;
1042  }
1043 
1044  };
1045 
1046 
1048  template <typename PeakT, typename ChromatogramPeakT>
1049  std::ostream & operator<<(std::ostream & os, const MSExperiment<PeakT, ChromatogramPeakT> & exp)
1050  {
1051  os << "-- MSEXPERIMENT BEGIN --" << std::endl;
1052 
1053  //experimental settings
1054  os << static_cast<const ExperimentalSettings &>(exp);
1055 
1056  //spectra
1057  for (typename MSExperiment<PeakT>::const_iterator it = exp.begin(); it != exp.end(); ++it)
1058  {
1059  os << *it;
1060  }
1061 
1062  //chromatograms
1063  for (typename std::vector<MSChromatogram<ChromatogramPeakT> >::const_iterator it = exp.getChromatograms().begin(); it != exp.getChromatograms().end(); ++it)
1064  {
1065  os << *it;
1066  }
1067 
1068  os << "-- MSEXPERIMENT END --" << std::endl;
1069 
1070  return os;
1071  }
1072 
1073 } // namespace OpenMS
1074 
1075 #endif // OPENMS_KERNEL_MSEXPERIMENT_H
MSSpectrum< PeakType > SpectrumType
Spectrum Type.
Definition: MSExperiment.h:93
const double C13C12_MASSDIFF_U
Internal::AreaIterator< PeakT, PeakT &, PeakT *, Iterator, typename SpectrumType::Iterator > AreaIterator
Mutable area iterator type (for traversal of a rectangular subset of the peaks)
Definition: MSExperiment.h:107
void get2DData(Container &cont) const
Reads out a 2D Spectrum.
Definition: MSExperiment.h:247
Size getNrSpectra() const
get the total number of spectra available
Definition: MSExperiment.h:876
A more convenient string class.
Definition: String.h:57
void reserveSpaceChromatograms(Size s)
Definition: MSExperiment.h:175
void set2DData(const Container &container)
Assignment of a data container with RT and MZ to an MSExperiment.
Definition: MSExperiment.h:341
bool operator==(const ExperimentalSettings &rhs) const
Equality operator.
static void addData_(SpectrumType *spectrum, const ContainerValueType *item)
general method for adding data points
Definition: MSExperiment.h:960
SpectrumType * createSpec_(typename PeakType::CoordinateType rt)
Definition: MSExperiment.h:1013
void reset()
Resets all internal values.
Definition: MSExperiment.h:696
PositionRangeType pos_range_
Position range (D-dimensional)
Definition: RangeManager.h:151
Size size() const
Definition: MSExperiment.h:119
std::vector< SpectrumType >::iterator Iterator
Mutable iterator.
Definition: MSExperiment.h:103
bool operator==(const MSExperiment &rhs) const
Equality operator.
Definition: MSExperiment.h:225
CoordinateType maxX() const
Accessor for min_ coordinate maximum.
Definition: DIntervalBase.h:253
Base::value_type value_type
Definition: MSExperiment.h:115
std::vector< MSChromatogram< ChromatogramPeakType > > chromatograms_
chromatograms
Definition: MSExperiment.h:941
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:107
Iterator RTEnd(CoordinateType rt)
Fast search for spectrum range end (returns the past-the-end iterator)
Definition: MSExperiment.h:448
bool clearMetaDataArrays()
Clears the meta data arrays of all contained spectra (float, integer and string arrays) ...
Definition: MSExperiment.h:708
MSExperiment()
Constructor.
Definition: MSExperiment.h:181
ChromatogramPeakT ChromatogramPeakType
Chromatogram peak type.
Definition: MSExperiment.h:83
Forward iterator for an area of peaks in an experiment.
Definition: AreaIterator.h:58
Iterator begin()
Definition: MSExperiment.h:149
std::vector< MSChromatogram< ChromatogramPeakType > > & getChromatograms()
returns the chromatogram list (mutable)
Definition: MSExperiment.h:856
void sortSpectra(bool sort_mz=true)
Sorts the data points by retention time.
Definition: MSExperiment.h:636
Base::const_iterator const_iterator
Definition: MSExperiment.h:117
SpectrumType * createSpec_(typename PeakType::CoordinateType rt, const StringList &metadata_names)
Definition: MSExperiment.h:1030
void resize(Size s)
Definition: MSExperiment.h:124
PeakType::IntensityType IntensityType
Intensity type of peaks.
Definition: MSExperiment.h:89
void swap(MSExperiment &from)
Swaps the content of this map with the content of from.
Definition: MSExperiment.h:788
CoordinateType getMaxMZ() const
returns the maximal m/z value
Definition: MSExperiment.h:588
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
ConstIterator RTEnd(CoordinateType rt) const
Fast search for spectrum range end (returns the past-the-end iterator)
Definition: MSExperiment.h:424
Precondition failed exception.
Definition: Exception.h:167
const MSChromatogram< ChromatogramPeakType > getTIC() const
returns the total ion chromatogram (TIC)
Definition: MSExperiment.h:889
void addChromatogram(const MSChromatogram< ChromatogramPeakType > &chromatogram)
adds a chromatogram to the list
Definition: MSExperiment.h:844
ConstAreaIterator areaEndConst() const
Returns an non-mutable invalid area iterator marking the end of an area.
Definition: MSExperiment.h:398
MSSpectrum< PeakT > & getSpectrum(Size id)
returns a single spectrum
Definition: MSExperiment.h:870
CoordinateType getMinMZ() const
returns the minimal m/z value
Definition: MSExperiment.h:582
CoordinateType getMinRT() const
returns the minimal retention time value
Definition: MSExperiment.h:594
SpectrumType & operator[](Size n)
Definition: MSExperiment.h:139
RangeManager< 2 > RangeManagerType
RangeManager type.
Definition: MSExperiment.h:91
#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:159
static void addData_(SpectrumType *spectrum, const ContainerValueType *item)
ConstIterator RTBegin(CoordinateType rt) const
Fast search for spectrum range begin.
Definition: MSExperiment.h:410
Base::iterator iterator
Definition: MSExperiment.h:116
MSChromatogram< ChromatogramPeakType > ChromatogramType
Chromatogram type.
Definition: MSExperiment.h:95
void sortChromatograms(bool sort_rt=true)
Sorts the data points of the chromatograms by m/z.
Definition: MSExperiment.h:655
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:474
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:388
void reserve(Size s)
Definition: MSExperiment.h:134
CoordinateType minX() const
Accessor for min_ coordinate minimum.
Definition: DIntervalBase.h:241
MSChromatogram< ChromatogramPeakType > & getChromatogram(Size id)
returns a single chromatogram
Definition: MSExperiment.h:864
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:298
RangeManager & operator=(const RangeManager &rhs)
Assignment operator.
Definition: RangeManager.h:77
Helper class to add either general data points in set2DData or use mass traces from meta values...
Definition: MSExperiment.h:950
const ExperimentalSettings & getExperimentalSettings() const
returns the meta information of this experiment (const access)
Definition: MSExperiment.h:725
void clearRanges()
Resets the ranges.
Definition: RangeManager.h:140
void setMSLevel(UInt ms_level)
Sets the MS level.
Definition: MSSpectrum.h:265
ConstIterator end() const
Definition: MSExperiment.h:164
bool operator!=(const MSExperiment &rhs) const
Equality operator.
Definition: MSExperiment.h:233
Size getNrChromatograms() const
get the total number of chromatograms available
Definition: MSExperiment.h:882
AreaIterator areaBegin(CoordinateType min_rt, CoordinateType max_rt, CoordinateType min_mz, CoordinateType max_mz)
Returns an area iterator for area.
Definition: MSExperiment.h:372
StringList getPrimaryMSRunPath() const
get the file path to the first MS run
Definition: MSExperiment.h:737
const std::vector< MSSpectrum< PeakT > > & getSpectra() const
returns the spectrum list
Definition: MSExperiment.h:826
PeakType::CoordinateType CoordinateType
Coordinate type of peak positions.
Definition: MSExperiment.h:87
IntensityRangeType int_range_
Intensity range (1-dimensional)
Definition: RangeManager.h:149
PeakT PeakType
Peak type.
Definition: MSExperiment.h:81
void reserveSpaceSpectra(Size s)
Definition: MSExperiment.h:171
std::vector< SpectrumType > spectra_
spectra
Definition: MSExperiment.h:944
DRange< 2 > AreaType
Area type.
Definition: MSExperiment.h:85
Internal::AreaIterator< const PeakT, const PeakT &, const PeakT *, ConstIterator, typename SpectrumType::ConstIterator > ConstAreaIterator
Immutable area iterator type (for traversal of a rectangular subset of the peaks) ...
Definition: MSExperiment.h:109
void addSpectrum(const MSSpectrum< PeakT > &spectrum)
adds a spectrum to the list
Definition: MSExperiment.h:820
ExperimentalSettings & getExperimentalSettings()
returns the meta information of this experiment (mutable access)
Definition: MSExperiment.h:731
void setRT(double rt)
Sets the absolute retention time (is seconds)
Definition: MSSpectrum.h:249
const std::vector< UInt > & getMSLevels() const
returns an array of MS levels
Definition: MSExperiment.h:622
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:74
MSExperiment(const MSExperiment &source)
Copy constructor.
Definition: MSExperiment.h:189
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:71
bool isSorted(bool check_mz=true) const
Checks if all spectra are sorted with respect to ascending RT.
Definition: MSExperiment.h:674
Float data array class.
Definition: MSSpectrum.h:74
ExperimentalSettings & operator=(const ExperimentalSettings &source)
Assignment operator.
void setChromatograms(const std::vector< MSChromatogram< ChromatogramPeakType > > &chromatograms)
sets the chromatogram list
Definition: MSExperiment.h:838
const AreaType & getDataRange() const
Returns RT and m/z range the data lies in.
Definition: MSExperiment.h:610
MSExperiment & operator=(const ExperimentalSettings &source)
Assignment operator.
Definition: MSExperiment.h:218
std::vector< MSSpectrum< PeakT > > & getSpectra()
returns the spectrum list (mutable)
Definition: MSExperiment.h:832
std::vector< SpectrumType >::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSExperiment.h:105
AreaIterator areaEnd()
Returns an invalid area iterator marking the end of an area.
Definition: MSExperiment.h:382
CoordinateType getMaxRT() const
returns the maximal retention time value
Definition: MSExperiment.h:600
UInt64 getSize() const
returns the total number of peaks
Definition: MSExperiment.h:616
static void addData_(SpectrumType *spectrum, const ContainerValueType *item)
specialization for adding feature mass traces (does not support metadata_names currently) ...
Definition: MSExperiment.h:984
Definition: ChromatogramSettings.h:77
void clear(bool clear_meta_data)
Clears all data and meta data.
Definition: MSExperiment.h:918
MSExperiment & operator=(const MSExperiment &source)
Assignment operator.
Definition: MSExperiment.h:199
bool empty() const
Definition: MSExperiment.h:129
Iterator RTBegin(CoordinateType rt)
Fast search for spectrum range begin.
Definition: MSExperiment.h:436
std::vector< SpectrumType > Base
STL base class type.
Definition: MSExperiment.h:97
void setSpectra(const std::vector< MSSpectrum< PeakT > > &spectra)
sets the spectrum list
Definition: MSExperiment.h:814
Handles the management of a position and intensity range.
Definition: RangeManager.h:48
const FloatDataArrays & getFloatDataArrays() const
Returns a const reference to the float meta data arrays.
Definition: MSSpectrum.h:298
void set2DData(const Container &container)
Assignment of a data container with RT and MZ to an MSExperiment.
Definition: MSExperiment.h:278
virtual void updateRanges()
Updates minimum and maximum position/intensity.
Definition: MSExperiment.h:464
UInt64 total_size_
Number of all data points.
Definition: MSExperiment.h:938
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:968
int Int
Signed integer type.
Definition: Types.h:103
ConstIterator getPrecursorSpectrum(ConstIterator iterator) const
Returns the precursor spectrum of the scan pointed to by iterator.
Definition: MSExperiment.h:767
Description of the experimental settings.
Definition: ExperimentalSettings.h:59
const std::vector< MSChromatogram< ChromatogramPeakType > > & getChromatograms() const
returns the chromatogram list
Definition: MSExperiment.h:850
ConstIterator begin() const
Definition: MSExperiment.h:154
std::vector< UInt > ms_levels_
MS levels of the data.
Definition: MSExperiment.h:936
const std::vector< SourceFile > & getSourceFiles() const
returns a const reference to the source data file
ExperimentalSettings()
Constructor.

OpenMS / TOPP release 2.0.0 Documentation generated on Tue Jan 31 2017 06:39:49 using doxygen 1.8.8