Skip to content

Commit

Permalink
feat(ms-spectrum): getBestPeaks have now min and maxValue (#224)
Browse files Browse the repository at this point in the history
* feat(ms-spectrum): getBestPeaks have now min and maxValue

closes: #222

* feat(peptide): allow conversion of lowercase AA sequences (#223)

* feat(peptide): allow conversion of lowercase AA sequences

* chore: add --coverage to test-only
  • Loading branch information
lpatiny authored Nov 27, 2024
1 parent f547db4 commit 8a3ae33
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/ms-spectrum/src/__tests__/getBestPeaks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,31 @@ describe('test getBestPeaks', () => {
]);
});

it('maxValue', () => {
let result = getBestPeaks(peaks, { maxValue: 2 });
expect(result).toStrictEqual([
{ x: 1, y: 1, close: false },
{ x: 3, y: 2, close: false },
]);
});

it('minValue', () => {
let result = getBestPeaks(peaks, { minValue: 3 });
expect(result).toStrictEqual([
{ x: 2, y: 4, close: false },
{ x: 4, y: 5, close: false },
{ x: 5, y: 3, close: false },
]);
});

it('minValue maxValue', () => {
let result = getBestPeaks(peaks, { minValue: 2, maxValue: 3 });
expect(result).toStrictEqual([
{ x: 3, y: 2, close: false },
{ x: 5, y: 3, close: false },
]);
});

it('complex spectrum', () => {
const data = xy2ToXY(
JSON.parse(
Expand Down
5 changes: 5 additions & 0 deletions packages/ms-spectrum/src/getBestPeaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { xyObjectMaxXPoint, xyObjectMinXPoint } from 'ml-spectra-processing';
* @param {object} [options={}]
* @param {number} [options.from] - min X value of the window to consider
* @param {number} [options.to] - max X value of the window to consider
* @param {number} [options.minValue=Number.NEGATIVE_INFINITY] - min Y value of the window to consider
* @param {number} [options.maxValue=Number.POSITIVE_INFINITY] - max Y value of the window to consider
* @param {number} [options.searchMonoisotopicRatio=0] - search previous peaks with at least ratio height
* @param {number} [options.limit=20] - max number of peaks
* @param {number} [options.threshold=0.01] - minimal intensity compare to base peak
Expand All @@ -26,11 +28,14 @@ export function getBestPeaks(peaks, options = {}) {
threshold = 0.01,
numberCloseSlots = 50,
numberSlots = 10,
minValue = Number.NEGATIVE_INFINITY,
maxValue = Number.POSITIVE_INFINITY,
} = options;
let slot = (to - from) / numberSlots;
let closeSlot = (to - from) / numberCloseSlots;
let selected = peaks
.filter((peak) => peak.x >= from && peak.x <= to)
.filter((peak) => peak.y >= minValue && peak.y <= maxValue)
.map((peak) => {
return {
peak,
Expand Down

0 comments on commit 8a3ae33

Please sign in to comment.