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

mf-matcher

Package Overview
Dependencies
Maintainers
0
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mf-matcher - npm Package Compare versions

Comparing version 3.1.1 to 3.2.0

lib/generalMatcher.d.ts

247

lib/index.js

@@ -1,231 +0,18 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var mfUtilities = require('mf-utilities');
var mlSpectraProcessing = require('ml-spectra-processing');
/**
* @param {object} [entry={}]
* @param {object} [options={}]
* @param {number} [options.min=-Infinity] - Minimal unsaturation
* @param {number} [options.max=+Infinity] - Maximal unsaturation
* @param {boolean} [options.onlyInteger=false] - Integer unsaturation
* @param {boolean} [options.onlyNonInteger=false] - Non integer unsaturation
* @return {boolean}
*/
function unsaturationMatcher(entry, options = {}) {
const {
min = Number.MIN_SAFE_INTEGER,
max = Number.MAX_SAFE_INTEGER,
onlyInteger,
onlyNonInteger,
} = options;
if (entry.unsaturation !== undefined) {
if (entry.unsaturation < min || entry.unsaturation > max) return false;
if (onlyInteger && !Number.isInteger(entry.unsaturation)) return false;
if (onlyNonInteger && Number.isInteger(entry.unsaturation)) return false;
}
return true;
}
/**
* Returns true if the entry containing MF information match
* @param {object} [entry={}] - object containing mw, ...
* @param {object} [options={}]
* @param {number} [options.minMW=0] - Minimal molecular weight
* @param {number} [options.maxMW=+Infinity] - Maximal molecular weight
* @param {number} [options.minEM=0] - Minimal monoisotopic mass
* @param {number} [options.maxEM=+Infinity] - Maximal monoisotopic mass
* @param {number} [options.minCharge=-Infinity] - Minimal charge
* @param {number} [options.maxCharge=+Infinity] - Maximal charge
* @param {boolean} [options.absoluteCharge=false] - If true, the charge is absolute (so between 0 and +Infinity by default)
* @param {object} [options.unsaturation={}]
* @param {number} [options.unsaturation.min=-Infinity] - Minimal unsaturation
* @param {number} [options.unsaturation.max=+Infinity] - Maximal unsaturation
* @param {boolean} [options.unsaturation.onlyInteger=false] - Integer unsaturation
* @param {boolean} [options.unsaturation.onlyNonInteger=false] - Non integer unsaturation
* @param {object} [options.atoms] - object of atom:{min, max}
* @return {boolean}
*/
function generalMatcher(entry, options = {}) {
const {
minMW = 0,
maxMW = +Infinity,
minEM = 0,
maxEM = +Infinity,
minCharge = Number.MIN_SAFE_INTEGER,
maxCharge = Number.MAX_SAFE_INTEGER,
absoluteCharge = false,
unsaturation = {},
atoms,
} = options;
if (entry.mw !== undefined) {
if (entry.mw < minMW || entry.mw > maxMW) return false;
}
if (entry.em !== undefined) {
if (entry.em < minEM || entry.em > maxEM) return false;
}
if (entry.charge !== undefined) {
let charge = absoluteCharge ? Math.abs(entry.charge) : entry.charge;
if (charge < minCharge || charge > maxCharge) return false;
}
if (unsaturation !== undefined && entry.unsaturation !== undefined) {
if (!unsaturationMatcher(entry, unsaturation)) return false;
}
if (entry.atoms !== undefined && atoms) {
// all the atoms of the entry must fit in the range
for (let atom in entry.atoms) {
if (!atoms[atom]) return false;
if (entry.atoms[atom] < atoms[atom].min) return false;
if (entry.atoms[atom] > atoms[atom].max) return false;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
}
return true;
}
/**
* @typedef {object} MSEMFilterOptions
* @property {object} [ionization={ mf: '', em: 0, charge: 0 }] - ionization method
* @property {boolean} [forceIonization=false] - If true ignore existing ionizations
* @property {number} [precision=1000] - The precision on the experimental mass
* @property {number} [targetMass] - Target mass, allows to calculate error and filter results
* @property {number[]} [targetMasses] - Target masses: SORTED array of numbers
* @property {number[]} [targetIntensities] - Target intensities: SORTED array of numbers
* @property {number} [minMW=-Infinity] - Minimal monoisotopic mass
* @property {number} [maxMW=+Infinity] - Maximal monoisotopic mass
* @property {number} [minEM=-Infinity] - Minimal monoisotopic mass
* @property {number} [maxEM=+Infinity] - Maximal monoisotopic mass
* @property {number} [minMSEM=-Infinity] - Minimal monoisotopic mass observed by mass
* @property {number} [maxMSEM=+Infinity] - Maximal monoisotopic mass observed by mass
* @property {number} [minCharge=-Infinity] - Minimal charge
* @property {number} [maxCharge=+Infinity] - Maximal charge
* @property {boolean} [absoluteCharge=false] - If true, the charge is absolute (so between 0 and +Infinity by default)
* @property {boolean} [allowNegativeAtoms=false] - Allow to have negative number of atoms
* @property {object} [unsaturation={}]
* @property {number} [unsaturation.min=-Infinity] - Minimal unsaturation
* @property {number} [unsaturation.max=+Infinity] - Maximal unsaturation
* @property {boolean} [unsaturation.onlyInteger=false] - Integer unsaturation
* @property {boolean} [unsaturation.onlyNonInteger=false] - Non integer unsaturation
* @property {boolean} [atoms] - object of atom:{min, max}
* @property {Function} [callback] - a function that contains information about the current MF
*/
/**
* @param {object} [entry={}]
* @param {MSEMFilterOptions} [options={}]
* @return {boolean}
*/
/**
* We always recalculate msem
*/
function msemMatcher(entry, options = {}) {
const {
ionization = { mf: '', em: 0, charge: 0, atoms: {} },
forceIonization = false,
precision = 1000,
minCharge = Number.MIN_SAFE_INTEGER,
maxCharge = Number.MAX_SAFE_INTEGER,
absoluteCharge = false,
unsaturation = {},
targetMass, // if present we will calculate the errors
targetMasses, // if present we will calculate the smallest error
targetIntensities, // if present it will be added in the report
minEM = -Infinity,
maxEM = +Infinity,
minMSEM = -Infinity,
maxMSEM = +Infinity,
minMW = -Infinity,
maxMW = +Infinity,
allowNegativeAtoms = false,
atoms,
callback,
} = options;
if (entry.mw !== undefined) {
if (entry.mw < minMW || entry.mw > maxMW) return false;
}
let msInfo = mfUtilities.getMsInfo(entry, {
ionization,
forceIonization,
targetMass,
});
let ms = msInfo.ms;
if (entry.em !== undefined) {
if (entry.em < minEM || entry.em > maxEM) return false;
}
if (ms.em !== undefined) {
if (ms.em < minMSEM || ms.em > maxMSEM) return false;
}
if (targetMass && Math.abs(ms.ppm) > precision) return false;
if (ms.charge !== undefined) {
let charge = absoluteCharge ? Math.abs(ms.charge) : ms.charge;
if (charge < minCharge || charge > maxCharge) return false;
}
if (unsaturation !== undefined && entry.unsaturation !== undefined) {
if (!unsaturationMatcher(entry, unsaturation)) {
return false;
}
}
if (entry.atoms !== undefined && atoms) {
// all the atoms of the entry must fit in the range
for (let atom in entry.atoms) {
if (!atoms[atom]) return false;
if (entry.atoms[atom] < atoms[atom].min) return false;
if (entry.atoms[atom] > atoms[atom].max) return false;
}
}
if (entry.atoms !== undefined && !allowNegativeAtoms) {
const ionizationAtoms =
(msInfo.ionization && msInfo.ionization.atoms) || {};
const atomKeys = new Set(
Object.keys(ionizationAtoms).concat(Object.keys(entry.atoms)),
);
for (let atom of atomKeys) {
if ((entry.atoms[atom] || 0) + (ionizationAtoms[atom] || 0) < 0) {
return false;
}
}
}
if (targetMasses && targetMasses.length > 0) {
let index = mlSpectraProcessing.xFindClosestIndex(targetMasses, ms.em);
let closestMass = targetMasses[index];
msInfo = mfUtilities.getMsInfo(entry, {
ionization,
forceIonization,
targetMass: closestMass,
});
msInfo.ms.target = { mass: closestMass };
if (targetIntensities) {
msInfo.ms.target.intensity = targetIntensities[index];
}
// need to find the closest targetMasses
if (Math.abs(msInfo.ms.ppm) > precision) return false;
}
if (callback) {
if (!callback(entry)) return false;
}
return msInfo;
}
exports.generalMatcher = generalMatcher;
exports.msemMatcher = msemMatcher;
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./generalMatcher.js"), exports);
__exportStar(require("./msemMatcher.js"), exports);
{
"name": "mf-matcher",
"version": "3.1.1",
"version": "3.2.0",
"description": "Returns true / false for an object using mw, em, msem, unsaturation and atoms",

@@ -23,4 +23,4 @@ "main": "lib/index.js",

"dependencies": {
"mf-utilities": "^3.1.1",
"ml-spectra-processing": "^14.2.2"
"mf-utilities": "^3.2.0",
"ml-spectra-processing": "^14.5.1"
},

@@ -30,3 +30,3 @@ "devDependencies": {

},
"gitHead": "b9f99ec6f05ce6b0034d35f4ae0452ae653f90c2"
"gitHead": "28dae91d3b42556a23097ee08acfe4061f276ed0"
}
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