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

mf-generator

Package Overview
Dependencies
Maintainers
2
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 1.2.0 to 1.2.1

15

CHANGELOG.md

@@ -6,9 +6,9 @@ # Change Log

# [1.2.0](https://github.com/cheminfo/molecular-formula/compare/mf-generator@1.1.6...mf-generator@1.2.0) (2020-08-19)
## 1.2.1 (2021-03-12)
### Features
* limit number of generated MF ([d361ed7](https://github.com/cheminfo/molecular-formula/commit/d361ed75f1d129fda64b19c2ee3cd421486aeeac))
## 0.59.2 (2021-03-12)
**Note:** Version bump only for package mf-generator

@@ -18,4 +18,11 @@

## [1.1.6](https://github.com/cheminfo/molecular-formula/compare/mf-generator@1.1.5...mf-generator@1.1.6) (2020-04-18)
# [1.2.0](https://github.com/cheminfo/mass-tools/compare/mf-generator@1.1.6...mf-generator@1.2.0) (2020-08-19)
### Features
- limit number of generated MF ([d361ed7](https://github.com/cheminfo/mass-tools/commit/d361ed75f1d129fda64b19c2ee3cd421486aeeac))
## [1.1.6](https://github.com/cheminfo/mass-tools/compare/mf-generator@1.1.5...mf-generator@1.1.6) (2020-04-18)
**Note:** Version bump only for package mf-generator
{
"name": "mf-generator",
"version": "1.2.0",
"version": "1.2.1",
"description": "",

@@ -11,3 +11,3 @@ "main": "src/index.js",

"type": "git",
"url": "git+https://github.com/cheminfo/molecular-formula.git"
"url": "git+https://github.com/cheminfo/mass-tools.git"
},

@@ -18,14 +18,13 @@ "keywords": [],

"bugs": {
"url": "https://github.com/cheminfo/molecular-formula/issues"
"url": "https://github.com/cheminfo/mass-tools/issues"
},
"homepage": "https://github.com/cheminfo/molecular-formula/tree/master/packages/mf-generator#readme",
"homepage": "https://github.com/cheminfo/mass-tools/tree/master/packages/mf-generator#readme",
"dependencies": {
"chemical-elements": "^1.1.5",
"mf-finder": "^1.1.6",
"mf-matcher": "^1.1.6",
"mf-parser": "^1.1.6",
"mf-utilities": "^1.2.0",
"chemical-elements": "^1.1.6",
"mf-finder": "^1.1.7",
"mf-matcher": "^1.1.7",
"mf-parser": "^1.1.7",
"mf-utilities": "^1.2.1",
"sum-object-keys": "^1.0.2"
},
"gitHead": "cfb4dd864b00757572700c8751b620d500682476"
}
}

@@ -97,2 +97,14 @@ 'use strict';

it('filterFct', function () {
let mfsArray = [
{ name: 'C', value: 'C0-5' },
{ name: 'D', value: 'O0-5' },
];
let result = generateMFs(mfsArray, {
ionizations: '++',
filterFct: 'C<D && (C+D)===3 && atoms.O>=2',
});
expect(result).toHaveLength(2);
});
it('From array of string to large array and filter unsaturation', function () {

@@ -106,2 +118,15 @@ let mfsArray = ['C0-100', 'H0-100'];

it('Filter callback', function () {
let mfsArray = ['C0-4', 'H0-4'];
let result = generateMFs(mfsArray, {
filter: {
callback: (entry) => {
if (entry.atoms.C - entry.atoms.H === 0) return true;
return false;
},
},
});
expect(result).toHaveLength(4);
});
it('From array of string to large array and filter unsaturation min/max and integer unsaturation', function () {

@@ -108,0 +133,0 @@ let mfsArray = ['C0-100', 'H0-100'];

'use strict';
const { ELECTRON_MASS } = require('chemical-elements/src/constants');
const MF = require('mf-parser').MF;

@@ -30,7 +31,10 @@ const matcher = require('mf-matcher').msem;

* @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.unsaturation={}}]
* @param {number} [options.filter.unsaturation.min=-Infinity] - Minimal unsaturation
* @param {number} [options.filter.unsaturation.max=+Infinity] - Maximal unsaturation
* @param {number} [options.filter.unsaturation.onlyInteger=false] - Integer unsaturation
* @param {number} [options.filter.unsaturation.onlyNonInteger=false] - Non integer unsaturation
* @param {object} [options.filter.atoms] - object of atom:{min, max}
* @param {function} [options.filter.callback] - a function to filter the MF
* @param {string} [options.filterFct]
* @returns {Array}

@@ -40,3 +44,26 @@ */

module.exports = function generateMFs(keys, options = {}) {
options = { ...options };
let { limit = 100000, uniqueMFs = true, estimate = false } = options;
options.filterFctVariables = {};
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (typeof key === 'object' && key.name) {
options.filterFctVariables[key.name] = i;
keys[i] = key.value;
}
}
if (options.filterFct) {
// we create a real javascript function
let variables = Object.keys(options.filterFctVariables);
variables.push('mm', 'mz', 'charge', 'unsaturation', 'atoms');
// eslint-disable-next-line no-new-func
options.filterFct = new Function(
...variables,
`return ${options.filterFct}`,
);
}
if (uniqueMFs === true) options.canonizeMF = true;

@@ -184,3 +211,19 @@ if (options.canonizeMF === undefined) options.canonizeMF = true;

let result = getEMFromParts(keys, currents, ionization);
if (options.filterFct) {
let variables = [];
for (let key in options.filterFctVariables) {
variables.push(currents[options.filterFctVariables[key]]);
}
variables.push(
result.em,
(result.em + ionization.em - ionization.charge * ELECTRON_MASS) /
Math.abs(ionization.charge),
result.charge + result.ionization.charge,
result.unsaturation,
result.atoms,
);
if (!options.filterFct.apply(null, variables)) continue;
}
let match = matcher(result, filter);

@@ -187,0 +230,0 @@ if (!match) continue;

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