New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mf-finder

Package Overview
Dependencies
Maintainers
2
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mf-finder - npm Package Compare versions

Comparing version 1.4.2 to 1.5.0

22

package.json
{
"name": "mf-finder",
"version": "1.4.2",
"version": "1.5.0",
"description": "Find a molecular formula from a monoisotopic mass",
"main": "src/index.js",
"types": "mfFinder.d.ts",
"main": "lib/index.js",
"module": "src/index.js",
"files": [
"src",
"lib"
"src"
],

@@ -22,11 +20,11 @@ "repository": {

},
"homepage": "https://github.com/cheminfo/mass-tools/tree/main/packages/mf-finder#readme",
"homepage": "https://github.com/cheminfo/mass-tools/tree/master/packages/mf-finder#readme",
"dependencies": {
"atom-sorter": "^1.1.11",
"chemical-elements": "^1.2.4",
"mf-matcher": "^1.2.8",
"mf-parser": "^1.4.8",
"mf-utilities": "^1.4.2"
"atom-sorter": "^1.2.0",
"chemical-elements": "^1.3.0",
"mf-matcher": "^1.3.0",
"mf-parser": "^1.5.0",
"mf-utilities": "^1.5.0"
},
"gitHead": "bd2c06e05f2196c5f9c6ff011cf3ef41e1b6a0f9"
"gitHead": "ade929b07af4e2f0f8b3fe1aaf0df70c50f4b2db"
}

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

import { findMFs } from '..';
'use strict';
const findMFs = require('..');
describe('test mf-finder', () => {

@@ -4,0 +6,0 @@ it('basic case', async () => {

@@ -1,5 +0,7 @@

import { preprocessRanges } from 'mf-utilities';
'use strict';
import { TargetMassCache } from '../TargetMassCache';
const preprocessRanges = require('mf-utilities/src/preprocessRanges');
const TargetMassCache = require('../TargetMassCache');
describe('TargetMassCache', () => {

@@ -6,0 +8,0 @@ it('the result with one atom', () => {

@@ -1,11 +0,13 @@

import { atomSorter } from 'atom-sorter';
import { msemMatcher } from 'mf-matcher';
import {
preprocessIonizations,
preprocessRanges,
getMsInfo,
} from 'mf-utilities';
'use strict';
import { TargetMassCache } from './TargetMassCache';
const matcher = require('mf-matcher').msem;
const atomSorter = require('atom-sorter');
const getMsInfo = require('mf-utilities/src/getMsInfo');
const preprocessIonizations = require('mf-utilities/src/preprocessIonizations');
const preprocessRanges = require('mf-utilities/src/preprocessRanges');
const TargetMassCache = require('./TargetMassCache');
let targetMassCache;
/**

@@ -34,3 +36,3 @@ * @param {number} targetMass - Monoisotopic mass

export async function findMFs(targetMass, options = {}) {
module.exports = async function mfFinder(targetMass, options = {}) {
const {

@@ -49,3 +51,3 @@ filter = {},

} = options;
let targetMassCache;
const {

@@ -57,3 +59,3 @@ minCharge = Number.MIN_SAFE_INTEGER,

let filterUnsaturation = !!unsaturation;
let filterUnsaturation = unsaturation ? true : false;
// we calculate not the real unsaturation but the one before dividing by 2 + 1

@@ -104,6 +106,7 @@ let fakeMinUnsaturation =

if (possibilities.length === 0) return { mfs: [] };
targetMassCache = new TargetMassCache(targetMass, possibilities, {
...options,
...{ charge: ionization.charge },
});
targetMassCache = new TargetMassCache(
targetMass,
possibilities,
Object.assign({}, options, { charge: ionization.charge }),
);

@@ -118,3 +121,3 @@ let theEnd = false;

initializePossibilities(possibilities, currentIonization, targetMassCache);
initializePossibilities(possibilities, currentIonization);

@@ -171,3 +174,3 @@ // if (DEBUG) console.log('possibilities', possibilities.map((a) => `${a.mf + a.originalMinCount}-${a.originalMaxCount}`));

if (advancedFilter) {
isValid = msemMatcher(newResult, advancedFilter) !== false;
isValid = matcher(newResult, advancedFilter) !== false;
}

@@ -200,3 +203,2 @@ if (isValid) {

possibilities[currentPosition - 1],
targetMassCache,
);

@@ -224,3 +226,3 @@ } else {

return result;
}
};

@@ -250,4 +252,6 @@ /**

continue;
} else if (current.currentCounts[i] < bestCounts[i]) {
continue next;
} else {
if (current.currentCounts[i] < bestCounts[i]) {
continue next;
}
}

@@ -300,6 +304,8 @@ }

result.mf += `${possibility.mf}`;
} else if (possibility.mf.match(/^\([^()]*\)$/)) {
result.mf += `${possibility.mf}${possibility.currentCount}`;
} else {
result.mf += `(${possibility.mf})${possibility.currentCount}`;
if (possibility.mf.match(/^\([^()]*\)$/)) {
result.mf += `${possibility.mf}${possibility.currentCount}`;
} else {
result.mf += `(${possibility.mf})${possibility.currentCount}`;
}
}

@@ -333,3 +339,3 @@ if (result.groups[possibility.mf]) {

function setCurrentMinMax(currentAtom, previousAtom, targetMassCache) {
function setCurrentMinMax(currentAtom, previousAtom) {
// the current min max can only be optimize if the charge will not change anymore

@@ -368,11 +374,7 @@ if (currentAtom.innerCharge === true || currentAtom.charge !== 0) {

function initializePossibilities(
possibilities,
currentIonization,
targetMassCache,
) {
function initializePossibilities(possibilities, currentIonization) {
for (let i = 0; i < possibilities.length; i++) {
if (i === 0) {
updateCurrentAtom(possibilities[i], currentIonization);
setCurrentMinMax(possibilities[i], currentIonization, targetMassCache);
setCurrentMinMax(possibilities[i], currentIonization);
} else {

@@ -379,0 +381,0 @@ updateCurrentAtom(possibilities[i], possibilities[i - 1]);

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

import { ELECTRON_MASS } from 'chemical-elements';
'use strict';
const ELECTRON_MASS = require('chemical-elements/src/constants').ELECTRON_MASS;
/**

@@ -7,70 +9,73 @@ * returns all the possible neutral mass for a defined experimental (targetMass) mass

export class TargetMassCache {
constructor(targetMass, possibilities, options = {}) {
const {
allowNeutral = false, // msem because em in this case !
minCharge = Number.MIN_SAFE_INTEGER,
maxCharge = Number.MAX_SAFE_INTEGER,
charge = 0,
precision = 100,
} = options;
let TargetMassCache = function TargetMassCache(
targetMass,
possibilities,
options = {},
) {
const {
allowNeutral = false, // msem because em in this case !
minCharge = Number.MIN_SAFE_INTEGER,
maxCharge = Number.MAX_SAFE_INTEGER,
charge = 0,
precision = 100,
} = options;
if (!possibilities || possibilities.length === 0) return {};
if (!possibilities || possibilities.length === 0) return;
let firstPossibility = possibilities[0];
let currentMinCharge = Math.max(
minCharge,
firstPossibility.minCharge + charge,
);
let currentMaxCharge = Math.min(
maxCharge,
firstPossibility.maxCharge + charge,
);
let firstPossibility = possibilities[0];
let currentMinCharge = Math.max(
minCharge,
firstPossibility.minCharge + charge,
);
let currentMaxCharge = Math.min(
maxCharge,
firstPossibility.maxCharge + charge,
);
this.minCharge = currentMinCharge;
this.maxCharge = currentMaxCharge;
this.minCharge = currentMinCharge;
this.maxCharge = currentMaxCharge;
let size = this.maxCharge - this.minCharge + 1;
this.data = [];
let minMass = 0;
let maxMass = 0;
let range = (targetMass * precision) / 1e6;
for (let i = 0; i < size; i++) {
let currentCharge = i + this.minCharge;
if (currentCharge === 0) {
if (allowNeutral) {
minMass = targetMass - range;
maxMass = targetMass + range;
} else {
minMass = Number.MAX_SAFE_INTEGER;
maxMass = Number.MIN_SAFE_INTEGER;
}
let size = this.maxCharge - this.minCharge + 1;
this.data = [];
let minMass = 0;
let maxMass = 0;
let range = (targetMass * precision) / 1e6;
for (let i = 0; i < size; i++) {
let currentCharge = i + this.minCharge;
if (currentCharge === 0) {
if (allowNeutral) {
minMass = targetMass - range;
maxMass = targetMass + range;
} else {
minMass =
(targetMass - range) * Math.abs(currentCharge) +
ELECTRON_MASS * currentCharge;
maxMass =
(targetMass + range) * Math.abs(currentCharge) +
ELECTRON_MASS * currentCharge;
minMass = Number.MAX_SAFE_INTEGER;
maxMass = Number.MIN_SAFE_INTEGER;
}
this.data.push({
charge: currentCharge,
minMass,
maxMass,
});
} else {
minMass =
(targetMass - range) * Math.abs(currentCharge) +
ELECTRON_MASS * currentCharge;
maxMass =
(targetMass + range) * Math.abs(currentCharge) +
ELECTRON_MASS * currentCharge;
}
}
getMinMass(charge) {
return this.data[charge - this.minCharge]
? this.data[charge - this.minCharge].minMass
: Number.MAX_SAFE_INTEGER;
this.data.push({
charge: currentCharge,
minMass,
maxMass,
});
}
};
getMaxMass(charge) {
return this.data[charge - this.minCharge]
? this.data[charge - this.minCharge].maxMass
: Number.MIN_SAFE_INTEGER;
}
}
module.exports = TargetMassCache;
TargetMassCache.prototype.getMinMass = function getMinMass(charge) {
return this.data[charge - this.minCharge]
? this.data[charge - this.minCharge].minMass
: Number.MAX_SAFE_INTEGER;
};
TargetMassCache.prototype.getMaxMass = function getMaxMass(charge) {
return this.data[charge - this.minCharge]
? this.data[charge - this.minCharge].maxMass
: Number.MIN_SAFE_INTEGER;
};
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