nmr-processing 3.4.0 → 6.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 (148) hide show
  1. package/lib/assignment/get13CAssignments.js.map +1 -1
  2. package/lib/assignment/utils/buildAssignments.js +0 -1
  3. package/lib/assignment/utils/buildAssignments.js.map +1 -1
  4. package/lib/assignment/utils/createMapPossibleAssignments.js +0 -1
  5. package/lib/assignment/utils/createMapPossibleAssignments.js.map +1 -1
  6. package/lib/constants/couplingValues.js.map +1 -1
  7. package/lib/index.d.ts +1 -1
  8. package/lib/index.js +1 -1
  9. package/lib/peaks/peaksFilterImpurities.js +1 -1
  10. package/lib/peaks/peaksFilterImpurities.js.map +1 -1
  11. package/lib/peaks/peaksToRanges.js +11 -17
  12. package/lib/peaks/peaksToRanges.js.map +1 -1
  13. package/lib/peaks/util/determineRealTop.d.ts +2 -2
  14. package/lib/peaks/util/determineRealTop.js +3 -2
  15. package/lib/peaks/util/determineRealTop.js.map +1 -1
  16. package/lib/peaks/util/jAnalyzer.js +12 -13
  17. package/lib/peaks/util/jAnalyzer.js.map +1 -1
  18. package/lib/peaks/util/peakOptimizer.d.ts +2 -2
  19. package/lib/peaks/util/peakOptimizer.js.map +1 -1
  20. package/lib/prediction/predictAll.js +1 -1
  21. package/lib/prediction/predictAll.js.map +1 -1
  22. package/lib/prediction/predictHSQC.js.map +1 -1
  23. package/lib/prediction/predictProton.js +1 -1
  24. package/lib/prediction/predictProton.js.map +1 -1
  25. package/lib/prediction/utils/getFilteredIDiaIDs.js.map +1 -1
  26. package/lib/prediction/utils/getNuclei.js +1 -1
  27. package/lib/prediction/utils/getNuclei.js.map +1 -1
  28. package/lib/prediction/utils/getPredictions.d.ts +2 -2
  29. package/lib/prediction/utils/queryByHOSE.js.map +1 -1
  30. package/lib/ranges/rangesToXY.d.ts +2 -2
  31. package/lib/ranges/rangesToXY.js +10 -2
  32. package/lib/ranges/rangesToXY.js.map +1 -1
  33. package/lib/signal/signalJoinCouplings.d.ts +1 -1
  34. package/lib/signal/signalJoinCouplings.js +3 -3
  35. package/lib/signal/signalJoinCouplings.js.map +1 -1
  36. package/lib/signals/signalsJoin.d.ts +1 -1
  37. package/lib/signals/signalsJoin.js +7 -7
  38. package/lib/signals/signalsJoin.js.map +1 -1
  39. package/lib/signals/signalsToXY.d.ts +2 -2
  40. package/lib/signals/simulation/simulate1D.d.ts +4 -3
  41. package/lib/signals/simulation/simulate1D.js.map +1 -1
  42. package/lib/signals/simulation/splitSpinSystem.js.map +1 -1
  43. package/lib/types/NMRPeak1D.d.ts +2 -9
  44. package/lib/types/NMRSignal2D.d.ts +6 -6
  45. package/lib/types/NMRZone.d.ts +3 -7
  46. package/lib/types/jcoupling.d.ts +1 -1
  47. package/lib/types/modules/nmr-parser.d.ts +11 -0
  48. package/lib/types/modules/nmr-parser.js +2 -0
  49. package/lib/types/modules/nmr-parser.js.map +1 -0
  50. package/lib/types/prediction1D.d.ts +2 -2
  51. package/lib/utilities/joinPatterns.js.map +1 -1
  52. package/lib/xy/xyAutoPeaksPicking.d.ts +4 -60
  53. package/lib/xy/xyAutoPeaksPicking.js +3 -3
  54. package/lib/xy/xyAutoPeaksPicking.js.map +1 -1
  55. package/lib/xyz/{xyzAutoPeaksPicking.d.ts → xyzAutoZonesPicking.d.ts} +2 -2
  56. package/lib/xyz/{xyzAutoPeaksPicking.js → xyzAutoZonesPicking.js} +38 -24
  57. package/lib/xyz/xyzAutoZonesPicking.js.map +1 -0
  58. package/lib/xyz/xyzJResAnalyzer.js.map +1 -1
  59. package/lib-esm/assignment/get13CAssignments.js.map +1 -1
  60. package/lib-esm/assignment/utils/buildAssignments.js +0 -1
  61. package/lib-esm/assignment/utils/buildAssignments.js.map +1 -1
  62. package/lib-esm/assignment/utils/createMapPossibleAssignments.js +0 -1
  63. package/lib-esm/assignment/utils/createMapPossibleAssignments.js.map +1 -1
  64. package/lib-esm/constants/couplingValues.js.map +1 -1
  65. package/lib-esm/index.js +1 -1
  66. package/lib-esm/peaks/peaksFilterImpurities.js +1 -1
  67. package/lib-esm/peaks/peaksFilterImpurities.js.map +1 -1
  68. package/lib-esm/peaks/peaksToRanges.js +11 -17
  69. package/lib-esm/peaks/peaksToRanges.js.map +1 -1
  70. package/lib-esm/peaks/util/determineRealTop.js +4 -3
  71. package/lib-esm/peaks/util/determineRealTop.js.map +1 -1
  72. package/lib-esm/peaks/util/jAnalyzer.js +12 -13
  73. package/lib-esm/peaks/util/jAnalyzer.js.map +1 -1
  74. package/lib-esm/peaks/util/peakOptimizer.js.map +1 -1
  75. package/lib-esm/prediction/predictAll.js +1 -1
  76. package/lib-esm/prediction/predictAll.js.map +1 -1
  77. package/lib-esm/prediction/predictHSQC.js.map +1 -1
  78. package/lib-esm/prediction/predictProton.js +1 -1
  79. package/lib-esm/prediction/predictProton.js.map +1 -1
  80. package/lib-esm/prediction/utils/getFilteredIDiaIDs.js.map +1 -1
  81. package/lib-esm/prediction/utils/getNuclei.js +1 -1
  82. package/lib-esm/prediction/utils/getNuclei.js.map +1 -1
  83. package/lib-esm/prediction/utils/queryByHOSE.js.map +1 -1
  84. package/lib-esm/ranges/rangesToXY.js +10 -2
  85. package/lib-esm/ranges/rangesToXY.js.map +1 -1
  86. package/lib-esm/signal/signalJoinCouplings.js +3 -3
  87. package/lib-esm/signal/signalJoinCouplings.js.map +1 -1
  88. package/lib-esm/signals/signalsJoin.js +7 -7
  89. package/lib-esm/signals/signalsJoin.js.map +1 -1
  90. package/lib-esm/signals/simulation/simulate1D.js.map +1 -1
  91. package/lib-esm/signals/simulation/splitSpinSystem.js.map +1 -1
  92. package/lib-esm/types/modules/nmr-parser.js +2 -0
  93. package/lib-esm/types/modules/nmr-parser.js.map +1 -0
  94. package/lib-esm/utilities/joinPatterns.js.map +1 -1
  95. package/lib-esm/xy/xyAutoPeaksPicking.js +3 -3
  96. package/lib-esm/xy/xyAutoPeaksPicking.js.map +1 -1
  97. package/lib-esm/xyz/{xyzAutoPeaksPicking.js → xyzAutoZonesPicking.js} +36 -22
  98. package/lib-esm/xyz/xyzAutoZonesPicking.js.map +1 -0
  99. package/lib-esm/xyz/xyzJResAnalyzer.js.map +1 -1
  100. package/package.json +19 -16
  101. package/src/assignment/get13CAssignments.ts +4 -1
  102. package/src/assignment/utils/buildAssignments.ts +2 -5
  103. package/src/assignment/utils/createMapPossibleAssignments.ts +4 -2
  104. package/src/constants/couplingValues.ts +1 -1
  105. package/src/index.ts +1 -1
  106. package/src/peaks/peaksFilterImpurities.ts +1 -1
  107. package/src/peaks/peaksToRanges.ts +11 -17
  108. package/src/peaks/util/determineRealTop.ts +6 -9
  109. package/src/peaks/util/jAnalyzer.ts +14 -16
  110. package/src/peaks/util/peakOptimizer.ts +4 -3
  111. package/src/prediction/predictAll.ts +5 -5
  112. package/src/prediction/predictHSQC.ts +4 -1
  113. package/src/prediction/predictProton.ts +1 -1
  114. package/src/prediction/utils/getFilteredIDiaIDs.ts +1 -2
  115. package/src/prediction/utils/getNuclei.ts +3 -3
  116. package/src/prediction/utils/getPredictions.ts +3 -3
  117. package/src/prediction/utils/queryByHOSE.ts +1 -1
  118. package/src/ranges/rangesToXY.ts +12 -5
  119. package/src/signal/signalJoinCouplings.ts +3 -3
  120. package/src/signals/signalsJoin.ts +7 -7
  121. package/src/signals/signalsToXY.ts +3 -3
  122. package/src/signals/simulation/simulate1D.ts +4 -3
  123. package/src/signals/simulation/splitSpinSystem.ts +10 -2
  124. package/src/types/NMRPeak1D.ts +3 -9
  125. package/src/types/NMRSignal2D.ts +7 -7
  126. package/src/types/NMRZone.ts +6 -6
  127. package/src/types/dataStructure.ts +1 -1
  128. package/src/types/jcoupling.ts +1 -1
  129. package/src/types/ml-matrix-peaks-finder/index.d.ts +2 -2
  130. package/src/types/ml-simple-clustering/index.d.ts +1 -1
  131. package/src/types/ml-spectra-processing/index.d.ts +8 -2
  132. package/src/types/modules/nmr-parser.ts +17 -0
  133. package/src/types/openchemlib-utils/index..d.ts +17 -6
  134. package/src/types/prediction1D.ts +2 -2
  135. package/src/utilities/joinPatterns.ts +0 -1
  136. package/src/xy/xyAutoPeaksPicking.ts +19 -58
  137. package/src/xyz/{xyzAutoPeaksPicking.ts → xyzAutoZonesPicking.ts} +40 -24
  138. package/src/xyz/xyzJResAnalyzer.ts +4 -4
  139. package/CHANGELOG.md +0 -543
  140. package/lib/types/MPFPeak.d.ts +0 -9
  141. package/lib/types/MPFPeak.js +0 -3
  142. package/lib/types/MPFPeak.js.map +0 -1
  143. package/lib/xyz/xyzAutoPeaksPicking.js.map +0 -1
  144. package/lib-esm/types/MPFPeak.js +0 -2
  145. package/lib-esm/types/MPFPeak.js.map +0 -1
  146. package/lib-esm/xyz/xyzAutoPeaksPicking.js.map +0 -1
  147. package/src/types/MPFPeak.ts +0 -9
  148. package/src/types/ml-gsd/index.d.ts +0 -164
@@ -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,
@@ -53,7 +53,11 @@ interface SplitClusterOptions {
53
53
  connectivity: Matrix;
54
54
  }
55
55
 
56
- function splitCluster(cluster: Cluster, clusterList: Array<Int16Array>, options: SplitClusterOptions) {
56
+ function splitCluster(
57
+ cluster: Cluster,
58
+ clusterList: Array<Int16Array>,
59
+ options: SplitClusterOptions,
60
+ ) {
57
61
  let { maxClusterSize, force, nSpins, connectivity } = options;
58
62
  if (!force && cluster.size <= maxClusterSize) {
59
63
  clusterList.push(getMembers(cluster.indices(), nSpins));
@@ -102,7 +106,11 @@ function splitCluster(cluster: Cluster, clusterList: Array<Int16Array>, options:
102
106
  }
103
107
  }
104
108
 
105
- function calculateBetas(chemicalShifts: number[], couplingConstants: Matrix, frequency: number) {
109
+ function calculateBetas(
110
+ chemicalShifts: number[],
111
+ couplingConstants: Matrix,
112
+ frequency: number,
113
+ ) {
106
114
  let nRows = couplingConstants.rows;
107
115
  let nColumns = couplingConstants.columns;
108
116
  let betas = Matrix.zeros(nRows, nRows);
@@ -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,4 +1,5 @@
1
- import type { MPFPeak } from './MPFPeak';
1
+ import type { FromTo } from 'cheminfo-types';
2
+ import type { Peak2D } from 'ml-matrix-peaks-finder';
2
3
 
3
4
  export interface Signal2DAxisData {
4
5
  nucleus?: string;
@@ -6,17 +7,16 @@ export interface Signal2DAxisData {
6
7
  resolution?: number;
7
8
  atoms?: number[];
8
9
  diaIDs?: string[];
9
- fromTo?: {
10
- from: number;
11
- to: number
12
- };
13
10
  }
14
11
  export interface NMRSignal2D {
15
12
  x: Signal2DAxisData;
16
13
  y: Signal2DAxisData;
14
+ j?: {
15
+ pathLength?: number | FromTo;
16
+ };
17
17
  id?: string;
18
- peaks?: MPFPeak[];
18
+ peaks?: Peak2D[];
19
19
  kind?: string;
20
- //eslint-disable-next-line
20
+
21
21
  _highlight?: (number | string)[];
22
22
  }
@@ -1,10 +1,10 @@
1
- import type { NMRSignal2D } from "./NMRSignal2D";
1
+ import type { FromTo } from 'cheminfo-types';
2
2
 
3
- interface FromTo { from: number, to: number }
3
+ import type { NMRSignal2D } from './NMRSignal2D';
4
4
 
5
5
  export interface NMRZone {
6
- x: FromTo,
7
- y: FromTo,
6
+ x: FromTo;
7
+ y: FromTo;
8
8
  id?: string;
9
- signals: NMRSignal2D
10
- }
9
+ signals: NMRSignal2D[];
10
+ }
@@ -2,4 +2,4 @@ export interface DataBaseLevelStructure {
2
2
  [key: string]: number[] | undefined;
3
3
  }
4
4
 
5
- export type DataBaseStructure = DataBaseLevelStructure[];
5
+ export type DataBaseStructure = DataBaseLevelStructure[];
@@ -4,5 +4,5 @@ export interface Jcoupling {
4
4
  assignment?: string | string[];
5
5
  diaIDs?: string[];
6
6
  multiplicity?: string;
7
- distance?: number;
7
+ pathLength?: number;
8
8
  }
@@ -8,7 +8,7 @@ declare module 'ml-matrix-peaks-finder' {
8
8
  cols: number;
9
9
  labelling?: 'drain' | 'floodfill';
10
10
  }
11
- interface MPFPeak {
11
+ interface Peak2D {
12
12
  x: number;
13
13
  y: number;
14
14
  z: number;
@@ -20,5 +20,5 @@ declare module 'ml-matrix-peaks-finder' {
20
20
  function findPeaks2DRegion(
21
21
  absoluteData: number[] | Float64Array,
22
22
  options?: FindPeaks2DRegionOptions,
23
- ): MPFPeak[];
23
+ ): Peak2D[];
24
24
  }
@@ -9,4 +9,4 @@ declare module 'ml-simple-clustering' {
9
9
  interface OptionsSimpleClustering {
10
10
  threshold?: number;
11
11
  out?: 'assignment' | 'indexes' | 'values';
12
- }
12
+ }
@@ -45,7 +45,13 @@ declare module 'ml-spectra-processing' {
45
45
 
46
46
  interface XYIntegrationOptions extends XGetFromToIndexOptions {}
47
47
 
48
- function xyIntegration(data: XYNumberArray, options?: XYIntegrationOptions): number;
48
+ function xyIntegration(
49
+ data: XYNumberArray,
50
+ options?: XYIntegrationOptions,
51
+ ): number;
49
52
 
50
- function xGetFromToIndex(x: number[] | Float64Array, options?: XGetFromToIndexOptions): number;
53
+ function xGetFromToIndex(
54
+ x: number[] | Float64Array,
55
+ options?: XGetFromToIndexOptions,
56
+ ): number;
51
57
  }
@@ -0,0 +1,17 @@
1
+ declare module 'nmr-parser' {
2
+ interface FromBrukerOptions {
3
+ base64?: boolean;
4
+ shiftX?: number;
5
+ info?: any;
6
+ name?: string;
7
+ }
8
+
9
+ function fromBruker(
10
+ zipFile: ArrayBuffer | string,
11
+ options?: Partial<FromBrukerOptions>,
12
+ ): Promise<Array<any>>;
13
+
14
+ function fromJCAMP(buffer: string | ArrayBuffer, options?: any): Array<any>;
15
+
16
+ function fromJEOL(buffer: ArrayBuffer): any;
17
+ }
@@ -48,7 +48,10 @@ declare module 'openchemlib-utils' {
48
48
  export interface PathInfo extends AtomInfo {
49
49
  paths: HoseCodesForPath[];
50
50
  }
51
- function getPathsInfo(molecule: Molecule, options?: GetPathsInfoOptions): PathInfo[];
51
+ function getPathsInfo(
52
+ molecule: Molecule,
53
+ options?: GetPathsInfoOptions,
54
+ ): PathInfo[];
52
55
 
53
56
  export interface AtomInfo {
54
57
  oclID: string;
@@ -102,20 +105,25 @@ declare module 'openchemlib-utils' {
102
105
  export interface HoseCodesForPath {
103
106
  atoms: number[];
104
107
  from: number;
105
- to: number,
106
- torsion?: number,
108
+ to: number;
109
+ torsion?: number;
107
110
  hoses: Hoses;
108
111
  length: number;
109
112
  }
110
113
 
111
- function getHoseCodesForPath(molecule: Molecule, from: string, to: string, maxLength: number): HoseCodesForPath;
114
+ function getHoseCodesForPath(
115
+ molecule: Molecule,
116
+ from: string,
117
+ to: string,
118
+ maxLength: number,
119
+ ): HoseCodesForPath;
112
120
 
113
121
  export interface GetConnectivityMatrixOptions {
114
122
  /**
115
123
  * get the path length between atoms
116
124
  * @default false
117
125
  */
118
- pathLength?: boolean
126
+ pathLength?: boolean;
119
127
  /**
120
128
  * set the nominal mass of the atoms on diagonal
121
129
  * @default false
@@ -142,7 +150,10 @@ declare module 'openchemlib-utils' {
142
150
  */
143
151
  stda?: boolean | number;
144
152
  }
145
- function getConnectivityMatrix(molecule: Molecule, options?: GetConnectivityMatrixOptions): number[][] | Float64Array[];
153
+ function getConnectivityMatrix(
154
+ molecule: Molecule,
155
+ options?: GetConnectivityMatrixOptions,
156
+ ): number[][] | Float64Array[];
146
157
 
147
158
  function getDiastereotopicAtomIDs(molecule: Molecule): string[];
148
159
  }
@@ -1,7 +1,7 @@
1
1
  import type { Molecule } from 'openchemlib';
2
2
 
3
- import type { NMRRange } from "./NMRRange";
4
- import type { NMRSignal1D } from "./NMRSignal1D";
3
+ import type { NMRRange } from './NMRRange';
4
+ import type { NMRSignal1D } from './NMRSignal1D';
5
5
 
6
6
  export interface Prediction1D {
7
7
  molfile: string;
@@ -1,7 +1,6 @@
1
1
  import { couplingPatterns } from '../constants/couplingPatterns';
2
2
  import { couplingValues } from '../constants/couplingValues';
3
3
 
4
-
5
4
  export function joinPatterns(patterns: string[]) {
6
5
  const sum = patterns.reduce((sum, pattern) => {
7
6
  if (isNaN(couplingValues[pattern])) {
@@ -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
+ GSDOptions,
6
+ OptimizePeaksOptions,
7
+ JoinBroadPeaksOptions,
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 GSDOptions,
30
+ OptimizePeaksOptions,
31
+ JoinBroadPeaksOptions {
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,13 +1,14 @@
1
1
  import { Matrix } from 'ml-matrix';
2
2
  import * as convolution from 'ml-matrix-convolution';
3
3
  import * as matrixPeakFinders from 'ml-matrix-peaks-finder';
4
+ import type { Peak2D } from 'ml-matrix-peaks-finder';
4
5
  import simpleClustering from 'ml-simple-clustering';
5
6
 
7
+ import { NMRZone } from '..';
6
8
  import { determineRealTop } from '../peaks/util/determineRealTop';
7
9
  import { getKernel } from '../peaks/util/getKernel';
8
10
  import type { GetKernelOptions } from '../peaks/util/getKernel';
9
11
  import * as PeakOptimizer from '../peaks/util/peakOptimizer';
10
- import type { MPFPeak } from '../types/MPFPeak';
11
12
  import type { NMRSignal2D } from '../types/NMRSignal2D';
12
13
 
13
14
  const smallFilter = [
@@ -86,7 +87,7 @@ export interface XYZAutoPeaksPickingOptions {
86
87
  kernel?: GetKernelOptions;
87
88
  }
88
89
 
89
- export function xyzAutoPeaksPicking(
90
+ export function xyzAutoZonesPicking(
90
91
  spectraData: Data2D,
91
92
  options: XYZAutoPeaksPickingOptions,
92
93
  ) {
@@ -178,7 +179,41 @@ export function xyzAutoPeaksPicking(
178
179
  signals = PeakOptimizer.enhanceSymmetry(signals);
179
180
  }
180
181
 
181
- return signals;
182
+ return formatZones(signals);
183
+ }
184
+
185
+ function formatZones(signals: NMRSignal2D[]) {
186
+ let zones: NMRZone[] = [];
187
+ for (const signal of signals) {
188
+ let minMax1 = [Number.MAX_VALUE, 0];
189
+ let minMax2 = [Number.MAX_VALUE, 0];
190
+ for (const peak of signal.peaks || []) {
191
+ if (peak.minX < minMax1[0]) {
192
+ minMax1[0] = peak.minX;
193
+ }
194
+ if (peak.maxX > minMax1[1]) {
195
+ minMax1[1] = peak.maxX;
196
+ }
197
+ if (peak.minY < minMax2[0]) {
198
+ minMax2[0] = peak.minY;
199
+ }
200
+ if (peak.maxY > minMax2[1]) {
201
+ minMax2[1] = peak.maxY;
202
+ }
203
+ }
204
+ zones.push({
205
+ x: {
206
+ from: minMax1[0],
207
+ to: minMax1[1],
208
+ },
209
+ y: {
210
+ from: minMax2[0],
211
+ to: minMax2[1],
212
+ },
213
+ signals: [signal],
214
+ });
215
+ }
216
+ return zones;
182
217
  }
183
218
 
184
219
  /**
@@ -201,7 +236,7 @@ export interface CreateSignals2DOptions {
201
236
  minX: number;
202
237
  maxX: number;
203
238
  }
204
- const createSignals2D = (peaks: MPFPeak[], options: CreateSignals2DOptions) => {
239
+ const createSignals2D = (peaks: Peak2D[], options: CreateSignals2DOptions) => {
205
240
  let {
206
241
  nCols,
207
242
  nRows,
@@ -246,9 +281,6 @@ const createSignals2D = (peaks: MPFPeak[], options: CreateSignals2DOptions) => {
246
281
  peaks[i].maxY = minY + dy * peaks[i].maxY;
247
282
 
248
283
  // Still having problems to correctly detect peaks on those areas. So I'm removing everything there.
249
- if (peaks[i].y < -1 || peaks[i].y >= 210) {
250
- peaks.splice(i, 1);
251
- }
252
284
  }
253
285
  // The connectivity matrix is an square and symmetric matrix, so we'll only store the upper diagonal in an
254
286
  // array like form
@@ -283,9 +315,7 @@ const createSignals2D = (peaks: MPFPeak[], options: CreateSignals2DOptions) => {
283
315
  resolution: dy,
284
316
  },
285
317
  };
286
- let peaks2D = [];
287
- let minMax1 = [Number.MAX_VALUE, 0];
288
- let minMax2 = [Number.MAX_VALUE, 0];
318
+ let peaks2D: Peak2D[] = [];
289
319
  let sumZ = 0;
290
320
 
291
321
  for (let jPeak = 0; jPeak < cluster.length; jPeak++) {
@@ -294,23 +324,9 @@ const createSignals2D = (peaks: MPFPeak[], options: CreateSignals2DOptions) => {
294
324
  signal.x.delta += peaks[jPeak].x * peaks[jPeak].z;
295
325
  signal.y.delta += peaks[jPeak].y * peaks[jPeak].z;
296
326
  sumZ += peaks[jPeak].z;
297
- if (peaks[jPeak].minX < minMax1[0]) {
298
- minMax1[0] = peaks[jPeak].minX;
299
- }
300
- if (peaks[jPeak].maxX > minMax1[1]) {
301
- minMax1[1] = peaks[jPeak].maxX;
302
- }
303
- if (peaks[jPeak].minY < minMax2[0]) {
304
- minMax2[0] = peaks[jPeak].minY;
305
- }
306
- if (peaks[jPeak].maxY > minMax2[1]) {
307
- minMax2[1] = peaks[jPeak].maxY;
308
- }
309
327
  }
310
328
  }
311
329
 
312
- signal.x.fromTo = { from: minMax1[0], to: minMax1[1] };
313
- signal.y.fromTo = { from: minMax2[0], to: minMax2[1] };
314
330
  signal.x.delta /= sumZ;
315
331
  signal.y.delta /= sumZ;
316
332
  signal.peaks = peaks2D;
@@ -1,8 +1,8 @@
1
+ import type { Peak2D } from 'ml-matrix-peaks-finder';
1
2
  import simpleClustering from 'ml-simple-clustering';
2
3
 
3
4
  import type { JAxisKeys } from '../peaks/util/jAnalyzer';
4
5
  import jAnalyzer from '../peaks/util/jAnalyzer';
5
- import type { MPFPeak } from '../types/MPFPeak';
6
6
  import type { MakeMandatory } from '../types/MakeMandatory';
7
7
  import type { NMRSignal2D } from '../types/NMRSignal2D';
8
8
 
@@ -96,7 +96,7 @@ function compilePattern(
96
96
  for (const peak of peaks) {
97
97
  if (!peak.width) peak.width = 0.02;
98
98
  }
99
- peaks.sort((a: MPFPeak, b: MPFPeak) => a.y - b.y);
99
+ peaks.sort((a: Peak2D, b: Peak2D) => a.y - b.y);
100
100
  }
101
101
 
102
102
  for (let i = 0; i < signals.length; i++) {
@@ -137,7 +137,7 @@ function compilePattern(
137
137
  return signals;
138
138
  }
139
139
 
140
- interface Peak2DHack extends MPFPeak {
140
+ interface Peak2DHack extends Peak2D {
141
141
  width?: number;
142
142
  }
143
143
  type Signal2DHack = Omit<NMRSignal2D, 'peaks'> & {
@@ -149,7 +149,7 @@ type Signal2DHack = Omit<NMRSignal2D, 'peaks'> & {
149
149
  observe: number;
150
150
  };
151
151
 
152
- function createSignals2D(peaksInput: MPFPeak[], options: any) {
152
+ function createSignals2D(peaksInput: Peak2D[], options: any) {
153
153
  let { observedFrequencies, tolerances, nuclei, dx, dy } = options;
154
154
 
155
155
  const peaks: Peak2DHack[] = JSON.parse(JSON.stringify(peaksInput));