mf-matcher
Advanced tools
Comparing version 1.1.22 to 1.2.0
{ | ||
"name": "mf-matcher", | ||
"version": "1.1.22", | ||
"version": "1.2.0", | ||
"description": "Returns true / false for an object using mw, em, msem, unsaturation and atoms", | ||
@@ -21,6 +21,9 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"mf-utilities": "^1.2.16", | ||
"mf-utilities": "^1.3.0", | ||
"ml-spectra-processing": "8.3.1" | ||
}, | ||
"gitHead": "cfe22caded1fa8266dfc28df065f4d8d71fd031e" | ||
"devDependencies": { | ||
"jest-matcher-deep-close-to": "^3.0.2" | ||
}, | ||
"gitHead": "0cceb8fe88adb924d371419bf3738b0e2d0a438c" | ||
} |
'use strict'; | ||
const { toBeDeepCloseTo } = require('jest-matcher-deep-close-to'); | ||
expect.extend({ toBeDeepCloseTo }); | ||
const matcher = require('../msemMatcher'); | ||
describe('test msemMatcher', () => { | ||
describe('msemMatcher', () => { | ||
it('various parameters', () => { | ||
@@ -180,2 +184,68 @@ let entry = { | ||
}); | ||
it('negative atoms', () => { | ||
let entry = { | ||
mf: 'C-10', | ||
charge: 0, | ||
atoms: { | ||
C: -10, | ||
}, | ||
}; | ||
expect(matcher(entry, { allowNegativeAtoms: true })).toStrictEqual({ | ||
ionization: { atoms: {}, charge: 0, em: 0, mf: '' }, | ||
ms: { charge: 0, em: 0, ionization: '' }, | ||
}); | ||
expect(matcher(entry)).toBe(false); | ||
expect( | ||
matcher(entry, { | ||
ionization: { mf: '(H+)2', charge: 2, em: 0, atoms: { H: 2 } }, | ||
}), | ||
).toBe(false); | ||
}); | ||
it('negative ionizations', () => { | ||
let entry = { | ||
mf: 'C10', | ||
em: 120, | ||
charge: 0, | ||
atoms: { | ||
C: 10, | ||
}, | ||
}; | ||
expect( | ||
matcher(entry, { | ||
allowNegativeAtoms: true, | ||
ionization: { mf: '(H+)-2', charge: -2, em: 0, atoms: { H: -2 } }, | ||
}), | ||
).toBeDeepCloseTo({ | ||
ms: { ionization: '(H+)-2', em: 60.00054857990907, charge: -2 }, | ||
ionization: { mf: '(H+)-2', charge: -2, em: 0, atoms: { H: -2 } }, | ||
}); | ||
expect( | ||
matcher(entry, { | ||
ionization: { mf: 'C-2(+)', charge: 1, em: -24, atoms: { C: -2 } }, | ||
}), | ||
).toBeDeepCloseTo({ | ||
ms: { ionization: 'C-2(+)', em: 95.99945142009094, charge: 1 }, | ||
ionization: { mf: 'C-2(+)', charge: 1, em: -24, atoms: { C: -2 } }, | ||
}); | ||
expect( | ||
matcher(entry, { | ||
ionization: { mf: '(H+)-2', charge: -2, em: 0, atoms: { H: -2 } }, | ||
}), | ||
).toBe(false); | ||
expect( | ||
matcher(entry, { | ||
ionization: { mf: 'C-20', charge: 0, em: 0, atoms: { C: -20 } }, | ||
}), | ||
).toBe(false); | ||
expect( | ||
matcher(entry, { | ||
ionization: { mf: 'C-10', charge: 0, em: 0, atoms: { C: -10 } }, | ||
}), | ||
).toStrictEqual({ | ||
ionization: { atoms: { C: -10 }, charge: 0, em: 0, mf: 'C-10' }, | ||
ms: { charge: 0, em: 0, ionization: 'C-10' }, | ||
}); | ||
}); | ||
}); |
@@ -7,4 +7,4 @@ 'use strict'; | ||
/** | ||
* @param {object} [entry={}}] | ||
* @param {object} [options={}}] | ||
* @param {object} [entry={}] | ||
* @param {object} [options={}] | ||
* @param {object} [options.ionization={ mf: '', em: 0, charge: 0 }] - ionization method | ||
@@ -22,3 +22,4 @@ * @param {boolean} [options.forceIonization=false] - If true ignore existing ionizations | ||
* @param {number} [options.maxCharge=+Infinity] - Maximal charge | ||
* @param {object} [options.unsaturation={}}] | ||
* @param {boolean} [options.allowNegativeAtoms=false] - Allow to have negative number of atoms | ||
* @param {object} [options.unsaturation={}] | ||
* @param {number} [options.unsaturation.min=-Infinity] - Minimal unsaturation | ||
@@ -39,3 +40,3 @@ * @param {number} [options.unsaturation.max=+Infinity] - Maximal unsaturation | ||
const { | ||
ionization = { mf: '', em: 0, charge: 0 }, | ||
ionization = { mf: '', em: 0, charge: 0, atoms: {} }, | ||
forceIonization = false, | ||
@@ -53,2 +54,3 @@ precision = 1000, | ||
maxMSEM = +Infinity, | ||
allowNegativeAtoms = false, | ||
atoms, | ||
@@ -85,3 +87,3 @@ callback, | ||
// all the atoms of the entry must fit in the range | ||
for (let atom of Object.keys(entry.atoms)) { | ||
for (let atom in entry.atoms) { | ||
if (!atoms[atom]) return false; | ||
@@ -93,2 +95,15 @@ if (entry.atoms[atom] < atoms[atom].min) return false; | ||
if (entry.atoms !== undefined && !allowNegativeAtoms) { | ||
const ionizationAtoms = | ||
(msInfo.ionization && msInfo.ionization.atoms) || {}; | ||
const atomKeys = new Set( | ||
Object.keys(ionizationAtoms).concat(Object.keys(entry.atoms)), | ||
); | ||
for (let atom of atomKeys) { | ||
if ((entry.atoms[atom] || 0) + (ionizationAtoms[atom] || 0) < 0) { | ||
return false; | ||
} | ||
} | ||
} | ||
if (targetMasses && targetMasses.length > 0) { | ||
@@ -95,0 +110,0 @@ let index = xFindClosestIndex(targetMasses, ms.em); |
17108
476
1
Updatedmf-utilities@^1.3.0