isotopic-distribution
Advanced tools
Comparing version 3.2.0 to 3.2.1
{ | ||
"name": "isotopic-distribution", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "Calculate the isotopic distribution of a molecular formula", | ||
"main": "lib/index.js", | ||
"main": "lib/src/index.js", | ||
"module": "src/index.js", | ||
@@ -23,5 +23,5 @@ "files": [ | ||
"dependencies": { | ||
"chemical-elements": "^2.1.0", | ||
"mf-parser": "^3.2.0", | ||
"mf-utilities": "^3.2.0", | ||
"chemical-elements": "^2.1.1", | ||
"mf-parser": "^3.2.1", | ||
"mf-utilities": "^3.2.1", | ||
"spectrum-generator": "^8.0.11" | ||
@@ -32,3 +32,3 @@ }, | ||
}, | ||
"gitHead": "28dae91d3b42556a23097ee08acfe4061f276ed0" | ||
"gitHead": "838f98a30846d4b1721b8ed7aa94a55e854d7521" | ||
} |
@@ -33,3 +33,3 @@ import { closestPointX } from './utils/closestPointX.js'; | ||
get sumY() { | ||
if (!isNaN(this.cache.sumY)) return this.cache.sumY; | ||
if (!Number.isNaN(this.cache.sumY)) return this.cache.sumY; | ||
let sumY = 0; | ||
@@ -45,3 +45,3 @@ for (let item of this.array) { | ||
get minX() { | ||
if (!isNaN(this.cache.minX)) return this.cache.minX; | ||
if (!Number.isNaN(this.cache.minX)) return this.cache.minX; | ||
let minX = Number.POSITIVE_INFINITY; | ||
@@ -59,3 +59,3 @@ for (let item of this.array) { | ||
get maxX() { | ||
if (!isNaN(this.cache.maxX)) return this.cache.maxX; | ||
if (!Number.isNaN(this.cache.maxX)) return this.cache.maxX; | ||
let maxX = Number.NEGATIVE_INFINITY; | ||
@@ -73,3 +73,3 @@ for (let item of this.array) { | ||
get minY() { | ||
if (!isNaN(this.cache.minY)) return this.cache.minY; | ||
if (!Number.isNaN(this.cache.minY)) return this.cache.minY; | ||
let minY = Number.POSITIVE_INFINITY; | ||
@@ -87,3 +87,3 @@ for (let item of this.array) { | ||
get maxY() { | ||
if (!isNaN(this.cache.maxY)) return this.cache.maxY; | ||
if (!Number.isNaN(this.cache.maxY)) return this.cache.maxY; | ||
let maxY = Number.NEGATIVE_INFINITY; | ||
@@ -116,4 +116,4 @@ for (let item of this.array) { | ||
push(point) { | ||
this.array.push(point); | ||
push(...points) { | ||
this.array.push(...points); | ||
this.emptyCache(); | ||
@@ -195,3 +195,3 @@ } | ||
distCopy.cache = { ...this.cache }; | ||
distCopy.array = JSON.parse(JSON.stringify(this.array)); | ||
distCopy.array = structuredClone(this.array); | ||
return distCopy; | ||
@@ -231,8 +231,8 @@ } | ||
ySorted: false, | ||
minX: NaN, | ||
maxX: NaN, | ||
minY: NaN, | ||
maxY: NaN, | ||
sumY: NaN, | ||
minX: Number.NaN, | ||
maxX: Number.NaN, | ||
minY: Number.NaN, | ||
maxY: Number.NaN, | ||
sumY: Number.NaN, | ||
}; | ||
} |
@@ -11,9 +11,9 @@ import { ELECTRON_MASS } from 'chemical-elements'; | ||
/** | ||
* An object containing two arrays | ||
* @typedef {object} XY | ||
* @property {number[]} x - The x array | ||
* @property {number[]} y - The y array | ||
*/ | ||
/** @typedef {import('mf-parser').IsotopesInfo} IsotopesInfo */ | ||
/** @typedef {import('mf-parser').PartInfo} PartInfo */ | ||
/** @typedef {import('./IsotopicDistribution.types').XY} XY */ | ||
/** @typedef {import('./IsotopicDistribution.types').IsotopicDistributionPart} IsotopicDistributionPart */ | ||
/** @typedef {import('./IsotopicDistribution.types').IsotopicDistributionOptions} IsotopicDistributionOptions */ | ||
/** | ||
@@ -24,15 +24,6 @@ * A class that allows to manage isotopic distribution | ||
/** | ||
* Class that manage isotopic distribution | ||
* @param {string|array} value - Molecular formula or an array of parts | ||
* @param {object} [options={}] | ||
* @param {string} [options.ionizations=''] - string containing a comma separated list of modifications | ||
* @param {number} [options.fwhm=0.01] - Amount of Dalton under which 2 peaks are joined | ||
* @param {number} [options.maxLines=5000] - Maximal number of lines during calculations | ||
* @param {number} [options.minY=1e-8] - Minimal signal height during calculations | ||
* @param {boolean} [options.ensureCase=false] - Ensure uppercase / lowercase | ||
* @param {number} [options.threshold] - We can filter the result based on the relative height of the peaks | ||
* @param {number} [options.limit] - We may define the maximum number of peaks to keep | ||
* @param {boolean} [options.allowNeutral=true] - Should we keep the distribution if the molecule has no charge | ||
* Class that manages isotopic distribution | ||
* @param {string|Array<any>} value - Molecular formula or an array of parts. | ||
* @param {IsotopicDistributionOptions} [options] | ||
*/ | ||
constructor(value, options = {}) { | ||
@@ -42,3 +33,3 @@ this.threshold = options.threshold; | ||
if (Array.isArray(value)) { | ||
this.parts = JSON.parse(JSON.stringify(value)); | ||
this.parts = structuredClone(value); | ||
for (let part of this.parts) { | ||
@@ -53,4 +44,5 @@ part.confidence = 0; | ||
let mfInfo = mf.getInfo(); | ||
let ionizations = preprocessIonizations(options.ionizations); | ||
let parts = mfInfo.parts || [mfInfo]; | ||
const ionizations = preprocessIonizations(options.ionizations); | ||
/** @type {PartInfo} */ | ||
const parts = 'parts' in mfInfo ? mfInfo.parts : [mfInfo]; | ||
this.parts = []; | ||
@@ -60,3 +52,3 @@ for (let partOriginal of parts) { | ||
for (const ionization of ionizations) { | ||
let part = JSON.parse(JSON.stringify(partOriginal)); | ||
let part = structuredClone(partOriginal); | ||
part.em = part.monoisotopicMass; // TODO: To remove !!! we change the name !? | ||
@@ -87,2 +79,5 @@ part.isotopesInfo = new MF( | ||
/** | ||
* @returns {Array<IsotopicDistributionPart>} | ||
*/ | ||
getParts() { | ||
@@ -120,5 +115,3 @@ return this.parts; | ||
if (isotope.number > 0) { | ||
const newDistribution = JSON.parse( | ||
JSON.stringify(isotope.distribution), | ||
); | ||
const newDistribution = structuredClone(isotope.distribution); | ||
if (this.fwhm === MINIMAL_FWHM) { | ||
@@ -143,5 +136,5 @@ // add composition | ||
if (charge) { | ||
totalDistribution.array.forEach((e) => { | ||
for (const e of totalDistribution.array) { | ||
e.x = (e.x - ELECTRON_MASS * charge) / absoluteCharge; | ||
}); | ||
} | ||
} | ||
@@ -152,4 +145,3 @@ | ||
part.fromX = totalDistribution.array[0].x; | ||
part.toX = | ||
totalDistribution.array[totalDistribution.array.length - 1].x; | ||
part.toX = totalDistribution.array.at(-1).x; | ||
} | ||
@@ -285,3 +277,3 @@ | ||
// we need to copy the array because we prefer no side effects | ||
peaks = JSON.parse(JSON.stringify(peaks)); | ||
peaks = structuredClone(peaks); | ||
for (const peak of peaks) { | ||
@@ -341,6 +333,8 @@ peak.y = peak.y / factor; | ||
* @param {object} [options={}] | ||
* @param {number} [options.gaussianWidth=10] | ||
* @param {number} [options.gaussianWidth=10] // how good should look the gaussian ? By default we take 10 times the fwhm as number of points | ||
* @param {number} [options.threshold=0.00001] // minimal height to return point | ||
* @param {number} [options.maxLength=1e6] // minimal height to return point | ||
* @param {number} [options.maxValue] // rescale Y to reach maxValue | ||
* @param {number} [options.from] // minimal x value, default to the first point - 2 | ||
* @param {number} [options.to] // maximal x value, default to the last point + 2 | ||
* @param {function} [options.peakWidthFct=(mz)=>(this.fwhm)] | ||
@@ -362,6 +356,6 @@ * @return {XY} isotopic distribution as an object containing 2 properties: x:[] and y:[] | ||
const from = Math.floor(options.from || points[0].x - 2); | ||
const to = Math.ceil(options.to || points[points.length - 1].x + 2); | ||
const to = Math.ceil(options.to || points.at(-1).x + 2); | ||
const nbPoints = Math.round(((to - from) * gaussianWidth) / this.fwhm + 1); | ||
if (nbPoints > maxLength) { | ||
throw Error( | ||
throw new Error( | ||
`Number of points is over the maxLength: ${nbPoints}>${maxLength}`, | ||
@@ -368,0 +362,0 @@ ); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Unpopular package
QualityThis package is not very popular.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
95695
31
1684
103
1
2
6
Updatedchemical-elements@^2.1.1
Updatedmf-parser@^3.2.1
Updatedmf-utilities@^3.2.1