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

mf-generator

Package Overview
Dependencies
Maintainers
1
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mf-generator - npm Package Compare versions

Comparing version 0.4.3 to 0.5.0

src/__tests__/combineMFs.js

6

package.json
{
"name": "mf-generator",
"version": "0.4.3",
"version": "0.5.0",
"description": "",

@@ -21,4 +21,6 @@ "main": "src/index.js",

"dependencies": {
"mf-parser": "^0.4.3"
"chemical-elements": "^0.5.0",
"mf-matcher": "^0.5.0",
"mf-parser": "^0.5.0"
}
}
'use strict';
const {ELECTRON_MASS} = require('chemical-elements/src/constants');
const { ELECTRON_MASS } = require('chemical-elements/src/constants');
const MF = require('mf-parser').MF;
const matcher = require('mf-matcher');
const sum = require('sum-object-keys');

@@ -13,10 +14,18 @@ /**

* @param options
* @param {number} [options.limit=1000000] - Maximum number of results
* @param {number} [options.minMass=0] - Minimal monoisotopic mass
* @param {number} [options.maxMass=+Infinity] - Maximal monoisotopic mass
* @param {number} [options.minMSMass=0] - Minimal observed monoisotopic mass
* @param {number} [options.maxMSMass=+Infinity] - Maximal observed monoisotopic mass
* @param {number} [options.minCharge=-Infinity] - Minimal charge
* @param {number} [options.maxCharge=+Infinity] - Maximal charge
* @param {number} [options.limit=10000000] - Maximum number of results
* @param {boolean} [canonizeMF=true] - Canonize molecular formula
* @param {boolean} [uniqueMFs=true] - Force canonization and make MF unique
* @param {number} [options.filter.minMass=0] - Minimal monoisotopic mass
* @param {number} [options.filter.maxMass=+Infinity] - Maximal monoisotopic mass
* @param {number} [options.filter.minEM=0] - Minimal neutral monoisotopic mass
* @param {number} [options.filter.maxEM=+Infinity] - Maximal neutral monoisotopic mass
* @param {number} [options.filter.minMSEM=0] - Minimal observed monoisotopic mass
* @param {number} [options.filter.maxMSEM=+Infinity] - Maximal observed monoisotopic mass
* @param {number} [options.filter.minCharge=-Infinity] - Minimal charge
* @param {number} [options.filter.maxCharge=+Infinity] - Maximal charge
* @param {number} [options.filter.minUnsaturation=-Infinity] - Minimal unsaturation
* @param {number} [options.filter.maxUnsaturation=+Infinity] - Maximal unsaturation
* @param {number} [options.filter.onlyIntegerUnsaturation=false] - Integer unsaturation
* @param {number} [options.filter.onlyNonIntegerUnsaturation=false] - Non integer unsaturation
* @param {object} [options.filter.atoms] - object of atom:{min, max}
* @returns {Array}

@@ -28,4 +37,8 @@ */

let {
limit = 1000000,
limit = 10000000,
uniqueMFs
} = options;
if (uniqueMFs === undefined) uniqueMFs = true;
if (uniqueMFs === true) options.canonizeMF = true;
if (options.canonizeMF === undefined) options.canonizeMF = true;

@@ -82,6 +95,14 @@ if (!Array.isArray(keys)) throw new Error('You need to specify an array of strings or arrays');

if (evolution > limit) {
throw new Error('You have reached the limit of ' + options.limit + '. You could still change this value using the limit option but it is likely to crash.');
throw new Error(`You have reached the limit of ${limit}. You could still change this value using the limit option but it is likely to crash.`);
}
}
appendResult(results, currents, keys, options);
if (uniqueMFs) {
var uniqueMFsObject = {};
results.forEach((r) => {
uniqueMFsObject[r.mf] = r;
});
results = Object.keys(uniqueMFsObject).map((k) => uniqueMFsObject[k]);
}
results.sort((a, b) => (a.em - b.em));
return results;

@@ -93,3 +114,3 @@ };

// internal method to for cache
// internal method used as a cache
function getMonoisotopicMass(mfString) {

@@ -103,3 +124,5 @@ if (!ems[mfString]) {

charge: info.charge,
mw: info.mass
mw: info.mass,
unsaturation: (info.unsaturation - 1) * 2,
atoms: info.atoms
};

@@ -114,2 +137,5 @@ }

var mw = 0;
var unsaturation = 0;
var validUnsaturation = true;
var atoms = {};

@@ -123,2 +149,6 @@ for (var i = 0; i < parts.length; i++) {

mw += info.mw;
sum(atoms, info.atoms);
if (info.unsaturation && validUnsaturation) {
unsaturation += info.unsaturation;
}
}

@@ -138,3 +168,5 @@ }

msem,
mw
mw,
unsaturation: validUnsaturation ? unsaturation / 2 + 1 : undefined,
atoms
};

@@ -145,11 +177,5 @@ }

const {
minMass = 0,
maxMass = +Infinity,
minMSMass = 0,
maxMSMass = +Infinity,
minCharge = -Infinity,
maxCharge = +Infinity,
canonizeMF
canonizeMF,
filter
} = options;
// this script is designed to combine molecular formula

@@ -159,22 +185,8 @@ // that may contain comments after a "$" sign

var info = getEMFromParts(keys, currents);
var result = getEMFromParts(keys, currents);
if (!matcher(result, filter)) return;
var em = info.em;
var mw = info.mw;
var msem = info.msem;
var charge = info.charge;
result.parts = [];
result.mf = '';
if ((mw < minMass) || (mw > maxMass)) return;
if ((msem < minMSMass) || (msem > maxMSMass)) return;
if ((charge < minCharge) || (charge > maxCharge)) return;
var result = {
mf: '',
em,
mw,
msem,
charge,
parts: []
};
var comments = [];

@@ -197,3 +209,3 @@ for (var i = 0; i < keys.length; i++) {

if (comments.length > 0) result.mf += '$' + comments.join(' ');
if (comments.length > 0) result.mf += `$${comments.join(' ')}`;
results.push(result);

@@ -204,3 +216,3 @@ }

var results = [];
var parts = string.split(/([0-9]+-[0-9]+)/).filter(v => v); // remove empty parts
var parts = string.split(/([0-9]+-[0-9]+)/).filter((v) => v); // remove empty parts
let position = -1;

@@ -257,3 +269,3 @@ var mfs = [];

}
if (comment) mf += '$' + comment;
if (comment) mf += `$${comment}`;
return mf;

@@ -260,0 +272,0 @@ }

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