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

ml-gsd

Package Overview
Dependencies
Maintainers
9
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-gsd - npm Package Compare versions

Comparing version 11.3.0 to 12.0.0-pre.1661358412

lib-esm/utils/addMissingIDs.d.ts

6

lib-esm/gsd.d.ts

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

import { GSDPeak } from './GSDPeak';
import { MakeMandatory } from './utils/MakeMandatory';
import { MakeOptional } from './utils/MakeOptional';
export interface GSDOptions {

@@ -45,2 +47,4 @@ /**

}
export declare type GSDPeakID = MakeMandatory<GSDPeak, 'id'>;
export declare type GSDPeakIDOptionalShape = MakeOptional<GSDPeak, 'shape'>;
/**

@@ -53,3 +57,3 @@ * Global spectra deconvolution

*/
export declare function gsd(data: DataXY, options?: GSDOptions): GSDPeak[];
export declare function gsd(data: DataXY, options?: GSDOptions): GSDPeakID[];
//# sourceMappingURL=gsd.d.ts.map

6

lib-esm/gsd.js

@@ -0,5 +1,6 @@

import { v4 as generateID } from '@lukeed/uuid';
import { sgg } from 'ml-savitzky-golay-generalized';
import { xIsEquallySpaced, xIsMonotoneIncreasing, xMinValue, xMaxValue, xNoiseStandardDeviation, } from 'ml-spectra-processing';
import { appendShapeAndFWHM } from './utils/appendShapeAndFWHM';
import { optimizeTop } from './utils/optimizeTop';
import { setShape } from './utils/setShape';
/**

@@ -164,2 +165,3 @@ * Global spectra deconvolution

peaks.push({
id: generateID(),
x: deltaX,

@@ -190,4 +192,4 @@ y: yData[minddYIndex],

});
return appendShapeAndFWHM(peaks, { shape });
return setShape(peaks, { shape });
}
//# sourceMappingURL=gsd.js.map

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

import { Shape1D } from 'ml-peak-shape-generator';
export interface GSDBroadenPeak {
id?: string;
x: number;
y: number;
width: number;
shape?: Shape1D;
index: number;

@@ -6,0 +9,0 @@ from: {

import { Shape1D } from 'ml-peak-shape-generator';
export interface GSDPeak {
id?: string;
x: number;

@@ -4,0 +5,0 @@ y: number;

import { Shape1D } from 'ml-peak-shape-generator';
export interface GSDPeakOptimized {
id?: string;
x: number;

@@ -4,0 +5,0 @@ y: number;

@@ -6,3 +6,4 @@ export * from './gsd';

export * from './post/broadenPeaks';
export * from './utils/appendShapeAndFWHM';
export * from './utils/setShape';
export * from './utils/addMissingShape';
export * from './GSDBroadenPeak';

@@ -9,0 +10,0 @@ export * from './GSDPeak';

@@ -6,3 +6,4 @@ export * from './gsd';

export * from './post/broadenPeaks';
export * from './utils/appendShapeAndFWHM';
export * from './utils/setShape';
export * from './utils/addMissingShape';
export * from './GSDBroadenPeak';

@@ -9,0 +10,0 @@ export * from './GSDPeak';

@@ -0,3 +1,19 @@

import { Shape1D } from 'ml-peak-shape-generator';
import { GSDBroadenPeak } from '../GSDBroadenPeak';
import { GSDPeak } from '../GSDPeak';
import { MakeOptional } from '../utils/MakeOptional';
declare type GSDPeakOptionalShape = MakeOptional<GSDPeak, 'shape'>;
declare type GSDBroadenPeakWithID = GSDBroadenPeak & {
id: string;
};
declare type GSDBroadenPeakWithShape = GSDBroadenPeak & {
shape: Shape1D;
};
declare type GSDBroadenPeakWithShapeID = GSDBroadenPeakWithID & {
shape: Shape1D;
};
export declare type WithOrWithout<T, ToExtends, TrueType, FalseType> = T extends ToExtends ? TrueType : FalseType;
export declare type WithIDOrShape<T> = T extends {
id: string;
} ? WithOrWithout<T, GSDPeak, GSDBroadenPeakWithShapeID, GSDBroadenPeakWithID> : WithOrWithout<T, GSDPeak, GSDBroadenPeakWithShape, GSDBroadenPeak>;
/**

@@ -10,3 +26,3 @@ * This method will allow to enlarge peaks while preventing overlap between peaks

*/
export declare function broadenPeaks(peakList: Omit<GSDPeak, 'shape'>[], options?: {
export declare function broadenPeaks<T extends GSDPeakOptionalShape>(peakList: T[], options?: {
/**

@@ -21,3 +37,4 @@ * @default 2

overlap?: boolean;
}): GSDBroadenPeak[];
}): WithIDOrShape<T>[];
export {};
//# sourceMappingURL=broadenPeaks.d.ts.map

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

import { getShape1D } from 'ml-peak-shape-generator';
/**

@@ -10,14 +11,3 @@ * This method will allow to enlarge peaks while preventing overlap between peaks

const { factor = 2, overlap = false } = options;
const peaks = peakList.map((peak) => {
const xFrom = peak.x - (peak.x - peak.inflectionPoints.from.x) * factor;
const xTo = peak.x + (peak.inflectionPoints.to.x - peak.x) * factor;
return {
x: peak.x,
y: peak.y,
index: peak.index,
width: xTo - xFrom,
from: { x: xFrom },
to: { x: xTo },
};
});
const peaks = mapPeaks(peakList, factor);
if (!overlap) {

@@ -35,7 +25,36 @@ for (let i = 0; i < peaks.length - 1; i++) {

}
for (let peak of peaks) {
for (const peak of peaks) {
peak.width = peak.to.x - peak.from.x;
if (peak.shape) {
const { shape, width } = peak;
if (shape.fwhm !== undefined) {
const shapeFct = getShape1D(shape);
peak.shape.fwhm = shapeFct.widthToFWHM(width);
}
}
}
return peaks;
}
function mapPeaks(peaks, factor) {
return peaks.map((peak) => {
const { id, shape } = peak;
const xFrom = peak.x - (peak.x - peak.inflectionPoints.from.x) * factor;
const xTo = peak.x + (peak.inflectionPoints.to.x - peak.x) * factor;
let result = {
x: peak.x,
y: peak.y,
index: peak.index,
width: xTo - xFrom,
from: { x: xFrom },
to: { x: xTo },
};
if (id) {
result = { ...result, id };
}
if (shape) {
result = { ...result, shape };
}
return result;
});
}
//# sourceMappingURL=broadenPeaks.js.map
import type { Shape1D } from 'ml-peak-shape-generator';
import { OptimizationOptions } from 'ml-spectra-fitting';
import { GSDPeak } from '../GSDPeak';
import { MakeOptional } from '../utils/MakeOptional';
import { GSDPeakOptimizedID } from './optimizePeaksWithLogs';
export interface JoinBroadPeaksOptions {

@@ -27,3 +29,4 @@ /**

*/
export declare function joinBroadPeaks(peakList: GSDPeak[], options?: JoinBroadPeaksOptions): GSDPeak[];
export declare type GSDPeakOptionalShape = MakeOptional<GSDPeak, 'shape'>;
export declare function joinBroadPeaks<T extends GSDPeakOptionalShape>(peakList: T[], options?: JoinBroadPeaksOptions): GSDPeakOptimizedID[];
//# sourceMappingURL=joinBroadPeaks.d.ts.map

@@ -1,6 +0,5 @@

import { appendShapeAndFWHM } from '../utils/appendShapeAndFWHM';
import { v4 as generateID } from '@lukeed/uuid';
import { addMissingIDs } from '../utils/addMissingIDs';
import { addMissingShape } from '../utils/addMissingShape';
import { optimizePeaks } from './optimizePeaks';
/**
* This function tries to join the peaks that seems to belong to a broad signal in a single broad peak.
*/
export function joinBroadPeaks(peakList, options = {}) {

@@ -12,5 +11,5 @@ let { shape = { kind: 'gaussian' }, optimization = { kind: 'lm', options: { timeout: 10 } }, broadWidth = 0.25, broadRatio = 0.0025, } = options;

const broadLines = [];
const peaks = appendShapeAndFWHM(peakList, { shape });
if (peaks.length < 2)
return peaks;
if (peakList.length < 2) {
return addMissingIDs(addMissingShape(peakList.map(getGSDPeakOptimizedStructure), { shape }));
}
let maxDdy = peakList[0].ddY;

@@ -21,6 +20,10 @@ for (let i = 1; i < peakList.length; i++) {

}
for (let i = peaks.length - 1; i >= 0; i--) {
if (Math.abs(peaks[i].ddY) <= broadRatio * maxDdy) {
broadLines.push(peaks.splice(i, 1)[0]);
const newPeaks = [];
for (const peak of peakList) {
if (Math.abs(peak.ddY) <= broadRatio * maxDdy) {
broadLines.push(peak);
}
else {
newPeaks.push(getGSDPeakOptimizedStructure(peak));
}
}

@@ -49,2 +52,3 @@ //@ts-expect-error Push a feke peak

{
id: generateID(),
x: broadLines[maxI].x,

@@ -55,11 +59,9 @@ y: max,

], { shape, optimization });
//@ts-expect-error type is equal as expected
peaks.push(fitted[0]);
newPeaks.push(fitted[0]);
}
else {
// Put back the candidates to the peak list
indexes.forEach((index) => {
// @ts-expect-error todo 2
peaks.push(broadLines[index]);
});
for (const index of indexes) {
newPeaks.push(getGSDPeakOptimizedStructure(broadLines[index]));
}
}

@@ -73,7 +75,19 @@ candidates = { x: [broadLines[i].x], y: [broadLines[i].y] };

}
peaks.sort((a, b) => {
newPeaks.sort((a, b) => {
return a.x - b.x;
});
return peaks;
return addMissingIDs(newPeaks, { output: newPeaks });
}
function getGSDPeakOptimizedStructure(peak) {
const { id, shape, x, y, width } = peak;
let newPeak = {
x,
y,
width,
shape,
};
if (id)
newPeak.id = id;
return newPeak;
}
//# sourceMappingURL=joinBroadPeaks.js.map

@@ -1,6 +0,6 @@

import type { DataXY, PeakXYWidth } from 'cheminfo-types';
import type { DataXY } from 'cheminfo-types';
import { FromTo } from 'cheminfo-types';
import { Shape1D } from 'ml-peak-shape-generator';
import type { OptimizationOptions } from 'ml-spectra-fitting';
import { GSDPeakOptimized } from '../GSDPeakOptimized';
import { Peak } from './optimizePeaksWithLogs';
export interface OptimizePeaksOptions {

@@ -41,3 +41,5 @@ /**

*/
export declare function optimizePeaks(data: DataXY, peakList: PeakXYWidth[], options?: OptimizePeaksOptions): GSDPeakOptimized[];
export declare function optimizePeaks<T extends Peak>(data: DataXY, peakList: T[], options?: OptimizePeaksOptions): (T extends {
id: string;
} ? import("./optimizePeaksWithLogs").GSDPeakOptimizedID : import("..").GSDPeakOptimized)[];
//# sourceMappingURL=optimizePeaks.d.ts.map
import type { DataXY, PeakXYWidth } from 'cheminfo-types';
import { GSDPeakOptimized } from '../GSDPeakOptimized';
import { MakeMandatory } from '../utils/MakeMandatory';
import { OptimizePeaksOptions } from './optimizePeaks';
export interface Peak extends PeakXYWidth {
id?: string;
}
export declare type GSDPeakOptimizedID = MakeMandatory<GSDPeakOptimized, 'id'>;
declare type GSDPeakOptimizedIDOrNot<T extends Peak> = T extends {
id: string;
} ? GSDPeakOptimizedID : GSDPeakOptimized;
/**

@@ -10,6 +18,7 @@ * Optimize the position (x), max intensity (y), full width at half maximum (fwhm)

*/
export declare function optimizePeaksWithLogs(data: DataXY, peakList: PeakXYWidth[], options?: OptimizePeaksOptions): {
export declare function optimizePeaksWithLogs<T extends Peak>(data: DataXY, peakList: T[], options?: OptimizePeaksOptions): {
logs: any[];
optimizedPeaks: GSDPeakOptimized[];
optimizedPeaks: GSDPeakOptimizedIDOrNot<T>[];
};
export {};
//# sourceMappingURL=optimizePeaksWithLogs.d.ts.map
import { getShape1D } from 'ml-peak-shape-generator';
import { optimize } from 'ml-spectra-fitting';
import { xGetFromToIndex } from 'ml-spectra-processing';
import { appendShapeAndFWHM } from '../utils/appendShapeAndFWHM';
import { addMissingShape } from '../utils/addMissingShape';
import { groupPeaks } from '../utils/groupPeaks';

@@ -30,3 +30,3 @@ /**

// In order to make optimization we will add fwhm and shape on all the peaks
const peaks = appendShapeAndFWHM(peakGroup, { shape });
const peaks = addMissingShape(peakGroup, { shape });
const firstPeak = peaks[0];

@@ -68,3 +68,3 @@ const lastPeak = peaks[peaks.length - 1];

else {
results = results.concat(peaks);
results.push(...peaks);
logs.push({

@@ -71,0 +71,0 @@ ...log,

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

import { GSDPeak } from './GSDPeak';
import { MakeMandatory } from './utils/MakeMandatory';
import { MakeOptional } from './utils/MakeOptional';
export interface GSDOptions {

@@ -45,2 +47,4 @@ /**

}
export declare type GSDPeakID = MakeMandatory<GSDPeak, 'id'>;
export declare type GSDPeakIDOptionalShape = MakeOptional<GSDPeak, 'shape'>;
/**

@@ -53,3 +57,3 @@ * Global spectra deconvolution

*/
export declare function gsd(data: DataXY, options?: GSDOptions): GSDPeak[];
export declare function gsd(data: DataXY, options?: GSDOptions): GSDPeakID[];
//# sourceMappingURL=gsd.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.gsd = void 0;
const uuid_1 = require("@lukeed/uuid");
const ml_savitzky_golay_generalized_1 = require("ml-savitzky-golay-generalized");
const ml_spectra_processing_1 = require("ml-spectra-processing");
const appendShapeAndFWHM_1 = require("./utils/appendShapeAndFWHM");
const optimizeTop_1 = require("./utils/optimizeTop");
const setShape_1 = require("./utils/setShape");
/**

@@ -167,2 +168,3 @@ * Global spectra deconvolution

peaks.push({
id: (0, uuid_1.v4)(),
x: deltaX,

@@ -193,5 +195,5 @@ y: yData[minddYIndex],

});
return (0, appendShapeAndFWHM_1.appendShapeAndFWHM)(peaks, { shape });
return (0, setShape_1.setShape)(peaks, { shape });
}
exports.gsd = gsd;
//# sourceMappingURL=gsd.js.map

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

import { Shape1D } from 'ml-peak-shape-generator';
export interface GSDBroadenPeak {
id?: string;
x: number;
y: number;
width: number;
shape?: Shape1D;
index: number;

@@ -6,0 +9,0 @@ from: {

import { Shape1D } from 'ml-peak-shape-generator';
export interface GSDPeak {
id?: string;
x: number;

@@ -4,0 +5,0 @@ y: number;

import { Shape1D } from 'ml-peak-shape-generator';
export interface GSDPeakOptimized {
id?: string;
x: number;

@@ -4,0 +5,0 @@ y: number;

@@ -6,3 +6,4 @@ export * from './gsd';

export * from './post/broadenPeaks';
export * from './utils/appendShapeAndFWHM';
export * from './utils/setShape';
export * from './utils/addMissingShape';
export * from './GSDBroadenPeak';

@@ -9,0 +10,0 @@ export * from './GSDPeak';

@@ -22,3 +22,4 @@ "use strict";

__exportStar(require("./post/broadenPeaks"), exports);
__exportStar(require("./utils/appendShapeAndFWHM"), exports);
__exportStar(require("./utils/setShape"), exports);
__exportStar(require("./utils/addMissingShape"), exports);
__exportStar(require("./GSDBroadenPeak"), exports);

@@ -25,0 +26,0 @@ __exportStar(require("./GSDPeak"), exports);

@@ -0,3 +1,19 @@

import { Shape1D } from 'ml-peak-shape-generator';
import { GSDBroadenPeak } from '../GSDBroadenPeak';
import { GSDPeak } from '../GSDPeak';
import { MakeOptional } from '../utils/MakeOptional';
declare type GSDPeakOptionalShape = MakeOptional<GSDPeak, 'shape'>;
declare type GSDBroadenPeakWithID = GSDBroadenPeak & {
id: string;
};
declare type GSDBroadenPeakWithShape = GSDBroadenPeak & {
shape: Shape1D;
};
declare type GSDBroadenPeakWithShapeID = GSDBroadenPeakWithID & {
shape: Shape1D;
};
export declare type WithOrWithout<T, ToExtends, TrueType, FalseType> = T extends ToExtends ? TrueType : FalseType;
export declare type WithIDOrShape<T> = T extends {
id: string;
} ? WithOrWithout<T, GSDPeak, GSDBroadenPeakWithShapeID, GSDBroadenPeakWithID> : WithOrWithout<T, GSDPeak, GSDBroadenPeakWithShape, GSDBroadenPeak>;
/**

@@ -10,3 +26,3 @@ * This method will allow to enlarge peaks while preventing overlap between peaks

*/
export declare function broadenPeaks(peakList: Omit<GSDPeak, 'shape'>[], options?: {
export declare function broadenPeaks<T extends GSDPeakOptionalShape>(peakList: T[], options?: {
/**

@@ -21,3 +37,4 @@ * @default 2

overlap?: boolean;
}): GSDBroadenPeak[];
}): WithIDOrShape<T>[];
export {};
//# sourceMappingURL=broadenPeaks.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.broadenPeaks = void 0;
const ml_peak_shape_generator_1 = require("ml-peak-shape-generator");
/**

@@ -13,14 +14,3 @@ * This method will allow to enlarge peaks while preventing overlap between peaks

const { factor = 2, overlap = false } = options;
const peaks = peakList.map((peak) => {
const xFrom = peak.x - (peak.x - peak.inflectionPoints.from.x) * factor;
const xTo = peak.x + (peak.inflectionPoints.to.x - peak.x) * factor;
return {
x: peak.x,
y: peak.y,
index: peak.index,
width: xTo - xFrom,
from: { x: xFrom },
to: { x: xTo },
};
});
const peaks = mapPeaks(peakList, factor);
if (!overlap) {

@@ -38,4 +28,11 @@ for (let i = 0; i < peaks.length - 1; i++) {

}
for (let peak of peaks) {
for (const peak of peaks) {
peak.width = peak.to.x - peak.from.x;
if (peak.shape) {
const { shape, width } = peak;
if (shape.fwhm !== undefined) {
const shapeFct = (0, ml_peak_shape_generator_1.getShape1D)(shape);
peak.shape.fwhm = shapeFct.widthToFWHM(width);
}
}
}

@@ -45,2 +42,24 @@ return peaks;

exports.broadenPeaks = broadenPeaks;
function mapPeaks(peaks, factor) {
return peaks.map((peak) => {
const { id, shape } = peak;
const xFrom = peak.x - (peak.x - peak.inflectionPoints.from.x) * factor;
const xTo = peak.x + (peak.inflectionPoints.to.x - peak.x) * factor;
let result = {
x: peak.x,
y: peak.y,
index: peak.index,
width: xTo - xFrom,
from: { x: xFrom },
to: { x: xTo },
};
if (id) {
result = { ...result, id };
}
if (shape) {
result = { ...result, shape };
}
return result;
});
}
//# sourceMappingURL=broadenPeaks.js.map
import type { Shape1D } from 'ml-peak-shape-generator';
import { OptimizationOptions } from 'ml-spectra-fitting';
import { GSDPeak } from '../GSDPeak';
import { MakeOptional } from '../utils/MakeOptional';
import { GSDPeakOptimizedID } from './optimizePeaksWithLogs';
export interface JoinBroadPeaksOptions {

@@ -27,3 +29,4 @@ /**

*/
export declare function joinBroadPeaks(peakList: GSDPeak[], options?: JoinBroadPeaksOptions): GSDPeak[];
export declare type GSDPeakOptionalShape = MakeOptional<GSDPeak, 'shape'>;
export declare function joinBroadPeaks<T extends GSDPeakOptionalShape>(peakList: T[], options?: JoinBroadPeaksOptions): GSDPeakOptimizedID[];
//# sourceMappingURL=joinBroadPeaks.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.joinBroadPeaks = void 0;
const appendShapeAndFWHM_1 = require("../utils/appendShapeAndFWHM");
const uuid_1 = require("@lukeed/uuid");
const addMissingIDs_1 = require("../utils/addMissingIDs");
const addMissingShape_1 = require("../utils/addMissingShape");
const optimizePeaks_1 = require("./optimizePeaks");
/**
* This function tries to join the peaks that seems to belong to a broad signal in a single broad peak.
*/
function joinBroadPeaks(peakList, options = {}) {

@@ -15,5 +14,5 @@ let { shape = { kind: 'gaussian' }, optimization = { kind: 'lm', options: { timeout: 10 } }, broadWidth = 0.25, broadRatio = 0.0025, } = options;

const broadLines = [];
const peaks = (0, appendShapeAndFWHM_1.appendShapeAndFWHM)(peakList, { shape });
if (peaks.length < 2)
return peaks;
if (peakList.length < 2) {
return (0, addMissingIDs_1.addMissingIDs)((0, addMissingShape_1.addMissingShape)(peakList.map(getGSDPeakOptimizedStructure), { shape }));
}
let maxDdy = peakList[0].ddY;

@@ -24,6 +23,10 @@ for (let i = 1; i < peakList.length; i++) {

}
for (let i = peaks.length - 1; i >= 0; i--) {
if (Math.abs(peaks[i].ddY) <= broadRatio * maxDdy) {
broadLines.push(peaks.splice(i, 1)[0]);
const newPeaks = [];
for (const peak of peakList) {
if (Math.abs(peak.ddY) <= broadRatio * maxDdy) {
broadLines.push(peak);
}
else {
newPeaks.push(getGSDPeakOptimizedStructure(peak));
}
}

@@ -52,2 +55,3 @@ //@ts-expect-error Push a feke peak

{
id: (0, uuid_1.v4)(),
x: broadLines[maxI].x,

@@ -58,11 +62,9 @@ y: max,

], { shape, optimization });
//@ts-expect-error type is equal as expected
peaks.push(fitted[0]);
newPeaks.push(fitted[0]);
}
else {
// Put back the candidates to the peak list
indexes.forEach((index) => {
// @ts-expect-error todo 2
peaks.push(broadLines[index]);
});
for (const index of indexes) {
newPeaks.push(getGSDPeakOptimizedStructure(broadLines[index]));
}
}

@@ -76,8 +78,20 @@ candidates = { x: [broadLines[i].x], y: [broadLines[i].y] };

}
peaks.sort((a, b) => {
newPeaks.sort((a, b) => {
return a.x - b.x;
});
return peaks;
return (0, addMissingIDs_1.addMissingIDs)(newPeaks, { output: newPeaks });
}
exports.joinBroadPeaks = joinBroadPeaks;
function getGSDPeakOptimizedStructure(peak) {
const { id, shape, x, y, width } = peak;
let newPeak = {
x,
y,
width,
shape,
};
if (id)
newPeak.id = id;
return newPeak;
}
//# sourceMappingURL=joinBroadPeaks.js.map

@@ -1,6 +0,6 @@

import type { DataXY, PeakXYWidth } from 'cheminfo-types';
import type { DataXY } from 'cheminfo-types';
import { FromTo } from 'cheminfo-types';
import { Shape1D } from 'ml-peak-shape-generator';
import type { OptimizationOptions } from 'ml-spectra-fitting';
import { GSDPeakOptimized } from '../GSDPeakOptimized';
import { Peak } from './optimizePeaksWithLogs';
export interface OptimizePeaksOptions {

@@ -41,3 +41,5 @@ /**

*/
export declare function optimizePeaks(data: DataXY, peakList: PeakXYWidth[], options?: OptimizePeaksOptions): GSDPeakOptimized[];
export declare function optimizePeaks<T extends Peak>(data: DataXY, peakList: T[], options?: OptimizePeaksOptions): (T extends {
id: string;
} ? import("./optimizePeaksWithLogs").GSDPeakOptimizedID : import("..").GSDPeakOptimized)[];
//# sourceMappingURL=optimizePeaks.d.ts.map
import type { DataXY, PeakXYWidth } from 'cheminfo-types';
import { GSDPeakOptimized } from '../GSDPeakOptimized';
import { MakeMandatory } from '../utils/MakeMandatory';
import { OptimizePeaksOptions } from './optimizePeaks';
export interface Peak extends PeakXYWidth {
id?: string;
}
export declare type GSDPeakOptimizedID = MakeMandatory<GSDPeakOptimized, 'id'>;
declare type GSDPeakOptimizedIDOrNot<T extends Peak> = T extends {
id: string;
} ? GSDPeakOptimizedID : GSDPeakOptimized;
/**

@@ -10,6 +18,7 @@ * Optimize the position (x), max intensity (y), full width at half maximum (fwhm)

*/
export declare function optimizePeaksWithLogs(data: DataXY, peakList: PeakXYWidth[], options?: OptimizePeaksOptions): {
export declare function optimizePeaksWithLogs<T extends Peak>(data: DataXY, peakList: T[], options?: OptimizePeaksOptions): {
logs: any[];
optimizedPeaks: GSDPeakOptimized[];
optimizedPeaks: GSDPeakOptimizedIDOrNot<T>[];
};
export {};
//# sourceMappingURL=optimizePeaksWithLogs.d.ts.map

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

const ml_spectra_processing_1 = require("ml-spectra-processing");
const appendShapeAndFWHM_1 = require("../utils/appendShapeAndFWHM");
const addMissingShape_1 = require("../utils/addMissingShape");
const groupPeaks_1 = require("../utils/groupPeaks");

@@ -34,3 +34,3 @@ /**

// In order to make optimization we will add fwhm and shape on all the peaks
const peaks = (0, appendShapeAndFWHM_1.appendShapeAndFWHM)(peakGroup, { shape });
const peaks = (0, addMissingShape_1.addMissingShape)(peakGroup, { shape });
const firstPeak = peaks[0];

@@ -72,3 +72,3 @@ const lastPeak = peaks[peaks.length - 1];

else {
results = results.concat(peaks);
results.push(...peaks);
logs.push({

@@ -75,0 +75,0 @@ ...log,

{
"name": "ml-gsd",
"version": "11.3.0",
"version": "12.0.0-pre.1661358412",
"description": "Global Spectra Deconvolution",

@@ -82,8 +82,9 @@ "main": "./lib/index.js",

"dependencies": {
"@lukeed/uuid": "^2.0.0",
"cheminfo-types": "^1.1.0",
"ml-peak-shape-generator": "^4.1.1",
"ml-savitzky-golay-generalized": "4.0.1",
"ml-spectra-fitting": "4.1.0",
"ml-savitzky-golay-generalized": "^4.0.1",
"ml-spectra-fitting": "^4.1.0",
"ml-spectra-processing": "^11.6.0"
}
}

@@ -36,2 +36,3 @@ import type { DataXY } from 'cheminfo-types';

{
id: peakList[0].id,
x: -0.5,

@@ -52,2 +53,3 @@ y: 0.6945098953985852,

{
id: peakList[1].id,
x: 0.5,

@@ -54,0 +56,0 @@ y: 0.6945098953985852,

@@ -66,3 +66,3 @@ import type { DataXY } from 'cheminfo-types';

];
expect(peakList).toBeDeepCloseTo(expected);
expect(peakList).toBeDeepCloseTo(addMissingID(peakList, expected));
});

@@ -105,3 +105,3 @@

];
expect(peakList).toBeDeepCloseTo(expected);
expect(peakList).toBeDeepCloseTo(addMissingID(peakList, expected));
});

@@ -148,3 +148,3 @@

expect(peakList).toBeDeepCloseTo(expected);
expect(peakList).toBeDeepCloseTo(addMissingID(peakList, expected));
});

@@ -191,3 +191,3 @@

expect(peakList).toBeDeepCloseTo(expected);
expect(peakList).toBeDeepCloseTo(addMissingID(peakList, expected));
});

@@ -203,1 +203,8 @@

});
function addMissingID(peaks, expected) {
for (let i = 0; i < expected.length; i++) {
expected[i].id = peaks[i].id;
}
return expected;
}

@@ -54,2 +54,3 @@ import type { DataXY } from 'cheminfo-types';

{
id: peakList[0].id,
x: 5,

@@ -81,2 +82,3 @@ y: 10000,

{
id: peakList[0].id,
x: 4.45,

@@ -97,2 +99,3 @@ y: 7921,

{
id: peakList[1].id,
x: 5,

@@ -113,2 +116,3 @@ y: 10000,

{
id: peakList[2].id,
x: 5.55,

@@ -115,0 +119,0 @@ y: 7921,

@@ -25,3 +25,5 @@ import { readFileSync } from 'fs';

});
expect(peaks[0]).toBeDeepCloseTo({
id: peaks[0].id,
x: 200.05527917306466,

@@ -28,0 +30,0 @@ y: 28.795378784444413,

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

import { v4 as generateID } from '@lukeed/uuid';
import type { DataXY } from 'cheminfo-types';

@@ -13,4 +14,6 @@ import { Shape1D } from 'ml-peak-shape-generator';

import { GSDPeak } from './GSDPeak';
import { appendShapeAndFWHM } from './utils/appendShapeAndFWHM';
import { MakeMandatory } from './utils/MakeMandatory';
import { MakeOptional } from './utils/MakeOptional';
import { optimizeTop } from './utils/optimizeTop';
import { setShape } from './utils/setShape';

@@ -56,3 +59,4 @@ export interface GSDOptions {

}
export type GSDPeakID = MakeMandatory<GSDPeak, 'id'>;
export type GSDPeakIDOptionalShape = MakeOptional<GSDPeak, 'shape'>;
/**

@@ -66,3 +70,3 @@ * Global spectra deconvolution

export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeak[] {
export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeakID[] {
let {

@@ -223,3 +227,3 @@ sgOptions = {

const peaks: GSDPeak[] = [];
const peaks: GSDPeakIDOptionalShape[] = [];
for (const minddYIndex of minddY) {

@@ -252,2 +256,3 @@ let deltaX = x[minddYIndex];

peaks.push({
id: generateID(),
x: deltaX,

@@ -262,3 +267,3 @@ y: yData[minddYIndex],

},
} as GSDPeak);
});
}

@@ -283,3 +288,3 @@ }

return appendShapeAndFWHM(peaks, { shape });
return setShape(peaks, { shape }) as GSDPeakID[];
}

@@ -0,5 +1,9 @@

import { Shape1D } from 'ml-peak-shape-generator';
export interface GSDBroadenPeak {
id?: string;
x: number;
y: number;
width: number;
shape?: Shape1D;
index: number;

@@ -6,0 +10,0 @@ from: { x: number };

import { Shape1D } from 'ml-peak-shape-generator';
export interface GSDPeak {
id?: string;
x: number;

@@ -5,0 +6,0 @@ y: number;

import { Shape1D } from 'ml-peak-shape-generator';
export interface GSDPeakOptimized {
id?: string;
x: number;

@@ -5,0 +6,0 @@ y: number;

@@ -6,5 +6,6 @@ export * from './gsd';

export * from './post/broadenPeaks';
export * from './utils/appendShapeAndFWHM';
export * from './utils/setShape';
export * from './utils/addMissingShape';
export * from './GSDBroadenPeak';
export * from './GSDPeak';
export * from './GSDPeakOptimized';

@@ -303,2 +303,3 @@ import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';

{
id: '1',
x: -0.5,

@@ -331,2 +332,3 @@ y: 1,

index: 575,
shape: { kind: 'gaussian' },
inflectionPoints: {

@@ -340,29 +342,34 @@ from: { index: 573, x: 10.46 },

);
expect(result).toBeDeepCloseTo([
{
x: -0.5,
y: 1,
index: 25,
width: 1.3,
from: { x: -1.3 },
to: { x: 0 },
},
{
x: 0.5,
y: 1,
index: 75,
width: 1.3,
from: { x: 0 },
to: { x: 1.3 },
},
{
x: 10.5,
y: 1,
index: 575,
width: 1.6,
from: { x: 9.7 },
to: { x: 11.3 },
},
]);
expect(result).toBeDeepCloseTo(
[
{
id: '1',
x: -0.5,
y: 1,
index: 25,
width: 1.3,
from: { x: -1.3 },
to: { x: 0 },
},
{
x: 0.5,
y: 1,
index: 75,
width: 1.3,
from: { x: 0 },
to: { x: 1.3 },
},
{
x: 10.5,
y: 1,
index: 575,
shape: { kind: 'gaussian' },
width: 1.6,
from: { x: 9.7 },
to: { x: 11.3 },
},
],
1,
);
});
});

@@ -29,3 +29,2 @@ import { generateSpectrum } from 'spectrum-generator';

});
expect(peaks.length).toBeGreaterThan(3);

@@ -32,0 +31,0 @@ expect(newPeaks).toHaveLength(3);

@@ -0,4 +1,20 @@

import { getShape1D, Shape1D } from 'ml-peak-shape-generator';
import { GSDBroadenPeak } from '../GSDBroadenPeak';
import { GSDPeak } from '../GSDPeak';
import { MakeOptional } from '../utils/MakeOptional';
type GSDPeakOptionalShape = MakeOptional<GSDPeak, 'shape'>;
type GSDBroadenPeakWithID = GSDBroadenPeak & { id: string };
type GSDBroadenPeakWithShape = GSDBroadenPeak & { shape: Shape1D };
type GSDBroadenPeakWithShapeID = GSDBroadenPeakWithID & { shape: Shape1D };
export type WithOrWithout<T, ToExtends, TrueType, FalseType> =
T extends ToExtends ? TrueType : FalseType;
export type WithIDOrShape<T> = T extends { id: string }
? WithOrWithout<T, GSDPeak, GSDBroadenPeakWithShapeID, GSDBroadenPeakWithID>
: WithOrWithout<T, GSDPeak, GSDBroadenPeakWithShape, GSDBroadenPeak>;
/**

@@ -12,4 +28,4 @@ * This method will allow to enlarge peaks while preventing overlap between peaks

export function broadenPeaks(
peakList: Omit<GSDPeak, 'shape'>[],
export function broadenPeaks<T extends GSDPeakOptionalShape>(
peakList: T[],
options: {

@@ -26,17 +42,6 @@ /**

} = {},
): GSDBroadenPeak[] {
) {
const { factor = 2, overlap = false } = options;
const peaks = peakList.map((peak) => {
const xFrom = peak.x - (peak.x - peak.inflectionPoints.from.x) * factor;
const xTo = peak.x + (peak.inflectionPoints.to.x - peak.x) * factor;
return {
x: peak.x,
y: peak.y,
index: peak.index,
width: xTo - xFrom,
from: { x: xFrom },
to: { x: xTo },
};
});
const peaks = mapPeaks(peakList, factor);

@@ -56,4 +61,11 @@ if (!overlap) {

for (let peak of peaks) {
for (const peak of peaks) {
peak.width = peak.to.x - peak.from.x;
if (peak.shape) {
const { shape, width } = peak;
if (shape.fwhm !== undefined) {
const shapeFct = getShape1D(shape);
peak.shape.fwhm = shapeFct.widthToFWHM(width);
}
}
}

@@ -63,1 +75,33 @@

}
function mapPeaks<T extends GSDPeakOptionalShape>(
peaks: T[],
factor: number,
): WithIDOrShape<T>[] {
return peaks.map((peak) => {
const { id, shape } = peak;
const xFrom = peak.x - (peak.x - peak.inflectionPoints.from.x) * factor;
const xTo = peak.x + (peak.inflectionPoints.to.x - peak.x) * factor;
let result = {
x: peak.x,
y: peak.y,
index: peak.index,
width: xTo - xFrom,
from: { x: xFrom },
to: { x: xTo },
} as GSDBroadenPeak;
if (id) {
result = { ...result, id } as GSDBroadenPeakWithID;
}
if (shape) {
result = { ...result, shape } as T extends { id: string }
? GSDBroadenPeakWithShapeID
: GSDBroadenPeakWithShape;
}
return result as WithIDOrShape<T>;
});
}

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

import { v4 as generateID } from '@lukeed/uuid';
import type { Shape1D } from 'ml-peak-shape-generator';

@@ -6,5 +7,8 @@ import { OptimizationOptions } from 'ml-spectra-fitting';

import { GSDPeakOptimized } from '../GSDPeakOptimized';
import { appendShapeAndFWHM } from '../utils/appendShapeAndFWHM';
import { MakeOptional } from '../utils/MakeOptional';
import { addMissingIDs } from '../utils/addMissingIDs';
import { addMissingShape } from '../utils/addMissingShape';
import { optimizePeaks } from './optimizePeaks';
import { GSDPeakOptimizedID } from './optimizePeaksWithLogs';

@@ -36,6 +40,8 @@ export interface JoinBroadPeaksOptions {

export function joinBroadPeaks(
peakList: GSDPeak[],
export type GSDPeakOptionalShape = MakeOptional<GSDPeak, 'shape'>;
export function joinBroadPeaks<T extends GSDPeakOptionalShape>(
peakList: T[],
options: JoinBroadPeaksOptions = {},
): GSDPeak[] {
): GSDPeakOptimizedID[] {
let {

@@ -51,6 +57,9 @@ shape = { kind: 'gaussian' },

let count = 1;
const broadLines: GSDPeakOptimized[] = [];
const peaks = appendShapeAndFWHM(peakList, { shape });
const broadLines: T[] = [];
if (peaks.length < 2) return peaks;
if (peakList.length < 2) {
return addMissingIDs(
addMissingShape(peakList.map(getGSDPeakOptimizedStructure), { shape }),
);
}

@@ -62,5 +71,8 @@ let maxDdy = peakList[0].ddY;

for (let i: number = peaks.length - 1; i >= 0; i--) {
if (Math.abs(peaks[i].ddY) <= broadRatio * maxDdy) {
broadLines.push(peaks.splice(i, 1)[0]);
const newPeaks: GSDPeakOptimized[] = [];
for (const peak of peakList) {
if (Math.abs(peak.ddY) <= broadRatio * maxDdy) {
broadLines.push(peak);
} else {
newPeaks.push(getGSDPeakOptimizedStructure(peak));
}

@@ -93,2 +105,3 @@ }

{
id: generateID(),
x: broadLines[maxI].x,

@@ -101,10 +114,8 @@ y: max,

);
//@ts-expect-error type is equal as expected
peaks.push(fitted[0]);
newPeaks.push(fitted[0]);
} else {
// Put back the candidates to the peak list
indexes.forEach((index) => {
// @ts-expect-error todo 2
peaks.push(broadLines[index]);
});
for (const index of indexes) {
newPeaks.push(getGSDPeakOptimizedStructure(broadLines[index]));
}
}

@@ -119,7 +130,22 @@

}
peaks.sort((a, b) => {
newPeaks.sort((a, b) => {
return a.x - b.x;
});
return peaks;
return addMissingIDs(newPeaks, { output: newPeaks });
}
function getGSDPeakOptimizedStructure<T extends GSDPeakOptionalShape>(peak: T) {
const { id, shape, x, y, width } = peak;
let newPeak = {
x,
y,
width,
shape,
} as GSDPeakOptimized;
if (id) newPeak.id = id;
return newPeak;
}

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

import type { DataXY, PeakXYWidth } from 'cheminfo-types';
import type { DataXY } from 'cheminfo-types';
import { FromTo } from 'cheminfo-types';

@@ -6,6 +6,4 @@ import { Shape1D } from 'ml-peak-shape-generator';

import { GSDPeakOptimized } from '../GSDPeakOptimized';
import { Peak, optimizePeaksWithLogs } from './optimizePeaksWithLogs';
import { optimizePeaksWithLogs } from './optimizePeaksWithLogs';
export interface OptimizePeaksOptions {

@@ -47,8 +45,8 @@ /**

*/
export function optimizePeaks(
export function optimizePeaks<T extends Peak>(
data: DataXY,
peakList: PeakXYWidth[],
peakList: T[],
options: OptimizePeaksOptions = {},
): GSDPeakOptimized[] {
) {
return optimizePeaksWithLogs(data, peakList, options).optimizedPeaks;
}

@@ -7,3 +7,4 @@ import type { DataXY, PeakXYWidth } from 'cheminfo-types';

import { GSDPeakOptimized } from '../GSDPeakOptimized';
import { appendShapeAndFWHM } from '../utils/appendShapeAndFWHM';
import { MakeMandatory } from '../utils/MakeMandatory';
import { addMissingShape } from '../utils/addMissingShape';
import { groupPeaks } from '../utils/groupPeaks';

@@ -13,2 +14,14 @@

export interface Peak extends PeakXYWidth {
id?: string;
}
export type GSDPeakOptimizedID = MakeMandatory<GSDPeakOptimized, 'id'>;
type GSDPeakOptimizedIDOrNot<T extends Peak> = T extends {
id: string;
}
? GSDPeakOptimizedID
: GSDPeakOptimized;
/**

@@ -20,7 +33,7 @@ * Optimize the position (x), max intensity (y), full width at half maximum (fwhm)

*/
export function optimizePeaksWithLogs(
export function optimizePeaksWithLogs<T extends Peak>(
data: DataXY,
peakList: PeakXYWidth[],
peakList: T[],
options: OptimizePeaksOptions = {},
): { logs: any[]; optimizedPeaks: GSDPeakOptimized[] } {
): { logs: any[]; optimizedPeaks: GSDPeakOptimizedIDOrNot<T>[] } {
const {

@@ -47,7 +60,7 @@ fromTo = {},

let logs: any[] = [];
let results: GSDPeakOptimized[] = [];
let results: GSDPeakOptimizedIDOrNot<T>[] = [];
groups.forEach((peakGroup) => {
const start = Date.now();
// In order to make optimization we will add fwhm and shape on all the peaks
const peaks = appendShapeAndFWHM(peakGroup, { shape });
const peaks = addMissingShape(peakGroup, { shape });

@@ -97,3 +110,3 @@ const firstPeak = peaks[0];

),
});
} as GSDPeakOptimizedIDOrNot<T>);
}

@@ -107,3 +120,3 @@ logs.push({

} else {
results = results.concat(peaks);
results.push(...(peaks as GSDPeakOptimizedIDOrNot<T>[]));
logs.push({

@@ -110,0 +123,0 @@ ...log,

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

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