mf-matcher
Advanced tools
Comparing version 1.2.8 to 1.3.0
{ | ||
"name": "mf-matcher", | ||
"version": "1.2.8", | ||
"version": "1.3.0", | ||
"description": "Returns true / false for an object using mw, em, msem, unsaturation and atoms", | ||
"main": "lib/index.js", | ||
"module": "src/index.js", | ||
"main": "src/index.js", | ||
"files": [ | ||
"src", | ||
"lib" | ||
"src" | ||
], | ||
@@ -21,6 +19,6 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/cheminfo/mass-tools/tree/main/packages/mf-matcher#readme", | ||
"homepage": "https://github.com/cheminfo/mass-tools/tree/master/packages/mf-matcher#readme", | ||
"dependencies": { | ||
"mf-utilities": "^1.4.2", | ||
"ml-spectra-processing": "^11.14.0" | ||
"mf-utilities": "^1.5.0", | ||
"ml-spectra-processing": "^11.1.0" | ||
}, | ||
@@ -30,3 +28,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "bd2c06e05f2196c5f9c6ff011cf3ef41e1b6a0f9" | ||
"gitHead": "ade929b07af4e2f0f8b3fe1aaf0df70c50f4b2db" | ||
} |
@@ -1,3 +0,5 @@ | ||
import { generalMatcher } from '..'; | ||
'use strict'; | ||
const matcher = require('../generalMatcher'); | ||
test('mfFilter', () => { | ||
@@ -16,8 +18,8 @@ let entry = { | ||
expect(generalMatcher(entry, { minCharge: 1 })).toBe(false); | ||
expect(generalMatcher(entry, { maxCharge: -1 })).toBe(false); | ||
expect(generalMatcher(entry, { maxCharge: 0 })).toBe(true); | ||
expect(generalMatcher(entry, { minCharge: -1 })).toBe(true); | ||
expect(matcher(entry, { minCharge: 1 })).toBe(false); | ||
expect(matcher(entry, { maxCharge: -1 })).toBe(false); | ||
expect(matcher(entry, { maxCharge: 0 })).toBe(true); | ||
expect(matcher(entry, { minCharge: -1 })).toBe(true); | ||
expect( | ||
generalMatcher(entry, { | ||
matcher(entry, { | ||
atoms: { | ||
@@ -29,3 +31,3 @@ C: { min: 10, max: 20 }, | ||
expect( | ||
generalMatcher(entry, { | ||
matcher(entry, { | ||
atoms: { | ||
@@ -37,3 +39,3 @@ N: { min: 10, max: 20 }, | ||
expect( | ||
generalMatcher(entry, { | ||
matcher(entry, { | ||
atoms: { | ||
@@ -45,3 +47,3 @@ C: { min: 5, max: 9 }, | ||
expect( | ||
generalMatcher(entry, { | ||
matcher(entry, { | ||
atoms: { | ||
@@ -48,0 +50,0 @@ C: { min: 10, max: 20 }, |
@@ -1,7 +0,9 @@ | ||
import { toBeDeepCloseTo } from 'jest-matcher-deep-close-to'; | ||
'use strict'; | ||
import { msemMatcher } from '..'; | ||
const { toBeDeepCloseTo } = require('jest-matcher-deep-close-to'); | ||
expect.extend({ toBeDeepCloseTo }); | ||
const matcher = require('../msemMatcher'); | ||
describe('msemMatcher', () => { | ||
@@ -20,6 +22,6 @@ it('various parameters', () => { | ||
expect(msemMatcher(entry, { targetMass: 120, minCharge: 1 })).toBe(false); | ||
expect(msemMatcher(entry, { targetMass: 120, maxCharge: -1 })).toBe(false); | ||
expect(matcher(entry, { targetMass: 120, minCharge: 1 })).toBe(false); | ||
expect(matcher(entry, { targetMass: 120, maxCharge: -1 })).toBe(false); | ||
expect( | ||
msemMatcher(entry, { | ||
matcher(entry, { | ||
targetMass: 120, | ||
@@ -33,3 +35,3 @@ ionization: { charge: 1, em: 0 }, | ||
expect( | ||
msemMatcher(entry, { | ||
matcher(entry, { | ||
targetMass: 120, | ||
@@ -42,3 +44,3 @@ atoms: { | ||
expect( | ||
msemMatcher(entry, { | ||
matcher(entry, { | ||
targetMass: 120, | ||
@@ -62,3 +64,3 @@ ionization: { charge: 1, em: 0 }, | ||
expect( | ||
msemMatcher(entry, { | ||
matcher(entry, { | ||
callback: (item) => item.atoms.C > 15, | ||
@@ -68,3 +70,3 @@ }), | ||
expect( | ||
msemMatcher(entry, { | ||
matcher(entry, { | ||
callback: (item) => item.atoms.C > 5, | ||
@@ -89,3 +91,3 @@ }), | ||
expect( | ||
msemMatcher(entry, { | ||
matcher(entry, { | ||
targetMass: 120, | ||
@@ -123,3 +125,3 @@ maxCharge: 1, | ||
expect( | ||
msemMatcher(entry, { | ||
matcher(entry, { | ||
targetMasses: [119, 120, 121, 122, 123], | ||
@@ -140,3 +142,3 @@ }), | ||
expect( | ||
msemMatcher(entry, { | ||
matcher(entry, { | ||
targetMasses: [119, 120, 121, 122, 123], | ||
@@ -171,3 +173,3 @@ targetIntensities: [5, 10, 15, 10, 5], | ||
expect( | ||
msemMatcher(entry, { | ||
matcher(entry, { | ||
targetMasses: [50, 60, 70], | ||
@@ -200,9 +202,9 @@ precision: 100, | ||
}; | ||
expect(msemMatcher(entry, { allowNegativeAtoms: true })).toStrictEqual({ | ||
expect(matcher(entry, { allowNegativeAtoms: true })).toStrictEqual({ | ||
ionization: { atoms: {}, charge: 0, em: 0, mf: '' }, | ||
ms: { charge: 0, em: 0, ionization: '' }, | ||
}); | ||
expect(msemMatcher(entry)).toBe(false); | ||
expect(matcher(entry)).toBe(false); | ||
expect( | ||
msemMatcher(entry, { | ||
matcher(entry, { | ||
ionization: { mf: '(H+)2', charge: 2, em: 0, atoms: { H: 2 } }, | ||
@@ -223,3 +225,3 @@ }), | ||
expect( | ||
msemMatcher(entry, { | ||
matcher(entry, { | ||
allowNegativeAtoms: true, | ||
@@ -233,3 +235,3 @@ ionization: { mf: '(H+)-2', charge: -2, em: 0, atoms: { H: -2 } }, | ||
expect( | ||
msemMatcher(entry, { | ||
matcher(entry, { | ||
ionization: { mf: 'C-2(+)', charge: 1, em: -24, atoms: { C: -2 } }, | ||
@@ -242,3 +244,3 @@ }), | ||
expect( | ||
msemMatcher(entry, { | ||
matcher(entry, { | ||
ionization: { mf: '(H+)-2', charge: -2, em: 0, atoms: { H: -2 } }, | ||
@@ -248,3 +250,3 @@ }), | ||
expect( | ||
msemMatcher(entry, { | ||
matcher(entry, { | ||
ionization: { mf: 'C-20', charge: 0, em: 0, atoms: { C: -20 } }, | ||
@@ -254,3 +256,3 @@ }), | ||
expect( | ||
msemMatcher(entry, { | ||
matcher(entry, { | ||
ionization: { mf: 'C-10', charge: 0, em: 0, atoms: { C: -10 } }, | ||
@@ -257,0 +259,0 @@ }), |
@@ -1,7 +0,7 @@ | ||
import { unsaturationMatcher } from './unsaturationMatcher.js'; | ||
'use strict'; | ||
/** | ||
* Returns true if the entry containing MF information match | ||
* @param {object} [entry={}] - object containing mw, ... | ||
* @param {object} [options={}] | ||
* @param {object} [entry={}}] - object containing mw, ... | ||
* @param {object} [options={}}] | ||
* @param {number} [options.minMW=0] - Minimal molecular weight | ||
@@ -13,3 +13,3 @@ * @param {number} [options.maxMW=+Infinity] - Maximal molecular weight | ||
* @param {number} [options.maxCharge=+Infinity] - Maximal charge | ||
* @param {object} [options.unsaturation={}] | ||
* @param {object} [options.unsaturation={}}] | ||
* @param {number} [options.unsaturation.min=-Infinity] - Minimal unsaturation | ||
@@ -23,3 +23,3 @@ * @param {number} [options.unsaturation.max=+Infinity] - Maximal unsaturation | ||
export function generalMatcher(entry, options = {}) { | ||
module.exports = function generalMatcher(entry, options = {}) { | ||
const { | ||
@@ -49,3 +49,3 @@ minMW = 0, | ||
if (unsaturation !== undefined && entry.unsaturation !== undefined) { | ||
if (!unsaturationMatcher(entry, unsaturation)) return false; | ||
if (!require('./unsaturationMatcher')(entry, unsaturation)) return false; | ||
} | ||
@@ -55,3 +55,3 @@ | ||
// all the atoms of the entry must fit in the range | ||
for (let atom in entry.atoms) { | ||
for (let atom of Object.keys(entry.atoms)) { | ||
if (!atoms[atom]) return false; | ||
@@ -63,2 +63,2 @@ if (entry.atoms[atom] < atoms[atom].min) return false; | ||
return true; | ||
} | ||
}; |
@@ -1,2 +0,6 @@ | ||
export * from './generalMatcher.js'; | ||
export * from './msemMatcher.js'; | ||
'use strict'; | ||
module.exports = { | ||
general: require('./generalMatcher'), | ||
msem: require('./msemMatcher'), | ||
}; |
@@ -1,5 +0,6 @@ | ||
import { getMsInfo } from 'mf-utilities'; | ||
import { xFindClosestIndex } from 'ml-spectra-processing'; | ||
'use strict'; | ||
import { unsaturationMatcher } from './unsaturationMatcher.js'; | ||
const getMsInfo = require('mf-utilities/src/getMsInfo.js'); | ||
const xFindClosestIndex = require('ml-spectra-processing').xFindClosestIndex; | ||
/** | ||
@@ -35,3 +36,3 @@ * @param {object} [entry={}] | ||
export function msemMatcher(entry, options = {}) { | ||
module.exports = function msemMatcher(entry, options = {}) { | ||
const { | ||
@@ -77,3 +78,3 @@ ionization = { mf: '', em: 0, charge: 0, atoms: {} }, | ||
if (unsaturation !== undefined && entry.unsaturation !== undefined) { | ||
if (!unsaturationMatcher(entry, unsaturation)) { | ||
if (!require('./unsaturationMatcher')(entry, unsaturation)) { | ||
return false; | ||
@@ -125,2 +126,2 @@ } | ||
return msInfo; | ||
} | ||
}; |
@@ -0,4 +1,6 @@ | ||
'use strict'; | ||
/** | ||
* @param {object} [entry={}] | ||
* @param {object} [options={}] | ||
* @param {object} [entry={}}] | ||
* @param {object} [options={}}] | ||
* @param {number} [options.min=-Infinity] - Minimal unsaturation | ||
@@ -11,3 +13,3 @@ * @param {number} [options.max=+Infinity] - Maximal unsaturation | ||
export function unsaturationMatcher(entry, options = {}) { | ||
module.exports = function unsaturationMatcher(entry, options = {}) { | ||
const { | ||
@@ -26,2 +28,2 @@ min = Number.MIN_SAFE_INTEGER, | ||
return true; | ||
} | ||
}; |
17104
9
476
Updatedmf-utilities@^1.5.0