Skip to content

Commit 505121d

Browse files
authored
feat: add shape to gsd result (#102)
* feat: add shape to gsd result adapt to new version of ml-spectra * chore: remove support for node 12 * chore: reverse change in test case
1 parent 51a56ec commit 505121d

File tree

12 files changed

+97
-10
lines changed

12 files changed

+97
-10
lines changed

.github/workflows/nodejs-ts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ jobs:
1111
# Documentation: https://github.com/zakodium/workflows#nodejs-ci
1212
uses: zakodium/workflows/.github/workflows/nodejs.yml@nodejs-v1
1313
with:
14-
node-version-matrix: '[12, 14, 16, 18]'
14+
node-version-matrix: '[14, 16, 18]'
1515
lint-check-types: true

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"cheminfo-types": "^1.1.0",
8383
"ml-peak-shape-generator": "^4.1.1",
8484
"ml-savitzky-golay-generalized": "4.0.1",
85-
"ml-spectra-fitting": "4.0.2",
85+
"ml-spectra-fitting": "4.1.0",
8686
"ml-spectra-processing": "^11.6.0"
8787
}
8888
}

src/GSDPeak.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Shape1D } from 'ml-peak-shape-generator';
2+
13
export interface GSDPeak {
24
x: number;
35
y: number;
@@ -14,6 +16,9 @@ export interface GSDPeak {
1416
* This allows to determine if a peak is soft or not
1517
*/
1618
ddY: number;
19+
20+
shape: Shape1D;
21+
1722
inflectionPoints: {
1823
from: { x: number; index: number };
1924
to: { x: number; index: number };

src/__tests__/gaussian-smooth.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ describe('gaussian simulated peaks', () => {
3838
ddY: -259.83290100626783,
3939
width: 0.08,
4040
index: 25,
41+
shape: {
42+
fwhm: 0.09419280180123805,
43+
kind: 'gaussian',
44+
},
4145
inflectionPoints: {
4246
from: { x: -0.54, index: 23 },
4347
to: { x: -0.46, index: 27 },
@@ -49,6 +53,10 @@ describe('gaussian simulated peaks', () => {
4953
ddY: -259.83290100626783,
5054
width: 0.08,
5155
index: 75,
56+
shape: {
57+
fwhm: 0.09419280180123805,
58+
kind: 'gaussian',
59+
},
5260
inflectionPoints: {
5361
from: { x: 0.46, index: 73 },
5462
to: { x: 0.54, index: 77 },

src/__tests__/gaussian.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ describe('smooth:false option', () => {
3838
ddY: -259.83290100626783,
3939
width: 0.08,
4040
index: 25,
41+
shape: {
42+
fwhm: 0.09419280180123805,
43+
kind: 'gaussian',
44+
},
4145
inflectionPoints: {
4246
from: { index: 23, x: -0.54 },
4347
to: { index: 27, x: -0.46 },
@@ -49,6 +53,10 @@ describe('smooth:false option', () => {
4953
ddY: -259.83290100626783,
5054
width: 0.08,
5155
index: 75,
56+
shape: {
57+
fwhm: 0.09419280180123805,
58+
kind: 'gaussian',
59+
},
5260
inflectionPoints: {
5361
from: { index: 73, x: 0.46 },
5462
to: { index: 77, x: 0.54 },
@@ -68,6 +76,10 @@ describe('smooth:false option', () => {
6876
ddY: -259.83290100626783,
6977
width: 0.08,
7078
index: 25,
79+
shape: {
80+
fwhm: 0.09419280180123805,
81+
kind: 'gaussian',
82+
},
7183
inflectionPoints: {
7284
from: { index: 23, x: -0.54 },
7385
to: { index: 27, x: -0.46 },
@@ -79,6 +91,10 @@ describe('smooth:false option', () => {
7991
ddY: -259.83290100626783,
8092
width: 0.08,
8193
index: 75,
94+
shape: {
95+
fwhm: 0.09419280180123805,
96+
kind: 'gaussian',
97+
},
8298
inflectionPoints: {
8399
from: { index: 73, x: 0.46 },
84100
to: { index: 77, x: 0.54 },
@@ -101,6 +117,10 @@ describe('smooth:false option', () => {
101117
ddY: 259.83290100626783,
102118
width: 0.08,
103119
index: 25,
120+
shape: {
121+
fwhm: 0.09419280180123805,
122+
kind: 'gaussian',
123+
},
104124
inflectionPoints: {
105125
from: { index: 23, x: -0.54 },
106126
to: { index: 27, x: -0.46 },
@@ -112,6 +132,10 @@ describe('smooth:false option', () => {
112132
ddY: 259.83290100626783,
113133
width: 0.08,
114134
index: 75,
135+
shape: {
136+
fwhm: 0.09419280180123805,
137+
kind: 'gaussian',
138+
},
115139
inflectionPoints: {
116140
from: { index: 73, x: 0.46 },
117141
to: { index: 77, x: 0.54 },
@@ -135,6 +159,10 @@ describe('smooth:false option', () => {
135159
ddY: 259.83290100626783,
136160
width: 0.08,
137161
index: 25,
162+
shape: {
163+
fwhm: 0.09419280180123805,
164+
kind: 'gaussian',
165+
},
138166
inflectionPoints: {
139167
from: { index: 23, x: -0.54 },
140168
to: { index: 27, x: -0.46 },
@@ -146,6 +174,10 @@ describe('smooth:false option', () => {
146174
ddY: 259.83290100626783,
147175
width: 0.08,
148176
index: 75,
177+
shape: {
178+
fwhm: 0.09419280180123805,
179+
kind: 'gaussian',
180+
},
149181
inflectionPoints: {
150182
from: { index: 73, x: 0.46 },
151183
to: { index: 77, x: 0.54 },

src/__tests__/power.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ describe('power', () => {
5656
width: 0.3,
5757
index: 100,
5858
ddY: -33832.03463203485,
59+
shape: {
60+
fwhm: 0.35322300675464324,
61+
kind: 'gaussian',
62+
},
5963
inflectionPoints: {
6064
from: { x: 4.85, index: 97 },
6165
to: { x: 5.15, index: 103 },
@@ -78,6 +82,10 @@ describe('power', () => {
7882
width: 0.05,
7983
index: 89,
8084
ddY: 800,
85+
shape: {
86+
fwhm: 0.05887050112577352,
87+
kind: 'gaussian',
88+
},
8189
inflectionPoints: {
8290
from: { x: 4.4, index: 88 },
8391
to: { x: 4.45, index: 89 },
@@ -89,6 +97,10 @@ describe('power', () => {
8997
width: 0.2,
9098
index: 100,
9199
ddY: -44914.28571428623,
100+
shape: {
101+
fwhm: 0.2354820045030941,
102+
kind: 'gaussian',
103+
},
92104
inflectionPoints: {
93105
from: { x: 4.9, index: 98 },
94106
to: { x: 5.1, index: 102 },
@@ -100,6 +112,10 @@ describe('power', () => {
100112
width: 0.05,
101113
index: 111,
102114
ddY: 800,
115+
shape: {
116+
fwhm: 0.05887050112577352,
117+
kind: 'gaussian',
118+
},
103119
inflectionPoints: {
104120
from: { x: 5.55, index: 111 },
105121
to: { x: 5.6, index: 112 },

src/__tests__/ubiquitin.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ describe('Global spectra deconvolution ubiquitin', () => {
2828
ddY: -15468134.039875854,
2929
width: 0.002420000000000755,
3030
index: 11,
31+
shape: {
32+
fwhm: 0.0028493322544883375,
33+
kind: 'gaussian',
34+
},
3135
inflectionPoints: {
3236
from: { x: 200.054133, index: 9 },
3337
to: { x: 200.056553, index: 13 },

src/gsd.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { DataXY } from 'cheminfo-types';
2+
import { Shape1D } from 'ml-peak-shape-generator';
23
import { sgg, SGGOptions } from 'ml-savitzky-golay-generalized';
34
import {
45
xIsEquallySpaced,
@@ -9,6 +10,7 @@ import {
910
} from 'ml-spectra-processing';
1011

1112
import { GSDPeak } from './GSDPeak';
13+
import { appendShapeAndFWHM } from './utils/appendShapeAndFWHM';
1214
import { optimizeTop } from './utils/optimizeTop';
1315

1416
export interface GSDOptions {
@@ -44,6 +46,11 @@ export interface GSDOptions {
4446
* @default false
4547
*/
4648
realTopDetection?: boolean;
49+
/**
50+
* Shape used to add FWHM property in the peaks
51+
* @default {kind:'gaussian'}
52+
*/
53+
shape?: Shape1D;
4754
}
4855

4956
/**
@@ -60,6 +67,7 @@ export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeak[] {
6067
windowSize: 9,
6168
polynomial: 3,
6269
},
70+
shape,
6371
noiseLevel,
6472
smoothY = false,
6573
maxCriteria = true,
@@ -239,14 +247,14 @@ export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeak[] {
239247
peaks.push({
240248
x: deltaX,
241249
y: yData[minddYIndex],
242-
width: width,
250+
width,
243251
index: minddYIndex,
244252
ddY: ddY[minddYIndex],
245253
inflectionPoints: {
246254
from: intervalL[possible],
247255
to: intervalR[possible],
248256
},
249-
});
257+
} as GSDPeak);
250258
}
251259
}
252260
}
@@ -266,5 +274,5 @@ export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeak[] {
266274
return a.x - b.x;
267275
});
268276

269-
return peaks;
277+
return appendShapeAndFWHM(peaks, { shape });
270278
}

src/post/__tests__/optimizePeaksWithLogs.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('optimizePeaksWithLogs', () => {
3030
expect(result.logs).toMatchObject([
3131
{
3232
iterations: 100,
33-
error: 0.000017852930772995625,
33+
error: 0.000017852931247867768,
3434
parameters: { kind: 'lm', options: { timeout: 10 } },
3535
message: 'optimization successful',
3636
groupSize: 1,

src/post/broadenPeaks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { GSDPeak } from '../GSDPeak';
1010
*/
1111

1212
export function broadenPeaks(
13-
peakList: GSDPeak[],
13+
peakList: Omit<GSDPeak, 'shape'>[],
1414
options: {
1515
/**
1616
* @default 2

0 commit comments

Comments
 (0)