Huge News!Announcing our $40M Series B led by Abstract Ventures.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.5.0 to 2.0.0

lib/index.js

22

package.json
{
"name": "mf-finder",
"version": "1.5.0",
"version": "2.0.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"
"src",
"lib"
],

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

},
"homepage": "https://github.com/cheminfo/mass-tools/tree/master/packages/mf-finder#readme",
"homepage": "https://github.com/cheminfo/mass-tools/tree/main/packages/mf-finder#readme",
"dependencies": {
"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"
"atom-sorter": "^2.0.0",
"chemical-elements": "^2.0.0",
"mf-matcher": "^2.0.0",
"mf-parser": "^2.0.0",
"mf-utilities": "^2.0.0"
},
"gitHead": "ade929b07af4e2f0f8b3fe1aaf0df70c50f4b2db"
"gitHead": "c6ebfbd64c711f8839a02a43c5708e71a379885b"
}

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

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

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

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

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

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

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

'use strict';
import { atomSorter } from 'atom-sorter';
import { msemMatcher } from 'mf-matcher';
import {
preprocessIonizations,
preprocessRanges,
getMsInfo,
} from 'mf-utilities';
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');
import { TargetMassCache } from './TargetMassCache';
const TargetMassCache = require('./TargetMassCache');
let targetMassCache;
/**

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

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

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

} = options;
let targetMassCache;
const {

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

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

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

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

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

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

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

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

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

possibilities[currentPosition - 1],
targetMassCache,
);

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

return result;
};
}

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

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

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

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

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

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

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

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

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

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

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

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

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 {};
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 firstPossibility = possibilities[0];
let currentMinCharge = Math.max(
minCharge,
firstPossibility.minCharge + charge,
);
let currentMaxCharge = Math.min(
maxCharge,
firstPossibility.maxCharge + charge,
);
if (!possibilities || possibilities.length === 0) return;
this.minCharge = currentMinCharge;
this.maxCharge = currentMaxCharge;
let firstPossibility = possibilities[0];
let currentMinCharge = Math.max(
minCharge,
firstPossibility.minCharge + charge,
);
let currentMaxCharge = Math.min(
maxCharge,
firstPossibility.maxCharge + charge,
);
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;
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;
}
} else {
minMass = Number.MAX_SAFE_INTEGER;
maxMass = Number.MIN_SAFE_INTEGER;
minMass =
(targetMass - range) * Math.abs(currentCharge) +
ELECTRON_MASS * currentCharge;
maxMass =
(targetMass + range) * Math.abs(currentCharge) +
ELECTRON_MASS * currentCharge;
}
} else {
minMass =
(targetMass - range) * Math.abs(currentCharge) +
ELECTRON_MASS * currentCharge;
maxMass =
(targetMass + range) * Math.abs(currentCharge) +
ELECTRON_MASS * currentCharge;
this.data.push({
charge: currentCharge,
minMass,
maxMass,
});
}
}
this.data.push({
charge: currentCharge,
minMass,
maxMass,
});
getMinMass(charge) {
return this.data[charge - this.minCharge]
? this.data[charge - this.minCharge].minMass
: Number.MAX_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;
};
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