nmr-processing
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "nmr-processing", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "", | ||
@@ -12,2 +12,3 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"build": "rollup -c && cheminfo-build --root NMRProcessing", | ||
"eslint": "eslint src", | ||
@@ -44,2 +45,3 @@ "eslint-fix": "npm run eslint -- --fix", | ||
"@types/jest": "^25.2.1", | ||
"cheminfo-build": "^1.1.1", | ||
"eslint": "^7.0.0", | ||
@@ -46,0 +48,0 @@ "eslint-config-cheminfo": "^3.0.0", |
import round from 'lodash.round'; | ||
import { peaksFilterImpurities } from './peaksFilterImpurities'; | ||
// import { Ranges } from 'spectra-data-ranges'; | ||
import { xyGetArea } from '../xy/xyGetArea'; | ||
import jAnalyzer from './util/jAnalyzer'; | ||
import { joinRanges } from './util/joinRanges'; | ||
@@ -13,2 +16,3 @@ const defaultOptions = { | ||
optimize: true, | ||
joinOverlapRanges: true, | ||
frequencyCluster: 16, | ||
@@ -20,3 +24,3 @@ keepPeaks: false, | ||
* This function clustering peaks and calculate the integral value for each range from the peak list returned from extractPeaks function. | ||
* @param {SD} spectrum - SD instance | ||
* @param {Object} data - spectra data | ||
* @param {Object} peakList - nmr signals | ||
@@ -35,12 +39,11 @@ * @param {Object} options - options object with some parameter for GSD, detectSignal functions. | ||
export function peaksToRanges(peakList, options) { | ||
export function peaksToRanges(data, peakList, options = {}) { | ||
options = Object.assign({}, defaultOptions, options); | ||
let i, j; | ||
let nH = options.nH; | ||
peakList = peaksFilterImpurities(peakList, options.removeImpurity); | ||
let signals = detectSignals(peakList, options); | ||
let { nH, joinOverlapRanges, clean, compile } = options; | ||
if (options.clean) { | ||
for (i = 0; i < signals.length; i++) { | ||
if (signals[i].integralData.value < options.clean) { | ||
let signals = detectSignals(data, peakList, options); | ||
if (clean) { | ||
for (let i = 0; i < signals.length; i++) { | ||
if (signals[i].integralData.value < clean) { | ||
signals.splice(i, 1); | ||
@@ -51,5 +54,5 @@ } | ||
if (options.compile) { | ||
if (compile) { | ||
let nHi, sum; | ||
for (i = 0; i < signals.length; i++) { | ||
for (let i = 0; i < signals.length; i++) { | ||
jAnalyzer.compilePattern(signals[i]); | ||
@@ -66,3 +69,3 @@ | ||
let peaksO = []; | ||
for (j = signals[i].maskPattern.length - 1; j >= 0; j--) { | ||
for (let j = signals[i].maskPattern.length - 1; j >= 0; j--) { | ||
sum += computeArea(signals[i].peaks[j]); | ||
@@ -83,9 +86,9 @@ if (signals[i].maskPattern[j] === false) { | ||
let peaks1 = []; | ||
for (j = peaksO.length - 1; j >= 0; j--) { | ||
for (let j = peaksO.length - 1; j >= 0; j--) { | ||
peaks1.push(peaksO[j]); | ||
} | ||
options.nH = nHi; | ||
let ranges = detectSignals(peaks1, options); | ||
let ranges = detectSignals(data, peaks1, options); | ||
for (j = 0; j < ranges.length; j++) { | ||
for (let j = 0; j < ranges.length; j++) { | ||
signals.push(ranges[j]); | ||
@@ -99,3 +102,3 @@ } | ||
let sumObserved = 0; | ||
for (i = 0; i < signals.length; i++) { | ||
for (let i = 0; i < signals.length; i++) { | ||
sumObserved += Math.round(signals[i].integralData.value); | ||
@@ -105,3 +108,3 @@ } | ||
sumIntegral = nH / sumObserved; | ||
for (i = 0; i < signals.length; i++) { | ||
for (let i = 0; i < signals.length; i++) { | ||
signals[i].integralData.value *= sumIntegral; | ||
@@ -112,9 +115,9 @@ } | ||
signals.sort(function (a, b) { | ||
signals.sort((a, b) => { | ||
return b.delta1 - a.delta1; | ||
}); | ||
if (options.clean) { | ||
for (i = signals.length - 1; i >= 0; i--) { | ||
if (signals[i].integralData.value < options.clean) { | ||
if (clean) { | ||
for (let i = signals.length - 1; i >= 0; i--) { | ||
if (signals[i].integralData.value < clean) { | ||
signals.splice(i, 1); | ||
@@ -125,4 +128,4 @@ } | ||
let ranges = new Array(signals.length); | ||
for (i = 0; i < signals.length; i++) { | ||
let ranges = []; //new Array(signals.length); | ||
for (let i = 0; i < signals.length; i++) { | ||
let signal = signals[i]; | ||
@@ -150,2 +153,5 @@ ranges[i] = { | ||
if (joinOverlapRanges) ranges = joinRanges(ranges); | ||
// return new Ranges(ranges); | ||
return ranges; | ||
@@ -156,3 +162,3 @@ } | ||
* Extract the signals from the peakList and the given spectrum. | ||
* @param {object} spectrum - spectra data | ||
* @param {object} data - spectra data | ||
* @param {object} peakList - nmr signals | ||
@@ -167,3 +173,3 @@ * @param {object} options | ||
*/ | ||
function detectSignals(peakList, options = {}) { | ||
function detectSignals(data, peakList, options = {}) { | ||
let { | ||
@@ -177,3 +183,3 @@ nH = 100, | ||
let i, j, signal1D, peaks; | ||
let signal1D, peaks; | ||
let signals = []; | ||
@@ -183,3 +189,3 @@ let prevPeak = { x: 100000 }; | ||
frequencyCluster /= frequency; | ||
for (i = 0; i < peakList.length; i++) { | ||
for (let i = 0; i < peakList.length; i++) { | ||
if (Math.abs(peakList[i].x - prevPeak.x) > frequencyCluster) { | ||
@@ -230,3 +236,3 @@ signal1D = { | ||
for (i = 0; i < signals.length; i++) { | ||
for (let i = 0; i < signals.length; i++) { | ||
peaks = signals[i].peaks; | ||
@@ -237,3 +243,3 @@ let integral = signals[i].integralData; | ||
for (j = 0; j < peaks.length; j++) { | ||
for (let j = 0; j < peaks.length; j++) { | ||
let area = computeArea(peaks[j]); | ||
@@ -246,3 +252,6 @@ chemicalShift += peaks[j].x * area; | ||
if (integralType === 'sum') { | ||
integral.value = 10; //spectrum.getArea(integral.from, integral.to); //@TODO | ||
integral.value = xyGetArea(data, { | ||
from: integral.from, | ||
to: integral.to, | ||
}); | ||
} else { | ||
@@ -256,3 +265,3 @@ integral.value = integralPeaks; | ||
let integralFactor = nH / spectrumIntegral; | ||
for (i = 0; i < signals.length; i++) { | ||
for (let i = 0; i < signals.length; i++) { | ||
let integral = signals[i].integralData; | ||
@@ -259,0 +268,0 @@ integral.value *= integralFactor; |
@@ -9,5 +9,5 @@ import { peaksFilterImpurities } from '../peaks/peaksFilterImpurities'; | ||
peaks = peaksFilterImpurities(peaks, options.impurities); | ||
let ranges = peaksToRanges(peaks, options.ranges); | ||
let ranges = peaksToRanges(data, peaks, options.peakPicking); | ||
return ranges; | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
196890
20
8781
15
1