nmr-processing 3.4.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/lib/peaks/peaksFilterImpurities.js +1 -1
  3. package/lib/peaks/peaksFilterImpurities.js.map +1 -1
  4. package/lib/peaks/peaksToRanges.js +11 -17
  5. package/lib/peaks/peaksToRanges.js.map +1 -1
  6. package/lib/peaks/util/determineRealTop.js +3 -2
  7. package/lib/peaks/util/determineRealTop.js.map +1 -1
  8. package/lib/peaks/util/jAnalyzer.js +9 -11
  9. package/lib/peaks/util/jAnalyzer.js.map +1 -1
  10. package/lib/ranges/rangesToXY.d.ts +2 -2
  11. package/lib/ranges/rangesToXY.js.map +1 -1
  12. package/lib/signals/signalsToXY.d.ts +2 -2
  13. package/lib/signals/simulation/simulate1D.d.ts +4 -3
  14. package/lib/signals/simulation/simulate1D.js.map +1 -1
  15. package/lib/types/NMRPeak1D.d.ts +2 -9
  16. package/lib/xy/xyAutoPeaksPicking.d.ts +4 -60
  17. package/lib/xy/xyAutoPeaksPicking.js +3 -3
  18. package/lib/xy/xyAutoPeaksPicking.js.map +1 -1
  19. package/lib-esm/peaks/peaksFilterImpurities.js +1 -1
  20. package/lib-esm/peaks/peaksFilterImpurities.js.map +1 -1
  21. package/lib-esm/peaks/peaksToRanges.js +11 -17
  22. package/lib-esm/peaks/peaksToRanges.js.map +1 -1
  23. package/lib-esm/peaks/util/determineRealTop.js +4 -3
  24. package/lib-esm/peaks/util/determineRealTop.js.map +1 -1
  25. package/lib-esm/peaks/util/jAnalyzer.js +9 -11
  26. package/lib-esm/peaks/util/jAnalyzer.js.map +1 -1
  27. package/lib-esm/ranges/rangesToXY.js.map +1 -1
  28. package/lib-esm/signals/simulation/simulate1D.js.map +1 -1
  29. package/lib-esm/xy/xyAutoPeaksPicking.js +3 -3
  30. package/lib-esm/xy/xyAutoPeaksPicking.js.map +1 -1
  31. package/package.json +4 -4
  32. package/src/peaks/peaksFilterImpurities.ts +1 -1
  33. package/src/peaks/peaksToRanges.ts +11 -17
  34. package/src/peaks/util/determineRealTop.ts +4 -6
  35. package/src/peaks/util/jAnalyzer.ts +10 -12
  36. package/src/ranges/rangesToXY.ts +2 -2
  37. package/src/signals/signalsToXY.ts +2 -2
  38. package/src/signals/simulation/simulate1D.ts +4 -3
  39. package/src/types/NMRPeak1D.ts +3 -9
  40. package/src/xy/xyAutoPeaksPicking.ts +19 -58
  41. package/src/types/ml-gsd/index.d.ts +0 -164
@@ -219,13 +219,13 @@ function updateSignal(signal: SignalInternMandatory, jCouplings: number[]) {
219
219
  // Update the limits of the signal
220
220
  let peaks = signal.peaksComp; // Always in Hz
221
221
  let nbPeaks = peaks.length;
222
- signal.startX = peaks[0].x / signal.observe - peaks[0].shape.width;
222
+ signal.startX = peaks[0].x / signal.observe - peaks[0].width;
223
223
  signal.stopX =
224
- peaks[nbPeaks - 1].x / signal.observe + peaks[nbPeaks - 1].shape.width;
224
+ peaks[nbPeaks - 1].x / signal.observe + peaks[nbPeaks - 1].width;
225
225
  signal.integralData.from =
226
- peaks[0].x / signal.observe - peaks[0].shape.width * 3;
226
+ peaks[0].x / signal.observe - peaks[0].width * 3;
227
227
  signal.integralData.to =
228
- peaks[nbPeaks - 1].x / signal.observe + peaks[nbPeaks - 1].shape.width * 3;
228
+ peaks[nbPeaks - 1].x / signal.observe + peaks[nbPeaks - 1].width * 3;
229
229
  // Compile the pattern and format the constant couplings
230
230
  signal.maskPattern = signal.mask2;
231
231
  signal.multiplicity = abstractPattern(signal, jCouplings);
@@ -466,9 +466,7 @@ function symmetrize(
466
466
  peaks[i] = {
467
467
  x: peak[jAxis] * newSignal.observe,
468
468
  intensity: peak[intensity],
469
- shape: {
470
- width: peak.shape.width,
471
- },
469
+ width: peak.width,
472
470
  };
473
471
  }
474
472
  // Join the peaks that are closer than 0.25 Hz
@@ -480,7 +478,7 @@ function symmetrize(
480
478
  peaks[i].intensity = peaks[i].intensity + peaks[i + 1].intensity;
481
479
  peaks[i].x /= peaks[i].intensity;
482
480
  peaks[i].intensity /= 2;
483
- peaks[i].shape.width += peaks[i + 1].shape.width;
481
+ peaks[i].width += peaks[i + 1].width;
484
482
  peaks.splice(i + 1, 1);
485
483
  }
486
484
  }
@@ -528,11 +526,11 @@ function symmetrize(
528
526
  if (Math.abs(diffL - diffR) < maxError) {
529
527
  avg = Math.min(peaks[left].intensity, peaks[right].intensity);
530
528
  avgWidth = Math.min(
531
- peaks[left].shape.width,
532
- peaks[right].shape.width,
529
+ peaks[left].width,
530
+ peaks[right].width,
533
531
  );
534
532
  peaks[left].intensity = peaks[right].intensity = avg;
535
- peaks[left].shape.width = peaks[right].shape.width = avgWidth;
533
+ peaks[left].width = peaks[right].width = avgWidth;
536
534
  middle = [
537
535
  middle[0] + (peaks[right].x + peaks[left].x) / 2,
538
536
  middle[1] + 1,
@@ -712,5 +710,5 @@ function chemicalShift(peaks: Peak1DIntern[], mask: boolean[] = []) {
712
710
  * @private
713
711
  */
714
712
  function getArea(peak: Peak1DIntern) {
715
- return Math.abs(peak.intensity * peak.shape.width * 1.57); // 1.772453851);
713
+ return Math.abs(peak.intensity * peak.width * 1.57); // 1.772453851);
716
714
  }
@@ -1,7 +1,7 @@
1
1
  import { DoubleArray } from 'cheminfo-types';
2
2
  import arraySequentialFill from 'ml-array-sequential-fill';
3
+ import type { Shape1D } from 'ml-peak-shape-generator';
3
4
  import { SpectrumGenerator } from 'spectrum-generator';
4
- import type { Shape1DOptions } from 'spectrum-generator';
5
5
 
6
6
  import { hackSignalsToXY } from '../signals/hackSignalsToXY';
7
7
  import type { MakeMandatory } from '../types/MakeMandatory';
@@ -40,7 +40,7 @@ export interface RangeToXYOptions {
40
40
  * options of signals.
41
41
  * @default { kind: 'gaussian' }
42
42
  */
43
- shape: Shape1DOptions;
43
+ shape: Shape1D;
44
44
  }
45
45
  function checkForSignals(
46
46
  ranges: NMRRange[],
@@ -1,6 +1,6 @@
1
1
  import rescale from 'ml-array-rescale';
2
2
  import arraySequentialFill from 'ml-array-sequential-fill';
3
- import type { Shape1DOptions } from 'spectrum-generator';
3
+ import type { Shape1D } from 'ml-peak-shape-generator';
4
4
 
5
5
  import type { MakeMandatory } from '../types/MakeMandatory';
6
6
  import type { NMRSignal1D } from '../types/NMRSignal1D';
@@ -25,7 +25,7 @@ export interface OptionsSignalsToXY {
25
25
  /**
26
26
  * Shape options for ml-spectrum-generator
27
27
  */
28
- shape?: Shape1DOptions;
28
+ shape?: Shape1D;
29
29
  /**
30
30
  * The linewidth of the output spectrum, expresed in Hz.
31
31
  * @default 1
@@ -1,9 +1,10 @@
1
1
  import binarySearch from 'binary-search';
2
+ import { DataXY } from 'cheminfo-types';
2
3
  import { Matrix, EVD } from 'ml-matrix';
3
4
  import type { Matrix as MatrixClassType } from 'ml-matrix';
5
+ import type { Shape1D } from 'ml-peak-shape-generator';
4
6
  import { SparseMatrix } from 'ml-sparse-matrix';
5
7
  import { SpectrumGenerator } from 'spectrum-generator';
6
- import type { Shape1DOptions } from 'spectrum-generator';
7
8
 
8
9
  import type { SpinSystem } from '../../types/spinSystem';
9
10
 
@@ -46,7 +47,7 @@ interface Simulate1DOptions {
46
47
  * Shape options
47
48
  * @default {kind:'gaussian'}
48
49
  */
49
- shape?: Shape1DOptions;
50
+ shape?: Shape1D;
50
51
  }
51
52
 
52
53
  /**
@@ -59,7 +60,7 @@ export default function simulate1D(
59
60
  */
60
61
  spinSystem: SpinSystem,
61
62
  options: Simulate1DOptions = {},
62
- ) {
63
+ ): DataXY {
63
64
  let {
64
65
  lineWidth = 1,
65
66
  maxClusterSize = 8,
@@ -1,11 +1,5 @@
1
- export interface NMRPeak1D {
1
+ import type { Peak1D } from 'ml-gsd';
2
+
3
+ export interface NMRPeak1D extends Peak1D {
2
4
  kind?: string;
3
- x: number;
4
- y: number;
5
- shape: {
6
- width: number;
7
- noiseLevel?: number;
8
- soft?: boolean;
9
- kind?: string;
10
- };
11
5
  }
@@ -1,12 +1,17 @@
1
1
  import { DataXY } from 'cheminfo-types';
2
2
  import { gsd, joinBroadPeaks, optimizePeaks } from 'ml-gsd';
3
+ import type {
4
+ Peak1D,
5
+ IGSDOptions,
6
+ IOptimizePeaksOptions,
7
+ IJoinBroadPeaksOptions,
8
+ } from 'ml-gsd';
3
9
  import {
4
10
  xyExtract,
5
11
  xNoiseSanPlot,
6
12
  xAbsoluteMedian,
7
13
  } from 'ml-spectra-processing';
8
14
 
9
- import type { NMRPeak1D } from '../types/NMRPeak1D';
10
15
  /**
11
16
  * Implementation of the peak picking method described by Cobas in:
12
17
  * A new approach to improving automated analysis of proton NMR spectra
@@ -20,63 +25,19 @@ interface OptionsGetCutOff {
20
25
  thresholdFactor: number;
21
26
  }
22
27
 
23
- interface OptionsGetPeakList {
24
- /**
25
- * Noise threshold in spectrum y units. Default is three/thresholdFactor times the absolute median of data.y.
26
- * @default `median(data.y) * (options.thresholdFactor || 3)`
27
- */
28
- noiseLevel?: number;
29
- /**
30
- * Threshold to determine if a given peak should be considered as a noise, bases on its relative height compared to the highest peak.
31
- * @default 0.01
32
- */
33
- minMaxRatio: number;
34
- /**
35
- * If broadRatio is higher than 0, then all the peaks which second derivative smaller than broadRatio * maxAbsSecondDerivative will be marked with the soft mask equal to true.
36
- * @default 0.00025
37
- */
38
- broadRatio: number;
39
- /**
40
- * Select the peak intensities from a smoothed version of the independent variables.
41
- * @default true
42
- */
43
- smoothY: boolean;
28
+ export interface IGetPeakListOptions
29
+ extends IGSDOptions,
30
+ IOptimizePeaksOptions,
31
+ IJoinBroadPeaksOptions {
44
32
  /**
45
33
  * If it is true, the peaks parameters will be optimized.
46
34
  * @default false
47
35
  */
48
36
  optimize: boolean;
49
- /**
50
- * factor to determine the width at the moment to group the peaks in signals in 'GSD.optimizePeaks' function.
51
- * @default 4
52
- */
53
- factorWidth: number;
54
- /**
55
- * if it is true, it optimizes the x and intensity by extrapolation.
56
- */
57
- realTopDetection: boolean;
58
- /**
59
- * options to shape used to adapt the FWHM
60
- * @default {kind:'gaussian'}
61
- */
62
- shape: { kind: string };
63
- /**
64
- * options for optimization step, kind represent the algorithm
65
- * @default {kind:'lm'}
66
- */
67
- optimization: { kind: string };
68
- /**
69
- * Threshold to determine if some peak is candidate to clustering into range.
70
- * @default 0.25
71
- */
72
- broadWidth: number;
73
- /**
74
- * Options for savitz Golay
75
- */
76
- sgOptions: { windowSize: number; polynomial: number };
77
37
  }
78
38
 
79
- export interface OptionsXYAutoPeaksPicking extends Partial<OptionsGetPeakList> {
39
+ export interface OptionsXYAutoPeaksPicking
40
+ extends Partial<IGetPeakListOptions> {
80
41
  /**
81
42
  * Low limit value in the x axis to extract a sub set of points from the input data.
82
43
  */
@@ -105,7 +66,7 @@ export interface OptionsXYAutoPeaksPicking extends Partial<OptionsGetPeakList> {
105
66
  export function xyAutoPeaksPicking(
106
67
  data: DataXY,
107
68
  options: OptionsXYAutoPeaksPicking = {},
108
- ): NMRPeak1D[] {
69
+ ): Peak1D[] {
109
70
  const {
110
71
  from,
111
72
  to,
@@ -131,7 +92,7 @@ export function xyAutoPeaksPicking(
131
92
 
132
93
  const cutOff = getCutOff(data.y, { noiseLevel, useSanPlot, thresholdFactor });
133
94
 
134
- let getPeakOptions = {
95
+ let getPeakOptions: IGetPeakListOptions = {
135
96
  shape,
136
97
  broadWidth,
137
98
  optimize,
@@ -154,7 +115,7 @@ export function xyAutoPeaksPicking(
154
115
  return peaks;
155
116
  }
156
117
 
157
- function getPeakList(data: DataXY, options: OptionsGetPeakList) {
118
+ function getPeakList(data: DataXY, options: IGetPeakListOptions) {
158
119
  const {
159
120
  shape,
160
121
  broadWidth,
@@ -173,15 +134,15 @@ function getPeakList(data: DataXY, options: OptionsGetPeakList) {
173
134
  shape,
174
135
  sgOptions,
175
136
  minMaxRatio,
176
- broadRatio,
177
137
  noiseLevel,
178
138
  smoothY,
179
139
  realTopDetection,
180
140
  });
181
141
 
182
142
  if (broadWidth) {
183
- peakList = joinBroadPeaks(peakList, {
184
- width: broadWidth,
143
+ peakList = joinBroadPeaks(data, peakList, {
144
+ broadRatio,
145
+ broadWidth,
185
146
  shape,
186
147
  optimization,
187
148
  });
@@ -198,7 +159,7 @@ function getPeakList(data: DataXY, options: OptionsGetPeakList) {
198
159
  return peakList;
199
160
  }
200
161
 
201
- function getNegativePeaks(data: DataXY, options: OptionsGetPeakList) {
162
+ function getNegativePeaks(data: DataXY, options: IGetPeakListOptions) {
202
163
  let { x, y } = data;
203
164
  let negativeDataY = new Float64Array(data.y.length);
204
165
  for (let i = 0; i < negativeDataY.length; i++) {
@@ -1,164 +0,0 @@
1
- declare module 'ml-gsd' {
2
- export interface XYNumberArray {
3
- x: Array<number> | Float64Array;
4
- y: Array<number> | Float64Array;
5
- }
6
-
7
- export interface GSDOptions {
8
- /**
9
- * Noise threshold in spectrum y units. Default is three/thresholdFactor times the absolute median of data.y.
10
- * @default `median(data.y) * (options.thresholdFactor || 3)`
11
- */
12
- noiseLevel?: number;
13
- /**
14
- * Threshold to determine if a given peak should be considered as a noise, bases on its relative height compared to the highest peak.
15
- * @default 0.01
16
- */
17
- minMaxRatio?: number;
18
- /**
19
- * If broadRatio is higher than 0, then all the peaks which second derivative smaller than broadRatio * maxAbsSecondDerivative will be marked with the soft mask equal to true.
20
- * @default 0.00025
21
- */
22
- broadRatio?: number;
23
- /**
24
- * Select the peak intensities from a smoothed version of the independent variables.
25
- * @default true
26
- */
27
- smoothY?: boolean;
28
- /**
29
- * if it is true, it optimizes the x and intensity by extrapolation.
30
- * @default false
31
- */
32
- realTopDetection?: boolean;
33
- /**
34
- * options to shape used to adapt the FWHM
35
- * @default {kind:'gaussian'}
36
- */
37
- shape?: { kind: string };
38
- /**
39
- * Options for savitz Golay
40
- */
41
- sgOptions?: { windowSize: number; polynomial: number };
42
- /**
43
- * filter based on intensity of the first derive.
44
- * @default -1
45
- */
46
- /**
47
- * Peaks are local maximum(true) or minimum(false)
48
- * @default true
49
- */
50
- maxCriteria?: boolean;
51
- /**
52
- * Filters based on the amplitude of the first derivative
53
- * @default -1
54
- */
55
- derivativeThreshold?: number;
56
- /**
57
- * Factor to multiply the calculated height (usually 2)
58
- * @default 0
59
- */
60
- heightFactor?: number;
61
- }
62
-
63
- export interface GSDPeak {
64
- x: number;
65
- y: number;
66
- shape: {
67
- width: number;
68
- noiseLevel?: number;
69
- soft?: boolean;
70
- kind?: string;
71
- };
72
- }
73
-
74
- export interface OptimizePeaksOptions {
75
- /**
76
- * factor to determine the width at the moment to group the peaks in signals in 'GSD.optimizePeaks' function.
77
- * @default 1
78
- */
79
- factorWidth?: number;
80
- /**
81
- * times of width to use to optimize peaks
82
- * @default 2
83
- */
84
- factorLimits?: number;
85
- /**
86
- * options to shape used to adapt the FWHM
87
- * @default {kind:'gaussian'}
88
- */
89
- shape?: { kind: string };
90
- /**
91
- * options for optimization step
92
- */
93
- optimization?: OptimizationOptions;
94
- }
95
-
96
- export interface OptimizationOptions {
97
- /**
98
- * represent the algorithm to optimize.
99
- * @default {kind:'lm'}
100
- */
101
- kind?: string;
102
- /**
103
- * Time limit to stop the optimization in seconds.
104
- * @default 10
105
- */
106
- timeout?: number;
107
- }
108
-
109
- export interface OptimizedPeak {
110
- x: number;
111
- y: number;
112
- shape: {
113
- width: number;
114
- noiseLevel?: number;
115
- soft?: boolean;
116
- kind?: string;
117
- mu?: number;
118
- };
119
- }
120
-
121
- export function gsd(data: XYNumberArray, options?: GSDOptions): GSDPeak[];
122
-
123
- export function optimizePeaks(
124
- data: XYNumberArray,
125
- peakList: GSDPeak[],
126
- options?: OptimizePeaksOptions,
127
- ): OptimizedPeak[];
128
-
129
- export function joinBroadPeaks(
130
- peakList: GSDPeak[],
131
- options?: JoinBroadPeaksOptions,
132
- ): GSDPeak[];
133
-
134
- export interface JoinBroadPeaksOptions {
135
- /**
136
- * @default 0.25
137
- */
138
- width: number;
139
- /**
140
- * @default { kind: 'gaussian' }
141
- */
142
- shape: { kind: string };
143
- /**
144
- * @default { kind: 'lm', timeout: 10 }
145
- */
146
- optimization: OptimizationOptions;
147
- }
148
-
149
- export function groupPeaks(peakList: GSDPeak[], factor?: number): GSDPeak[][];
150
-
151
- export function broadenPeaks(
152
- peakList: GSDPeak[],
153
- options?: {
154
- /**
155
- * @default 2
156
- */
157
- factor: number;
158
- /**
159
- * @default false
160
- */
161
- overlap: boolean;
162
- },
163
- ): GSDPeak[];
164
- }