UNPKG

ml-gsd

Version:
29 lines 947 B
/** * Group peaks based on factor * In order to group peaks we only need the x and width value. This means that * in the current implementation we don't take into account the asymmetry of peaks */ export function groupPeaks(peaks, options = {}) { if (peaks?.length === 0) return []; const { factor = 1 } = options; peaks = JSON.parse(JSON.stringify(peaks)); peaks.sort((a, b) => a.x - b.x); let previousPeak = peaks[0]; let currentGroup = [previousPeak]; const groups = [currentGroup]; for (let i = 1; i < peaks.length; i++) { const peak = peaks[i]; if ((peak.x - previousPeak.x) / ((peak.width + previousPeak.width) / 2) <= factor) { currentGroup.push(peak); } else { currentGroup = [peak]; groups.push(currentGroup); } previousPeak = peak; } return groups; } //# sourceMappingURL=groupPeaks.js.map