Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nmr-processing

Package Overview
Dependencies
Maintainers
4
Versions
268
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nmr-processing - npm Package Compare versions

Comparing version 6.0.8 to 7.0.0

src/openchemlib-utils.d.ts

28

lib-esm/utilities/resurrectRange.js

@@ -9,12 +9,8 @@ import { rangeFromSignal } from './rangeFromSignal';

return;
// before parenthesis there should be only numbers but we will still split with space
const beforeParts = split.before
.split(/(?: |(?<=[0-9])-)/)
.map((part) => Number(part))
.filter((part) => !Number.isNaN(part));
if (beforeParts.length < 1 || beforeParts.length > 2) {
const beforeMatch = /.*?(?<from>-?[0-9.]+)-?(?<to>-?[0-9.]*).*/.exec(split.before);
if (!beforeMatch || !beforeMatch.groups)
return;
}
const from = beforeParts[0];
const to = beforeParts.length > 1 ? beforeParts[1] : beforeParts[0];
const isARange = beforeMatch.groups.to !== '';
const from = Number(beforeMatch.groups.from);
const to = isARange ? Number(beforeMatch.groups.to) : from;
const insideParts = split.inside.split(/ *, */);

@@ -31,10 +27,10 @@ let signal = { delta: NaN, js: [] };

if (multiplicity === 'm') {
if (beforeParts.length === 1) {
// a complex signal
signal.delta = beforeParts[0];
if (isARange) {
// a real range
signal.delta = (from + to) / 2;
signal.multiplicity = multiplicity;
}
else {
// a real range
signal.delta = (beforeParts[0] + beforeParts[1]) / 2;
// a complex signal
signal.delta = from;
signal.multiplicity = multiplicity;

@@ -45,5 +41,5 @@ }

// looks like a real multiplicity, s, d, dd, etc..
if (beforeParts.length === 1) {
if (!isARange) {
// a complex signal
signal.delta = beforeParts[0];
signal.delta = from;
signal.multiplicity = multiplicity;

@@ -50,0 +46,0 @@ }

@@ -1,9 +0,10 @@

import { gsd, joinBroadPeaks, optimizePeaks } from 'ml-gsd';
import { gsd, optimizePeaks, joinBroadPeaks, appendShapeAndFWHM } from 'ml-gsd';
import { xyExtract, xNoiseSanPlot, xAbsoluteMedian, } from 'ml-spectra-processing';
export function xyAutoPeaksPicking(data, options = {}) {
const { from, to, noiseLevel, thresholdFactor = 3, minMaxRatio = 0.05, broadRatio = 0.00025, useSanPlot = false, smoothY = true, optimize = false, factorWidth = 4, realTopDetection = true, shape = { kind: 'gaussian' }, optimization = { kind: 'lm' }, broadWidth = 0.25, lookNegative = false, sgOptions = { windowSize: 9, polynomial: 3 }, } = options;
const { from, to, noiseLevel, thresholdFactor = 3, minMaxRatio = 0.05, broadRatio = 0.00025, useSanPlot = false, smoothY = true, optimize = false, factorLimits = 4, realTopDetection = true, shape = { kind: 'gaussian' }, optimization = { kind: 'lm' }, broadWidth = 0.25, sgOptions = {}, lookNegative = false, } = options;
const { windowSize = 9, polynomial = 3 } = sgOptions;
if (from !== undefined && to !== undefined) {
data = xyExtract(data, { zones: [{ from, to }] });
}
if (data.x.length < sgOptions.windowSize)
if (data.x.length < windowSize)
return [];

@@ -15,4 +16,5 @@ const cutOff = getCutOff(data.y, { noiseLevel, useSanPlot, thresholdFactor });

optimize,
factorWidth,
sgOptions,
factorLimits,
maxCriteria: true,
sgOptions: { windowSize, polynomial },
minMaxRatio,

@@ -28,3 +30,4 @@ broadRatio,

getPeakOptions.noiseLevel = cutOff.negative;
peaks.push(...getNegativePeaks(data, getPeakOptions));
getPeakOptions.maxCriteria = false;
peaks.push(...getPeakList(data, getPeakOptions));
}

@@ -34,6 +37,6 @@ return peaks;

function getPeakList(data, options) {
const { shape, broadWidth, optimize, factorWidth, sgOptions, minMaxRatio, broadRatio, noiseLevel, smoothY, optimization, realTopDetection, } = options;
const { shape, broadWidth, optimize, maxCriteria, factorLimits, sgOptions, minMaxRatio, broadRatio, noiseLevel, smoothY, optimization, realTopDetection, } = options;
let peakList = gsd(data, {
shape,
sgOptions,
maxCriteria,
minMaxRatio,

@@ -45,3 +48,3 @@ noiseLevel,

if (broadWidth) {
peakList = joinBroadPeaks(data, peakList, {
peakList = joinBroadPeaks(peakList, {
broadRatio,

@@ -54,22 +57,10 @@ broadWidth,

if (optimize) {
peakList = optimizePeaks(data, peakList, {
return optimizePeaks(data, peakList, {
shape,
factorWidth,
factorLimits,
optimization,
});
}
return peakList;
return appendShapeAndFWHM(peakList, { shape });
}
function getNegativePeaks(data, options) {
let { x, y } = data;
let negativeDataY = new Float64Array(data.y.length);
for (let i = 0; i < negativeDataY.length; i++) {
negativeDataY[i] = -1 * y[i];
}
let peakList = getPeakList({ x, y: negativeDataY }, options);
for (const peak of peakList) {
peak.y *= -1;
}
return peakList;
}
function getCutOff(data, options) {

@@ -76,0 +67,0 @@ const { noiseLevel, useSanPlot, thresholdFactor } = options;

@@ -1,4 +0,7 @@

import type { Peak1D } from 'ml-gsd';
export interface NMRPeak1D extends Peak1D {
import type { PeakXYWidth } from 'cheminfo-types';
import type { Shape1D } from 'ml-peak-shape-generator';
export interface NMRPeak1D extends PeakXYWidth {
kind?: string;
fwhm?: number;
shape?: Shape1D;
}

@@ -57,5 +57,7 @@ import type { DataXY } from 'cheminfo-types';

}
declare type NMRPeak1DIntern = Omit<NMRPeak1D, 'fwhm' | 'shape'>;
/**
* This function clustering peaks and calculate the integration value for each range from the peak list returned from extractPeaks function.
*/
export declare function peaksToRanges(data: DataXY, peakList: NMRPeak1D[], options?: OptionsPeaksToRanges): NMRRange[];
export declare function peaksToRanges(data: DataXY, peakList: NMRPeak1DIntern[], options?: OptionsPeaksToRanges): NMRRange[];
export {};

@@ -13,3 +13,3 @@ import type { MakeMandatory } from '../../utilities/MakeMandatory';

}
export declare type Peak1DIntern = Omit<NMRPeak1D, 'y'> & {
export declare type Peak1DIntern = Omit<NMRPeak1D, 'y' | 'shape' | 'fwhm'> & {
intensity: number;

@@ -16,0 +16,0 @@ };

@@ -1,2 +0,2 @@

/// <reference path="../../../src/openchemlib.d.ts" />
/// <reference path="../../../src/openchemlib-utils.d.ts" />
import type { Molecule } from 'openchemlib';

@@ -3,0 +3,0 @@ import type { GroupDiastereotopicAtomIDs } from 'openchemlib-utils';

@@ -12,12 +12,8 @@ "use strict";

return;
// before parenthesis there should be only numbers but we will still split with space
const beforeParts = split.before
.split(/(?: |(?<=[0-9])-)/)
.map((part) => Number(part))
.filter((part) => !Number.isNaN(part));
if (beforeParts.length < 1 || beforeParts.length > 2) {
const beforeMatch = /.*?(?<from>-?[0-9.]+)-?(?<to>-?[0-9.]*).*/.exec(split.before);
if (!beforeMatch || !beforeMatch.groups)
return;
}
const from = beforeParts[0];
const to = beforeParts.length > 1 ? beforeParts[1] : beforeParts[0];
const isARange = beforeMatch.groups.to !== '';
const from = Number(beforeMatch.groups.from);
const to = isARange ? Number(beforeMatch.groups.to) : from;
const insideParts = split.inside.split(/ *, */);

@@ -34,10 +30,10 @@ let signal = { delta: NaN, js: [] };

if (multiplicity === 'm') {
if (beforeParts.length === 1) {
// a complex signal
signal.delta = beforeParts[0];
if (isARange) {
// a real range
signal.delta = (from + to) / 2;
signal.multiplicity = multiplicity;
}
else {
// a real range
signal.delta = (beforeParts[0] + beforeParts[1]) / 2;
// a complex signal
signal.delta = from;
signal.multiplicity = multiplicity;

@@ -48,5 +44,5 @@ }

// looks like a real multiplicity, s, d, dd, etc..
if (beforeParts.length === 1) {
if (!isARange) {
// a complex signal
signal.delta = beforeParts[0];
signal.delta = from;
signal.multiplicity = multiplicity;

@@ -53,0 +49,0 @@ }

import { DataXY } from 'cheminfo-types';
import type { Peak1D, GSDOptions, OptimizePeaksOptions, JoinBroadPeaksOptions } from 'ml-gsd';
export interface IGetPeakListOptions extends GSDOptions, OptimizePeaksOptions, JoinBroadPeaksOptions {
import type { GSDOptions, OptimizePeaksOptions, JoinBroadPeaksOptions } from 'ml-gsd';
import { NMRPeak1D } from '..';
export interface GetPeakListOptions extends GSDOptions, OptimizePeaksOptions, JoinBroadPeaksOptions {
/**

@@ -10,3 +11,3 @@ * If it is true, the peaks parameters will be optimized.

}
export interface OptionsXYAutoPeaksPicking extends Partial<IGetPeakListOptions> {
export interface OptionsXYAutoPeaksPicking extends Partial<GetPeakListOptions> {
/**

@@ -36,2 +37,2 @@ * Low limit value in the x axis to extract a sub set of points from the input data.

}
export declare function xyAutoPeaksPicking(data: DataXY, options?: OptionsXYAutoPeaksPicking): Peak1D[];
export declare function xyAutoPeaksPicking(data: DataXY, options?: OptionsXYAutoPeaksPicking): NMRPeak1D[];

@@ -7,7 +7,8 @@ "use strict";

function xyAutoPeaksPicking(data, options = {}) {
const { from, to, noiseLevel, thresholdFactor = 3, minMaxRatio = 0.05, broadRatio = 0.00025, useSanPlot = false, smoothY = true, optimize = false, factorWidth = 4, realTopDetection = true, shape = { kind: 'gaussian' }, optimization = { kind: 'lm' }, broadWidth = 0.25, lookNegative = false, sgOptions = { windowSize: 9, polynomial: 3 }, } = options;
const { from, to, noiseLevel, thresholdFactor = 3, minMaxRatio = 0.05, broadRatio = 0.00025, useSanPlot = false, smoothY = true, optimize = false, factorLimits = 4, realTopDetection = true, shape = { kind: 'gaussian' }, optimization = { kind: 'lm' }, broadWidth = 0.25, sgOptions = {}, lookNegative = false, } = options;
const { windowSize = 9, polynomial = 3 } = sgOptions;
if (from !== undefined && to !== undefined) {
data = (0, ml_spectra_processing_1.xyExtract)(data, { zones: [{ from, to }] });
}
if (data.x.length < sgOptions.windowSize)
if (data.x.length < windowSize)
return [];

@@ -19,4 +20,5 @@ const cutOff = getCutOff(data.y, { noiseLevel, useSanPlot, thresholdFactor });

optimize,
factorWidth,
sgOptions,
factorLimits,
maxCriteria: true,
sgOptions: { windowSize, polynomial },
minMaxRatio,

@@ -32,3 +34,4 @@ broadRatio,

getPeakOptions.noiseLevel = cutOff.negative;
peaks.push(...getNegativePeaks(data, getPeakOptions));
getPeakOptions.maxCriteria = false;
peaks.push(...getPeakList(data, getPeakOptions));
}

@@ -39,6 +42,6 @@ return peaks;

function getPeakList(data, options) {
const { shape, broadWidth, optimize, factorWidth, sgOptions, minMaxRatio, broadRatio, noiseLevel, smoothY, optimization, realTopDetection, } = options;
const { shape, broadWidth, optimize, maxCriteria, factorLimits, sgOptions, minMaxRatio, broadRatio, noiseLevel, smoothY, optimization, realTopDetection, } = options;
let peakList = (0, ml_gsd_1.gsd)(data, {
shape,
sgOptions,
maxCriteria,
minMaxRatio,

@@ -50,3 +53,3 @@ noiseLevel,

if (broadWidth) {
peakList = (0, ml_gsd_1.joinBroadPeaks)(data, peakList, {
peakList = (0, ml_gsd_1.joinBroadPeaks)(peakList, {
broadRatio,

@@ -59,22 +62,10 @@ broadWidth,

if (optimize) {
peakList = (0, ml_gsd_1.optimizePeaks)(data, peakList, {
return (0, ml_gsd_1.optimizePeaks)(data, peakList, {
shape,
factorWidth,
factorLimits,
optimization,
});
}
return peakList;
return (0, ml_gsd_1.appendShapeAndFWHM)(peakList, { shape });
}
function getNegativePeaks(data, options) {
let { x, y } = data;
let negativeDataY = new Float64Array(data.y.length);
for (let i = 0; i < negativeDataY.length; i++) {
negativeDataY[i] = -1 * y[i];
}
let peakList = getPeakList({ x, y: negativeDataY }, options);
for (const peak of peakList) {
peak.y *= -1;
}
return peakList;
}
function getCutOff(data, options) {

@@ -81,0 +72,0 @@ const { noiseLevel, useSanPlot, thresholdFactor } = options;

{
"name": "nmr-processing",
"version": "6.0.8",
"version": "7.0.0",
"description": "Pure functions allowing to process NMR spectra.",

@@ -43,3 +43,3 @@ "main": "./lib/index.js",

"cheminfo-build": "^1.1.11",
"cheminfo-types": "^0.9.1",
"cheminfo-types": "^0.11.1",
"eslint": "^8.8.0",

@@ -59,3 +59,2 @@ "eslint-config-cheminfo-typescript": "^10.3.0",

"dependencies": {
"assign-deep": "^1.0.1",
"binary-search": "^1.3.6",

@@ -69,3 +68,3 @@ "cross-fetch": "^3.1.5",

"ml-array-sum": "^1.1.6",
"ml-gsd": "^9.1.0",
"ml-gsd": "^10.1.1",
"ml-hclust": "^3.1.0",

@@ -82,4 +81,4 @@ "ml-levenberg-marquardt": "^4.0.0",

"openchemlib-utils": "^1.8.0",
"spectrum-generator": "^6.0.3"
"spectrum-generator": "^6.0.4"
}
}

@@ -1,5 +0,8 @@

import type { Peak1D } from 'ml-gsd';
import type { PeakXYWidth } from 'cheminfo-types';
import type { Shape1D } from 'ml-peak-shape-generator';
export interface NMRPeak1D extends Peak1D {
export interface NMRPeak1D extends PeakXYWidth {
kind?: string;
fwhm?: number;
shape?: Shape1D;
}

@@ -73,2 +73,4 @@ import type { DataXY } from 'cheminfo-types';

type NMRPeak1DIntern = Omit<NMRPeak1D, 'fwhm' | 'shape'>;
function checkSignalAfterCompilePattern(

@@ -87,3 +89,3 @@ signal: SignalIntern,

const assignSignal = (
peak: NMRPeak1D,
peak: NMRPeak1DIntern,
frequency: number,

@@ -120,3 +122,3 @@ nucleus: string,

data: DataXY,
peakList: NMRPeak1D[],
peakList: NMRPeak1DIntern[],
options: OptionsPeaksToRanges = {},

@@ -286,3 +288,3 @@ ): NMRRange[] {

data: DataXY,
peakList: NMRPeak1D[],
peakList: NMRPeak1DIntern[],
options: OptionsDetectSignals = {},

@@ -289,0 +291,0 @@ ): SignalIntern[] {

@@ -32,3 +32,5 @@ import type { MakeMandatory } from '../../utilities/MakeMandatory';

export type Peak1DIntern = Omit<NMRPeak1D, 'y'> & { intensity: number };
export type Peak1DIntern = Omit<NMRPeak1D, 'y' | 'shape' | 'fwhm'> & {
intensity: number;
};

@@ -35,0 +37,0 @@ export interface SignalIntern {

@@ -12,13 +12,13 @@ import type { NMRSignal1D } from '../signals/NMRSignal1D';

if (!split.before) return;
// before parenthesis there should be only numbers but we will still split with space
const beforeParts = split.before
.split(/(?: |(?<=[0-9])-)/)
.map((part: string) => Number(part))
.filter((part: number) => !Number.isNaN(part));
if (beforeParts.length < 1 || beforeParts.length > 2) {
return;
}
const from = beforeParts[0];
const to = beforeParts.length > 1 ? beforeParts[1] : beforeParts[0];
const beforeMatch = /.*?(?<from>-?[0-9.]+)-?(?<to>-?[0-9.]*).*/.exec(
split.before,
);
if (!beforeMatch || !beforeMatch.groups) return;
const isARange = beforeMatch.groups.to !== '';
const from = Number(beforeMatch.groups.from);
const to = isARange ? Number(beforeMatch.groups.to) : from;
const insideParts = split.inside.split(/ *, */);

@@ -41,9 +41,9 @@ let signal: NMRSignal1D = { delta: NaN, js: [] };

if (multiplicity === 'm') {
if (beforeParts.length === 1) {
// a complex signal
signal.delta = beforeParts[0];
if (isARange) {
// a real range
signal.delta = (from + to) / 2;
signal.multiplicity = multiplicity;
} else {
// a real range
signal.delta = (beforeParts[0] + beforeParts[1]) / 2;
// a complex signal
signal.delta = from;
signal.multiplicity = multiplicity;

@@ -53,5 +53,5 @@ }

// looks like a real multiplicity, s, d, dd, etc..
if (beforeParts.length === 1) {
if (!isARange) {
// a complex signal
signal.delta = beforeParts[0];
signal.delta = from;
signal.multiplicity = multiplicity;

@@ -58,0 +58,0 @@ }

import { DataXY } from 'cheminfo-types';
import { gsd, joinBroadPeaks, optimizePeaks } from 'ml-gsd';
import { gsd, optimizePeaks, joinBroadPeaks, appendShapeAndFWHM } from 'ml-gsd';
import type {
Peak1D,
GSDOptions,

@@ -15,2 +14,4 @@ OptimizePeaksOptions,

import { NMRPeak1D } from '..';
/**

@@ -29,3 +30,3 @@ * Implementation of the peak picking method described by Cobas in:

export interface IGetPeakListOptions
export interface GetPeakListOptions
extends GSDOptions,

@@ -40,5 +41,3 @@ OptimizePeaksOptions,

}
export interface OptionsXYAutoPeaksPicking
extends Partial<IGetPeakListOptions> {
export interface OptionsXYAutoPeaksPicking extends Partial<GetPeakListOptions> {
/**

@@ -72,3 +71,3 @@ * Low limit value in the x axis to extract a sub set of points from the input data.

options: OptionsXYAutoPeaksPicking = {},
): Peak1D[] {
): NMRPeak1D[] {
const {

@@ -84,3 +83,3 @@ from,

optimize = false,
factorWidth = 4,
factorLimits = 4,
realTopDetection = true,

@@ -90,19 +89,22 @@ shape = { kind: 'gaussian' },

broadWidth = 0.25,
sgOptions = {},
lookNegative = false,
sgOptions = { windowSize: 9, polynomial: 3 },
} = options;
const { windowSize = 9, polynomial = 3 } = sgOptions;
if (from !== undefined && to !== undefined) {
data = xyExtract(data, { zones: [{ from, to }] });
}
if (data.x.length < sgOptions.windowSize) return [];
if (data.x.length < windowSize) return [];
const cutOff = getCutOff(data.y, { noiseLevel, useSanPlot, thresholdFactor });
let getPeakOptions: IGetPeakListOptions = {
let getPeakOptions: GetPeakListOptions = {
shape,
broadWidth,
optimize,
factorWidth,
sgOptions,
factorLimits,
maxCriteria: true,
sgOptions: { windowSize, polynomial },
minMaxRatio,

@@ -120,3 +122,4 @@ broadRatio,

getPeakOptions.noiseLevel = cutOff.negative;
peaks.push(...getNegativePeaks(data, getPeakOptions));
getPeakOptions.maxCriteria = false;
peaks.push(...getPeakList(data, getPeakOptions));
}

@@ -126,3 +129,3 @@ return peaks;

function getPeakList(data: DataXY, options: IGetPeakListOptions) {
function getPeakList(data: DataXY, options: GetPeakListOptions) {
const {

@@ -132,3 +135,4 @@ shape,

optimize,
factorWidth,
maxCriteria,
factorLimits,
sgOptions,

@@ -144,4 +148,4 @@ minMaxRatio,

let peakList = gsd(data, {
shape,
sgOptions,
maxCriteria,
minMaxRatio,

@@ -154,3 +158,3 @@ noiseLevel,

if (broadWidth) {
peakList = joinBroadPeaks(data, peakList, {
peakList = joinBroadPeaks(peakList, {
broadRatio,

@@ -164,5 +168,5 @@ broadWidth,

if (optimize) {
peakList = optimizePeaks(data, peakList, {
return optimizePeaks(data, peakList, {
shape,
factorWidth,
factorLimits,
optimization,

@@ -172,20 +176,5 @@ });

return peakList;
return appendShapeAndFWHM(peakList, { shape });
}
function getNegativePeaks(data: DataXY, options: IGetPeakListOptions) {
let { x, y } = data;
let negativeDataY = new Float64Array(data.y.length);
for (let i = 0; i < negativeDataY.length; i++) {
negativeDataY[i] = -1 * y[i];
}
let peakList = getPeakList({ x, y: negativeDataY }, options);
for (const peak of peakList) {
peak.y *= -1;
}
return peakList;
}
function getCutOff(data: number[] | Float64Array, options: OptionsGetCutOff) {

@@ -192,0 +181,0 @@ const { noiseLevel, useSanPlot, thresholdFactor } = options;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc