Skip to content

Commit

Permalink
fix: update ml-spectra-processing and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed Mar 7, 2024
1 parent 1c405b0 commit 8b646d9
Show file tree
Hide file tree
Showing 26 changed files with 113 additions and 107 deletions.
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,32 @@
"trailingComma": "all"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.21.2",
"@babel/preset-typescript": "^7.21.0",
"@types/jest": "^29.5.0",
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@types/jest": "^29.5.12",
"chemcalc": "^3.4.1",
"cheminfo-build": "^1.2.0",
"eslint": "^8.36.0",
"eslint-config-cheminfo-typescript": "^11.3.1",
"eslint-plugin-jest": "^27.2.1",
"eslint": "^8.57.0",
"eslint-config-cheminfo-typescript": "^12.2.0",
"eslint-plugin-jest": "^27.9.0",
"esm": "^3.2.25",
"jest": "^29.5.0",
"jest": "^29.7.0",
"jest-matcher-deep-close-to": "^3.0.2",
"mf-global": "^2.1.2",
"mf-global": "^3.0.16",
"ml-stat": "^1.3.3",
"nodemon": "^2.0.22",
"prettier": "^2.8.7",
"rimraf": "^4.4.1",
"spectrum-generator": "^8.0.6",
"typescript": "^5.0.2",
"xy-parser": "^5.0.4"
"nodemon": "^3.1.0",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"spectrum-generator": "^8.0.11",
"typescript": "^5.4.2",
"xy-parser": "^5.0.5"
},
"dependencies": {
"@lukeed/uuid": "^2.0.0",
"cheminfo-types": "^1.4.0",
"@lukeed/uuid": "^2.0.1",
"cheminfo-types": "^1.7.2",
"ml-peak-shape-generator": "^4.1.2",
"ml-savitzky-golay-generalized": "^4.0.1",
"ml-spectra-fitting": "^4.2.1",
"ml-spectra-processing": "^14.0.0"
"ml-spectra-fitting": "^4.2.3",
"ml-spectra-processing": "^14.2.0"
}
}
4 changes: 2 additions & 2 deletions src/__tests__/ethylvinylether.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { gsd } from '../gsd';
describe('Global spectra deconvolution NMR spectra', () => {
// Test case obtained from Pag 443, Chap 8.
it('Ethylvinylether should have 21 peaks', () => {
let spectrum: number[][] = JSON.parse(
const spectrum: number[][] = JSON.parse(
readFileSync(`${__dirname}/data/ethylvinylether.json`, 'utf-8'),
);
let result = gsd(
const result = gsd(
{ x: spectrum[0].reverse(), y: spectrum[1].reverse() },
{
minMaxRatio: 0.03,
Expand Down
11 changes: 7 additions & 4 deletions src/__tests__/gaussian-noise.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ describe('smooth:false option', () => {
});

it('positive maxima peaks', () => {
let peakList = gsd(data);
const peakList = gsd(data);
expect(peakList).toMatchCloseTo([
{ x: -0.5, y: 1.131 },
{ x: 0.5, y: 1.05 },
]);
});

it('negative maxima peaks', () => {
let peakList = gsd({ x: data.x, y: data.y.map((value) => value - 2) }, {});
const peakList = gsd(
{ x: data.x, y: data.y.map((value) => value - 2) },
{},
);
expect(peakList).toMatchCloseTo([
{ x: -0.5, y: -0.868 },
{ x: 0.5, y: -0.95 },
Expand All @@ -46,7 +49,7 @@ describe('smooth:false option', () => {

it('Negative peaks', () => {
// we check negative peaks
let peakList = gsd(
const peakList = gsd(
{ x: data.x, y: data.y.map((value) => -value) },
{ maxCriteria: false },
);
Expand All @@ -58,7 +61,7 @@ describe('smooth:false option', () => {

it('minima peaks', () => {
// we check negative peaks
let peakList = gsd(
const peakList = gsd(
{ x: data.x, y: data.y.map((value) => 1 - value) },
{ maxCriteria: false },
);
Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/gaussian-noiseParam.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ describe('smooth:false option', () => {
});

it('positive maxima peaks but noiseLevel over the peaks', () => {
let peakList = gsd(data, { noiseLevel: 1.2 });
const peakList = gsd(data, { noiseLevel: 1.2 });
expect(peakList).toStrictEqual([]);
});

it('positive maxima peaks', () => {
let peakList = gsd(data, { noiseLevel: 0.5 });
const peakList = gsd(data, { noiseLevel: 0.5 });
expect(peakList).toMatchCloseTo([
{ x: -0.5, y: 1.131 },
{ x: 0.5, y: 1.05 },
]);
});

it('negative maxima peaks', () => {
let peakList = gsd(
const peakList = gsd(
{ x: data.x, y: data.y.map((value) => value - 2) },
{ noiseLevel: -1.5 },
);
Expand All @@ -54,7 +54,7 @@ describe('smooth:false option', () => {

it('Negative peaks', () => {
// we check negative peaks
let peakList = gsd(
const peakList = gsd(
{ x: data.x, y: data.y.map((value) => -value) },
{ maxCriteria: false, noiseLevel: -0.5 },
);
Expand All @@ -66,7 +66,7 @@ describe('smooth:false option', () => {

it('Negative peaks with noiseLevel too low', () => {
// we check negative peaks
let peakList = gsd(
const peakList = gsd(
{ x: data.x, y: data.y.map((value) => -value) },
{ maxCriteria: false, noiseLevel: -1.2 },
);
Expand All @@ -75,7 +75,7 @@ describe('smooth:false option', () => {

it('minima peaks', () => {
// we check negative peaks
let peakList = gsd(
const peakList = gsd(
{ x: data.x, y: data.y.map((value) => 1 - value) },
{ maxCriteria: false, noiseLevel: 0.5 },
);
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/gaussian-overlapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('gaussian overlapping', () => {
},
});

let peaks = gsd(data, {});
const peaks = gsd(data, {});
expect(peaks).toMatchCloseTo([
{
x: -0.1,
Expand All @@ -43,7 +43,7 @@ describe('gaussian overlapping', () => {
},
]);

let optimizedPeaks = optimizePeaks(data, peaks, { groupingFactor: 3 });
const optimizedPeaks = optimizePeaks(data, peaks, { groupingFactor: 3 });
expect(optimizedPeaks).toMatchCloseTo([
{
x: -0.1,
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/gaussian-smooth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('gaussian simulated peaks', () => {
},
});

let peakList = gsd(data, {
const peakList = gsd(data, {
smoothY: true,
});
expect(peakList).toBeDeepCloseTo([
Expand Down
21 changes: 12 additions & 9 deletions src/__tests__/gaussian.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ describe('smooth:false option', () => {
// we have here a low resolution spectrum so the impact is big

it('positive maxima peaks', () => {
let peakList = gsd(data);
const peakList = gsd(data);

let expected = [
const expected = [
{
x: -0.5,
y: 1,
Expand Down Expand Up @@ -59,9 +59,12 @@ describe('smooth:false option', () => {
});

it('negative maxima peaks', () => {
let peakList = gsd({ x: data.x, y: data.y.map((value) => value - 2) }, {});
const peakList = gsd(
{ x: data.x, y: data.y.map((value) => value - 2) },
{},
);

let expected = [
const expected = [
{
x: -0.5,
y: -1,
Expand Down Expand Up @@ -90,11 +93,11 @@ describe('smooth:false option', () => {

it('Negative peaks', () => {
// we check negative peaks
let peakList = gsd(
const peakList = gsd(
{ x: data.x, y: data.y.map((value) => -value) },
{ maxCriteria: false },
);
let expected = [
const expected = [
{
x: -0.5,
y: -1,
Expand Down Expand Up @@ -124,11 +127,11 @@ describe('smooth:false option', () => {

it('minima peaks', () => {
// we check negative peaks
let peakList = gsd(
const peakList = gsd(
{ x: data.x, y: data.y.map((value) => 1 - value) },
{ maxCriteria: false },
);
let expected = [
const expected = [
{
x: -0.5,
y: 0,
Expand Down Expand Up @@ -157,7 +160,7 @@ describe('smooth:false option', () => {
});

it('negative peaks with maxCriteria true', () => {
let peakList = gsd(
const peakList = gsd(
{ x: data.x, y: data.y.map((value) => -value) },
{ maxCriteria: true },
);
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/power.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ describe('power', () => {
// we have here a low resolution spectrum so the impact is big

it('default options', () => {
let peakList = gsd(data);
let expected = [
const peakList = gsd(data);
const expected = [
{
id: peakList[0].id,
x: 5,
Expand All @@ -66,7 +66,7 @@ describe('power', () => {
expect(peakList).toBeDeepCloseTo(expected);
});
it('custom options', () => {
let peakList = gsd(data, {
const peakList = gsd(data, {
smoothY: false,
sgOptions: { windowSize: 7, polynomial: 3 },
});
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/ubiquitin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ expect.extend({ toBeDeepCloseTo, toMatchCloseTo });

describe('Global spectra deconvolution ubiquitin', () => {
it('HR mass spectra', () => {
let spectrum = parseXY(
const spectrum = parseXY(
readFileSync(`${__dirname}/data/ubiquitin.txt`, 'utf-8'),
);

let peaks = gsd(spectrum, {
const peaks = gsd(spectrum, {
minMaxRatio: 0.0,
smoothY: false,
realTopDetection: true,
Expand Down
14 changes: 7 additions & 7 deletions src/__tests__/zero.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ import { gsd } from '../gsd';

describe('Simple test cases', () => {
it('length = 0', () => {
let x = [];
let y = [];
const x = [];
const y = [];
expect(() => {
gsd({ x, y });
}).toThrow('input must not be empty');
});

it('length = 2', () => {
let x = [1, 2];
let y = [2, 3];
const x = [1, 2];
const y = [2, 3];
expect(() => {
gsd({ x, y });
}).toThrow('Window size is higher than the data length 9>2');
});

it('no peaks', () => {
let x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
let y = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0];
let peaks = gsd({ x, y });
const x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
const y = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0];
const peaks = gsd({ x, y });
expect(peaks[0].x).toBe(8);
});
});
18 changes: 9 additions & 9 deletions src/gsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ export type GSDPeakID = MakeMandatory<GSDPeak, 'id'>;
*/

export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeakID[] {
let {
let { noiseLevel } = options;
const {
sgOptions = {
windowSize: 9,
polynomial: 3,
},
noiseLevel,
smoothY = false,
maxCriteria = true,
minMaxRatio = 0.00025,
realTopDetection = false,
} = options;

let { x, y } = data;
const { x } = data;
let { y } = data;
if (xIsMonotonic(x) !== 1) {
throw new Error('GSD only accepts monotone increasing x values');
}
Expand Down Expand Up @@ -141,9 +141,9 @@ export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeakID[] {

let lastMax: XIndex | null = null;
let lastMin: XIndex | null = null;
let minddY: number[] = [];
let intervalL: XIndex[] = [];
let intervalR: XIndex[] = [];
const minddY: number[] = [];
const intervalL: XIndex[] = [];
const intervalR: XIndex[] = [];

// By the intermediate value theorem We cannot find 2 consecutive maximum or minimum
for (let i = 1; i < yData.length - 1; ++i) {
Expand Down Expand Up @@ -186,7 +186,7 @@ export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeakID[] {

const peaks: GSDPeakID[] = [];
for (const minddYIndex of minddY) {
let deltaX = x[minddYIndex];
const deltaX = x[minddYIndex];
let possible = -1;
let k = lastK + 1;
let minDistance = Number.POSITIVE_INFINITY;
Expand All @@ -210,7 +210,7 @@ export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeakID[] {

if (possible !== -1) {
if (yData[minddYIndex] > yThreshold) {
let width = Math.abs(intervalR[possible].x - intervalL[possible].x);
const width = Math.abs(intervalR[possible].x - intervalL[possible].x);
peaks.push({
id: generateID(),
x: deltaX,
Expand Down
Loading

0 comments on commit 8b646d9

Please sign in to comment.