nmr-processing
Advanced tools
@@ -0,5 +1,5 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import { addDiastereotopicMissingChirality } from 'openchemlib-utils'; | ||
import { predictCarbon, } from '../prediction/predictCarbon'; | ||
import { buildAssignments } from './utils/buildAssignments'; | ||
import generateID from './utils/generateID'; | ||
function checkAtomsAndDiaIDs(signals) { | ||
@@ -6,0 +6,0 @@ for (const signal of signals) { |
@@ -0,5 +1,5 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import { addDiastereotopicMissingChirality } from 'openchemlib-utils'; | ||
import { predictProton, } from '../prediction/predictProton'; | ||
import { buildAssignments } from './utils/buildAssignments'; | ||
import generateID from './utils/generateID'; | ||
function checkAtomsAndDiaIDs(signals) { | ||
@@ -6,0 +6,0 @@ for (const signal of signals) { |
@@ -1,2 +0,2 @@ | ||
import generateID from '../generateID'; | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import { isSpectraData1D } from './isSpectraData1D'; | ||
@@ -3,0 +3,0 @@ export function checkIDs(input = []) { |
@@ -0,1 +1,2 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import { xyIntegration } from 'ml-spectra-processing'; | ||
@@ -17,2 +18,3 @@ import { joinRanges } from '../ranges/utils/joinRanges'; | ||
return { | ||
id: generateID(), | ||
delta: NaN, | ||
@@ -136,2 +138,3 @@ nbPeaks: 1, | ||
const range = { | ||
id: generateID(), | ||
from: signal.integralData.from, | ||
@@ -138,0 +141,0 @@ to: signal.integralData.to, |
@@ -27,3 +27,3 @@ import { generateSpectrum } from 'spectrum-generator'; | ||
const lastPeak = newPeaks[newPeaks.length - 1]; | ||
const { from = firstPeak.x - firstPeak.width * 2, to = lastPeak.x + lastPeak.width * 2, } = options; | ||
const { from = firstPeak.x - (firstPeak.width * 2) / options.frequency, to = lastPeak.x + (lastPeak.width * 2) / options.frequency, } = options; | ||
return { | ||
@@ -30,0 +30,0 @@ from, |
@@ -7,5 +7,5 @@ import { addMissingShape } from 'ml-gsd'; | ||
const factor = getShape1D(newPeak.shape).getFactor(); | ||
const { from = newPeak.x - peak.width * factor, to = newPeak.x + peak.width * factor, } = options; | ||
const { from = newPeak.x - (peak.width * factor) / options.frequency, to = newPeak.x + (peak.width * factor) / options.frequency, } = options; | ||
return peaksToXY([peak], { ...options, from, to }); | ||
} | ||
//# sourceMappingURL=peakToXY.js.map |
@@ -9,4 +9,5 @@ import { linearSumAssignment } from 'linear-sum-assignment'; | ||
import { splitSpinSystem } from '../signals/simulation/splitSpinSystem'; | ||
import { cloneArray } from '../utilities/clone'; | ||
export function solventSuppression(peakList, solvent, options = {}) { | ||
const peaks = [...peakList].sort((a, b) => a.x - b.x); | ||
const peaks = cloneArray(peakList).sort((a, b) => a.x - b.x); | ||
const xValues = peaks.map((peak) => peak.x); | ||
@@ -13,0 +14,0 @@ const { markSolventPeaks = false, solventZoneExtension = 1.2 } = options; |
import { hasProperty } from '../../utilities/hasProperty'; | ||
const { parse, stringify } = JSON; | ||
/** | ||
@@ -6,3 +7,3 @@ * convert width and fwhm to ppm | ||
export function convertWidth(peaks, options) { | ||
const { frequency, convertTo, output = JSON.parse(JSON.stringify(peaks)), } = options; | ||
const { frequency, convertTo, output = parse(stringify(peaks)), } = options; | ||
const convert = getConverter(convertTo, frequency); | ||
@@ -12,4 +13,5 @@ for (const peak of output) { | ||
if (hasProperty(peak, 'shape')) { | ||
if (peak.shape.fwhm) { | ||
peak.shape.fwhm = convert(peak.shape.fwhm); | ||
const shape = peak.shape; | ||
if (shape.fwhm) { | ||
shape.fwhm = convert(shape.fwhm); | ||
} | ||
@@ -16,0 +18,0 @@ } |
@@ -1,8 +0,9 @@ | ||
import generateID from '../assignment/utils/generateID'; | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import { addIDs } from '../assignment/utils/getAssignment/checkIDs'; | ||
import { detectSignals } from '../peaks/peaksToRanges'; | ||
import { solventSuppression } from '../peaks/solventSuppression'; | ||
import { cloneArray } from '../utilities/clone'; | ||
export function markSolventPeaks(input, solventSignals, options = {}) { | ||
const { frequency = 400 } = options; | ||
const ranges = addIDs([...input]); | ||
const ranges = addIDs(cloneArray(input)); | ||
let peakList = []; | ||
@@ -9,0 +10,0 @@ for (const range of ranges) { |
@@ -0,1 +1,2 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
export function joinRanges(ranges) { | ||
@@ -7,2 +8,3 @@ ranges.sort((a, b) => a.from - b.from); | ||
if (currentRange.to > nextRange.from) { | ||
currentRange.id = generateID(); | ||
currentRange.to = Math.max(nextRange.to, currentRange.to); | ||
@@ -9,0 +11,0 @@ if (currentRange.signals && nextRange.signals) { |
@@ -1,2 +0,2 @@ | ||
import { gsd, optimizePeaks, joinBroadPeaks } from 'ml-gsd'; | ||
import { gsd, optimizePeaks, joinBroadPeaks, } from 'ml-gsd'; | ||
import { xyExtract, xNoiseSanPlot, xAbsoluteMedian, } from 'ml-spectra-processing'; | ||
@@ -64,4 +64,4 @@ import { convertWidthToHz } from '../peaks/util/convertWidthToHz'; | ||
}); | ||
if (broadWidth) { | ||
peakList = joinBroadPeaks(peakList, { | ||
const newPeaks = broadWidth | ||
? joinBroadPeaks(peakList, { | ||
broadRatio, | ||
@@ -71,11 +71,11 @@ broadWidth, | ||
optimization, | ||
}); | ||
} | ||
}).map(toNMRPeak1DStructure) | ||
: peakList.map(toNMRPeak1DStructure); | ||
return convertWidthToHz(optimize | ||
? optimizePeaks(data, peakList, { | ||
? optimizePeaks(data, newPeaks, { | ||
shape, | ||
factorLimits, | ||
optimization, | ||
}) | ||
: peakList, { frequency }); | ||
}).map(toNMRPeak1DStructure) | ||
: newPeaks, { frequency }); | ||
} | ||
@@ -96,2 +96,12 @@ function getCutOff(data, options) { | ||
} | ||
function toNMRPeak1DStructure(peak) { | ||
const { id, shape, x, y, width } = peak; | ||
return { | ||
id, | ||
x, | ||
y, | ||
width, | ||
shape, | ||
}; | ||
} | ||
//# sourceMappingURL=xyAutoPeaksPicking.js.map |
@@ -0,1 +1,2 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
export function formatZones(signals) { | ||
@@ -21,2 +22,3 @@ let zones = []; | ||
zones.push({ | ||
id: generateID(), | ||
x: { | ||
@@ -23,0 +25,0 @@ from: minMax1[0], |
@@ -0,1 +1,2 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import { Matrix } from 'ml-matrix'; | ||
@@ -5,2 +6,3 @@ import * as convolution from 'ml-matrix-convolution'; | ||
import simpleClustering from 'ml-simple-clustering'; | ||
import { addMissingIDs } from '../peaks/util/addMissingIDs'; | ||
import { determineRealTop } from '../peaks/util/determineRealTop'; | ||
@@ -66,3 +68,3 @@ import { getKernel } from '../peaks/util/getKernel'; | ||
} | ||
let signals = createSignals2D(peaksMC1, { | ||
let signals = createSignals2D(addMissingIDs(peaksMC1), { | ||
nRows: nbSubSpectra, | ||
@@ -86,3 +88,3 @@ nCols: nbPoints, | ||
} | ||
const createSignals2D = (peaks, options) => { | ||
function createSignals2D(peaks, options) { | ||
let { nCols, nRows, absoluteData, originalData, observedFrequencies, tolerances, nuclei, realTopDetection, minY, maxY, minX, maxX, } = options; | ||
@@ -135,2 +137,3 @@ let [nucleusX, nucleusY] = nuclei; | ||
let signal = { | ||
id: generateID(), | ||
x: { | ||
@@ -164,4 +167,4 @@ delta: 0, | ||
return signals; | ||
}; | ||
const padData = (spectraData, options) => { | ||
} | ||
function padData(spectraData, options) { | ||
let { minX, maxX, minY, maxY } = spectraData; | ||
@@ -194,3 +197,3 @@ const width = options.width; | ||
}; | ||
}; | ||
} | ||
//# sourceMappingURL=xyzAutoZonesPicking.js.map |
@@ -0,4 +1,7 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import simpleClustering from 'ml-simple-clustering'; | ||
import { addMissingIDs } from '../peaks/util/addMissingIDs'; | ||
import jAnalyzer from '../signals/utils/jAnalyzer'; | ||
import { formatZones } from './util/formatZone'; | ||
const { parse, stringify } = JSON; | ||
export function xyzJResAnalyzer(signals, options = {}) { | ||
@@ -8,3 +11,3 @@ let { reference = 0, getZones = false, referenceMaxShiftError = 0.08, tolerances = [10, 100], nuclei = ['1H', '1H'], observedFrequencies = [400, 400], jAnalyzer = { | ||
}, } = options; | ||
let temporalSignals = compilePattern([...signals], { | ||
let temporalSignals = compilePattern(signals, { | ||
observedFrequencies, | ||
@@ -23,2 +26,3 @@ tolerances, | ||
} | ||
signals2D = addMissingIDs(signals2D); | ||
return getZones ? formatZones(signals2D) : signals2D; | ||
@@ -36,3 +40,3 @@ } | ||
const defaultWidth = 0.02 * observedFrequencies[0]; | ||
const newSignals = JSON.parse(JSON.stringify(signals)); | ||
const newSignals = parse(stringify(signals)); | ||
//adapt to 1D jAnalyzer | ||
@@ -89,3 +93,3 @@ for (const signal of newSignals) { | ||
let { observedFrequencies, tolerances, nuclei, dx, dy } = options; | ||
const peaks = JSON.parse(JSON.stringify(peaksInput)); | ||
const peaks = parse(stringify(peaksInput)); | ||
let [nucleusX, nucleusY] = nuclei; | ||
@@ -114,2 +118,3 @@ let [toleranceX, toleranceY] = tolerances; | ||
let signal = { | ||
id: generateID(), | ||
nucleusX, | ||
@@ -116,0 +121,0 @@ nucleusY, |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.get13CAssignments = void 0; | ||
const uuid_1 = require("@lukeed/uuid"); | ||
const openchemlib_utils_1 = require("openchemlib-utils"); | ||
const predictCarbon_1 = require("../prediction/predictCarbon"); | ||
const buildAssignments_1 = require("./utils/buildAssignments"); | ||
const generateID_1 = __importDefault(require("./utils/generateID")); | ||
function checkAtomsAndDiaIDs(signals) { | ||
@@ -39,3 +36,3 @@ for (const signal of signals) { | ||
for (const range of copyRanges) { | ||
const { id = (0, generateID_1.default)() } = range; | ||
const { id = (0, uuid_1.v4)() } = range; | ||
targets[id] = JSON.parse(JSON.stringify(range)); | ||
@@ -42,0 +39,0 @@ } |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.get1HAssignments = void 0; | ||
const uuid_1 = require("@lukeed/uuid"); | ||
const openchemlib_utils_1 = require("openchemlib-utils"); | ||
const predictProton_1 = require("../prediction/predictProton"); | ||
const buildAssignments_1 = require("./utils/buildAssignments"); | ||
const generateID_1 = __importDefault(require("./utils/generateID")); | ||
function checkAtomsAndDiaIDs(signals) { | ||
@@ -40,3 +37,3 @@ for (const signal of signals) { | ||
for (const range of ranges) { | ||
const { id = (0, generateID_1.default)() } = range; | ||
const { id = (0, uuid_1.v4)() } = range; | ||
targets[id] = JSON.parse(JSON.stringify(range)); | ||
@@ -43,0 +40,0 @@ } |
@@ -6,2 +6,2 @@ import type { NMRRange, NMRZone } from '../../..'; | ||
export declare function hasIDs(data: NMRRange[] | NMRZone[]): asserts data is NMRRangeWithIds[] | NMRZoneWithIds[]; | ||
export declare function addIDs<T extends NMRRange[] | NMRZone[]>(data: T): T & (NMRRangeWithIds[] | NMRZoneWithIds[]); | ||
export declare function addIDs<T extends NMRRange[] | NMRZone[]>(data: T): (T & NMRRangeWithIds[]) | (T & NMRZoneWithIds[]); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addIDs = exports.hasIDs = exports.checkIDs = void 0; | ||
const generateID_1 = __importDefault(require("../generateID")); | ||
const uuid_1 = require("@lukeed/uuid"); | ||
const isSpectraData1D_1 = require("./isSpectraData1D"); | ||
@@ -43,6 +40,6 @@ function checkIDs(input = []) { | ||
if (!element.id) | ||
element.id = (0, generateID_1.default)(); | ||
element.id = (0, uuid_1.v4)(); | ||
for (let signal of element.signals || []) { | ||
if (!signal.id) | ||
signal.id = (0, generateID_1.default)(); | ||
signal.id = (0, uuid_1.v4)(); | ||
} | ||
@@ -49,0 +46,0 @@ } |
import type { PeakXYWidth } from 'cheminfo-types'; | ||
import type { Shape1D } from 'ml-peak-shape-generator'; | ||
export interface NMRPeak1D extends PeakXYWidth { | ||
id?: string; | ||
kind?: string; | ||
shape?: Shape1D; | ||
} |
@@ -23,3 +23,3 @@ import { impurities } from '../constants/impurities'; | ||
*/ | ||
export declare function peaksFilterImpurities(peakList: NMRPeak1D[], options?: OptionsPeaksFilterImpurities): NMRPeak1D[]; | ||
export declare function peaksFilterImpurities<T extends NMRPeak1D>(peakList: T[], options?: OptionsPeaksFilterImpurities): T[]; | ||
export {}; |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.detectSignals = exports.peaksToRanges = void 0; | ||
const uuid_1 = require("@lukeed/uuid"); | ||
const ml_spectra_processing_1 = require("ml-spectra-processing"); | ||
@@ -24,2 +25,3 @@ const joinRanges_1 = require("../ranges/utils/joinRanges"); | ||
return { | ||
id: (0, uuid_1.v4)(), | ||
delta: NaN, | ||
@@ -143,2 +145,3 @@ nbPeaks: 1, | ||
const range = { | ||
id: (0, uuid_1.v4)(), | ||
from: signal.integralData.from, | ||
@@ -145,0 +148,0 @@ to: signal.integralData.to, |
@@ -31,3 +31,3 @@ "use strict"; | ||
const lastPeak = newPeaks[newPeaks.length - 1]; | ||
const { from = firstPeak.x - firstPeak.width * 2, to = lastPeak.x + lastPeak.width * 2, } = options; | ||
const { from = firstPeak.x - (firstPeak.width * 2) / options.frequency, to = lastPeak.x + (lastPeak.width * 2) / options.frequency, } = options; | ||
return { | ||
@@ -34,0 +34,0 @@ from, |
@@ -10,3 +10,3 @@ "use strict"; | ||
const factor = (0, ml_peak_shape_generator_1.getShape1D)(newPeak.shape).getFactor(); | ||
const { from = newPeak.x - peak.width * factor, to = newPeak.x + peak.width * factor, } = options; | ||
const { from = newPeak.x - (peak.width * factor) / options.frequency, to = newPeak.x + (peak.width * factor) / options.frequency, } = options; | ||
return (0, peaksToXY_1.peaksToXY)([peak], { ...options, from, to }); | ||
@@ -13,0 +13,0 @@ } |
@@ -12,4 +12,5 @@ "use strict"; | ||
const splitSpinSystem_1 = require("../signals/simulation/splitSpinSystem"); | ||
const clone_1 = require("../utilities/clone"); | ||
function solventSuppression(peakList, solvent, options = {}) { | ||
const peaks = [...peakList].sort((a, b) => a.x - b.x); | ||
const peaks = (0, clone_1.cloneArray)(peakList).sort((a, b) => a.x - b.x); | ||
const xValues = peaks.map((peak) => peak.x); | ||
@@ -16,0 +17,0 @@ const { markSolventPeaks = false, solventZoneExtension = 1.2 } = options; |
import { MakeMandatory } from '../../utilities/MakeMandatory'; | ||
import { NMRPeak1D } from '../NMRPeak1D'; | ||
export declare type NMRPeak1DWithShape = MakeMandatory<NMRPeak1D, 'shape'>; | ||
export interface ConvertWidthOptions { | ||
export interface ConvertWidthOptions<T> { | ||
convertTo: string & { | ||
@@ -9,3 +9,3 @@ _kind?: 'hz' | 'ppm'; | ||
frequency: number; | ||
output?: NMRPeak1D[]; | ||
output?: T[]; | ||
} | ||
@@ -15,2 +15,2 @@ /** | ||
*/ | ||
export declare function convertWidth(peaks: NMRPeak1D[], options: ConvertWidthOptions): NMRPeak1D[]; | ||
export declare function convertWidth<T extends NMRPeak1D>(peaks: T[], options: ConvertWidthOptions<T>): T[]; |
@@ -5,2 +5,3 @@ "use strict"; | ||
const hasProperty_1 = require("../../utilities/hasProperty"); | ||
const { parse, stringify } = JSON; | ||
/** | ||
@@ -10,3 +11,3 @@ * convert width and fwhm to ppm | ||
function convertWidth(peaks, options) { | ||
const { frequency, convertTo, output = JSON.parse(JSON.stringify(peaks)), } = options; | ||
const { frequency, convertTo, output = parse(stringify(peaks)), } = options; | ||
const convert = getConverter(convertTo, frequency); | ||
@@ -16,4 +17,5 @@ for (const peak of output) { | ||
if ((0, hasProperty_1.hasProperty)(peak, 'shape')) { | ||
if (peak.shape.fwhm) { | ||
peak.shape.fwhm = convert(peak.shape.fwhm); | ||
const shape = peak.shape; | ||
if (shape.fwhm) { | ||
shape.fwhm = convert(shape.fwhm); | ||
} | ||
@@ -20,0 +22,0 @@ } |
import { NMRPeak1D } from '../NMRPeak1D'; | ||
import { ConvertWidthOptions } from './convertWidth'; | ||
export declare type ConvertWidthTo = Omit<ConvertWidthOptions, 'convertTo'>; | ||
export declare function convertWidthToHz(peaks: NMRPeak1D[], options: ConvertWidthTo): NMRPeak1D[]; | ||
export declare type ConvertWidthTo<T> = Omit<ConvertWidthOptions<T>, 'convertTo'>; | ||
export declare function convertWidthToHz<T extends NMRPeak1D>(peaks: T[], options: ConvertWidthTo<T>): T[]; |
import { NMRPeak1D } from '../NMRPeak1D'; | ||
import { ConvertWidthTo } from './convertWidthToHz'; | ||
export declare function convertWidthToPPM(peaks: NMRPeak1D[], options: ConvertWidthTo): NMRPeak1D[]; | ||
export declare function convertWidthToPPM<T extends NMRPeak1D>(peaks: T[], options: ConvertWidthTo<T>): T[]; |
import type { Peak2D } from 'ml-matrix-peaks-finder'; | ||
export declare function determineRealTop(peaks: Peak2D[], options: any): Peak2D[]; | ||
export declare function determineRealTop<T extends Peak2D>(peaks: T[], options: any): T[]; |
@@ -0,1 +1,2 @@ | ||
/// <reference path="../../src/ml-matrix-peaks-finder.d.ts" /> | ||
import { Molecule } from 'openchemlib'; | ||
@@ -62,6 +63,6 @@ import { PredictProtonOptions } from './predictProton'; | ||
nuclei: string[]; | ||
joinedSignals: import("..").NMRSignal2D[]; | ||
joinedSignals: import("..").NMRSignal2D<import("ml-matrix-peaks-finder").Peak2D>[]; | ||
signals: any[]; | ||
zones: { | ||
signals: import("..").NMRSignal2D[]; | ||
signals: import("..").NMRSignal2D<import("ml-matrix-peaks-finder").Peak2D>[]; | ||
x: { | ||
@@ -68,0 +69,0 @@ from: number; |
@@ -0,1 +1,2 @@ | ||
/// <reference path="../../src/ml-matrix-peaks-finder.d.ts" /> | ||
import { Molecule } from 'openchemlib'; | ||
@@ -61,6 +62,6 @@ import type { PredictCarbonOptions } from './predictCarbon'; | ||
nuclei: string[]; | ||
joinedSignals: import("..").NMRSignal2D[]; | ||
joinedSignals: import("..").NMRSignal2D<import("ml-matrix-peaks-finder").Peak2D>[]; | ||
signals: any[]; | ||
zones: { | ||
signals: import("..").NMRSignal2D[]; | ||
signals: import("..").NMRSignal2D<import("ml-matrix-peaks-finder").Peak2D>[]; | ||
x: { | ||
@@ -67,0 +68,0 @@ from: number; |
@@ -0,1 +1,2 @@ | ||
/// <reference path="../../src/ml-matrix-peaks-finder.d.ts" /> | ||
import { Molecule } from 'openchemlib'; | ||
@@ -61,6 +62,6 @@ import { PredictCarbonOptions } from './predictCarbon'; | ||
nuclei: string[]; | ||
joinedSignals: import("..").NMRSignal2D[]; | ||
joinedSignals: import("..").NMRSignal2D<import("ml-matrix-peaks-finder").Peak2D>[]; | ||
signals: any[]; | ||
zones: { | ||
signals: import("..").NMRSignal2D[]; | ||
signals: import("..").NMRSignal2D<import("ml-matrix-peaks-finder").Peak2D>[]; | ||
x: { | ||
@@ -67,0 +68,0 @@ from: number; |
@@ -0,1 +1,2 @@ | ||
/// <reference path="../../../src/ml-matrix-peaks-finder.d.ts" /> | ||
import { Molecule } from 'openchemlib'; | ||
@@ -78,6 +79,6 @@ import type { NMRSignal2D } from '../../xyz/NMRSignal2D'; | ||
nuclei: string[]; | ||
joinedSignals: NMRSignal2D[]; | ||
joinedSignals: NMRSignal2D<import("ml-matrix-peaks-finder").Peak2D>[]; | ||
signals: any[]; | ||
zones: { | ||
signals: NMRSignal2D[]; | ||
signals: NMRSignal2D<import("ml-matrix-peaks-finder").Peak2D>[]; | ||
x: { | ||
@@ -84,0 +85,0 @@ from: number; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.markSolventPeaks = void 0; | ||
const generateID_1 = __importDefault(require("../assignment/utils/generateID")); | ||
const uuid_1 = require("@lukeed/uuid"); | ||
const checkIDs_1 = require("../assignment/utils/getAssignment/checkIDs"); | ||
const peaksToRanges_1 = require("../peaks/peaksToRanges"); | ||
const solventSuppression_1 = require("../peaks/solventSuppression"); | ||
const clone_1 = require("../utilities/clone"); | ||
function markSolventPeaks(input, solventSignals, options = {}) { | ||
const { frequency = 400 } = options; | ||
const ranges = (0, checkIDs_1.addIDs)([...input]); | ||
const ranges = (0, checkIDs_1.addIDs)((0, clone_1.cloneArray)(input)); | ||
let peakList = []; | ||
@@ -88,3 +86,3 @@ for (const range of ranges) { | ||
const signalResult = { | ||
id: (0, generateID_1.default)(), | ||
id: (0, uuid_1.v4)(), | ||
delta: signal.delta, | ||
@@ -91,0 +89,0 @@ kind: signal.kind || 'signal', |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.joinRanges = void 0; | ||
const uuid_1 = require("@lukeed/uuid"); | ||
function joinRanges(ranges) { | ||
@@ -10,2 +11,3 @@ ranges.sort((a, b) => a.from - b.from); | ||
if (currentRange.to > nextRange.from) { | ||
currentRange.id = (0, uuid_1.v4)(); | ||
currentRange.to = Math.max(nextRange.to, currentRange.to); | ||
@@ -12,0 +14,0 @@ if (currentRange.signals && nextRange.signals) { |
@@ -17,2 +17,3 @@ import type { NMRPeak1D } from '../../peaks/NMRPeak1D'; | ||
export interface SignalIntern { | ||
id: string; | ||
delta: number; | ||
@@ -19,0 +20,0 @@ nbPeaks: number; |
import { DataXY } from 'cheminfo-types'; | ||
import type { GSDOptions, OptimizePeaksOptions, JoinBroadPeaksOptions } from 'ml-gsd'; | ||
import { GSDOptions, OptimizePeaksOptions, JoinBroadPeaksOptions } from 'ml-gsd'; | ||
import { NMRPeak1D } from '..'; | ||
import { MakeMandatory } from '../utilities/MakeMandatory'; | ||
export interface GetPeakListOptions extends GSDOptions, OptimizePeaksOptions, JoinBroadPeaksOptions { | ||
@@ -44,2 +45,3 @@ /** | ||
} | ||
export declare function xyAutoPeaksPicking(data: DataXY, options: OptionsXYAutoPeaksPicking): NMRPeak1D[]; | ||
export declare type NMRPeak1DWithID = MakeMandatory<NMRPeak1D, 'id'>; | ||
export declare function xyAutoPeaksPicking(data: DataXY, options: OptionsXYAutoPeaksPicking): NMRPeak1DWithID[]; |
@@ -68,4 +68,4 @@ "use strict"; | ||
}); | ||
if (broadWidth) { | ||
peakList = (0, ml_gsd_1.joinBroadPeaks)(peakList, { | ||
const newPeaks = broadWidth | ||
? (0, ml_gsd_1.joinBroadPeaks)(peakList, { | ||
broadRatio, | ||
@@ -75,11 +75,11 @@ broadWidth, | ||
optimization, | ||
}); | ||
} | ||
}).map(toNMRPeak1DStructure) | ||
: peakList.map(toNMRPeak1DStructure); | ||
return (0, convertWidthToHz_1.convertWidthToHz)(optimize | ||
? (0, ml_gsd_1.optimizePeaks)(data, peakList, { | ||
? (0, ml_gsd_1.optimizePeaks)(data, newPeaks, { | ||
shape, | ||
factorLimits, | ||
optimization, | ||
}) | ||
: peakList, { frequency }); | ||
}).map(toNMRPeak1DStructure) | ||
: newPeaks, { frequency }); | ||
} | ||
@@ -100,2 +100,12 @@ function getCutOff(data, options) { | ||
} | ||
function toNMRPeak1DStructure(peak) { | ||
const { id, shape, x, y, width } = peak; | ||
return { | ||
id, | ||
x, | ||
y, | ||
width, | ||
shape, | ||
}; | ||
} | ||
//# sourceMappingURL=xyAutoPeaksPicking.js.map |
@@ -9,2 +9,4 @@ import { DataXY, PeakXYWidth } from 'cheminfo-types'; | ||
} | ||
export declare function xyPeaksOptimization(data: DataXY, peaks: PeakXYWidth[], options: XYPeaksOptimizationOptions): import("..").NMRPeak1D[]; | ||
export declare function xyPeaksOptimization<T extends PeakXYWidth>(data: DataXY, peaks: T[], options: XYPeaksOptimizationOptions): (T extends { | ||
id: string; | ||
} ? import("ml-gsd").GSDPeakOptimizedID : import("ml-gsd").GSDPeakOptimized)[]; |
@@ -10,3 +10,3 @@ import type { FromTo } from 'cheminfo-types'; | ||
} | ||
export interface NMRSignal2D { | ||
export interface NMRSignal2D<T extends Peak2D = Peak2D> { | ||
x: Signal2DProjection; | ||
@@ -18,4 +18,4 @@ y: Signal2DProjection; | ||
id?: string; | ||
peaks?: Peak2D[]; | ||
peaks?: T[]; | ||
kind?: string; | ||
} |
@@ -1,3 +0,2 @@ | ||
import { NMRSignal2D } from '../NMRSignal2D'; | ||
import { NMRZone } from '../NMRZone'; | ||
export declare function formatZones(signals: NMRSignal2D[]): NMRZone[]; | ||
import { NMRSignal2DWithID, NMRZoneWithID } from '../xyzAutoZonesPicking'; | ||
export declare function formatZones(signals: NMRSignal2DWithID[]): NMRZoneWithID[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.formatZones = void 0; | ||
const uuid_1 = require("@lukeed/uuid"); | ||
function formatZones(signals) { | ||
@@ -24,2 +25,3 @@ let zones = []; | ||
zones.push({ | ||
id: (0, uuid_1.v4)(), | ||
x: { | ||
@@ -26,0 +28,0 @@ from: minMax1[0], |
@@ -0,2 +1,6 @@ | ||
import type { Peak2D } from 'ml-matrix-peaks-finder'; | ||
import type { GetKernelOptions } from '../peaks/util/getKernel'; | ||
import { MakeMandatory } from '../utilities/MakeMandatory'; | ||
import type { NMRSignal2D } from './NMRSignal2D'; | ||
import { NMRZone } from './NMRZone'; | ||
export interface Data2D { | ||
@@ -64,3 +68,5 @@ z: number[][] | Float64Array[]; | ||
} | ||
export declare function xyzAutoZonesPicking(spectraData: Data2D, options: XYZAutoZonesPickingOptions): import("./NMRZone").NMRZone[]; | ||
export declare type NMRSignal2DWithID<T extends Peak2D = Peak2D> = MakeMandatory<NMRSignal2D<T>, 'id'>; | ||
export declare type NMRZoneWithID = MakeMandatory<NMRZone, 'id'>; | ||
export declare function xyzAutoZonesPicking(spectraData: Data2D, options: XYZAutoZonesPickingOptions): NMRZoneWithID[]; | ||
/** | ||
@@ -67,0 +73,0 @@ * This function converts a set of 2D-peaks in 2D-signals. Each signal could be composed |
@@ -30,2 +30,3 @@ "use strict"; | ||
exports.xyzAutoZonesPicking = void 0; | ||
const uuid_1 = require("@lukeed/uuid"); | ||
const ml_matrix_1 = require("ml-matrix"); | ||
@@ -35,2 +36,3 @@ const convolution = __importStar(require("ml-matrix-convolution")); | ||
const ml_simple_clustering_1 = __importDefault(require("ml-simple-clustering")); | ||
const addMissingIDs_1 = require("../peaks/util/addMissingIDs"); | ||
const determineRealTop_1 = require("../peaks/util/determineRealTop"); | ||
@@ -96,3 +98,3 @@ const getKernel_1 = require("../peaks/util/getKernel"); | ||
} | ||
let signals = createSignals2D(peaksMC1, { | ||
let signals = createSignals2D((0, addMissingIDs_1.addMissingIDs)(peaksMC1), { | ||
nRows: nbSubSpectra, | ||
@@ -117,3 +119,3 @@ nCols: nbPoints, | ||
exports.xyzAutoZonesPicking = xyzAutoZonesPicking; | ||
const createSignals2D = (peaks, options) => { | ||
function createSignals2D(peaks, options) { | ||
let { nCols, nRows, absoluteData, originalData, observedFrequencies, tolerances, nuclei, realTopDetection, minY, maxY, minX, maxX, } = options; | ||
@@ -166,2 +168,3 @@ let [nucleusX, nucleusY] = nuclei; | ||
let signal = { | ||
id: (0, uuid_1.v4)(), | ||
x: { | ||
@@ -195,4 +198,4 @@ delta: 0, | ||
return signals; | ||
}; | ||
const padData = (spectraData, options) => { | ||
} | ||
function padData(spectraData, options) { | ||
let { minX, maxX, minY, maxY } = spectraData; | ||
@@ -225,3 +228,3 @@ const width = options.width; | ||
}; | ||
}; | ||
} | ||
//# sourceMappingURL=xyzAutoZonesPicking.js.map |
@@ -0,1 +1,2 @@ | ||
import type { Peak2D } from 'ml-matrix-peaks-finder'; | ||
import type { JAxisKeys } from '../signals/utils/jAnalyzer'; | ||
@@ -28,3 +29,5 @@ import type { NMRSignal2D } from './NMRSignal2D'; | ||
} | ||
export declare function xyzJResAnalyzer(signals: NMRSignal2D[], options?: XYZJResAnalyzerOptions): NMRSignal2D[] | import("./NMRZone").NMRZone[]; | ||
export declare function xyzJResAnalyzer(signals: NMRSignal2D[], options?: XYZJResAnalyzerOptions): import("./xyzAutoZonesPicking").NMRZoneWithID[] | (NMRSignal2D<Peak2D> & { | ||
id: string; | ||
})[]; | ||
export {}; |
@@ -7,5 +7,8 @@ "use strict"; | ||
exports.xyzJResAnalyzer = void 0; | ||
const uuid_1 = require("@lukeed/uuid"); | ||
const ml_simple_clustering_1 = __importDefault(require("ml-simple-clustering")); | ||
const addMissingIDs_1 = require("../peaks/util/addMissingIDs"); | ||
const jAnalyzer_1 = __importDefault(require("../signals/utils/jAnalyzer")); | ||
const formatZone_1 = require("./util/formatZone"); | ||
const { parse, stringify } = JSON; | ||
function xyzJResAnalyzer(signals, options = {}) { | ||
@@ -15,3 +18,3 @@ let { reference = 0, getZones = false, referenceMaxShiftError = 0.08, tolerances = [10, 100], nuclei = ['1H', '1H'], observedFrequencies = [400, 400], jAnalyzer = { | ||
}, } = options; | ||
let temporalSignals = compilePattern([...signals], { | ||
let temporalSignals = compilePattern(signals, { | ||
observedFrequencies, | ||
@@ -30,2 +33,3 @@ tolerances, | ||
} | ||
signals2D = (0, addMissingIDs_1.addMissingIDs)(signals2D); | ||
return getZones ? (0, formatZone_1.formatZones)(signals2D) : signals2D; | ||
@@ -44,3 +48,3 @@ } | ||
const defaultWidth = 0.02 * observedFrequencies[0]; | ||
const newSignals = JSON.parse(JSON.stringify(signals)); | ||
const newSignals = parse(stringify(signals)); | ||
//adapt to 1D jAnalyzer | ||
@@ -97,3 +101,3 @@ for (const signal of newSignals) { | ||
let { observedFrequencies, tolerances, nuclei, dx, dy } = options; | ||
const peaks = JSON.parse(JSON.stringify(peaksInput)); | ||
const peaks = parse(stringify(peaksInput)); | ||
let [nucleusX, nucleusY] = nuclei; | ||
@@ -122,2 +126,3 @@ let [toleranceX, toleranceY] = tolerances; | ||
let signal = { | ||
id: (0, uuid_1.v4)(), | ||
nucleusX, | ||
@@ -124,0 +129,0 @@ nucleusY, |
{ | ||
"name": "nmr-processing", | ||
"version": "9.0.3-pre.1660735983", | ||
"version": "9.0.3-pre.1661572417", | ||
"description": "Pure functions allowing to process NMR spectra.", | ||
@@ -57,2 +57,3 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@lukeed/uuid": "^2.0.0", | ||
"binary-search": "^1.3.6", | ||
@@ -67,3 +68,3 @@ "cross-fetch": "^3.1.5", | ||
"ml-array-sum": "^1.1.6", | ||
"ml-gsd": "^12.0.0", | ||
"ml-gsd": "12.0.0-pre.1661543950", | ||
"ml-hclust": "^3.1.0", | ||
@@ -70,0 +71,0 @@ "ml-levenberg-marquardt": "^4.1.0", |
@@ -0,1 +1,2 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import { Molecule } from 'openchemlib'; | ||
@@ -16,3 +17,2 @@ import { addDiastereotopicMissingChirality } from 'openchemlib-utils'; | ||
import { RestrictionByCS1D, buildAssignments } from './utils/buildAssignments'; | ||
import generateID from './utils/generateID'; | ||
@@ -19,0 +19,0 @@ function checkAtomsAndDiaIDs( |
@@ -0,1 +1,2 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import { Molecule } from 'openchemlib'; | ||
@@ -13,3 +14,2 @@ import { addDiastereotopicMissingChirality } from 'openchemlib-utils'; | ||
import { buildAssignments, RestrictionByCS1D } from './utils/buildAssignments'; | ||
import generateID from './utils/generateID'; | ||
@@ -16,0 +16,0 @@ export type NMRSignal1DWithAtomsAndDiaIDs = MakeMandatory< |
@@ -0,1 +1,3 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import type { NMRRange, NMRZone } from '../../..'; | ||
@@ -8,3 +10,2 @@ import type { SpectraData } from '../../getAssignments'; | ||
} from '../../nmrAssigment'; | ||
import generateID from '../generateID'; | ||
@@ -11,0 +12,0 @@ import { isSpectraData1D } from './isSpectraData1D'; |
@@ -12,2 +12,3 @@ declare module 'ml-matrix-peaks-finder' { | ||
interface Peak2D { | ||
id?: string; | ||
x: number; | ||
@@ -14,0 +15,0 @@ y: number; |
@@ -5,4 +5,5 @@ import type { PeakXYWidth } from 'cheminfo-types'; | ||
export interface NMRPeak1D extends PeakXYWidth { | ||
id?: string; | ||
kind?: string; | ||
shape?: Shape1D; | ||
} |
@@ -37,4 +37,4 @@ import { impurities } from '../constants/impurities'; | ||
export function peaksFilterImpurities( | ||
peakList: NMRPeak1D[], | ||
export function peaksFilterImpurities<T extends NMRPeak1D>( | ||
peakList: T[], | ||
options: OptionsPeaksFilterImpurities = {}, | ||
@@ -60,4 +60,4 @@ ) { | ||
function checkImpurity( | ||
peakList: NMRPeak1D[], | ||
function checkImpurity<T extends NMRPeak1D>( | ||
peakList: T[], | ||
impurity: ImpuritySignal[], | ||
@@ -64,0 +64,0 @@ options: OptionsCheckImpurity, |
@@ -0,1 +1,2 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import type { DataXY } from 'cheminfo-types'; | ||
@@ -93,2 +94,3 @@ import { xyIntegration } from 'ml-spectra-processing'; | ||
return { | ||
id: generateID(), | ||
delta: NaN, | ||
@@ -236,2 +238,3 @@ nbPeaks: 1, | ||
const range: NMRRange = { | ||
id: generateID(), | ||
from: signal.integralData.from, | ||
@@ -238,0 +241,0 @@ to: signal.integralData.to, |
@@ -56,4 +56,4 @@ import { generateSpectrum, OptionsSG1D } from 'spectrum-generator'; | ||
const { | ||
from = firstPeak.x - firstPeak.width * 2, | ||
to = lastPeak.x + lastPeak.width * 2, | ||
from = firstPeak.x - (firstPeak.width * 2) / options.frequency, | ||
to = lastPeak.x + (lastPeak.width * 2) / options.frequency, | ||
} = options; | ||
@@ -60,0 +60,0 @@ |
@@ -12,4 +12,4 @@ import { addMissingShape } from 'ml-gsd'; | ||
const { | ||
from = newPeak.x - peak.width * factor, | ||
to = newPeak.x + peak.width * factor, | ||
from = newPeak.x - (peak.width * factor) / options.frequency, | ||
to = newPeak.x + (peak.width * factor) / options.frequency, | ||
} = options; | ||
@@ -16,0 +16,0 @@ |
@@ -12,2 +12,3 @@ import { PointXY } from 'cheminfo-types'; | ||
import { splitSpinSystem } from '../signals/simulation/splitSpinSystem'; | ||
import { cloneArray } from '../utilities/clone'; | ||
@@ -21,3 +22,3 @@ import { NMRPeak1D } from './NMRPeak1D'; | ||
) { | ||
const peaks = [...peakList].sort((a, b) => a.x - b.x); | ||
const peaks = cloneArray(peakList).sort((a, b) => a.x - b.x); | ||
@@ -24,0 +25,0 @@ const xValues = peaks.map((peak) => peak.x); |
@@ -0,1 +1,3 @@ | ||
import { Shape1D } from 'ml-peak-shape-generator'; | ||
import { MakeMandatory } from '../../utilities/MakeMandatory'; | ||
@@ -5,8 +7,10 @@ import { hasProperty } from '../../utilities/hasProperty'; | ||
const { parse, stringify } = JSON; | ||
export type NMRPeak1DWithShape = MakeMandatory<NMRPeak1D, 'shape'>; | ||
export interface ConvertWidthOptions { | ||
export interface ConvertWidthOptions<T> { | ||
convertTo: string & { _kind?: 'hz' | 'ppm' }; | ||
frequency: number; | ||
output?: NMRPeak1D[]; | ||
output?: T[]; | ||
} | ||
@@ -16,7 +20,10 @@ /** | ||
*/ | ||
export function convertWidth(peaks: NMRPeak1D[], options: ConvertWidthOptions) { | ||
export function convertWidth<T extends NMRPeak1D>( | ||
peaks: T[], | ||
options: ConvertWidthOptions<T>, | ||
): T[] { | ||
const { | ||
frequency, | ||
convertTo, | ||
output = JSON.parse(JSON.stringify(peaks)) as NMRPeak1D[], | ||
output = parse(stringify(peaks)) as T[], | ||
} = options; | ||
@@ -29,4 +36,5 @@ | ||
if (hasProperty(peak, 'shape')) { | ||
if (peak.shape.fwhm) { | ||
peak.shape.fwhm = convert(peak.shape.fwhm); | ||
const shape = peak.shape as Shape1D; | ||
if (shape.fwhm) { | ||
shape.fwhm = convert(shape.fwhm); | ||
} | ||
@@ -33,0 +41,0 @@ } |
@@ -5,6 +5,9 @@ import { NMRPeak1D } from '../NMRPeak1D'; | ||
export type ConvertWidthTo = Omit<ConvertWidthOptions, 'convertTo'>; | ||
export type ConvertWidthTo<T> = Omit<ConvertWidthOptions<T>, 'convertTo'>; | ||
export function convertWidthToHz(peaks: NMRPeak1D[], options: ConvertWidthTo) { | ||
export function convertWidthToHz<T extends NMRPeak1D>( | ||
peaks: T[], | ||
options: ConvertWidthTo<T>, | ||
): T[] { | ||
return convertWidth(peaks, { ...options, convertTo: 'hz' }); | ||
} |
@@ -6,4 +6,7 @@ import { NMRPeak1D } from '../NMRPeak1D'; | ||
export function convertWidthToPPM(peaks: NMRPeak1D[], options: ConvertWidthTo) { | ||
export function convertWidthToPPM<T extends NMRPeak1D>( | ||
peaks: T[], | ||
options: ConvertWidthTo<T>, | ||
) { | ||
return convertWidth(peaks, { ...options, convertTo: 'ppm' }); | ||
} |
@@ -12,3 +12,3 @@ import { levenbergMarquardt } from 'ml-levenberg-marquardt'; | ||
export function determineRealTop(peaks: Peak2D[], options: any) { | ||
export function determineRealTop<T extends Peak2D>(peaks: T[], options: any) { | ||
let { nCols, absoluteData, originalData, minX, maxX, minY, maxY } = options; | ||
@@ -15,0 +15,0 @@ for (let i = 0; i < peaks.length; i++) { |
@@ -0,3 +1,4 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import { NMRRangeWithIds, NMRSignal1DWithId } from '../assignment/nmrAssigment'; | ||
import generateID from '../assignment/utils/generateID'; | ||
import { addIDs } from '../assignment/utils/getAssignment/checkIDs'; | ||
@@ -9,2 +10,3 @@ import { NMRPeak1D } from '../peaks/NMRPeak1D'; | ||
import { SignalIntern } from '../signals/utils/jAnalyzer'; | ||
import { cloneArray } from '../utilities/clone'; | ||
import { NMRRange } from '../xy/NMRRange'; | ||
@@ -23,3 +25,3 @@ | ||
const { frequency = 400 } = options; | ||
const ranges = addIDs([...input]) as NMRRangeWithIds[]; | ||
const ranges = addIDs(cloneArray(input)) as NMRRangeWithIds[]; | ||
@@ -26,0 +28,0 @@ let peakList: NMRPeak1DWithSignalID[] = []; |
@@ -0,1 +1,3 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import type { NMRRange } from '../../xy/NMRRange'; | ||
@@ -11,2 +13,3 @@ | ||
if (currentRange.to > nextRange.from) { | ||
currentRange.id = generateID(); | ||
currentRange.to = Math.max(nextRange.to, currentRange.to); | ||
@@ -13,0 +16,0 @@ if (currentRange.signals && nextRange.signals) { |
@@ -37,2 +37,3 @@ import type { NMRPeak1D } from '../../peaks/NMRPeak1D'; | ||
export interface SignalIntern { | ||
id: string; | ||
delta: number; | ||
@@ -39,0 +40,0 @@ nbPeaks: number; |
import { DataXY } from 'cheminfo-types'; | ||
import { gsd, optimizePeaks, joinBroadPeaks } from 'ml-gsd'; | ||
import type { | ||
import { | ||
gsd, | ||
optimizePeaks, | ||
joinBroadPeaks, | ||
GSDPeakID, | ||
GSDOptions, | ||
OptimizePeaksOptions, | ||
JoinBroadPeaksOptions, | ||
GSDPeakOptimizedID, | ||
} from 'ml-gsd'; | ||
@@ -16,2 +20,3 @@ import { | ||
import { convertWidthToHz } from '../peaks/util/convertWidthToHz'; | ||
import { MakeMandatory } from '../utilities/MakeMandatory'; | ||
@@ -76,6 +81,8 @@ /** | ||
export type NMRPeak1DWithID = MakeMandatory<NMRPeak1D, 'id'>; | ||
export function xyAutoPeaksPicking( | ||
data: DataXY, | ||
options: OptionsXYAutoPeaksPicking, | ||
): NMRPeak1D[] { | ||
): NMRPeak1DWithID[] { | ||
const { | ||
@@ -185,19 +192,19 @@ from, | ||
if (broadWidth) { | ||
peakList = joinBroadPeaks(peakList, { | ||
broadRatio, | ||
broadWidth, | ||
shape, | ||
optimization, | ||
}); | ||
} | ||
const newPeaks = broadWidth | ||
? joinBroadPeaks(peakList, { | ||
broadRatio, | ||
broadWidth, | ||
shape, | ||
optimization, | ||
}).map(toNMRPeak1DStructure) | ||
: peakList.map(toNMRPeak1DStructure); | ||
return convertWidthToHz( | ||
optimize | ||
? optimizePeaks(data, peakList, { | ||
? optimizePeaks(data, newPeaks, { | ||
shape, | ||
factorLimits, | ||
optimization, | ||
}) | ||
: peakList, | ||
}).map(toNMRPeak1DStructure) | ||
: newPeaks, | ||
{ frequency }, | ||
@@ -223,1 +230,14 @@ ); | ||
} | ||
function toNMRPeak1DStructure( | ||
peak: GSDPeakID | GSDPeakOptimizedID, | ||
): NMRPeak1DWithID { | ||
const { id, shape, x, y, width } = peak; | ||
return { | ||
id, | ||
x, | ||
y, | ||
width, | ||
shape, | ||
}; | ||
} |
@@ -13,5 +13,5 @@ import { DataXY, PeakXYWidth } from 'cheminfo-types'; | ||
} | ||
export function xyPeaksOptimization( | ||
export function xyPeaksOptimization<T extends PeakXYWidth>( | ||
data: DataXY, | ||
peaks: PeakXYWidth[], | ||
peaks: T[], | ||
options: XYPeaksOptimizationOptions, | ||
@@ -18,0 +18,0 @@ ) { |
@@ -11,3 +11,3 @@ import type { FromTo } from 'cheminfo-types'; | ||
} | ||
export interface NMRSignal2D { | ||
export interface NMRSignal2D<T extends Peak2D = Peak2D> { | ||
x: Signal2DProjection; | ||
@@ -19,4 +19,4 @@ y: Signal2DProjection; | ||
id?: string; | ||
peaks?: Peak2D[]; | ||
peaks?: T[]; | ||
kind?: string; | ||
} |
@@ -1,6 +0,7 @@ | ||
import { NMRSignal2D } from '../NMRSignal2D'; | ||
import { NMRZone } from '../NMRZone'; | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
export function formatZones(signals: NMRSignal2D[]) { | ||
let zones: NMRZone[] = []; | ||
import { NMRSignal2DWithID, NMRZoneWithID } from '../xyzAutoZonesPicking'; | ||
export function formatZones(signals: NMRSignal2DWithID[]) { | ||
let zones: NMRZoneWithID[] = []; | ||
for (const signal of signals) { | ||
@@ -24,2 +25,3 @@ let minMax1 = [Number.MAX_VALUE, 0]; | ||
zones.push({ | ||
id: generateID(), | ||
x: { | ||
@@ -26,0 +28,0 @@ from: minMax1[0], |
@@ -0,1 +1,2 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import { Matrix } from 'ml-matrix'; | ||
@@ -7,2 +8,3 @@ import * as convolution from 'ml-matrix-convolution'; | ||
import { addMissingIDs } from '../peaks/util/addMissingIDs'; | ||
import { determineRealTop } from '../peaks/util/determineRealTop'; | ||
@@ -12,4 +14,6 @@ import { getKernel } from '../peaks/util/getKernel'; | ||
import * as PeakOptimizer from '../peaks/util/peakOptimizer'; | ||
import { MakeMandatory } from '../utilities/MakeMandatory'; | ||
import type { NMRSignal2D } from './NMRSignal2D'; | ||
import { NMRZone } from './NMRZone'; | ||
import { formatZones } from './util/formatZone'; | ||
@@ -93,6 +97,12 @@ | ||
export type NMRSignal2DWithID<T extends Peak2D = Peak2D> = MakeMandatory< | ||
NMRSignal2D<T>, | ||
'id' | ||
>; | ||
export type NMRZoneWithID = MakeMandatory<NMRZone, 'id'>; | ||
export function xyzAutoZonesPicking( | ||
spectraData: Data2D, | ||
options: XYZAutoZonesPickingOptions, | ||
) { | ||
): NMRZoneWithID[] { | ||
let { | ||
@@ -167,3 +177,3 @@ sizeToPad = 14, | ||
let signals = createSignals2D(peaksMC1, { | ||
let signals = createSignals2D(addMissingIDs(peaksMC1), { | ||
nRows: nbSubSpectra, | ||
@@ -210,3 +220,7 @@ nCols: nbPoints, | ||
} | ||
const createSignals2D = (peaks: Peak2D[], options: CreateSignals2DOptions) => { | ||
function createSignals2D<T extends Peak2D>( | ||
peaks: T[], | ||
options: CreateSignals2DOptions, | ||
) { | ||
let { | ||
@@ -275,6 +289,7 @@ nCols, | ||
let signals: NMRSignal2D[] = []; | ||
let signals: NMRSignal2DWithID<T>[] = []; | ||
if (clusters) { | ||
for (const cluster of clusters) { | ||
let signal: any = { | ||
id: generateID(), | ||
x: { | ||
@@ -291,3 +306,3 @@ delta: 0, | ||
}; | ||
let peaks2D: Peak2D[] = []; | ||
let peaks2D: T[] = []; | ||
let sumZ = 0; | ||
@@ -307,9 +322,9 @@ | ||
signal.peaks = peaks2D; | ||
signals.push(signal as NMRSignal2D); | ||
signals.push(signal as NMRSignal2DWithID<T>); | ||
} | ||
} | ||
return signals; | ||
}; | ||
} | ||
const padData = (spectraData: Data2D, options: { width: number }) => { | ||
function padData(spectraData: Data2D, options: { width: number }) { | ||
let { minX, maxX, minY, maxY } = spectraData; | ||
@@ -346,2 +361,2 @@ | ||
}; | ||
}; | ||
} |
@@ -0,4 +1,6 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import type { Peak2D } from 'ml-matrix-peaks-finder'; | ||
import simpleClustering from 'ml-simple-clustering'; | ||
import { addMissingIDs } from '../peaks/util/addMissingIDs'; | ||
import type { JAxisKeys } from '../signals/utils/jAnalyzer'; | ||
@@ -11,2 +13,4 @@ import jAnalyzer from '../signals/utils/jAnalyzer'; | ||
const { parse, stringify } = JSON; | ||
interface CompilePatternOptions { | ||
@@ -37,2 +41,14 @@ observedFrequencies?: number[] | Float64Array; | ||
interface Peak2DInternalCompiler extends Peak2D { | ||
width?: number; | ||
} | ||
type Signal2DInternalCompiler = Omit<NMRSignal2D, 'peaks'> & { | ||
peaks: Peak2DInternalCompiler[]; | ||
integralData: { from: number; to: number }; | ||
nbPeaks: number; | ||
multiplicity: string; | ||
pattern: string; | ||
observe: number; | ||
}; | ||
type CompilePatternOptionsMandatory = MakeMandatory< | ||
@@ -58,3 +74,3 @@ CompilePatternOptions, | ||
} = options; | ||
let temporalSignals = compilePattern([...signals], { | ||
let temporalSignals = compilePattern(signals, { | ||
observedFrequencies, | ||
@@ -72,2 +88,5 @@ tolerances, | ||
} | ||
signals2D = addMissingIDs(signals2D); | ||
return getZones ? formatZones(signals2D) : signals2D; | ||
@@ -96,3 +115,3 @@ } | ||
const defaultWidth = 0.02 * observedFrequencies[0]; | ||
const newSignals = JSON.parse(JSON.stringify(signals)); | ||
const newSignals = parse(stringify(signals)); | ||
//adapt to 1D jAnalyzer | ||
@@ -154,18 +173,6 @@ for (const signal of newSignals) { | ||
interface Peak2DHack extends Peak2D { | ||
width?: number; | ||
} | ||
type Signal2DHack = Omit<NMRSignal2D, 'peaks'> & { | ||
peaks: Peak2DHack[]; | ||
integralData: { from: number; to: number }; | ||
nbPeaks: number; | ||
multiplicity: string; | ||
pattern: string; | ||
observe: number; | ||
}; | ||
function createSignals2D(peaksInput: Peak2D[], options: any) { | ||
let { observedFrequencies, tolerances, nuclei, dx, dy } = options; | ||
const peaks: Peak2DHack[] = JSON.parse(JSON.stringify(peaksInput)); | ||
const peaks: Peak2DInternalCompiler[] = parse(stringify(peaksInput)); | ||
@@ -198,2 +205,3 @@ let [nucleusX, nucleusY] = nuclei; | ||
let signal: any = { | ||
id: generateID(), | ||
nucleusX, | ||
@@ -249,3 +257,3 @@ nucleusY, | ||
signal.peaks = peaks2D; | ||
signals.push(signal as Signal2DHack); | ||
signals.push(signal as Signal2DInternalCompiler); | ||
} | ||
@@ -252,0 +260,0 @@ } |
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
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
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
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
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
4344800
0.2%652
0.93%118213
0.13%24
4.35%