35 #ifndef OPENMS_KERNEL_MSEXPERIMENT_H
36 #define OPENMS_KERNEL_MSEXPERIMENT_H
70 template <
typename PeakT = Peak1D,
typename ChromatogramPeakT = ChromatogramPeak>
97 typedef std::vector<SpectrumType>
Base;
102 typedef typename std::vector<SpectrumType>::iterator
Iterator;
164 inline ConstIterator
end()
const
190 RangeManagerType(source),
201 if (&source ==
this)
return *
this;
246 template <
class Container>
249 for (
typename Base::const_iterator spec =
spectra_.begin(); spec !=
spectra_.end(); ++spec)
251 if (spec->getMSLevel() != 1)
255 typename Container::value_type s;
256 for (
typename SpectrumType::const_iterator it = spec->begin(); it != spec->end(); ++it)
259 cont.back().setRT(spec->getRT());
260 cont.back().setMZ(it->getMZ());
261 cont.back().setIntensity(it->getIntensity());
277 template <
class Container>
280 set2DData<false, Container>(container);
297 template <
class Container>
302 SpectrumType* spectrum = 0;
304 for (
typename Container::const_iterator iter = container.begin(); iter != container.end(); ++iter)
307 if (current_rt != iter->getRT() || spectrum == 0)
310 if (current_rt > iter->getRT())
314 current_rt = iter->getRT();
315 spectrum =
createSpec_(current_rt, store_metadata_names);
340 template <
bool add_mass_traces,
class Container>
345 SpectrumType* spectrum = 0;
347 for (
typename Container::const_iterator iter = container.begin(); iter != container.end(); ++iter)
350 if (current_rt != iter->getRT() || spectrum == 0)
353 if (current_rt > iter->getRT())
357 current_rt = iter->getRT();
371 AreaIterator
areaBegin(CoordinateType min_rt, CoordinateType max_rt, CoordinateType min_mz, CoordinateType max_mz)
388 ConstAreaIterator
areaBeginConst(CoordinateType min_rt, CoordinateType max_rt, CoordinateType min_mz, CoordinateType max_mz)
const
392 OPENMS_PRECONDITION(this->
isSorted(
true),
"Experiment is not sorted by RT and m/z! Using ConstAreaIterator will give invalid results!")
410 ConstIterator
RTBegin(CoordinateType rt)
const
414 return lower_bound(
spectra_.begin(),
spectra_.end(), s,
typename SpectrumType::RTLess());
424 ConstIterator
RTEnd(CoordinateType rt)
const
428 return upper_bound(
spectra_.begin(),
spectra_.end(), s,
typename SpectrumType::RTLess());
440 return lower_bound(
spectra_.begin(),
spectra_.end(), s,
typename SpectrumType::RTLess());
452 return upper_bound(
spectra_.begin(),
spectra_.end(), s,
typename SpectrumType::RTLess());
491 for (
typename Base::iterator it =
spectra_.begin(); it !=
spectra_.end(); ++it)
493 if (ms_level <
Int(0) ||
Int(it->getMSLevel()) == ms_level)
509 if (it->size() == 0)
continue;
523 if (ms_level == 1 && it->getMSLevel() == 2)
525 if (!it->getPrecursors().empty())
527 double pc_rt = it->getRT();
530 double pc_mz = it->getPrecursors()[0].getMZ();
565 if (it->size() == 0)
continue;
638 std::sort(
spectra_.begin(),
spectra_.end(),
typename SpectrumType::RTLess());
645 iter->sortByPosition();
664 it->sortByPosition();
710 bool meta_present =
false;
713 if (
spectra_[i].getFloatDataArrays().size() != 0 ||
spectra_[i].getIntegerDataArrays().size() != 0 ||
spectra_[i].getStringDataArrays().size() != 0)
717 spectra_[i].getStringDataArrays().clear();
718 spectra_[i].getIntegerDataArrays().clear();
719 spectra_[i].getFloatDataArrays().clear();
741 for (std::vector<SourceFile>::const_iterator it = sfs.begin(); it != sfs.end(); ++it)
744 String path = it->getPathToFile();
745 String filename = it->getNameOfFile();
747 if (path.empty() || filename.empty())
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;
755 String ms_run_location = path +
"/" + filename;
756 ms_run_paths.push_back(ms_run_location);
773 UInt ms_level = iterator->getMSLevel();
777 if (iterator->getMSLevel() < ms_level)
782 while (iterator !=
spectra_.begin());
793 tmp.RangeManagerType::operator=(* this);
795 from.RangeManagerType::operator=(tmp);
798 tmp.ExperimentalSettings::operator=(* this);
800 from.ExperimentalSettings::operator=(tmp);
893 for (
typename Base::const_iterator spec_it =
spectra_.begin(); spec_it !=
spectra_.end(); ++spec_it)
895 if (spec_it->getMSLevel() == 1)
897 double totalIntensity = 0;
899 for (
typename SpectrumType::const_iterator peak_it = spec_it->begin(); peak_it != spec_it->end(); ++peak_it)
901 totalIntensity += peak_it->getIntensity();
904 ChromatogramPeakType peak;
905 peak.setRT(spec_it->getRT());
906 peak.setIntensity(totalIntensity);
949 template<
typename ContainerValueType,
bool addMassTraces>
952 static void addData_(SpectrumType* spectrum,
const ContainerValueType* item);
953 static void addData_(SpectrumType* spectrum,
const ContainerValueType* item,
const StringList& store_metadata_names);
956 template<
typename ContainerValueType>
960 static void addData_(SpectrumType* spectrum,
const ContainerValueType* item)
963 spectrum->insert(spectrum->end(),
PeakType());
964 spectrum->back().setIntensity(item->getIntensity());
965 spectrum->back().setPosition(item->getMZ());
968 static void addData_(SpectrumType* spectrum,
const ContainerValueType* item,
const StringList& store_metadata_names)
971 for (StringList::const_iterator itm = store_metadata_names.begin(); itm != store_metadata_names.end(); ++itm)
973 float val = std::numeric_limits<float>::quiet_NaN();
974 if (item->metaValueExists(*itm)) val = item->getMetaValue(*itm);
980 template<
typename ContainerValueType>
984 static void addData_(SpectrumType* spectrum,
const ContainerValueType* item)
986 if (item->metaValueExists(
"num_of_masstraces"))
988 Size mts = item->getMetaValue(
"num_of_masstraces");
989 int charge = (item->getCharge()==0 ? 1 : item->getCharge());
990 for (
Size i = 0; i < mts; ++i)
993 if (!item->metaValueExists(meta_name))
995 throw Exception::Precondition(__FILE__, __LINE__, __PRETTY_FUNCTION__,
String(
"Meta value '") + meta_name +
"' expected but not found in container.");
997 ContainerValueType p;
998 p.setIntensity(item->getMetaValue(meta_name));
1015 SpectrumType* spectrum = 0;
1017 spectrum = &(spectra_.back());
1018 spectrum->
setRT(rt);
1035 StringList::const_iterator itm = metadata_names.begin();
1036 for (; itm != metadata_names.end(); ++itm)
1048 template <
typename PeakT,
typename ChromatogramPeakT>
1049 std::ostream & operator<<(std::ostream & os, const MSExperiment<PeakT, ChromatogramPeakT> & exp)
1051 os <<
"-- MSEXPERIMENT BEGIN --" << std::endl;
1054 os << static_cast<const ExperimentalSettings &>(exp);
1068 os <<
"-- MSEXPERIMENT END --" << std::endl;
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
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.