diff --git a/examples/full.js b/examples/full.js new file mode 100644 index 0000000..fc1e3d8 --- /dev/null +++ b/examples/full.js @@ -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); diff --git a/package.json b/package.json index dfd9f02..0ec7f4e 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/util/getPeaks.js b/src/util/getPeaks.js index 5cca722..cf68e4e 100644 --- a/src/util/getPeaks.js +++ b/src/util/getPeaks.js @@ -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 @@ -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;