nmr-processing 3.3.4 → 5.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 (109) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/lib/assignment/get13CAssignments.d.ts +35 -0
  3. package/lib/assignment/get13CAssignments.js +54 -0
  4. package/lib/assignment/get13CAssignments.js.map +1 -0
  5. package/lib/assignment/get1HAssignments.d.ts +42 -0
  6. package/lib/assignment/get1HAssignments.js +55 -0
  7. package/lib/assignment/get1HAssignments.js.map +1 -0
  8. package/lib/assignment/utils/buildAssignments.d.ts +33 -0
  9. package/lib/assignment/utils/buildAssignments.js +93 -0
  10. package/lib/assignment/utils/buildAssignments.js.map +1 -0
  11. package/lib/assignment/utils/createMapPossibleAssignments.d.ts +15 -0
  12. package/lib/assignment/utils/createMapPossibleAssignments.js +51 -0
  13. package/lib/assignment/utils/createMapPossibleAssignments.js.map +1 -0
  14. package/lib/assignment/utils/exploreTreeRec.d.ts +22 -0
  15. package/lib/assignment/utils/exploreTreeRec.js +77 -0
  16. package/lib/assignment/utils/exploreTreeRec.js.map +1 -0
  17. package/lib/assignment/utils/generateID.d.ts +1 -0
  18. package/lib/assignment/utils/generateID.js +13 -0
  19. package/lib/assignment/utils/generateID.js.map +1 -0
  20. package/lib/assignment/utils/partialScore.d.ts +16 -0
  21. package/lib/assignment/utils/partialScore.js +91 -0
  22. package/lib/assignment/utils/partialScore.js.map +1 -0
  23. package/lib/index.d.ts +2 -5
  24. package/lib/index.js +2 -5
  25. package/lib/index.js.map +1 -1
  26. package/lib/peaks/peaksFilterImpurities.js +1 -1
  27. package/lib/peaks/peaksFilterImpurities.js.map +1 -1
  28. package/lib/peaks/peaksToRanges.js +11 -17
  29. package/lib/peaks/peaksToRanges.js.map +1 -1
  30. package/lib/peaks/util/determineRealTop.js +3 -2
  31. package/lib/peaks/util/determineRealTop.js.map +1 -1
  32. package/lib/peaks/util/jAnalyzer.js +33 -35
  33. package/lib/peaks/util/jAnalyzer.js.map +1 -1
  34. package/lib/ranges/rangesToXY.d.ts +2 -2
  35. package/lib/ranges/rangesToXY.js +10 -2
  36. package/lib/ranges/rangesToXY.js.map +1 -1
  37. package/lib/signals/signals2DToZ.d.ts +2 -2
  38. package/lib/signals/signalsToXY.d.ts +2 -2
  39. package/lib/signals/simulation/simulate1D.d.ts +4 -3
  40. package/lib/signals/simulation/simulate1D.js.map +1 -1
  41. package/lib/types/NMRPeak1D.d.ts +2 -9
  42. package/lib/types/NMRRange.d.ts +1 -0
  43. package/lib/types/NMRSignal1D.d.ts +1 -0
  44. package/lib/types/NMRSignal2D.d.ts +3 -4
  45. package/lib/types/NMRZone.d.ts +4 -3
  46. package/lib/xy/xyAutoPeaksPicking.d.ts +4 -60
  47. package/lib/xy/xyAutoPeaksPicking.js +3 -3
  48. package/lib/xy/xyAutoPeaksPicking.js.map +1 -1
  49. package/lib/xyz/xyzAutoPeaksPicking.js +4 -2
  50. package/lib/xyz/xyzAutoPeaksPicking.js.map +1 -1
  51. package/lib-esm/assignment/get13CAssignments.js +47 -0
  52. package/lib-esm/assignment/get13CAssignments.js.map +1 -0
  53. package/lib-esm/assignment/get1HAssignments.js +48 -0
  54. package/lib-esm/assignment/get1HAssignments.js.map +1 -0
  55. package/lib-esm/assignment/utils/buildAssignments.js +86 -0
  56. package/lib-esm/assignment/utils/buildAssignments.js.map +1 -0
  57. package/lib-esm/assignment/utils/createMapPossibleAssignments.js +47 -0
  58. package/lib-esm/assignment/utils/createMapPossibleAssignments.js.map +1 -0
  59. package/lib-esm/assignment/utils/exploreTreeRec.js +73 -0
  60. package/lib-esm/assignment/utils/exploreTreeRec.js.map +1 -0
  61. package/lib-esm/assignment/utils/generateID.js +10 -0
  62. package/lib-esm/assignment/utils/generateID.js.map +1 -0
  63. package/lib-esm/assignment/utils/partialScore.js +87 -0
  64. package/lib-esm/assignment/utils/partialScore.js.map +1 -0
  65. package/lib-esm/index.js +2 -5
  66. package/lib-esm/index.js.map +1 -1
  67. package/lib-esm/peaks/peaksFilterImpurities.js +1 -1
  68. package/lib-esm/peaks/peaksFilterImpurities.js.map +1 -1
  69. package/lib-esm/peaks/peaksToRanges.js +11 -17
  70. package/lib-esm/peaks/peaksToRanges.js.map +1 -1
  71. package/lib-esm/peaks/util/determineRealTop.js +4 -3
  72. package/lib-esm/peaks/util/determineRealTop.js.map +1 -1
  73. package/lib-esm/peaks/util/jAnalyzer.js +33 -35
  74. package/lib-esm/peaks/util/jAnalyzer.js.map +1 -1
  75. package/lib-esm/ranges/rangesToXY.js +10 -2
  76. package/lib-esm/ranges/rangesToXY.js.map +1 -1
  77. package/lib-esm/signals/simulation/simulate1D.js.map +1 -1
  78. package/lib-esm/xy/xyAutoPeaksPicking.js +3 -3
  79. package/lib-esm/xy/xyAutoPeaksPicking.js.map +1 -1
  80. package/lib-esm/xyz/xyzAutoPeaksPicking.js +4 -2
  81. package/lib-esm/xyz/xyzAutoPeaksPicking.js.map +1 -1
  82. package/package.json +4 -4
  83. package/src/assignment/get13CAssignments.ts +100 -0
  84. package/src/assignment/get1HAssignments.ts +116 -0
  85. package/src/assignment/utils/buildAssignments.ts +155 -0
  86. package/src/assignment/utils/createMapPossibleAssignments.ts +76 -0
  87. package/src/assignment/utils/exploreTreeRec.ts +138 -0
  88. package/src/assignment/utils/generateID.ts +11 -0
  89. package/src/assignment/utils/partialScore.ts +128 -0
  90. package/src/index.ts +3 -6
  91. package/src/peaks/peaksFilterImpurities.ts +1 -1
  92. package/src/peaks/peaksToRanges.ts +11 -17
  93. package/src/peaks/util/determineRealTop.ts +4 -6
  94. package/src/peaks/util/jAnalyzer.ts +34 -36
  95. package/src/ranges/rangesToXY.ts +14 -7
  96. package/src/signals/signals2DToZ.ts +2 -2
  97. package/src/signals/signalsToXY.ts +2 -2
  98. package/src/signals/simulation/simulate1D.ts +4 -3
  99. package/src/types/NMRPeak1D.ts +3 -9
  100. package/src/types/NMRRange.ts +1 -0
  101. package/src/types/NMRSignal1D.ts +1 -0
  102. package/src/types/NMRSignal2D.ts +4 -4
  103. package/src/types/NMRZone.ts +4 -3
  104. package/src/types/ml-spectra-processing/index.d.ts +8 -8
  105. package/src/types/ml-tree-set/index.d.ts +18 -0
  106. package/src/types/openchemlib-utils/index..d.ts +2 -2
  107. package/src/xy/xyAutoPeaksPicking.ts +19 -58
  108. package/src/xyz/xyzAutoPeaksPicking.ts +4 -2
  109. package/src/types/ml-gsd/index.d.ts +0 -164
@@ -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++) {
@@ -309,8 +309,10 @@ const createSignals2D = (peaks: MPFPeak[], options: CreateSignals2DOptions) => {
309
309
  }
310
310
  }
311
311
 
312
- signal.x.fromTo = { from: minMax1[0], to: minMax1[1] };
313
- signal.y.fromTo = { from: minMax2[0], to: minMax2[1] };
312
+ signal.x.from = minMax1[0];
313
+ signal.y.from = minMax2[0];
314
+ signal.x.to = minMax1[1];
315
+ signal.y.to = minMax2[1];
314
316
  signal.x.delta /= sumZ;
315
317
  signal.y.delta /= sumZ;
316
318
  signal.peaks = peaks2D;
@@ -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
- }