Institute for Advanced Biosciences Keio University
MathDAMP Mathematica package for differential analysis of metabolite profiles
Home Overview Examples Downloads TriDAMP References Contact
MathDAMP > Examples > MathDAMP source > Core Functionality > Baseline subtraction / noise removal / smoothing

Baseline subtraction / noise removal / smoothing

Currently, only robust nonlinear regression to a polynomial is implemented as a baseline fitting algorithm. Any custom baseline fitting function may be passed as an option to the DAMPSubtractBaselines function which subtracts baselines from all electropherograms in the passed msdata.
The implementation of DAMPFitBaselineRobRegr was inspired by Ruckstuhl et al [1]. The weights are calculated in the same way, although the regression is global. Binning chromatograms speeds up the baseline fitting. For this purpose, two functions were implemented, a versatile DAMPBinChromatogram for which the binning function can be passed as an options (default: Mean) and which bins precisely to the time intervals specified (in minutes), and a fast compiled version DAMPBinChromatogramFast with limitations in the two mentioned factors. The function for binning the data for baseline estimation can be passed to the DAMPRobustNonlinearFit function as an option. It is set to (DAMPBinChromatogramFast[#,0.25]&) by default.

Options[DAMPBinChromatogram] = {Global`BinningFunctionMean} ;

DAMPBinChromatogram[chrom_, timeint_, opts___] := Module[{binfunc, predat}, binfunc  ...  -1, 1〛, timeint}] ; binfunc[#] &/@Transpose[#] &/@predat] <br />

DAMPBinChromatogramFast = Compile[{{chrom, _Real, 2}, {timeint, _Real}}, Module[{},  ... hrom] - 1)/(chrom〚 -1, 1〛 - chrom〚1, 1〛) timeint]] ]] <br />

Options[DAMPRobustPolynomialFit] = {Global`BinningFunction (DAMPBinChromatogramFast[ ... 2754;1, Global`ConvergenceCriteria.001, MaxIterations10, Global`b4.05} ;

DAMPRobustPolynomialFit[chrom_, opts___] := Module[{binfunc, poldeg, cc, maxit, bval, ssqpre ... m〚All, 1〛, (BestFit/.rgr)/.xchrom〚All, 1〛}] ] <br />

Options[DAMPSubtractBaselines] = {Global`BaselineFittingFunctionDAMPRobustPolynomialFit, Global`SampleNameSuffix"bs"} <br />

DAMPSubtractBaselines[msdata_, opts___] := Module[{bfunc}, bfunc = Global`BaselineFi ... ta〚4〛, Global`SampleNameSuffix/.{opts}/.Options[DAMPSubtractBaselines]]} ]

Noise removal is done by calculating the standard deviation of signal intensities in the selected area of each chromatogram/electropherogram (where no signals are expected) and leveling to 0 of all signal intensities within a specified multiple of the calculated standard deviation. The chromatograms/electropherograms should be baseline subtracted before applying this noise removal. Some noise related signals may exceed the threshold and stay in the dataset. If no negative peaks are expected (or they are artifacts without significance), all negative signal intensities may be leveled to 0 by setting the LevelNegativeSignals option to True (default). Also, applying the DAMPRemoveSpikes function on the noise reduced data may remove additional noise-related signals which exceeded the threshold during noise removal. DAMPThreshold may be applied to msdata to level to 0 all signal intensities within ±threshold.

Options[DAMPRemoveNoise] = {Global`TimeRange {1, 3}, Global`SDThreshold5, Global`LevelNegativeSignalsTrue, Global`SampleNameSuffix"nr"} 

DAMPRemoveNoise[msdata_, opts___] := Module[{timerange, sdthreshold, levelnegs, posrange, ne ... #12314;4〛, Global`SampleNameSuffix/.{opts}/.Options[DAMPRemoveNoise]]} ] 

DAMPRemoveSpikesFromInts = Compile[{{ints, _Real, 1}}, Module[{}, Join[{ints〚 ... nts〚i〛], {i, 2, Length[ints] - 1}], {ints〚 -1〛}] ]] 

Options[DAMPRemoveSpikes] = {Global`SampleNameSuffix"sr"} <br />

DAMPRemoveSpikes[msdata_, opts___] := Module[{},  {DAMPRemoveSpikesFromInts[#] & ... 〚4〛, Global`SampleNameSuffix/.{opts}/.Options[DAMPRemoveSpikes]]} ] <br />

Options[DAMPThreshold] = {Global`SampleNameSuffix"t"} 

DAMPThreshold[msdata_, threshold_, opts___] := Module[{},  {Chop[1. msdata〚1& ... ame[msdata〚4〛, Global`SampleNameSuffix/.{opts}/.Options[DAMPThreshold]]} ]

Chromatogram/electropherogram smoothing is done via the DAMPSmooth function which takes the smoothing function as one of its parameters. It is set to DAMPMovingAverageFast[#,9]& by default. DAMPMovingAverageFast smoothes the list of signal intensities by averaging every signal intensity with an equal number of preceding and succeeding signal intensities. The signal intensities at the beginning and at the end of the list are averaged with the available intensities within the window only. This ensures the smoothed list to have an equal number of elements as the original list.

DAMPMovingAverageFast = Compile[{{ints, _Real, 1}, {winsize, _Integer}}, Module[{vicdist, in ... e[ints, {Max[1, i - vicdist], Min[i + vicdist, intslen]}]], {i, 1, intslen}] ]] 

Options[DAMPSmooth] = {Global`SmoothingFunction (DAMPMovingAverageFast[#, 9] &), Global`SampleNameSuffix"s"} 

DAMPSmooth[msdata_, opts___] := Module[{smoothingfunc}, smoothingfunc = Global`Smoot ... leName[msdata〚4〛, Global`SampleNameSuffix/.{opts}/.Options[DAMPSmooth]]} ]