nmr-processing 7.1.0 → 7.2.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.
- package/lib/assignment/get13CAssignments.d.ts +3 -3
- package/lib/assignment/get13CAssignments.js.map +1 -1
- package/lib/assignment/get1HAssignments.d.ts +3 -3
- package/lib/assignment/get1HAssignments.js.map +1 -1
- package/lib/assignment/getAssignments.d.ts +81 -0
- package/lib/assignment/getAssignments.js +44 -0
- package/lib/assignment/getAssignments.js.map +1 -0
- package/lib/assignment/utils/buildAssignments.d.ts +4 -4
- package/lib/assignment/utils/buildAssignments.js.map +1 -1
- package/lib/assignment/utils/createMapPossibleAssignments.d.ts +2 -2
- package/lib/assignment/utils/exploreTreeRec.d.ts +3 -3
- package/lib/assignment/utils/exploreTreeRec.js.map +1 -1
- package/lib/assignment/utils/getAssignment/buildAssignments.d.ts +72 -0
- package/lib/assignment/utils/getAssignment/buildAssignments.js +205 -0
- package/lib/assignment/utils/getAssignment/buildAssignments.js.map +1 -0
- package/lib/assignment/utils/getAssignment/checkIDs.d.ts +23 -0
- package/lib/assignment/utils/getAssignment/checkIDs.js +57 -0
- package/lib/assignment/utils/getAssignment/checkIDs.js.map +1 -0
- package/lib/assignment/utils/getAssignment/createMapPossibleAssignment.d.ts +15 -0
- package/lib/assignment/utils/getAssignment/createMapPossibleAssignment.js +55 -0
- package/lib/assignment/utils/getAssignment/createMapPossibleAssignment.js.map +1 -0
- package/lib/assignment/utils/getAssignment/exploreTree.d.ts +22 -0
- package/lib/assignment/utils/getAssignment/exploreTree.js +93 -0
- package/lib/assignment/utils/getAssignment/exploreTree.js.map +1 -0
- package/lib/assignment/utils/getAssignment/formatData.d.ts +14 -0
- package/lib/assignment/utils/getAssignment/formatData.js +20 -0
- package/lib/assignment/utils/getAssignment/formatData.js.map +1 -0
- package/lib/assignment/utils/getAssignment/getIntegrationOfAttachedProtons.d.ts +3 -0
- package/lib/assignment/utils/getAssignment/getIntegrationOfAttachedProtons.js +14 -0
- package/lib/assignment/utils/getAssignment/getIntegrationOfAttachedProtons.js.map +1 -0
- package/lib/assignment/utils/getAssignment/getTargetsAndCorrelations.d.ts +18 -0
- package/lib/assignment/utils/getAssignment/getTargetsAndCorrelations.js +37 -0
- package/lib/assignment/utils/getAssignment/getTargetsAndCorrelations.js.map +1 -0
- package/lib/assignment/utils/getAssignment/getWorkFlow.d.ts +19 -0
- package/lib/assignment/utils/getAssignment/getWorkFlow.js +52 -0
- package/lib/assignment/utils/getAssignment/getWorkFlow.js.map +1 -0
- package/lib/assignment/utils/getAssignment/groupCarbonTargetByIntegrationZone.d.ts +7 -0
- package/lib/assignment/utils/getAssignment/groupCarbonTargetByIntegrationZone.js +43 -0
- package/lib/assignment/utils/getAssignment/groupCarbonTargetByIntegrationZone.js.map +1 -0
- package/lib/assignment/utils/getAssignment/isSpectraData1D.d.ts +2 -0
- package/lib/assignment/utils/getAssignment/isSpectraData1D.js +8 -0
- package/lib/assignment/utils/getAssignment/isSpectraData1D.js.map +1 -0
- package/lib/assignment/utils/getAssignment/partialScore.d.ts +13 -0
- package/lib/assignment/utils/getAssignment/partialScore.js +221 -0
- package/lib/assignment/utils/getAssignment/partialScore.js.map +1 -0
- package/lib/assignment/utils/getAssignment/searchIndices.d.ts +6 -0
- package/lib/assignment/utils/getAssignment/searchIndices.js +21 -0
- package/lib/assignment/utils/getAssignment/searchIndices.js.map +1 -0
- package/lib/assignment/utils/partialScore.d.ts +2 -2
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/peaks/peaksToRanges.js +1 -0
- package/lib/peaks/peaksToRanges.js.map +1 -1
- package/lib/prediction/utils/predict2D.d.ts +0 -2
- package/lib/prediction/utils/predict2D.js.map +1 -1
- package/lib-esm/assignment/get13CAssignments.js.map +1 -1
- package/lib-esm/assignment/get1HAssignments.js.map +1 -1
- package/lib-esm/assignment/getAssignments.js +37 -0
- package/lib-esm/assignment/getAssignments.js.map +1 -0
- package/lib-esm/assignment/utils/buildAssignments.js.map +1 -1
- package/lib-esm/assignment/utils/exploreTreeRec.js.map +1 -1
- package/lib-esm/assignment/utils/getAssignment/buildAssignments.js +198 -0
- package/lib-esm/assignment/utils/getAssignment/buildAssignments.js.map +1 -0
- package/lib-esm/assignment/utils/getAssignment/checkIDs.js +48 -0
- package/lib-esm/assignment/utils/getAssignment/checkIDs.js.map +1 -0
- package/lib-esm/assignment/utils/getAssignment/createMapPossibleAssignment.js +51 -0
- package/lib-esm/assignment/utils/getAssignment/createMapPossibleAssignment.js.map +1 -0
- package/lib-esm/assignment/utils/getAssignment/exploreTree.js +89 -0
- package/lib-esm/assignment/utils/getAssignment/exploreTree.js.map +1 -0
- package/lib-esm/assignment/utils/getAssignment/formatData.js +16 -0
- package/lib-esm/assignment/utils/getAssignment/formatData.js.map +1 -0
- package/lib-esm/assignment/utils/getAssignment/getIntegrationOfAttachedProtons.js +10 -0
- package/lib-esm/assignment/utils/getAssignment/getIntegrationOfAttachedProtons.js.map +1 -0
- package/lib-esm/assignment/utils/getAssignment/getTargetsAndCorrelations.js +33 -0
- package/lib-esm/assignment/utils/getAssignment/getTargetsAndCorrelations.js.map +1 -0
- package/lib-esm/assignment/utils/getAssignment/getWorkFlow.js +50 -0
- package/lib-esm/assignment/utils/getAssignment/getWorkFlow.js.map +1 -0
- package/lib-esm/assignment/utils/getAssignment/groupCarbonTargetByIntegrationZone.js +41 -0
- package/lib-esm/assignment/utils/getAssignment/groupCarbonTargetByIntegrationZone.js.map +1 -0
- package/lib-esm/assignment/utils/getAssignment/isSpectraData1D.js +4 -0
- package/lib-esm/assignment/utils/getAssignment/isSpectraData1D.js.map +1 -0
- package/lib-esm/assignment/utils/getAssignment/partialScore.js +214 -0
- package/lib-esm/assignment/utils/getAssignment/partialScore.js.map +1 -0
- package/lib-esm/assignment/utils/getAssignment/searchIndices.js +17 -0
- package/lib-esm/assignment/utils/getAssignment/searchIndices.js.map +1 -0
- package/lib-esm/index.js +1 -0
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/peaks/peaksToRanges.js +1 -0
- package/lib-esm/peaks/peaksToRanges.js.map +1 -1
- package/lib-esm/prediction/utils/predict2D.js.map +1 -1
- package/package.json +2 -1
- package/src/assignment/get13CAssignments.ts +2 -2
- package/src/assignment/get1HAssignments.ts +2 -2
- package/src/assignment/getAssignments.ts +149 -0
- package/src/assignment/utils/buildAssignments.ts +4 -4
- package/src/assignment/utils/createMapPossibleAssignments.ts +2 -2
- package/src/assignment/utils/exploreTreeRec.ts +5 -5
- package/src/assignment/utils/getAssignment/buildAssignments.ts +339 -0
- package/src/assignment/utils/getAssignment/checkIDs.ts +76 -0
- package/src/assignment/utils/getAssignment/createMapPossibleAssignment.ts +85 -0
- package/src/assignment/utils/getAssignment/data/correlations.js +713 -0
- package/src/assignment/utils/getAssignment/data/predictions.js +34 -0
- package/src/assignment/utils/getAssignment/exploreTree.ts +171 -0
- package/src/assignment/utils/getAssignment/formatData.ts +35 -0
- package/src/assignment/utils/getAssignment/getIntegrationOfAttachedProtons.ts +16 -0
- package/src/assignment/utils/getAssignment/getTargetsAndCorrelations.ts +63 -0
- package/src/assignment/utils/getAssignment/getWorkFlow.ts +72 -0
- package/src/assignment/utils/getAssignment/groupCarbonTargetByIntegrationZone.ts +55 -0
- package/src/assignment/utils/getAssignment/isSpectraData1D.ts +7 -0
- package/src/assignment/utils/getAssignment/partialScore.ts +308 -0
- package/src/assignment/utils/getAssignment/searchIndices.ts +19 -0
- package/src/assignment/utils/partialScore.ts +2 -2
- package/src/index.ts +1 -0
- package/src/ml-tree-set.d.ts +1 -1
- package/src/peaks/peaksToRanges.ts +1 -0
- package/src/prediction/utils/predict2D.ts +0 -2
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const predictions = {
|
|
2
|
+
C: {
|
|
3
|
+
carbon1: {
|
|
4
|
+
delta: 49.2,
|
|
5
|
+
diaIDs: ['carbon1'],
|
|
6
|
+
allHydrogens: 2,
|
|
7
|
+
diaIDIndex: 0,
|
|
8
|
+
pathLength: [0, 1, 2, 1, 1],
|
|
9
|
+
},
|
|
10
|
+
carbon2: {
|
|
11
|
+
delta: 28,
|
|
12
|
+
diaIDs: ['carbon2'],
|
|
13
|
+
allHydrogens: 0,
|
|
14
|
+
diaIDIndex: 1,
|
|
15
|
+
pathLength: [1, 0, 1, 2, 2],
|
|
16
|
+
},
|
|
17
|
+
carbon3: {
|
|
18
|
+
delta: 26.3,
|
|
19
|
+
diaIDs: ['carbon3'],
|
|
20
|
+
allHydrogens: 0,
|
|
21
|
+
diaIDIndex: 2,
|
|
22
|
+
pathLegth: [2, 1, 0, 3, 3],
|
|
23
|
+
},
|
|
24
|
+
carbon4: {
|
|
25
|
+
delta: 120,
|
|
26
|
+
diaIDs: ['carbon4'],
|
|
27
|
+
allHydrogens: 2,
|
|
28
|
+
diaIDIndex: 3,
|
|
29
|
+
pathLength: [2, 1, 0, 3, 3],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default predictions;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { StoreAssignments } from '../buildAssignments';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
RestrictionByCS,
|
|
5
|
+
DiaIDPeerPossibleAssignment,
|
|
6
|
+
InfoByAtomType,
|
|
7
|
+
Partial,
|
|
8
|
+
CurrentAtoms,
|
|
9
|
+
PredictionsByAtomType,
|
|
10
|
+
} from './buildAssignments';
|
|
11
|
+
import { MapPossibleAssignments } from './createMapPossibleAssignment';
|
|
12
|
+
import {
|
|
13
|
+
CorrelationWithIntegration,
|
|
14
|
+
TargetsByAtomType,
|
|
15
|
+
} from './getTargetsAndCorrelations';
|
|
16
|
+
import { partialScore } from './partialScore';
|
|
17
|
+
|
|
18
|
+
export interface ExploreTreeRecOptions {
|
|
19
|
+
currentAtomTypes: CurrentAtoms;
|
|
20
|
+
restrictionByCS: RestrictionByCS;
|
|
21
|
+
timeout: number;
|
|
22
|
+
timeStart: number;
|
|
23
|
+
maxSolutions: number;
|
|
24
|
+
targets: TargetsByAtomType;
|
|
25
|
+
predictions: PredictionsByAtomType;
|
|
26
|
+
correlations: CorrelationWithIntegration[];
|
|
27
|
+
lowerBoundScore: number;
|
|
28
|
+
possibleAssignmentMap: MapPossibleAssignments;
|
|
29
|
+
diaIDPeerPossibleAssignment: DiaIDPeerPossibleAssignment;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface AddSolutionOptions
|
|
33
|
+
extends Pick<ExploreTreeRecOptions, 'maxSolutions' | 'predictions'> {
|
|
34
|
+
partial: Partial;
|
|
35
|
+
score: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function exploreTree(
|
|
39
|
+
props: ExploreTreeRecOptions,
|
|
40
|
+
infoByAtomTypes: InfoByAtomType,
|
|
41
|
+
partial: Partial,
|
|
42
|
+
store: StoreAssignments,
|
|
43
|
+
) {
|
|
44
|
+
const {
|
|
45
|
+
currentAtomTypes,
|
|
46
|
+
restrictionByCS,
|
|
47
|
+
timeout,
|
|
48
|
+
timeStart,
|
|
49
|
+
maxSolutions,
|
|
50
|
+
targets,
|
|
51
|
+
predictions,
|
|
52
|
+
correlations,
|
|
53
|
+
lowerBoundScore,
|
|
54
|
+
possibleAssignmentMap,
|
|
55
|
+
diaIDPeerPossibleAssignment,
|
|
56
|
+
} = props;
|
|
57
|
+
|
|
58
|
+
const currentDate = new Date();
|
|
59
|
+
if (currentDate.getTime() - timeStart > timeout) {
|
|
60
|
+
new Error('timeout expired');
|
|
61
|
+
return store;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
for (const atomType of currentAtomTypes) {
|
|
65
|
+
const { currentIndex, nSources } = infoByAtomTypes[atomType];
|
|
66
|
+
|
|
67
|
+
if (
|
|
68
|
+
currentIndex >= nSources - 1 &&
|
|
69
|
+
partial[atomType][currentIndex] !== null
|
|
70
|
+
) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const diaID = diaIDPeerPossibleAssignment[atomType][currentIndex];
|
|
75
|
+
const possibleAssignments = possibleAssignmentMap[atomType][diaID];
|
|
76
|
+
|
|
77
|
+
for (let targetID of possibleAssignments) {
|
|
78
|
+
partial[atomType][currentIndex] = targetID;
|
|
79
|
+
|
|
80
|
+
let score = partialScore(partial, {
|
|
81
|
+
diaIDPeerPossibleAssignment,
|
|
82
|
+
infoByAtomTypes,
|
|
83
|
+
restrictionByCS,
|
|
84
|
+
predictions,
|
|
85
|
+
correlations,
|
|
86
|
+
targets,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if (score === 0) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (
|
|
94
|
+
isLastOne(currentAtomTypes, infoByAtomTypes) &&
|
|
95
|
+
score >= lowerBoundScore
|
|
96
|
+
) {
|
|
97
|
+
addSolution(store, { predictions, partial, score, maxSolutions });
|
|
98
|
+
} else {
|
|
99
|
+
const newInfo = JSON.parse(JSON.stringify(infoByAtomTypes));
|
|
100
|
+
newInfo[atomType].currentIndex += 1;
|
|
101
|
+
exploreTree(
|
|
102
|
+
{
|
|
103
|
+
currentAtomTypes,
|
|
104
|
+
restrictionByCS,
|
|
105
|
+
timeout,
|
|
106
|
+
timeStart,
|
|
107
|
+
maxSolutions,
|
|
108
|
+
targets,
|
|
109
|
+
predictions,
|
|
110
|
+
correlations,
|
|
111
|
+
lowerBoundScore,
|
|
112
|
+
possibleAssignmentMap,
|
|
113
|
+
diaIDPeerPossibleAssignment,
|
|
114
|
+
},
|
|
115
|
+
newInfo,
|
|
116
|
+
JSON.parse(JSON.stringify(partial)),
|
|
117
|
+
store,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface AssignmentSolution {
|
|
125
|
+
assignment: string[];
|
|
126
|
+
score: number;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function addSolution(store: StoreAssignments, props: AddSolutionOptions) {
|
|
130
|
+
let { score, maxSolutions, partial, predictions } = props;
|
|
131
|
+
score /= doubleAssignmentPenalty(partial, predictions);
|
|
132
|
+
let solution: AssignmentSolution = {
|
|
133
|
+
assignment: JSON.parse(JSON.stringify(partial)),
|
|
134
|
+
score,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
if (store.nSolutions >= maxSolutions) {
|
|
138
|
+
if (solution.score > store.solutions.last().score) {
|
|
139
|
+
store.solutions.pollLast();
|
|
140
|
+
store.solutions.add(solution);
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
store.solutions.add(solution);
|
|
144
|
+
store.nSolutions++;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function isLastOne(
|
|
149
|
+
currentAtomTypes: CurrentAtoms,
|
|
150
|
+
infoByAtomTypes: InfoByAtomType,
|
|
151
|
+
) {
|
|
152
|
+
let lastOne = true;
|
|
153
|
+
for (const atomType of currentAtomTypes) {
|
|
154
|
+
const { currentIndex, nSources } = infoByAtomTypes[atomType];
|
|
155
|
+
lastOne = lastOne && currentIndex >= nSources - 1;
|
|
156
|
+
}
|
|
157
|
+
return lastOne;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function doubleAssignmentPenalty(
|
|
161
|
+
partial: Partial,
|
|
162
|
+
predictions: PredictionsByAtomType,
|
|
163
|
+
) {
|
|
164
|
+
let nbDoubleAssignment = 0;
|
|
165
|
+
for (const atomType in predictions) {
|
|
166
|
+
const nbSources = Object.keys(predictions[atomType]).length;
|
|
167
|
+
let assignments = new Set(partial[atomType]);
|
|
168
|
+
nbDoubleAssignment += nbSources - assignments.size;
|
|
169
|
+
}
|
|
170
|
+
return nbDoubleAssignment > 0 ? 2 * nbDoubleAssignment : 1;
|
|
171
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NMRRangeWithIds,
|
|
3
|
+
NMRZoneWithIds,
|
|
4
|
+
SpectraData1DWithIds,
|
|
5
|
+
SpectraData2DWithIds,
|
|
6
|
+
SpectraDataWithIds,
|
|
7
|
+
} from './checkIDs';
|
|
8
|
+
import { isSpectraData1D } from './isSpectraData1D';
|
|
9
|
+
|
|
10
|
+
interface SpectraData1DFormatted extends Omit<SpectraData1DWithIds, 'ranges'> {
|
|
11
|
+
ranges: { values: NMRRangeWithIds[] };
|
|
12
|
+
}
|
|
13
|
+
interface SpectraData2DFormatted extends Omit<SpectraData2DWithIds, 'zones'> {
|
|
14
|
+
zones: { values: NMRZoneWithIds[] };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type SpectraDataFormatted =
|
|
18
|
+
| SpectraData1DFormatted
|
|
19
|
+
| SpectraData2DFormatted;
|
|
20
|
+
|
|
21
|
+
export function formatData(
|
|
22
|
+
input: SpectraDataWithIds[] = [],
|
|
23
|
+
): SpectraDataFormatted[] {
|
|
24
|
+
let inputClone = JSON.parse(JSON.stringify(input)) as SpectraDataWithIds[];
|
|
25
|
+
let spectra: SpectraDataFormatted[] = [];
|
|
26
|
+
for (const spectraData of inputClone) {
|
|
27
|
+
const { info } = spectraData;
|
|
28
|
+
if (isSpectraData1D(spectraData)) {
|
|
29
|
+
spectra.push({ info, ranges: { values: spectraData.ranges } });
|
|
30
|
+
} else {
|
|
31
|
+
spectra.push({ info, zones: { values: spectraData.zones } });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return spectra;
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Values } from 'nmr-correlation';
|
|
2
|
+
|
|
3
|
+
import type { CorrelationWithIntegration } from './getTargetsAndCorrelations';
|
|
4
|
+
|
|
5
|
+
export function getIntegrationOfAttachedProtons(
|
|
6
|
+
target: CorrelationWithIntegration,
|
|
7
|
+
correlations: Values,
|
|
8
|
+
) {
|
|
9
|
+
const { H: attachment = [] } = target.attachment;
|
|
10
|
+
let integration = 0;
|
|
11
|
+
for (const match of attachment) {
|
|
12
|
+
const correlation = correlations[match];
|
|
13
|
+
integration += Number(correlation.link[0].signal.integration);
|
|
14
|
+
}
|
|
15
|
+
return integration;
|
|
16
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { buildCorrelationData } from 'nmr-correlation';
|
|
2
|
+
import type { Correlation, Link } from 'nmr-correlation';
|
|
3
|
+
|
|
4
|
+
import { SpectraDataWithIds } from './checkIDs';
|
|
5
|
+
import { formatData } from './formatData';
|
|
6
|
+
import { getIntegrationOfAttachedProtons } from './getIntegrationOfAttachedProtons';
|
|
7
|
+
|
|
8
|
+
export interface CorrelationWithIntegration
|
|
9
|
+
extends Pick<
|
|
10
|
+
Correlation,
|
|
11
|
+
'link' | 'atomType' | 'label' | 'attachment' | 'protonsCount'
|
|
12
|
+
> {
|
|
13
|
+
integration: number;
|
|
14
|
+
indirectLinks: Array<Link>;
|
|
15
|
+
}
|
|
16
|
+
export interface Targets {
|
|
17
|
+
[key: string]: CorrelationWithIntegration;
|
|
18
|
+
}
|
|
19
|
+
export interface TargetsByAtomType {
|
|
20
|
+
H: Targets;
|
|
21
|
+
C: Targets;
|
|
22
|
+
}
|
|
23
|
+
export interface TargetsAndCorrelations {
|
|
24
|
+
targets: TargetsByAtomType;
|
|
25
|
+
correlations: CorrelationWithIntegration[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getTargetsAndCorrelations(
|
|
29
|
+
spectra: SpectraDataWithIds[],
|
|
30
|
+
options: any = {},
|
|
31
|
+
): TargetsAndCorrelations {
|
|
32
|
+
//add indirect links, if a carbon C1 is attached to a proton H1 that correlating
|
|
33
|
+
//with carbon C2, so the carbon C1 and C2 are also correlating
|
|
34
|
+
|
|
35
|
+
const { tolerance = { C: 0.25, H: 0.05 } } = options;
|
|
36
|
+
|
|
37
|
+
const spectraData = formatData(spectra);
|
|
38
|
+
const { values: correlations } = buildCorrelationData(spectraData, {
|
|
39
|
+
tolerance,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
let targets: any = {};
|
|
43
|
+
for (const correlation of correlations) {
|
|
44
|
+
if (correlation.pseudo) continue;
|
|
45
|
+
const { id: targetID, atomType } = correlation;
|
|
46
|
+
if (!targets[atomType]) targets[atomType] = {};
|
|
47
|
+
targets[atomType][targetID] = correlation;
|
|
48
|
+
if (atomType === 'H') {
|
|
49
|
+
targets[atomType][targetID].integration =
|
|
50
|
+
correlation.link[0].signal.integration;
|
|
51
|
+
} else {
|
|
52
|
+
targets[atomType][targetID].integration = getIntegrationOfAttachedProtons(
|
|
53
|
+
correlation,
|
|
54
|
+
correlations,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
targets,
|
|
61
|
+
correlations,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Values } from 'nmr-correlation';
|
|
2
|
+
|
|
3
|
+
import { AtomTypes } from './buildAssignments';
|
|
4
|
+
/**
|
|
5
|
+
* if hsqc is present in experimentTypes we can just predict 13C
|
|
6
|
+
* spectrum and try to assign the carbons first.
|
|
7
|
+
* @param {*} correlations
|
|
8
|
+
* @param {*} justAssign
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
function getWorkFlow(
|
|
12
|
+
correlations: Values,
|
|
13
|
+
justAssign: Array<AtomTypes[]> = [],
|
|
14
|
+
) {
|
|
15
|
+
const experimentTypes = extractExperimentType(correlations);
|
|
16
|
+
|
|
17
|
+
const { hasHSQC, types } = experimentTypes;
|
|
18
|
+
|
|
19
|
+
if (justAssign.length > 0) {
|
|
20
|
+
return { assignmentOrder: justAssign, experimentTypes };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const assignmentOrder: Array<AtomTypes[]> = [];
|
|
24
|
+
|
|
25
|
+
if (hasHSQC) {
|
|
26
|
+
assignmentOrder.push(['C'], ['H']);
|
|
27
|
+
} else {
|
|
28
|
+
assignmentOrder.push(
|
|
29
|
+
types.filter((type) => type === 'H' || type === 'C') as AtomTypes[],
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return { assignmentOrder, experimentTypes };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default getWorkFlow;
|
|
37
|
+
|
|
38
|
+
interface ExperimentTypes {
|
|
39
|
+
types: string[];
|
|
40
|
+
hasProton: boolean;
|
|
41
|
+
hasCarbon: boolean;
|
|
42
|
+
hasHSQC: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function extractExperimentType(correlations: Values): ExperimentTypes {
|
|
46
|
+
const types: string[] = [];
|
|
47
|
+
for (const correlation of correlations) {
|
|
48
|
+
let experimentType: string = correlation.experimentType;
|
|
49
|
+
if (experimentType === '1d') {
|
|
50
|
+
experimentType = `${correlation.atomType.toUpperCase()}`;
|
|
51
|
+
}
|
|
52
|
+
if (!types.includes(experimentType)) {
|
|
53
|
+
types.push(experimentType);
|
|
54
|
+
}
|
|
55
|
+
for (const link of correlation.link) {
|
|
56
|
+
experimentType = link.experimentType;
|
|
57
|
+
if (experimentType === '1d') {
|
|
58
|
+
experimentType = `${link.atomType[0].toUpperCase()}`;
|
|
59
|
+
}
|
|
60
|
+
if (!types.includes(experimentType)) {
|
|
61
|
+
types.push(experimentType);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
types,
|
|
68
|
+
hasProton: types.includes('H'),
|
|
69
|
+
hasCarbon: types.includes('C'),
|
|
70
|
+
hasHSQC: types.includes('hsqc'),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CorrelationWithIntegration,
|
|
3
|
+
Targets,
|
|
4
|
+
} from './getTargetsAndCorrelations';
|
|
5
|
+
|
|
6
|
+
function groupCarbonTargetByIntegrationZone(
|
|
7
|
+
activeDomainOnTarget: string[],
|
|
8
|
+
targets: Targets,
|
|
9
|
+
correlations: CorrelationWithIntegration[],
|
|
10
|
+
) {
|
|
11
|
+
let targetID = activeDomainOnTarget[0];
|
|
12
|
+
let { H: attachments = [] } = targets[targetID].attachment;
|
|
13
|
+
|
|
14
|
+
let targetByIntegral = [
|
|
15
|
+
{ targetIDs: [targetID], attachments: new Set<number>(attachments) },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
for (let i = 1; i < activeDomainOnTarget.length; i++) {
|
|
19
|
+
let targetID = activeDomainOnTarget[i];
|
|
20
|
+
let target = targets[targetID];
|
|
21
|
+
let { H: attachments = [] } = target.attachment;
|
|
22
|
+
|
|
23
|
+
let alone = true;
|
|
24
|
+
for (let group of targetByIntegral) {
|
|
25
|
+
const pertain = attachments.some((attachment: any) =>
|
|
26
|
+
group.attachments.has(attachment),
|
|
27
|
+
);
|
|
28
|
+
if (pertain) {
|
|
29
|
+
alone = false;
|
|
30
|
+
group.targetIDs.push(targetID);
|
|
31
|
+
for (let attachment of attachments) {
|
|
32
|
+
group.attachments.add(attachment);
|
|
33
|
+
}
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (alone) {
|
|
38
|
+
targetByIntegral.push({
|
|
39
|
+
targetIDs: [targetID],
|
|
40
|
+
attachments: new Set<number>(attachments),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return targetByIntegral.map((t) => ({
|
|
45
|
+
atomType: 'C',
|
|
46
|
+
targetIDs: t.targetIDs,
|
|
47
|
+
integration: correlations
|
|
48
|
+
? Array.from(t.attachments).reduce((sum, index) => {
|
|
49
|
+
return correlations[index].integration + sum;
|
|
50
|
+
}, 0)
|
|
51
|
+
: 0,
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default groupCarbonTargetByIntegrationZone;
|