OpenMS
SpectraMerger Class Reference

Merges blocks of MS or MS2 spectra. More...

#include <OpenMS/FILTERING/TRANSFORMERS/SpectraMerger.h>

Inheritance diagram for SpectraMerger:
[legend]
Collaboration diagram for SpectraMerger:
[legend]

Classes

class  SpectraDistance_
 

Public Types

typedef std::map< Size, std::vector< Size > > MergeBlocks
 blocks of spectra (master-spectrum index to sacrifice-spectra(the ones being merged into the master-spectrum)) More...
 
typedef std::map< Size, std::vector< std::pair< Size, double > > > AverageBlocks
 blocks of spectra (master-spectrum index to update to spectra to average over) More...
 
- Public Types inherited from ProgressLogger
enum  LogType { CMD , GUI , NONE }
 Possible log types. More...
 

Public Member Functions

 SpectraMerger ()
 default constructor More...
 
 SpectraMerger (const SpectraMerger &source)
 copy constructor More...
 
 SpectraMerger (SpectraMerger &&source)=default
 move constructor More...
 
 ~SpectraMerger () override
 destructor More...
 
SpectraMergeroperator= (const SpectraMerger &source)
 assignment operator More...
 
SpectraMergeroperator= (SpectraMerger &&source)=default
 move-assignment operator More...
 
template<typename MapType >
void mergeSpectraBlockWise (MapType &exp)
 
template<typename MapType >
void mergeSpectraPrecursors (MapType &exp)
 merges spectra with similar precursors (must have MS2 level) More...
 
template<typename MapType >
void average (MapType &exp, const String &average_type, int ms_level=-1)
 average over neighbouring spectra More...
 
- Public Member Functions inherited from DefaultParamHandler
 DefaultParamHandler (const String &name)
 Constructor with name that is displayed in error messages. More...
 
 DefaultParamHandler (const DefaultParamHandler &rhs)
 Copy constructor. More...
 
virtual ~DefaultParamHandler ()
 Destructor. More...
 
DefaultParamHandleroperator= (const DefaultParamHandler &rhs)
 Assignment operator. More...
 
virtual bool operator== (const DefaultParamHandler &rhs) const
 Equality operator. More...
 
void setParameters (const Param &param)
 Sets the parameters. More...
 
const ParamgetParameters () const
 Non-mutable access to the parameters. More...
 
const ParamgetDefaults () const
 Non-mutable access to the default parameters. More...
 
const StringgetName () const
 Non-mutable access to the name. More...
 
void setName (const String &name)
 Mutable access to the name. More...
 
const std::vector< String > & getSubsections () const
 Non-mutable access to the registered subsections. More...
 
- Public Member Functions inherited from ProgressLogger
 ProgressLogger ()
 Constructor. More...
 
virtual ~ProgressLogger ()
 Destructor. More...
 
 ProgressLogger (const ProgressLogger &other)
 Copy constructor. More...
 
ProgressLoggeroperator= (const ProgressLogger &other)
 Assignment Operator. More...
 
void setLogType (LogType type) const
 Sets the progress log that should be used. The default type is NONE! More...
 
LogType getLogType () const
 Returns the type of progress log being used. More...
 
void startProgress (SignedSize begin, SignedSize end, const String &label) const
 Initializes the progress display. More...
 
void setProgress (SignedSize value) const
 Sets the current progress. More...
 
void endProgress (UInt64 bytes_processed=0) const
 
void nextProgress () const
 increment progress by 1 (according to range begin-end) More...
 

Static Public Member Functions

static bool areMassesMatched (double mz1, double mz2, double tol_ppm, int max_c)
 check if the first and second mzs might be from the same mass More...
 
- Static Public Member Functions inherited from DefaultParamHandler
static void writeParametersToMetaValues (const Param &write_this, MetaInfoInterface &write_here, const String &key_prefix="")
 Writes all parameters to meta values. More...
 

Protected Member Functions

template<typename MapType >
void mergeSpectra_ (MapType &exp, const MergeBlocks &spectra_to_merge, const UInt ms_level)
 merges blocks of spectra of a certain level More...
 
template<typename MapType >
void averageProfileSpectra_ (MapType &exp, const AverageBlocks &spectra_to_average_over, const UInt ms_level)
 average spectra (profile mode) More...
 
template<typename MapType >
void averageCentroidSpectra_ (MapType &exp, const AverageBlocks &spectra_to_average_over, const UInt ms_level)
 average spectra (centroid mode) More...
 
- Protected Member Functions inherited from DefaultParamHandler
virtual void updateMembers_ ()
 This method is used to update extra member variables at the end of the setParameters() method. More...
 
void defaultsToParam_ ()
 Updates the parameters after the defaults have been set in the constructor. More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from ProgressLogger
static String logTypeToFactoryName_ (LogType type)
 Return the name of the factory product used for this log type. More...
 
- Protected Attributes inherited from DefaultParamHandler
Param param_
 Container for current parameters. More...
 
Param defaults_
 Container for default parameters. This member should be filled in the constructor of derived classes! More...
 
std::vector< Stringsubsections_
 Container for registered subsections. This member should be filled in the constructor of derived classes! More...
 
String error_name_
 Name that is displayed in error messages during the parameter checking. More...
 
bool check_defaults_
 If this member is set to false no checking if parameters in done;. More...
 
bool warn_empty_defaults_
 If this member is set to false no warning is emitted when defaults are empty;. More...
 
- Protected Attributes inherited from ProgressLogger
LogType type_
 
time_t last_invoke_
 
ProgressLoggerImplcurrent_logger_
 
- Static Protected Attributes inherited from ProgressLogger
static int recursion_depth_
 

Detailed Description

Merges blocks of MS or MS2 spectra.

Parameter's are accessible via the DefaultParamHandler.

Parameters of this class are:

NameTypeDefaultRestrictionsDescription
mz_binning_width float5.0 min: 0.0minimum m/z distance for two data points (profile data) or peaks (centroided data) to be considered distinct. Closer data points or peaks will be merged.
mz_binning_width_unit stringppm Da, ppmUnit in which the distance between two data points or peaks is given.
sort_blocks stringRT_ascending RT_ascending, RT_descendingSort blocks by before merging them (useful for precursor order)
average_gaussian:spectrum_type stringautomatic profile, centroid, automaticSpectrum type of the MS level to be averaged
average_gaussian:ms_level int1 min: 0If set to be 0, each MS level will be merged from 1 to max. Otherwise, average spectra of this level. All other spectra remain unchanged.
average_gaussian:rt_FWHM float5.0 min: 0.0 max: 1.0e11FWHM of Gauss curve in seconds to be averaged over.
average_gaussian:cutoff float0.01 min: 0.0 max: 1.0Intensity cutoff for Gaussian. The Gaussian RT profile decreases from 1 at its apex to 0 at infinity. Spectra for which the intensity of the Gaussian drops below the cutoff do not contribute to the average.
average_gaussian:precursor_mass_tol float0.0 min: 0.0PPM mass tolerance for precursor mass. If set, MSn (n>2) spectra of precursor masses within the tolerance are averaged.
average_gaussian:precursor_max_charge int1 min: 1Possible maximum precursor ion charge. Effective only when average_gaussian:precursor_mass_tol option is active.
average_tophat:spectrum_type stringautomatic profile, centroid, automaticSpectrum type of the MS level to be averaged
average_tophat:ms_level int1 min: 0If set to be 0, each MS level will be merged from 1 to max. Otherwise, average spectra of this level. All other spectra remain unchanged.
average_tophat:rt_range float5.0 min: 0.0 max: 1.0e11RT range to be averaged over, i.e. +/-(RT range)/2 from each spectrum.
average_tophat:rt_unit stringscans scans, secondsUnit for RT range.
block_method:ms_levels int list[1] min: 1Merge spectra of this level. All spectra with other MS levels remain untouched.
block_method:rt_block_size int5 min: 1Maximum number of scans to be summed up.
block_method:rt_max_length float0.0 min: 0.0 max: 1.0e11Maximum RT size of the block in seconds (0.0 = no size restriction).
precursor_method:mz_tolerance float1.0e-04 min: 0.0Max m/z distance of the precursor entries of two spectra to be merged in [Da].
precursor_method:mass_tolerance float0.0 min: 0.0Max mass distance of the precursor entries of two spectra to be merged in [Da]. Active when set to a positive value.
precursor_method:rt_tolerance float5.0 min: 0.0Max RT distance of the precursor entries of two spectra to be merged in [s].

Note:
  • If a section name is documented, the documentation is displayed as tooltip.
  • Advanced parameter names are italic.

Member Typedef Documentation

◆ AverageBlocks

typedef std::map<Size, std::vector<std::pair<Size, double> > > AverageBlocks

blocks of spectra (master-spectrum index to update to spectra to average over)

◆ MergeBlocks

typedef std::map<Size, std::vector<Size> > MergeBlocks

blocks of spectra (master-spectrum index to sacrifice-spectra(the ones being merged into the master-spectrum))

Constructor & Destructor Documentation

◆ SpectraMerger() [1/3]

default constructor

◆ SpectraMerger() [2/3]

SpectraMerger ( const SpectraMerger source)

copy constructor

◆ SpectraMerger() [3/3]

SpectraMerger ( SpectraMerger &&  source)
default

move constructor

◆ ~SpectraMerger()

~SpectraMerger ( )
override

destructor

Member Function Documentation

◆ areMassesMatched()

static bool areMassesMatched ( double  mz1,
double  mz2,
double  tol_ppm,
int  max_c 
)
inlinestatic

check if the first and second mzs might be from the same mass

Parameters
mz1the first m/z value
mz2the second m/z value
tol_ppmtolerance in ppm
max_cmaximum possible charge value

References OpenMS::Constants::ISOTOPE_MASSDIFF_55K_U, and OpenMS::Constants::PROTON_MASS_U.

◆ average()

void average ( MapType exp,
const String average_type,
int  ms_level = -1 
)
inline

average over neighbouring spectra

Parameters
expexperimental data to be averaged
average_typeaveraging type to be used ("gaussian" or "tophat")
ms_leveltarge MS level. If it is -1, ms_level will be determined by ms_level parameter.

References MSExperiment::begin(), SpectrumSettings::CENTROID, MSExperiment::end(), SpectrumSettings::PROFILE, MSExperiment::sortSpectra(), and OpenMS::Math::sum().

Referenced by TOPPFLASHDeconv::main_().

◆ averageCentroidSpectra_()

void averageCentroidSpectra_ ( MapType exp,
const AverageBlocks spectra_to_average_over,
const UInt  ms_level 
)
inlineprotected

average spectra (centroid mode)

Averages spectra in centroid mode of one MS level in an experiment. The blocks of spectra to be combined and their relative weights have previously determined. The averaged spectra are generated in two steps: (1) The m/z of all spectra in a block are collected and sorted. Their corresponding intensities are weighted. (2) m/z positions closer than mz_binning_width are combined to a single peak. The m/z are averaged and the corresponding intensities summed.

Parameters
expexperimental data to be averaged
spectra_to_average_overmapping of spectral index to set of spectra to average over with corresponding weights
ms_levelMS level of spectra to be averaged

References MSExperiment::addSpectrum(), MSExperiment::begin(), MSSpectrum::clear(), MSExperiment::end(), ProgressLogger::endProgress(), Peak1D::setIntensity(), Peak1D::setMZ(), ProgressLogger::setProgress(), and ProgressLogger::startProgress().

◆ averageProfileSpectra_()

void averageProfileSpectra_ ( MapType exp,
const AverageBlocks spectra_to_average_over,
const UInt  ms_level 
)
inlineprotected

average spectra (profile mode)

Averages spectra in profile mode of one MS level in an experiment. The blocks of spectra to be combined and their relative weights have previously been determined. The averaged spectra are generated in two steps: (1) The m/z of all spectra in a block are collected and sorted. m/z positions closer than mz_binning_width are removed. (2) At these positions the weighted sum of all spline interpolations is calculated.

The first step ensures roughly the same sampling rate as the one of the original spectra. The exact m/z position is not crucial, since not the original intensities but the spline-interpolated intensities are used.

Parameters
expexperimental data to be averaged
spectra_to_average_overmapping of spectral index to set of spectra to average over with corresponding weights
ms_levelMS level of spectra to be averaged

References MSExperiment::addSpectrum(), MSExperiment::begin(), MSSpectrum::clear(), MSExperiment::end(), SplineInterpolatedPeaks::Navigator::eval(), SplineInterpolatedPeaks::getNavigator(), SplineInterpolatedPeaks::getPosMax(), SplineInterpolatedPeaks::getPosMin(), Peak1D::setIntensity(), and Peak1D::setMZ().

◆ mergeSpectra_()

void mergeSpectra_ ( MapType exp,
const MergeBlocks spectra_to_merge,
const UInt  ms_level 
)
inlineprotected

merges blocks of spectra of a certain level

Merges spectra belonging to the same block, setting their MS level to ms_level. All old spectra of level ms_level are removed, and the new consensus spectra (one per block) are added. All spectra with other MS levels remain untouched. The resulting map is NOT sorted!

References MSExperiment::addSpectrum(), MSExperiment::begin(), MSExperiment::clear(), MSSpectrum::clear(), MSExperiment::end(), SpectrumSettings::getNativeID(), SpectrumSettings::getPrecursors(), MSSpectrum::getRT(), MSExperiment::getSpectra(), SpectrumAlignment::getSpectrumAlignment(), OPENMS_LOG_INFO, OPENMS_LOG_WARN, MSSpectrum::setMSLevel(), SpectrumSettings::setNativeID(), DefaultParamHandler::setParameters(), SpectrumSettings::setPrecursors(), MSSpectrum::setRT(), Param::setValue(), MSExperiment::size(), MSSpectrum::sortByPosition(), and SpectrumSettings::unify().

◆ mergeSpectraBlockWise()

void mergeSpectraBlockWise ( MapType exp)
inline

◆ mergeSpectraPrecursors()

void mergeSpectraPrecursors ( MapType exp)
inline

◆ operator=() [1/2]

SpectraMerger& operator= ( const SpectraMerger source)

assignment operator

◆ operator=() [2/2]

SpectraMerger& operator= ( SpectraMerger &&  source)
default

move-assignment operator