Skip to content

Commit

Permalink
fix: getPeaks heightFilter is based on the median of Y
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed Feb 20, 2020
1 parent a91930c commit 3c231e7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
16 changes: 16 additions & 0 deletions examples/full.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { SpectrumGenerator } from 'spectrum-generator';
import { Chromatogram } from '../src';
let spectrumGenerator = new SpectrumGenerator({ start: 0, end: 1000 });

spectrumGenerator.addPeak([100, 100]);
spectrumGenerator.addPeak([200, 20]);
spectrumGenerator.addPeak([300, 30]);
spectrumGenerator.addPeak([400, 40]);
spectrumGenerator.addPeak([500, 50]);

const { x, y } = spectrumGenerator.getSpectrum();

const chromatogram = new Chromatogram(x, { tic: y });

const peaks = chromatogram.getPeaks({ heightFilter: 2 });
console.log(peaks);
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"jest": "^25.1.0",
"jest-matcher-deep-close-to": "^1.3.0",
"prettier": "^1.19.1",
"rollup": "^1.31.1"
"rollup": "^1.31.1",
"spectrum-generator": "^3.1.0"
},
"dependencies": {
"binary-search": "^1.3.6",
Expand All @@ -57,6 +58,7 @@
"mf-parser": "^0.13.1",
"ml-array-max": "^1.1.2",
"ml-array-mean": "^1.1.2",
"ml-array-median": "^1.1.2",
"ml-array-sum": "^1.1.2",
"ml-gsd": "^2.0.7",
"ml-regression-polynomial": "^2.1.0",
Expand Down
5 changes: 3 additions & 2 deletions src/util/getPeaks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { gsd, post } from 'ml-gsd';

import median from 'ml-array-median';
/**
* Apply the GSD peak picking algorithm
* @param {Chromatogram} chromatogram - GC/MS chromatogram where make the peak picking
Expand Down Expand Up @@ -58,7 +58,8 @@ export function getPeaks(chromatogram, options = {}) {
peakList.sort((a, b) => a.height - b.height);

// filter height by factor
let medianHeight = peakList[Math.floor((peakList.length - 1) / 2)].height;
let medianHeight = median(serie);

peakList = peakList.filter((val) => val.height > medianHeight * heightFilter);

let { factor = 1, overlap = false } = broadenPeaks;
Expand Down

0 comments on commit 3c231e7

Please sign in to comment.