nmr-processing 9.7.2 → 9.7.3-pre.1687951924
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.
- package/lib/prediction/predictAll.d.ts +2 -10
- package/lib/prediction/predictAll.js +46 -20
- package/lib/prediction/predictAll.js.map +1 -1
- package/lib-esm/prediction/predictAll.js +46 -20
- package/lib-esm/prediction/predictAll.js.map +1 -1
- package/package.json +2 -1
- package/src/prediction/predictAll.ts +48 -32
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import type { Molecule } from 'openchemlib/full';
|
|
2
|
+
import type { Logger } from 'cheminfo-types';
|
|
2
3
|
import type { Prediction1D } from './Prediction1D';
|
|
3
4
|
import { PredictCarbonOptions } from './predictCarbon';
|
|
4
5
|
import { PredictProtonOptions } from './predictProton';
|
|
5
6
|
import type { Predictor } from './utils/predict2D';
|
|
6
7
|
export interface PredictAllOptions {
|
|
7
|
-
/**
|
|
8
|
-
* nucleus label to use in the X axis
|
|
9
|
-
* @default 'H'
|
|
10
|
-
*/
|
|
11
|
-
from?: 'H' | 'C';
|
|
12
|
-
/**
|
|
13
|
-
* nucleus label to use in the Y axis
|
|
14
|
-
* @default 'C';
|
|
15
|
-
*/
|
|
16
|
-
to?: 'H' | 'C';
|
|
17
8
|
/**
|
|
18
9
|
* maximum number of bonds to take into account.
|
|
19
10
|
* @default 1
|
|
@@ -59,6 +50,7 @@ export interface PredictAllOptions {
|
|
|
59
50
|
H?: Prediction1D;
|
|
60
51
|
C?: Prediction1D;
|
|
61
52
|
};
|
|
53
|
+
logger?: Logger;
|
|
62
54
|
}
|
|
63
55
|
export interface PredictedAll {
|
|
64
56
|
molfile: string;
|
|
@@ -13,34 +13,47 @@ const getPredictions_1 = require("./utils/getPredictions");
|
|
|
13
13
|
* @returns {Promise<object>} - object with molfile, diaIDs, 1D and 2D signals, joined signals, ranges and zones.
|
|
14
14
|
*/
|
|
15
15
|
async function predictAll(molecule, options = {}) {
|
|
16
|
-
let {
|
|
16
|
+
let { logger, predictor = { H: predictProton_1.predictProton, C: predictCarbon_1.predictCarbon }, predictions, joinDistance = { H: 0.05, C: 0.5 }, predictOptions = {}, } = options;
|
|
17
17
|
const diaIDs = (0, openchemlib_utils_1.getDiastereotopicAtomIDs)(molecule);
|
|
18
|
-
const xPrediction = await (0, getPredictions_1.getPredictions)(
|
|
19
|
-
const yPrediction = await (0, getPredictions_1.getPredictions)(
|
|
18
|
+
const xPrediction = await (0, getPredictions_1.getPredictions)('H', molecule, predictOptions, predictor, predictions);
|
|
19
|
+
const yPrediction = await (0, getPredictions_1.getPredictions)('C', molecule, predictOptions, predictor, predictions);
|
|
20
20
|
if (!xPrediction || !yPrediction) {
|
|
21
21
|
throw new Error('predictions are not availaible');
|
|
22
22
|
}
|
|
23
|
+
const spectra = {};
|
|
24
|
+
if (check1DPrediction(xPrediction)) {
|
|
25
|
+
spectra.proton = xPrediction;
|
|
26
|
+
}
|
|
27
|
+
if (check1DPrediction(yPrediction)) {
|
|
28
|
+
spectra.carbon = yPrediction;
|
|
29
|
+
}
|
|
30
|
+
const { molfile } = xPrediction;
|
|
23
31
|
predictions = {
|
|
24
32
|
H: xPrediction,
|
|
25
33
|
C: yPrediction,
|
|
26
34
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
spectra.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
if (spectra.proton) {
|
|
36
|
+
spectra.cosy = await (0, predictCOSY_1.predictCOSY)(molecule, {
|
|
37
|
+
predictions,
|
|
38
|
+
joinDistance,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else if (logger) {
|
|
42
|
+
logger.warn('Proton prediction is missing so COSY could not be generated.');
|
|
43
|
+
}
|
|
44
|
+
if (spectra.carbon && spectra.proton) {
|
|
45
|
+
spectra.hsqc = await (0, predictHSQC_1.predictHSQC)(molecule, {
|
|
46
|
+
predictions,
|
|
47
|
+
joinDistance,
|
|
48
|
+
});
|
|
49
|
+
spectra.hmbc = await (0, predictHMBC_1.predictHMBC)(molecule, {
|
|
50
|
+
predictions,
|
|
51
|
+
joinDistance,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else if (logger) {
|
|
55
|
+
logger.warn('Carbon and / or proton prediction is missing so HSQC and HMBC could not be generated.');
|
|
56
|
+
}
|
|
44
57
|
for (const key in spectra) {
|
|
45
58
|
delete spectra[key].molfile;
|
|
46
59
|
delete spectra[key].diaIDs;
|
|
@@ -52,4 +65,17 @@ async function predictAll(molecule, options = {}) {
|
|
|
52
65
|
};
|
|
53
66
|
}
|
|
54
67
|
exports.predictAll = predictAll;
|
|
68
|
+
function check1DPrediction(prediction) {
|
|
69
|
+
if (!prediction)
|
|
70
|
+
return false;
|
|
71
|
+
if (prediction.ranges.length === 0)
|
|
72
|
+
return false;
|
|
73
|
+
const { signals, diaIDs } = prediction;
|
|
74
|
+
for (const signal of signals) {
|
|
75
|
+
const isCorrect = signal.diaIDs?.every((diaID) => diaIDs.includes(diaID));
|
|
76
|
+
if (!isCorrect)
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
55
81
|
//# sourceMappingURL=predictAll.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predictAll.js","sourceRoot":"","sources":["../../src/prediction/predictAll.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"predictAll.js","sourceRoot":"","sources":["../../src/prediction/predictAll.ts"],"names":[],"mappings":";;;AAEA,yDAA6D;AAG7D,+CAA4C;AAC5C,mDAAsE;AACtE,+CAA4C;AAC5C,+CAA4C;AAC5C,mDAAsE;AACtE,2DAAwD;AAgDxD;;;GAGG;AACI,KAAK,UAAU,UAAU,CAC9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ED,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE;QACpC,OAAO,CAAC,IAAI,GAAG,MAAM,IAAA,yBAAW,EAAC,QAAQ,EAAE;YACzC,WAAW;YACX,YAAY;SACb,CAAC,CAAC;QACH,OAAO,CAAC,IAAI,GAAG,MAAM,IAAA,yBAAW,EAAC,QAAQ,EAAE;YACzC,WAAW;YACX,YAAY;SACb,CAAC,CAAC;KACJ;SAAM,IAAI,MAAM,EAAE;QACjB,MAAM,CAAC,IAAI,CACT,uFAAuF,CACxF,CAAC;KACH;IAED,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;QACzB,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;QAC5B,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;KAC5B;IAED,OAAO;QACL,OAAO;QACP,MAAM;QACN,OAAO;KACR,CAAC;AACJ,CAAC;AAnFD,gCAmFC;AAED,SAAS,iBAAiB,CAAC,UAAyB;IAClD,IAAI,CAAC,UAAU;QAAE,OAAO,KAAK,CAAC;IAC9B,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACjD,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC;IACvC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1E,IAAI,CAAC,SAAS;YAAE,OAAO,KAAK,CAAC;KAC9B;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -10,34 +10,47 @@ import { getPredictions } from './utils/getPredictions';
|
|
|
10
10
|
* @returns {Promise<object>} - object with molfile, diaIDs, 1D and 2D signals, joined signals, ranges and zones.
|
|
11
11
|
*/
|
|
12
12
|
export async function predictAll(molecule, options = {}) {
|
|
13
|
-
let {
|
|
13
|
+
let { logger, predictor = { H: predictProton, C: predictCarbon }, predictions, joinDistance = { H: 0.05, C: 0.5 }, predictOptions = {}, } = options;
|
|
14
14
|
const diaIDs = getDiastereotopicAtomIDs(molecule);
|
|
15
|
-
const xPrediction = await getPredictions(
|
|
16
|
-
const yPrediction = await getPredictions(
|
|
15
|
+
const xPrediction = await getPredictions('H', molecule, predictOptions, predictor, predictions);
|
|
16
|
+
const yPrediction = await getPredictions('C', molecule, predictOptions, predictor, predictions);
|
|
17
17
|
if (!xPrediction || !yPrediction) {
|
|
18
18
|
throw new Error('predictions are not availaible');
|
|
19
19
|
}
|
|
20
|
+
const spectra = {};
|
|
21
|
+
if (check1DPrediction(xPrediction)) {
|
|
22
|
+
spectra.proton = xPrediction;
|
|
23
|
+
}
|
|
24
|
+
if (check1DPrediction(yPrediction)) {
|
|
25
|
+
spectra.carbon = yPrediction;
|
|
26
|
+
}
|
|
27
|
+
const { molfile } = xPrediction;
|
|
20
28
|
predictions = {
|
|
21
29
|
H: xPrediction,
|
|
22
30
|
C: yPrediction,
|
|
23
31
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
spectra.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
if (spectra.proton) {
|
|
33
|
+
spectra.cosy = await predictCOSY(molecule, {
|
|
34
|
+
predictions,
|
|
35
|
+
joinDistance,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else if (logger) {
|
|
39
|
+
logger.warn('Proton prediction is missing so COSY could not be generated.');
|
|
40
|
+
}
|
|
41
|
+
if (spectra.carbon && spectra.proton) {
|
|
42
|
+
spectra.hsqc = await predictHSQC(molecule, {
|
|
43
|
+
predictions,
|
|
44
|
+
joinDistance,
|
|
45
|
+
});
|
|
46
|
+
spectra.hmbc = await predictHMBC(molecule, {
|
|
47
|
+
predictions,
|
|
48
|
+
joinDistance,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else if (logger) {
|
|
52
|
+
logger.warn('Carbon and / or proton prediction is missing so HSQC and HMBC could not be generated.');
|
|
53
|
+
}
|
|
41
54
|
for (const key in spectra) {
|
|
42
55
|
delete spectra[key].molfile;
|
|
43
56
|
delete spectra[key].diaIDs;
|
|
@@ -48,4 +61,17 @@ export async function predictAll(molecule, options = {}) {
|
|
|
48
61
|
spectra,
|
|
49
62
|
};
|
|
50
63
|
}
|
|
64
|
+
function check1DPrediction(prediction) {
|
|
65
|
+
if (!prediction)
|
|
66
|
+
return false;
|
|
67
|
+
if (prediction.ranges.length === 0)
|
|
68
|
+
return false;
|
|
69
|
+
const { signals, diaIDs } = prediction;
|
|
70
|
+
for (const signal of signals) {
|
|
71
|
+
const isCorrect = signal.diaIDs?.every((diaID) => diaIDs.includes(diaID));
|
|
72
|
+
if (!isCorrect)
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
51
77
|
//# sourceMappingURL=predictAll.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predictAll.js","sourceRoot":"","sources":["../../src/prediction/predictAll.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"predictAll.js","sourceRoot":"","sources":["../../src/prediction/predictAll.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAG7D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAwB,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAA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|
2
2
|
"name": "nmr-processing",
|
|
3
|
-
"version": "9.7.
|
|
3
|
+
"version": "9.7.3-pre.1687951924",
|
|
4
4
|
"description": "Pure functions allowing to process NMR spectra.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"cheminfo-types": "^1.7.2",
|
|
44
44
|
"eslint": "^8.36.0",
|
|
45
45
|
"eslint-config-cheminfo-typescript": "^11.3.1",
|
|
46
|
+
"fifo-logger": "^0.6.1",
|
|
46
47
|
"jest": "^29.5.0",
|
|
47
48
|
"jest-matcher-deep-close-to": "^3.0.2",
|
|
48
49
|
"md5": "^2.3.0",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Molecule } from 'openchemlib/full';
|
|
2
|
+
import type { Logger } from 'cheminfo-types';
|
|
2
3
|
import { getDiastereotopicAtomIDs } from 'openchemlib-utils';
|
|
3
4
|
|
|
4
5
|
import type { Prediction1D } from './Prediction1D';
|
|
@@ -11,16 +12,6 @@ import { getPredictions } from './utils/getPredictions';
|
|
|
11
12
|
import type { Predictor } from './utils/predict2D';
|
|
12
13
|
|
|
13
14
|
export interface PredictAllOptions {
|
|
14
|
-
/**
|
|
15
|
-
* nucleus label to use in the X axis
|
|
16
|
-
* @default 'H'
|
|
17
|
-
*/
|
|
18
|
-
from?: 'H' | 'C';
|
|
19
|
-
/**
|
|
20
|
-
* nucleus label to use in the Y axis
|
|
21
|
-
* @default 'C';
|
|
22
|
-
*/
|
|
23
|
-
to?: 'H' | 'C';
|
|
24
15
|
/**
|
|
25
16
|
* maximum number of bonds to take into account.
|
|
26
17
|
* @default 1
|
|
@@ -57,6 +48,7 @@ export interface PredictAllOptions {
|
|
|
57
48
|
H?: Prediction1D;
|
|
58
49
|
C?: Prediction1D;
|
|
59
50
|
};
|
|
51
|
+
logger?: Logger;
|
|
60
52
|
}
|
|
61
53
|
|
|
62
54
|
export interface PredictedAll {
|
|
@@ -73,8 +65,7 @@ export async function predictAll(
|
|
|
73
65
|
options: PredictAllOptions = {},
|
|
74
66
|
): Promise<PredictedAll> {
|
|
75
67
|
let {
|
|
76
|
-
|
|
77
|
-
to = 'C',
|
|
68
|
+
logger,
|
|
78
69
|
predictor = { H: predictProton, C: predictCarbon },
|
|
79
70
|
predictions,
|
|
80
71
|
joinDistance = { H: 0.05, C: 0.5 },
|
|
@@ -84,7 +75,7 @@ export async function predictAll(
|
|
|
84
75
|
const diaIDs = getDiastereotopicAtomIDs(molecule);
|
|
85
76
|
|
|
86
77
|
const xPrediction = await getPredictions(
|
|
87
|
-
|
|
78
|
+
'H',
|
|
88
79
|
molecule,
|
|
89
80
|
predictOptions,
|
|
90
81
|
predictor,
|
|
@@ -92,7 +83,7 @@ export async function predictAll(
|
|
|
92
83
|
);
|
|
93
84
|
|
|
94
85
|
const yPrediction = await getPredictions(
|
|
95
|
-
|
|
86
|
+
'C',
|
|
96
87
|
molecule,
|
|
97
88
|
predictOptions,
|
|
98
89
|
predictor,
|
|
@@ -103,30 +94,44 @@ export async function predictAll(
|
|
|
103
94
|
throw new Error('predictions are not availaible');
|
|
104
95
|
}
|
|
105
96
|
|
|
97
|
+
const spectra: any = {};
|
|
98
|
+
if (check1DPrediction(xPrediction)) {
|
|
99
|
+
spectra.proton = xPrediction;
|
|
100
|
+
}
|
|
101
|
+
if (check1DPrediction(yPrediction)) {
|
|
102
|
+
spectra.carbon = yPrediction;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const { molfile } = xPrediction;
|
|
106
|
+
|
|
106
107
|
predictions = {
|
|
107
108
|
H: xPrediction,
|
|
108
109
|
C: yPrediction,
|
|
109
110
|
};
|
|
110
111
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
112
|
+
if (spectra.proton) {
|
|
113
|
+
spectra.cosy = await predictCOSY(molecule, {
|
|
114
|
+
predictions,
|
|
115
|
+
joinDistance,
|
|
116
|
+
});
|
|
117
|
+
} else if (logger) {
|
|
118
|
+
logger.warn('Proton prediction is missing so COSY could not be generated.');
|
|
119
|
+
}
|
|
117
120
|
|
|
118
|
-
spectra.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
121
|
+
if (spectra.carbon && spectra.proton) {
|
|
122
|
+
spectra.hsqc = await predictHSQC(molecule, {
|
|
123
|
+
predictions,
|
|
124
|
+
joinDistance,
|
|
125
|
+
});
|
|
126
|
+
spectra.hmbc = await predictHMBC(molecule, {
|
|
127
|
+
predictions,
|
|
128
|
+
joinDistance,
|
|
129
|
+
});
|
|
130
|
+
} else if (logger) {
|
|
131
|
+
logger.warn(
|
|
132
|
+
'Carbon and / or proton prediction is missing so HSQC and HMBC could not be generated.',
|
|
133
|
+
);
|
|
134
|
+
}
|
|
130
135
|
|
|
131
136
|
for (const key in spectra) {
|
|
132
137
|
delete spectra[key].molfile;
|
|
@@ -139,3 +144,14 @@ export async function predictAll(
|
|
|
139
144
|
spectra,
|
|
140
145
|
};
|
|
141
146
|
}
|
|
147
|
+
|
|
148
|
+
function check1DPrediction(prediction?: Prediction1D) {
|
|
149
|
+
if (!prediction) return false;
|
|
150
|
+
if (prediction.ranges.length === 0) return false;
|
|
151
|
+
const { signals, diaIDs } = prediction;
|
|
152
|
+
for (const signal of signals) {
|
|
153
|
+
const isCorrect = signal.diaIDs?.every((diaID) => diaIDs.includes(diaID));
|
|
154
|
+
if (!isCorrect) return false;
|
|
155
|
+
}
|
|
156
|
+
return true;
|
|
157
|
+
}
|