nmr-correlation
Advanced tools
Comparing version 1.1.1 to 1.1.2
{ | ||
"name": "nmr-correlation", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Create and manage correlations from 1D and 2D NMR data", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -7,120 +7,70 @@ import Correlation from './model/Correlation'; | ||
const defaultTolerance = { | ||
C: 0.25, | ||
H: 0.02, | ||
N: 0.25, | ||
F: 0.25, | ||
Si: 0.25, | ||
P: 0.25, | ||
}; | ||
export default class CorrelationManager { | ||
constructor(options = {}, spectra = [], values = []) { | ||
this.options = options; | ||
if (!this.options.tolerance) { | ||
this.options.tolerance = defaultTolerance; | ||
} | ||
this.state = {}; | ||
this.spectra = spectra; | ||
this.values = values.map( | ||
(correlation) => new Correlation({ ...correlation }), | ||
); | ||
static getOptions(data) { | ||
return data.options; | ||
} | ||
getOptions() { | ||
return this.options; | ||
static getState(data) { | ||
return data.state; | ||
} | ||
setOptions(options = {}) { | ||
this.options = options; | ||
static getCorrelations(data) { | ||
return data.values; | ||
} | ||
setOption(key, value) { | ||
this.setOptions({ ...this.options, [key]: value }); | ||
static getCorrelationIndex(data, id) { | ||
return data.values.findIndex((correlation) => correlation.getID() === id); | ||
} | ||
deleteOption(key) { | ||
delete this.options[key]; | ||
static addCorrelation(data, correlation) { | ||
data.values = data.values.concat([correlation]); | ||
return data; | ||
} | ||
setMF(mf) { | ||
this.setOption('mf', mf); | ||
this.build(); | ||
static deleteCorrelation(data, id) { | ||
data.values = data.values.filter((correlation) => correlation.id !== id); | ||
return data; | ||
} | ||
unsetMF() { | ||
this.deleteOption('mf'); | ||
} | ||
static setCorrelation(data, id, correlation) { | ||
let correlationIndex = data.values.findIndex( | ||
(_correlation) => _correlation.id === id, | ||
); | ||
const _values = data.values.slice(); | ||
_values.splice(correlationIndex, 1, correlation); | ||
data.values = _values; | ||
getMF() { | ||
return this.getOptions().mf; | ||
return data; | ||
} | ||
setTolerance(tolerance) { | ||
this.setOption('tolerance', tolerance); | ||
this.build(); | ||
static buildCorrelationObjects(data) { | ||
return data && data.values | ||
? data.values.map((correlation) => new Correlation({ ...correlation })) | ||
: []; | ||
} | ||
getTolerance() { | ||
return this.getOptions().tolerance; | ||
static init(data) { | ||
if (data) { | ||
data.values = CorrelationManager.buildCorrelationObjects(data); | ||
return data; | ||
} | ||
return { values: [], state: {}, options: {} }; | ||
} | ||
getState() { | ||
return this.state; | ||
} | ||
getSpectra() { | ||
return this.spectra; | ||
} | ||
setSpectra(spectra) { | ||
this.spectra = spectra; | ||
this.build(); | ||
} | ||
getCorrelations() { | ||
return this.values; | ||
} | ||
getCorrelationIndex(id) { | ||
return this.values.findIndex((correlation) => correlation.getID() === id); | ||
} | ||
getData() { | ||
return { | ||
options: Object.assign({}, this.options), | ||
values: this.values.slice(), | ||
state: Object.assign({}, this.state), | ||
static build(spectra, mf, tolerance, prevData) { | ||
const values = buildCorrelationsData( | ||
spectra, | ||
mf, | ||
tolerance, | ||
CorrelationManager.buildCorrelationObjects(prevData), | ||
); | ||
const data = { | ||
values, | ||
options: { mf, tolerance }, | ||
}; | ||
} | ||
const correlationsState = buildCorrelationsState(data); | ||
data.state = correlationsState; | ||
addCorrelation(correlation) { | ||
this.values = this.values.concat([correlation]); | ||
this.build(); | ||
return data; | ||
} | ||
deleteCorrelation(id) { | ||
this.values = this.values.filter((correlation) => correlation.id !== id); | ||
this.build(); | ||
} | ||
setCorrelation(id, correlation) { | ||
let correlationIndex = this.values.findIndex( | ||
(_correlation) => _correlation.id === id, | ||
); | ||
const _values = this.values.slice(); | ||
_values.splice(correlationIndex, 1, correlation); | ||
this.values = _values; | ||
this.build(); | ||
} | ||
build() { | ||
this.values = buildCorrelationsData( | ||
this.getSpectra(), | ||
this.getMF(), | ||
this.getTolerance(), | ||
this.getCorrelations(), | ||
); | ||
this.state = buildCorrelationsState(this.getData()); | ||
} | ||
} |
export { default as CorrelationManager } from './CorrelationManager'; | ||
export { default as Correlation } from './model/Correlation'; | ||
export { default as Link } from './model/Link'; | ||
export * as CorrelationUtilities from './utilities/CorrelationUtilities'; | ||
export * as GeneralUtilities from './utilities/GeneralUtilities'; | ||
export * as ProtonsCountUtilities from './utilities/ProtonsCountUtilities'; | ||
export * as Utilities from './utilities/GeneralUtilities'; |
@@ -455,6 +455,6 @@ import lodash from 'lodash'; | ||
const buildCorrelationsState = (correlationData) => { | ||
const buildCorrelationsState = (correlationsData) => { | ||
const state = {}; | ||
const atoms = getAtomCounts(correlationData); | ||
const atomTypesInCorrelations = correlationData.values.reduce( | ||
const atoms = getAtomCounts(correlationsData); | ||
const atomTypesInCorrelations = correlationsData.values.reduce( | ||
(array, correlation) => | ||
@@ -469,3 +469,3 @@ array.includes(correlation.getAtomType()) | ||
const correlationsAtomType = getCorrelationsByAtomType( | ||
correlationData.values, | ||
correlationsData.values, | ||
atomType, | ||
@@ -498,3 +498,3 @@ ); | ||
// add protons count from pseudo correlations without any pseudo HSQC correlation | ||
correlationData.values.forEach((correlation) => { | ||
correlationsData.values.forEach((correlation) => { | ||
if ( | ||
@@ -522,3 +522,3 @@ correlation.getPseudo() === true && | ||
? array.concat( | ||
getCorrelationIndex(correlationData.values, correlation), | ||
getCorrelationIndex(correlationsData.values, correlation), | ||
) | ||
@@ -546,3 +546,3 @@ : array, | ||
? array.concat( | ||
getCorrelationIndex(correlationData.values, correlation), | ||
getCorrelationIndex(correlationsData.values, correlation), | ||
) | ||
@@ -549,0 +549,0 @@ : array, |
@@ -1,2 +0,2 @@ | ||
// the whole file content was copied from https://github.com/cheminfo/nmr-displayer/blob/master/src/data/utilities/generateID.js on master branch on 15th February 2021 at 11:25 AM | ||
// this file content was copied from https://github.com/cheminfo/nmr-displayer/blob/master/src/data/utilities/generateID.js in "master" branch on 15th February 2021 at 11:25 AM (commit 3d8d70c) | ||
@@ -3,0 +3,0 @@ const BASE62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
637207
19072