Skip to content

Commit 2b3a403

Browse files
authored
feat!: homogenize and generalize output (#63)
* feat!: refactor gsd homogenize output rename base to noiseLevel by default width is FWHM of a gaussian remove properties 'left' and 'right' * feat!: refactor broadenPeaks homogenize output remove properties 'from' and 'to' * chore: refactor groupPeaks make a copy * feat!: refactor joinBroadPeaks make a copy homogenize output * feat!: homogenize input/output optimizePeaks * chore: adaptation of test cases * chore: remove nodejs 10.x 15.x n add 16.x * feat!: update ml-spectra-fitting to 2.0.0 * chore: use toBeClose instead of toStrictEqual
1 parent e2c843a commit 2b3a403

21 files changed

+169
-219
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
runs-on: ubuntu-latest
2525
strategy:
2626
matrix:
27-
node-version: [10.x, 12.x, 14.x, 15.x]
27+
node-version: [12.x, 14.x, 16.x]
2828
fail-fast: false
2929
steps:
3030
- uses: actions/checkout@v2

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"eslint-fix": "npm run eslint -- --fix",
2121
"compile": "rollup -c",
2222
"prepack": "npm run compile",
23+
"prettier": "prettier --check src",
24+
"prettier-write": "prettier --write src",
2325
"test": "npm run test-coverage && npm run eslint",
2426
"test-only": "jest",
2527
"test-coverage": "jest --coverage"
@@ -77,7 +79,7 @@
7779
"cheminfo-types": "^0.5.0",
7880
"ml-peak-shape-generator": "^2.0.2",
7981
"ml-savitzky-golay-generalized": "2.0.3",
80-
"ml-spectra-fitting": "^1.0.0",
82+
"ml-spectra-fitting": "^2.0.0",
8183
"ml-spectra-processing": "^6.8.0"
8284
}
8385
}

src/__tests__/bigLowS2NSpectrum.js renamed to src/__tests__/bigLowS2NSpectrum.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('Global spectra deconvolution NMR spectra', () => {
2323
},
2424
);
2525

26-
joinBroadPeaks(pp, { width: 0.25 });
26+
pp = joinBroadPeaks(pp, { width: 0.25 });
2727

2828
expect(pp).toHaveLength(91);
2929
});

src/__tests__/broadNMR.js renamed to src/__tests__/broadNMR.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ describe('Global spectra deconvolution NMR spectra', () => {
2121
},
2222
},
2323
);
24-
joinBroadPeaks(result, { width: 0.25, shape: { kind: 'lorentzian' } });
25-
expect(result).toHaveLength(14);
26-
result.forEach((peak) => {
24+
const newResult = joinBroadPeaks(result, { width: 0.25, shape: { kind: 'lorentzian' } });
25+
expect(newResult).toHaveLength(14);
26+
newResult.forEach((peak) => {
2727
if (Math.abs(peak.x - 4.31) < 0.01) {
28-
expect(peak.width).toBeCloseTo(0.39, 2);
28+
expect(peak.shape.width).toBeCloseTo(0.39, 2);
2929
}
3030
});
3131
});
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/__tests__/massPeakPicking.js renamed to src/__tests__/massPeakPicking.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,26 @@ describe('Check the peak picking of a simulated mass spectrum', () => {
4343
});
4444
expect(result[0].x).toBeCloseTo(69.938, 1);
4545
expect(result[0].y).toBeCloseTo(max, 2);
46-
expect(result[0].width).toBeCloseTo(0.01, 4);
46+
expect(result[0].shape.width).toBeCloseTo(0.01, 4);
4747

4848
expect(result[1].x).toBeCloseTo(71.935, 2);
4949
expect(result[1].y).toBeCloseTo((63.99155 * max) / 100, 3);
50-
expect(result[1].width).toBeCloseTo(0.01, 4);
50+
expect(result[1].shape.width).toBeCloseTo(0.01, 4);
5151

5252
expect(result[2].x).toBeCloseTo(73.932, 1);
5353
expect(result[2].y).toBeCloseTo((10.2373 * max) / 100, 2);
54-
expect(result[2].width).toBeCloseTo(0.01, 4);
54+
expect(result[2].shape.width).toBeCloseTo(0.01, 4);
5555

5656
expect(result[3].x).toBeCloseTo(157.837, 1);
5757
expect(result[3].y).toBeCloseTo((51.39931 * max) / 100, 2);
58-
expect(result[3].width).toBeCloseTo(0.01, 4);
58+
expect(result[3].shape.width).toBeCloseTo(0.01, 4);
5959

6060
expect(result[4].x).toBeCloseTo(159.835, 1);
6161
expect(result[4].y).toBeCloseTo(max, 2);
62-
expect(result[4].width).toBeCloseTo(0.01, 4);
62+
expect(result[4].shape.width).toBeCloseTo(0.01, 4);
6363

6464
expect(result[5].x).toBeCloseTo(161.833, 1);
6565
expect(result[5].y).toBeCloseTo((48.63878 * max) / 100, 2);
66-
expect(result[5].width).toBeCloseTo(0.01, 4);
66+
expect(result[5].shape.width).toBeCloseTo(0.01, 4);
6767
});
6868
});

src/__tests__/simple.js renamed to src/__tests__/simple.test.js

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { toMatchCloseTo } from 'jest-matcher-deep-close-to';
2+
import { getShape1D } from 'ml-peak-shape-generator';
23

34
import { gsd } from '..';
45

@@ -25,6 +26,8 @@ describe('Simple test cases', () => {
2526
negY.push(0);
2627
}
2728

29+
let widthToFWHM = getShape1D('gaussian').widthToFWHM;
30+
2831
it('gsd not realtop', () => {
2932
let peaks = gsd(
3033
{ x, y },
@@ -39,8 +42,8 @@ describe('Simple test cases', () => {
3942
);
4043

4144
expect(peaks[0].y).toBeCloseTo(4.657, 3);
42-
expect(peaks[0].base).toBeCloseTo(1.1956, 3);
43-
expect(peaks[0].x).toStrictEqual(15);
45+
expect(peaks[0].shape.noiseLevel).toBeCloseTo(1.1956, 3);
46+
expect(peaks[0].x).toBeCloseTo(15, 2);
4447
});
4548

4649
it('gsd negative peak', () => {
@@ -57,8 +60,8 @@ describe('Simple test cases', () => {
5760
},
5861
);
5962
expect(peaks[0].y).toBeCloseTo(-4.657, 3);
60-
expect(peaks[0].base).toBeCloseTo(1.1956, 3);
61-
expect(peaks[0].x).toStrictEqual(15);
63+
expect(peaks[0].shape.noiseLevel).toBeCloseTo(1.1956, 3);
64+
expect(peaks[0].x).toBeCloseTo(15,2);
6265
});
6366

6467
it('gsd not realtop asymetric', () => {
@@ -79,18 +82,11 @@ describe('Simple test cases', () => {
7982
expect(peaks).toMatchCloseTo(
8083
[
8184
{
82-
base: 1.2434539324230613,
83-
index: 15,
84-
left: {
85-
index: 13,
86-
x: 13,
87-
},
88-
right: {
89-
index: 16,
90-
x: 16,
85+
shape: {
86+
noiseLevel: 1.2434539324230613,
87+
soft: false,
88+
width: widthToFWHM(3),
9189
},
92-
soft: false,
93-
width: 3,
9490
x: 15,
9591
y: 5,
9692
},
@@ -116,18 +112,7 @@ describe('Simple test cases', () => {
116112
expect(peaks).toMatchCloseTo(
117113
[
118114
{
119-
base: 1.2434539324230613,
120-
index: 15,
121-
left: {
122-
index: 13,
123-
x: 13,
124-
},
125-
right: {
126-
index: 16,
127-
x: 16,
128-
},
129-
soft: false,
130-
width: 3,
115+
shape: { noiseLevel: 1.2434539324230613, soft: false, width: widthToFWHM(3) },
131116
x: 14.5,
132117
y: 4.006546067576939,
133118
},

src/__tests__/simpleShifted.js renamed to src/__tests__/simpleShifted.test.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { toMatchCloseTo } from 'jest-matcher-deep-close-to';
2+
import { getShape1D } from 'ml-peak-shape-generator';
23

34
import { gsd } from '..';
45

@@ -37,16 +38,16 @@ describe('Simple shifted baseline test cases', () => {
3738
},
3839
},
3940
);
41+
let widthToFWHM = getShape1D('gaussian').widthToFWHM;
4042
expect(peaks).toHaveLength(1);
4143
expect(peaks[0]).toMatchCloseTo({
42-
index: 15,
4344
x: 15,
4445
y: 4.657142857142857,
45-
width: 2,
46-
soft: false,
47-
left: { x: 14, index: 14 },
48-
right: { x: 16, index: 16 },
49-
base: 0.6695521174585716,
46+
shape: {
47+
width: widthToFWHM(2),
48+
soft: false,
49+
noiseLevel: 0.6695521174585716,
50+
},
5051
});
5152
});
5253

@@ -63,16 +64,16 @@ describe('Simple shifted baseline test cases', () => {
6364
},
6465
},
6566
);
67+
let widthToFWHM = getShape1D('gaussian').widthToFWHM;
6668
expect(peaks).toHaveLength(1);
6769
expect(peaks[0]).toMatchCloseTo({
68-
index: 15,
6970
x: 15,
7071
y: -4.657142857142857,
71-
width: 2,
72-
soft: false,
73-
left: { x: 14, index: 14 },
74-
right: { x: 16, index: 16 },
75-
base: 0.6695521174585716,
72+
shape: {
73+
width: widthToFWHM(2),
74+
soft: false,
75+
noiseLevel: 0.6695521174585716,
76+
},
7677
});
7778
});
7879
});

0 commit comments

Comments
 (0)