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

mf-finder

Package Overview
Dependencies
Maintainers
1
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 0.5.8 to 0.5.9

9

package.json
{
"name": "mf-finder",
"version": "0.5.8",
"version": "0.5.9",
"description": "Find a molecular formula from a monoisotopic mass",

@@ -21,7 +21,8 @@ "main": "src/index.js",

"dependencies": {
"chemical-elements": "^0.5.8",
"mf-parser": "^0.5.8",
"mf-utilities": "^0.5.8",
"atom-sorter": "^0.5.9",
"chemical-elements": "^0.5.9",
"mf-parser": "^0.5.9",
"mf-utilities": "^0.5.9",
"molecular-formula": "^1.1.0"
}
}

@@ -96,4 +96,6 @@ 'use strict';

allowNeutral: true,
minUnsaturation: 0,
maxUnsaturation: 1
unsaturation: {
min: 0,
max: 1
}
});

@@ -112,5 +114,7 @@ expect(result.mfs).toHaveLength(2);

allowNeutral: true,
minUnsaturation: 0,
maxUnsaturation: 1,
onlyIntegerUnsaturation: true,
unsaturation: {
min: 0,
max: 1,
onlyInteger: true
}
});

@@ -239,2 +243,17 @@ expect(result.mfs).toHaveLength(1);

it('check order in molecular formula', () => {
let result = findMFs(1199, {
ranges: [
{ mf: 'C', min: 0, max: 100 },
{ mf: 'H', min: 0, max: 100 },
{ mf: 'S', min: 0, max: 10 },
{ mf: 'N', min: 0, max: 10 },
{ mf: 'O', min: 0, max: 10 },
],
precision: 1,
allowNeutral: true
});
expect(result.mfs[0].mf).toBe('C88H5N3O4S');
});
it('check impossible charge', () => {

@@ -241,0 +260,0 @@

'use strict';
const atomSorter = require('atom-sorter');
const preprocessRanges = require('./preprocessRanges');

@@ -23,6 +24,3 @@ const preprocessIonizations = require('mf-utilities/src/preprocessIonizations');

maxCharge = Number.MAX_SAFE_INTEGER,
minUnsaturation = Number.MIN_SAFE_INTEGER,
maxUnsaturation = Number.MAX_SAFE_INTEGER,
onlyIntegerUnsaturation = false,
onlyNonIntegerUnsaturation = false,
unsaturation = {},
maxIterations = 1e8,

@@ -38,6 +36,6 @@ allowNeutral = true, // if there is no msem we use em !

let filterUnsaturation = (minUnsaturation !== Number.MIN_SAFE_INTEGER || maxUnsaturation !== Number.MAX_SAFE_INTEGER || onlyIntegerUnsaturation || onlyNonIntegerUnsaturation);
let filterUnsaturation = unsaturation ? true : false;
// we calculate not the real unsaturation but the one before dividing by 2 + 1
let fakeMinUnsaturation = (minUnsaturation === Number.MIN_SAFE_INTEGER) ? Number.MIN_SAFE_INTEGER : (minUnsaturation - 1) * 2;
let fakeMaxUnsaturation = (maxUnsaturation === Number.MAX_SAFE_INTEGER) ? Number.MAX_SAFE_INTEGER : (maxUnsaturation - 1) * 2;
let fakeMinUnsaturation = (unsaturation.min === undefined) ? Number.MIN_SAFE_INTEGER : (unsaturation.min - 1) * 2;
let fakeMaxUnsaturation = (unsaturation.max === undefined) ? Number.MAX_SAFE_INTEGER : (unsaturation.max - 1) * 2;

@@ -49,2 +47,3 @@ let filterCharge = (minCharge !== Number.MIN_SAFE_INTEGER || maxCharge !== Number.MAX_SAFE_INTEGER);

};
let orderMapping = []; // used to sort the atoms

@@ -63,2 +62,4 @@ // we need to make the processing for all the ionizations

let possibilities = preprocessRanges(ranges);
orderMapping = getOrderMapping(possibilities);
if (possibilities.length === 0) return { mfs: [] };

@@ -90,9 +91,9 @@ targetMassCache = new TargetMassCache(targetMass, possibilities, Object.assign({}, options, { charge: ionization.charge }));

if (filterUnsaturation) {
let unsaturation = lastPossibility.currentUnsaturation;
let isOdd = Math.abs(unsaturation % 2);
let unsaturationValue = lastPossibility.currentUnsaturation;
let isOdd = Math.abs(unsaturationValue % 2);
if (
(onlyIntegerUnsaturation && isOdd === 1) ||
(onlyNonIntegerUnsaturation && isOdd === 0) ||
(fakeMinUnsaturation > unsaturation) ||
(fakeMaxUnsaturation < unsaturation)
(unsaturation.onlyInteger && isOdd === 1) ||
(unsaturation.onlyNonInteger && isOdd === 0) ||
(fakeMinUnsaturation > unsaturationValue) ||
(fakeMaxUnsaturation < unsaturationValue)
) isValid = false;

@@ -112,3 +113,3 @@ }

if (isValid) {
result.mfs.push(getResult(possibilities, targetMass, allowNeutral, ionization));
result.mfs.push(getResult(possibilities, targetMass, allowNeutral, ionization, orderMapping));
result.info.numberResults++;

@@ -152,3 +153,3 @@ }

function getResult(possibilities, targetMass, allowNeutralMolecules, ionization) {
function getResult(possibilities, targetMass, allowNeutralMolecules, ionization, orderMapping) {
let lastPossibility = possibilities[possibilities.length - 1];

@@ -167,3 +168,5 @@

// in the final result
for (let possibility of possibilities) {
for (let i = 0; i < possibilities.length; i++) {
let possibility = possibilities[orderMapping[i]];
if (possibility.currentCount !== 0) {

@@ -215,1 +218,9 @@ if (possibility.isGroup) {

}
function getOrderMapping(possibilities) {
let mapping = possibilities.map((p, i) => ({ atom: p.mf, index: i }));
mapping.sort((a, b) => {
return atomSorter(a.atom, b.atom);
});
return mapping.map((a) => a.index);
}
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