Skip to content

Commit

Permalink
feat: use refactored nmr-correlation package (#1025)
Browse files Browse the repository at this point in the history
* chore: modifications regarding new nmr-correlation version

* chore: put optional previous correlation data into options

* fix: put previous correlations into options parameter

* chore: use nmr-correlation@1.3.2
  • Loading branch information
Michael Wenk committed May 6, 2021
1 parent aa04eef commit 990eb54
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 178 deletions.
236 changes: 123 additions & 113 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -71,7 +71,7 @@
"ml-spectra-processing": "^6.3.0",
"ml-stat": "^1.3.3",
"multiplet-analysis": "^1.0.0",
"nmr-correlation": "^1.2.0",
"nmr-correlation": "^1.3.2",
"nmr-parser": "^1.1.0",
"nmr-processing": "^1.2.0",
"nmredata": "^0.4.0",
Expand Down
@@ -1,8 +1,9 @@
import lodashCloneDeep from 'lodash/cloneDeep';
import {
CorrelationUtilities,
GeneralUtilities,
LinkUtilities,
addLink,
buildLink,
getCorrelationIndex,
removeLink,
} from 'nmr-correlation';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';

Expand Down Expand Up @@ -83,7 +84,7 @@ function AdditionalColumnField({
if (action === 'add') {
const pseudoLinkID = generateID();
const pseudoExperimentID = generateID();
const pseudoCommonLink = LinkUtilities.buildLink({
const pseudoCommonLink = buildLink({
experimentType,
experimentID: pseudoExperimentID,
atomType: [_columnCorrelation.atomType, _rowCorrelation.atomType],
Expand All @@ -92,38 +93,28 @@ function AdditionalColumnField({
signal: { id: generateID(), sign: 0 }, // pseudo signal
});

CorrelationUtilities.addLink(
addLink(
_columnCorrelation,
LinkUtilities.buildLink({
buildLink({
...pseudoCommonLink,
axis: 'x',
match: [
GeneralUtilities.getCorrelationIndex(
correlations,
_rowCorrelation,
),
],
match: [getCorrelationIndex(correlations, _rowCorrelation)],
}),
);
CorrelationUtilities.addLink(
addLink(
_rowCorrelation,
LinkUtilities.buildLink({
buildLink({
...pseudoCommonLink,
axis: 'y',
match: [
GeneralUtilities.getCorrelationIndex(
correlations,
_columnCorrelation,
),
],
match: [getCorrelationIndex(correlations, _columnCorrelation)],
}),
);
if (!_rowCorrelation.edited.protonsCount) {
_rowCorrelation.protonsCount = [pseudoLinkCountHSQC + 1];
}
} else if (action === 'remove') {
CorrelationUtilities.removeLink(_rowCorrelation, commonLink.id);
CorrelationUtilities.removeLink(_columnCorrelation, commonLink.id);
removeLink(_rowCorrelation, commonLink.id);
removeLink(_columnCorrelation, commonLink.id);
if (!_rowCorrelation.edited.protonsCount) {
_rowCorrelation.protonsCount =
pseudoLinkCountHSQC - 1 > 0 ? [pseudoLinkCountHSQC - 1] : [];
Expand Down
@@ -1,5 +1,5 @@
import lodashGet from 'lodash/get';
import { LinkUtilities, GeneralUtilities } from 'nmr-correlation';
import { buildLink, getLabel } from 'nmr-correlation';
import { useCallback, useMemo } from 'react';

import { buildID } from '../../../../data/utilities/Concatenation';
Expand Down Expand Up @@ -86,7 +86,7 @@ function CorrelationTableRow({
experimentLabel += ' (edited)';
}
commonLinks.push(
LinkUtilities.buildLink({
buildLink({
...link,
experimentLabel,
axis: undefined,
Expand Down Expand Up @@ -190,7 +190,7 @@ function CorrelationTableRow({
style: { ...tableDataProps.style, styleLabel },
}}
>
{GeneralUtilities.getLabel(correlations, correlation)}
{getLabel(correlations, correlation)}
</td>
<td {...tableDataProps}>
{lodashGet(correlation.signal, 'delta', false)
Expand Down
4 changes: 2 additions & 2 deletions src/component/panels/SummaryPanel/Overview.jsx
@@ -1,4 +1,4 @@
import { GeneralUtilities } from 'nmr-correlation';
import { getAtomCounts } from 'nmr-correlation';
import { memo } from 'react';

import { ErrorColors, Errors } from './CorrelationTable/Constants';
Expand All @@ -7,7 +7,7 @@ function Overview({ correlationsData }) {
if (!correlationsData) {
return null;
}
const atoms = GeneralUtilities.getAtomCounts(correlationsData.options.mf);
const atoms = getAtomCounts(correlationsData.options.mf);

return Object.keys(atoms).length > 0 ? (
Object.keys(atoms).map((atomType, i) => {
Expand Down
8 changes: 3 additions & 5 deletions src/component/reducer/Reducer.ts
@@ -1,5 +1,5 @@
import { produce } from 'immer';
import { Build, Types } from 'nmr-correlation';
import { buildCorrelationData, Types } from 'nmr-correlation';
import { predictionProton } from 'nmr-processing';
import OCL from 'openchemlib/full';

Expand Down Expand Up @@ -85,10 +85,8 @@ export const initialState = {
displayerMode: DISPLAYER_MODE.DM_1D,
tabActiveSpectrum: {},
spectraAnalysis: {},
correlations: Build.init({
values: [],
options: { tolerance: DefaultTolerance, mf: '' },
state: {},
correlations: buildCorrelationData([], {
tolerance: DefaultTolerance,
}),
displayerKey: '',
ZoomHistory: {},
Expand Down
43 changes: 17 additions & 26 deletions src/component/reducer/actions/CorrelationsActions.ts
@@ -1,16 +1,15 @@
import { original, Draft } from 'immer';
import lodashCloneDeep from 'lodash/cloneDeep';
import { Build, CorrelationUtilities, Types } from 'nmr-correlation';
import { buildCorrelationData, setCorrelation, Types } from 'nmr-correlation';

import { State } from '../Reducer';

function handleUpdateCorrelations(draft: Draft<State>) {
const { data: spectra, correlations } = draft;
draft.correlations = Build.build(
spectra as Types.Spectra,
correlations.options,
lodashCloneDeep(correlations.values),
);
draft.correlations = buildCorrelationData(spectra as Types.Spectra, {
...correlations.options,
values: lodashCloneDeep(correlations.values),
});
}

function handleSetMF(draft: Draft<State>, payload: { mf: string }) {
Expand All @@ -19,11 +18,11 @@ function handleSetMF(draft: Draft<State>, payload: { mf: string }) {
const { mf } = payload;
// update of correlation data is needed only if the following is true
if (correlations.options.mf === '' || correlations.options.mf !== mf) {
draft.correlations = Build.build(
spectra as Types.Spectra,
{ ...correlations.options, mf },
lodashCloneDeep(correlations.values),
);
draft.correlations = buildCorrelationData(spectra as Types.Spectra, {
...correlations.options,
mf,
values: lodashCloneDeep(correlations.values),
});
}
}

Expand All @@ -34,11 +33,11 @@ function handleSetTolerance(
const state = original(draft) as State;
const { data: spectra, correlations } = state;
const { tolerance } = payload;
draft.correlations = Build.build(
spectra as Types.Spectra,
{ ...correlations.options, tolerance },
lodashCloneDeep(correlations.values),
);
draft.correlations = buildCorrelationData(spectra as Types.Spectra, {
...correlations.options,
tolerance,
values: lodashCloneDeep(correlations.values),
});
}

function handleSetCorrelation(
Expand All @@ -48,11 +47,7 @@ function handleSetCorrelation(
const state = original(draft) as State;
const { correlations } = state;
const { id, correlation } = payload;
draft.correlations = CorrelationUtilities.setCorrelation(
correlations,
id,
correlation,
);
draft.correlations = setCorrelation(correlations, id, correlation);
handleUpdateCorrelations(draft);
}

Expand All @@ -63,11 +58,7 @@ function handleSetCorrelations(
const { ids, correlations } = payload;
ids.forEach((id, i) => {
const { correlations: correlationsData } = draft;
draft.correlations = CorrelationUtilities.setCorrelation(
correlationsData,
id,
correlations[i],
);
draft.correlations = setCorrelation(correlationsData, id, correlations[i]);
});
handleUpdateCorrelations(draft);
}
Expand Down
10 changes: 4 additions & 6 deletions src/component/reducer/actions/LoadActions.ts
@@ -1,6 +1,6 @@
import { Draft } from 'immer';
import lodashGet from 'lodash/get';
import { Build, Types } from 'nmr-correlation';
import { buildCorrelationData, Types } from 'nmr-correlation';

import { addJcamps, addJDFs } from '../../../data/SpectraManager';
import * as MoleculeManager from '../../../data/molecules/MoleculeManager';
Expand Down Expand Up @@ -47,13 +47,11 @@ function setData(
draft.exclusionZones = exclusionZones;

if (!correlations || Object.keys(correlations).length === 0) {
draft.correlations = Build.init({
values: [],
options: { tolerance: DefaultTolerance, mf: '' },
state: {},
draft.correlations = buildCorrelationData([], {
tolerance: DefaultTolerance,
});
} else {
draft.correlations = Build.init(correlations);
draft.correlations = correlations;
}

// const spectraAnalysis = AnalysisObj.getMultipleAnalysis();
Expand Down

0 comments on commit 990eb54

Please sign in to comment.