New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 12.0.0-pre.1661365726 to 12.0.0-pre.1661396593

lib-esm/utils/GSDPeakShape.d.ts

6

lib-esm/gsd.d.ts

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

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

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

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

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

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

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

import { v4 as generateID } from '@lukeed/uuid';
import { sgg } from 'ml-savitzky-golay-generalized';

@@ -165,3 +164,2 @@ import { xIsEquallySpaced, xIsMonotoneIncreasing, xMinValue, xMaxValue, xNoiseStandardDeviation, } from 'ml-spectra-processing';

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

@@ -168,0 +166,0 @@ y: yData[minddYIndex],

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

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

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

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

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

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

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

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

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>;
/**

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

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

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

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

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

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

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

const { factor = 2, overlap = false } = options;
const peaks = mapPeaks(peakList, factor);
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 },
};
});
if (!overlap) {

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

}
for (const peak of peaks) {
for (let 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 {

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

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

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

import { v4 as generateID } from '@lukeed/uuid';
import { addMissingIDs } from '../utils/addMissingIDs';
import { addMissingShape } from '../utils/addMissingShape';

@@ -11,5 +9,5 @@ import { optimizePeaks } from './optimizePeaks';

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

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

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

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

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

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

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

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

}
newPeaks.sort((a, b) => {
peaks.sort((a, b) => {
return a.x - b.x;
});
return addMissingIDs(newPeaks, { output: newPeaks });
return peaks;
}
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 } from 'cheminfo-types';
import type { DataXY, PeakXYWidth } from 'cheminfo-types';
import { FromTo } from 'cheminfo-types';
import { Shape1D } from 'ml-peak-shape-generator';
import type { OptimizationOptions } from 'ml-spectra-fitting';
import { Peak } from './optimizePeaksWithLogs';
import { GSDPeakOptimized } from '../GSDPeakOptimized';
export interface OptimizePeaksOptions {

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

*/
export declare function optimizePeaks<T extends Peak>(data: DataXY, peakList: T[], options?: OptimizePeaksOptions): (T extends {
id: string;
} ? import("./optimizePeaksWithLogs").GSDPeakOptimizedID : import("..").GSDPeakOptimized)[];
export declare function optimizePeaks(data: DataXY, peakList: PeakXYWidth[], options?: OptimizePeaksOptions): 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;
/**

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

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

@@ -67,3 +67,3 @@ import { getShape1D } from 'ml-peak-shape-generator';

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

@@ -70,0 +70,0 @@ ...log,

@@ -8,5 +8,5 @@ import { Shape1D } from 'ml-peak-shape-generator';

width: number;
shape?: Shape1D;
}>(peaks: T[], options?: {
shape?: Shape1D;
output?: T[];
}): (T & {

@@ -13,0 +13,0 @@ shape: Shape1D;

import { getShape1D } from 'ml-peak-shape-generator';
const { parse, stringify } = JSON;
/**

@@ -8,5 +7,5 @@ * add missing property if it does not exist in the peak,

export function addMissingShape(peaks, options = {}) {
const { shape = { kind: 'gaussian' }, output = parse(stringify(peaks)) } = options;
const { shape = { kind: 'gaussian' } } = options;
let shapeInstance = getShape1D(shape);
return output.map((peak) => {
return peaks.map((peak) => {
if (hasShape(peak)) {

@@ -13,0 +12,0 @@ if (!('fwhm' in peak.shape)) {

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

shape?: Shape1D;
output?: T[];
}): (T & {
shape: Shape1D;
shape: {
kind: "gaussian";
fwhm: number;
sd?: number | undefined;
} | {
kind: "lorentzian";
fwhm: number;
} | {
kind: "pseudoVoigt";
fwhm: number;
mu?: number | undefined;
};
})[];
//# sourceMappingURL=setShape.d.ts.map
import { getShape1D } from 'ml-peak-shape-generator';
const { parse, stringify } = JSON;
/**

@@ -7,5 +6,5 @@ * Append 2 properties to the peaks, shape and fwhm

export function setShape(peaks, options = {}) {
let { shape = { kind: 'gaussian' }, output = parse(stringify(peaks)), } = options;
let { shape = { kind: 'gaussian' } } = options;
let shapeInstance = getShape1D(shape);
return output.map((peak) => ({
return peaks.map((peak) => ({
...peak,

@@ -12,0 +11,0 @@ shape: { fwhm: shapeInstance.widthToFWHM(peak.width), ...shape },

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

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

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

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

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

*/
export declare function gsd(data: DataXY, options?: GSDOptions): GSDPeakID[];
export declare function gsd(data: DataXY, options?: GSDOptions): GSDPeak[];
//# 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");

@@ -168,3 +167,2 @@ const ml_spectra_processing_1 = require("ml-spectra-processing");

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

@@ -171,0 +169,0 @@ y: yData[minddYIndex],

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

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

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

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

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

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

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

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

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>;
/**

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

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

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

overlap?: boolean;
}): WithIDOrShape<T>[];
export {};
}): GSDBroadenPeak[];
//# 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");
/**

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

const { factor = 2, overlap = false } = options;
const peaks = mapPeaks(peakList, factor);
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 },
};
});
if (!overlap) {

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

}
for (const peak of peaks) {
for (let 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);
}
}
}

@@ -42,24 +45,2 @@ 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 {

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

*/
export declare type GSDPeakOptionalShape = MakeOptional<GSDPeak, 'shape'>;
export declare function joinBroadPeaks<T extends GSDPeakOptionalShape>(peakList: T[], options?: JoinBroadPeaksOptions): GSDPeakOptimizedID[];
export interface GSDPeakWithOptionalShape extends Omit<GSDPeak, 'shape'> {
shape?: Shape1D;
}
export declare function joinBroadPeaks(peakList: GSDPeakWithOptionalShape[], options?: JoinBroadPeaksOptions): GSDPeak[];
//# sourceMappingURL=joinBroadPeaks.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.joinBroadPeaks = void 0;
const uuid_1 = require("@lukeed/uuid");
const addMissingIDs_1 = require("../utils/addMissingIDs");
const addMissingShape_1 = require("../utils/addMissingShape");

@@ -14,5 +12,5 @@ const optimizePeaks_1 = require("./optimizePeaks");

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

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

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

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

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

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

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

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

}
newPeaks.sort((a, b) => {
peaks.sort((a, b) => {
return a.x - b.x;
});
return (0, addMissingIDs_1.addMissingIDs)(newPeaks, { output: newPeaks });
return peaks;
}
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 } from 'cheminfo-types';
import type { DataXY, PeakXYWidth } from 'cheminfo-types';
import { FromTo } from 'cheminfo-types';
import { Shape1D } from 'ml-peak-shape-generator';
import type { OptimizationOptions } from 'ml-spectra-fitting';
import { Peak } from './optimizePeaksWithLogs';
import { GSDPeakOptimized } from '../GSDPeakOptimized';
export interface OptimizePeaksOptions {

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

*/
export declare function optimizePeaks<T extends Peak>(data: DataXY, peakList: T[], options?: OptimizePeaksOptions): (T extends {
id: string;
} ? import("./optimizePeaksWithLogs").GSDPeakOptimizedID : import("..").GSDPeakOptimized)[];
export declare function optimizePeaks(data: DataXY, peakList: PeakXYWidth[], options?: OptimizePeaksOptions): 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;
/**

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

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

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

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

@@ -73,0 +73,0 @@ ...log,

@@ -8,5 +8,5 @@ import { Shape1D } from 'ml-peak-shape-generator';

width: number;
shape?: Shape1D;
}>(peaks: T[], options?: {
shape?: Shape1D;
output?: T[];
}): (T & {

@@ -13,0 +13,0 @@ shape: Shape1D;

@@ -5,3 +5,2 @@ "use strict";

const ml_peak_shape_generator_1 = require("ml-peak-shape-generator");
const { parse, stringify } = JSON;
/**

@@ -12,5 +11,5 @@ * add missing property if it does not exist in the peak,

function addMissingShape(peaks, options = {}) {
const { shape = { kind: 'gaussian' }, output = parse(stringify(peaks)) } = options;
const { shape = { kind: 'gaussian' } } = options;
let shapeInstance = (0, ml_peak_shape_generator_1.getShape1D)(shape);
return output.map((peak) => {
return peaks.map((peak) => {
if (hasShape(peak)) {

@@ -17,0 +16,0 @@ if (!('fwhm' in peak.shape)) {

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

shape?: Shape1D;
output?: T[];
}): (T & {
shape: Shape1D;
shape: {
kind: "gaussian";
fwhm: number;
sd?: number | undefined;
} | {
kind: "lorentzian";
fwhm: number;
} | {
kind: "pseudoVoigt";
fwhm: number;
mu?: number | undefined;
};
})[];
//# sourceMappingURL=setShape.d.ts.map

@@ -5,3 +5,2 @@ "use strict";

const ml_peak_shape_generator_1 = require("ml-peak-shape-generator");
const { parse, stringify } = JSON;
/**

@@ -11,5 +10,5 @@ * Append 2 properties to the peaks, shape and fwhm

function setShape(peaks, options = {}) {
let { shape = { kind: 'gaussian' }, output = parse(stringify(peaks)), } = options;
let { shape = { kind: 'gaussian' } } = options;
let shapeInstance = (0, ml_peak_shape_generator_1.getShape1D)(shape);
return output.map((peak) => ({
return peaks.map((peak) => ({
...peak,

@@ -16,0 +15,0 @@ shape: { fwhm: shapeInstance.widthToFWHM(peak.width), ...shape },

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

@@ -82,9 +82,8 @@ "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-pre.1661357854",
"ml-spectra-fitting": "^4.1.0",
"ml-spectra-processing": "^11.6.0"
}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@@ -59,4 +56,3 @@ import { setShape } from './utils/setShape';

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

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

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

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

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

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

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

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

},
});
} as GSDPeak);
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

);
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,
);
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 },
},
]);
});
});

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

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

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

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

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>;
/**

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

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

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

} = {},
) {
): GSDBroadenPeak[] {
const { factor = 2, overlap = false } = options;
const peaks = mapPeaks(peakList, factor);
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 },
};
});

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

for (const peak of peaks) {
for (let 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);
}
}
}

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

}
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>;
});
}

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

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

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

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

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

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

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

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

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

const newPeaks: GSDPeakOptimized[] = [];
for (const peak of peakList) {
if (Math.abs(peak.ddY) <= broadRatio * maxDdy) {
broadLines.push(peak);
} else {
newPeaks.push(getGSDPeakOptimizedStructure(peak));
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]);
}

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

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

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

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

@@ -130,22 +122,7 @@

}
newPeaks.sort((a, b) => {
peaks.sort((a, b) => {
return a.x - b.x;
});
return addMissingIDs(newPeaks, { output: newPeaks });
return peaks;
}
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 } from 'cheminfo-types';
import type { DataXY, PeakXYWidth } from 'cheminfo-types';
import { FromTo } from 'cheminfo-types';

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

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

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

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

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

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

@@ -14,14 +13,2 @@ import { groupPeaks } from '../utils/groupPeaks';

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

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

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

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

let logs: any[] = [];
let results: GSDPeakOptimizedIDOrNot<T>[] = [];
let results: GSDPeakOptimized[] = [];
groups.forEach((peakGroup) => {

@@ -110,3 +97,3 @@ const start = Date.now();

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

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

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

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

import { getShape1D, Shape1D } from 'ml-peak-shape-generator';
const { parse, stringify } = JSON;
/**

@@ -9,10 +8,9 @@ * add missing property if it does not exist in the peak,

export function addMissingShape<T extends { width: number }>(
export function addMissingShape<T extends { width: number; shape?: Shape1D }>(
peaks: T[],
options: { shape?: Shape1D; output?: T[] } = {},
options: { shape?: Shape1D } = {},
): (T & { shape: Shape1D })[] {
const { shape = { kind: 'gaussian' }, output = parse(stringify(peaks)) } =
options;
const { shape = { kind: 'gaussian' } } = options;
let shapeInstance = getShape1D(shape);
return output.map((peak) => {
return peaks.map((peak) => {
if (hasShape(peak)) {

@@ -19,0 +17,0 @@ if (!('fwhm' in peak.shape)) {

import { getShape1D, Shape1D } from 'ml-peak-shape-generator';
const { parse, stringify } = JSON;
/**

@@ -17,12 +15,7 @@ * Append 2 properties to the peaks, shape and fwhm

shape?: Shape1D;
output?: T[];
} = {},
): (T & { shape: Shape1D })[] {
let {
shape = { kind: 'gaussian' },
output = parse(stringify(peaks)) as T[],
} = options;
) {
let { shape = { kind: 'gaussian' } } = options;
let shapeInstance = getShape1D(shape);
return output.map((peak) => ({
return peaks.map((peak) => ({
...peak,

@@ -29,0 +22,0 @@ shape: { fwhm: shapeInstance.widthToFWHM(peak.width), ...shape },

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

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