Skip to content

efekarakus/d3-peaks

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

d3-peaks

Find peaks in an array based on "Improved peak detection" [1]

[1] Du, Pan, Warren A. Kibbe, and Simon M. Lin. "Improved peak detection in mass spectrum by incorporating continuous wavelet transform-based pattern matching." Bioinformatics 22.17 (2006): 2059-2065.

For examples, please see:

Installing

If you use NPM, npm install d3-peaks. Otherwise, download the latest release.

API Reference

Find Peaks

# d3_peaks.findPeaks([signal])

If specified, returns an array of points that represents the peaks in the signal. Otherwise, returns a function to find peaks. An example point returned is:

[{
  index: 10,
  width: 2,
  snr: 1.5
}]

Where index represents the index of the peak in the original signal, width is the width of the peak, and snr is the signal to noise ratio.

# widths([w])

If specified, [w] is an array of expected peak widths that the algorithm should find. Otherwise, returns the current values.

var findPeaks = d3_peaks.findPeaks().widths([1, 2, 10]);

# kernel(kernel)

If specified, changes the kernel function or "smoother". Otherwise, returns the current value.

var ricker = d3_peaks.ricker;
var findPeaks = d3_peaks.findPeaks().kernel(ricker);

# gapThreshold(gap)

If specified, gap represents the maximum allowed number of gaps in the ridgeline. The higher is this number the more connected peaks we will find. Otherwise, returns the current value.

var findPeaks = d3_peaks.findPeaks().gapThreshold(3);

# minLineLength(length)

If specified, length represents the minimum ridgeline length. The higher is this number the more constrained are the lines and we will find fewer peaks. Otherwise, returns the current value.

var findPeaks = d3_peaks.findPeaks().minLineLength(2);

# minSNR(snr)

If specified, snr represents the minimum signal to noise ratio the ridge lines should have. Otherwise, returns the current value. By default the minimum snr is 1.0 for peaks of width 1. This number should be higher for bigger widths.

var findPeaks = d3_peaks.findPeaks().minSNR(1.5);

Convolution

# d3_peaks.convolve([signal])

If specified, convolve the signal array with the smoother. Otherwise, returns a function to convolve a signal with the smoother.

# kernel(kernel)

If specified, changes the kernel function or "smoother". Otherwise, returns the current kernel.

var convolve = d3_peaks.convolve()
                        .kernel(ricker);
var signal = convolve([1,2,3,2.5,0,1,4,5,3,-1,-2]);

Kernels

# d3_peaks.ricker(x)

If specified , it returns φ(x). Otherwise, returns a function to compute the ricker wavelet with default standard deviation 1.0.

# std(value)

If specified, it sets the standard deviation of the curve to value. Otherwise, returns the "width" or standard deviation of the wavelet.

# reach()

Returns the range value reach such that φ(reach) ~ 0.

var y = d3_peaks.ricker()
  .std(2);
var output = y(3.5);
var reach = y.reach();