mf-matcher
Advanced tools
Comparing version 2.0.4 to 2.1.0
@@ -44,2 +44,3 @@ 'use strict'; | ||
* @param {number} [options.maxCharge=+Infinity] - Maximal charge | ||
* @param {boolean} [options.absoluteCharge=false] - If true, the charge is absolute (so between 0 and +Infinity by default) | ||
* @param {object} [options.unsaturation={}] | ||
@@ -62,2 +63,3 @@ * @param {number} [options.unsaturation.min=-Infinity] - Minimal unsaturation | ||
maxCharge = Number.MAX_SAFE_INTEGER, | ||
absoluteCharge = false, | ||
unsaturation = {}, | ||
@@ -76,3 +78,4 @@ atoms, | ||
if (entry.charge !== undefined) { | ||
if (entry.charge < minCharge || entry.charge > maxCharge) return false; | ||
let charge = absoluteCharge ? Math.abs(entry.charge) : entry.charge; | ||
if (charge < minCharge || charge > maxCharge) return false; | ||
} | ||
@@ -110,2 +113,3 @@ | ||
* @param {number} [options.maxCharge=+Infinity] - Maximal charge | ||
* @param {boolean} [options.absoluteCharge=false] - If true, the charge is absolute (so between 0 and +Infinity by default) | ||
* @param {boolean} [options.allowNegativeAtoms=false] - Allow to have negative number of atoms | ||
@@ -133,2 +137,3 @@ * @param {object} [options.unsaturation={}] | ||
maxCharge = Number.MAX_SAFE_INTEGER, | ||
absoluteCharge = false, | ||
unsaturation = {}, | ||
@@ -164,4 +169,5 @@ targetMass, // if present we will calculate the errors | ||
if (entry.charge !== undefined) { | ||
if (ms.charge < minCharge || ms.charge > maxCharge) return false; | ||
if (ms.charge !== undefined) { | ||
let charge = absoluteCharge ? Math.abs(ms.charge) : ms.charge; | ||
if (charge < minCharge || charge > maxCharge) return false; | ||
} | ||
@@ -168,0 +174,0 @@ if (unsaturation !== undefined && entry.unsaturation !== undefined) { |
{ | ||
"name": "mf-matcher", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"description": "Returns true / false for an object using mw, em, msem, unsaturation and atoms", | ||
@@ -29,3 +29,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "eaf15749dfc3cf47932c45669772647cf3034d69" | ||
"gitHead": "d309de1c7a86730c8e4f0bd836896e1a16c95cb7" | ||
} |
@@ -20,2 +20,3 @@ import { generalMatcher } from '..'; | ||
expect(generalMatcher(entry, { minCharge: -1 })).toBe(true); | ||
expect( | ||
@@ -51,1 +52,26 @@ generalMatcher(entry, { | ||
}); | ||
test('negative charge', () => { | ||
let entry = { | ||
mf: 'C10', | ||
em: 120, | ||
charge: -1, | ||
msem: 0, | ||
unsaturation: 11, | ||
}; | ||
expect(generalMatcher(entry, { minCharge: 0 })).toBe(false); | ||
expect(generalMatcher(entry, { minCharge: -1 })).toBe(true); | ||
expect(generalMatcher(entry, { minCharge: 0, absoluteCharge: true })).toBe( | ||
true, | ||
); | ||
expect( | ||
generalMatcher(entry, { minCharge: 0, maxCharge: 0, absoluteCharge: true }), | ||
).toBe(false); | ||
expect(generalMatcher(entry, { minCharge: 2, absoluteCharge: true })).toBe( | ||
false, | ||
); | ||
expect(generalMatcher(entry, { minCharge: 1, absoluteCharge: true })).toBe( | ||
true, | ||
); | ||
}); |
@@ -70,2 +70,31 @@ import { toBeDeepCloseTo } from 'jest-matcher-deep-close-to'; | ||
it('negative charge', () => { | ||
let entry = { | ||
mf: 'C10', | ||
em: 120, | ||
charge: 0, | ||
msem: 0, | ||
unsaturation: 11, | ||
atoms: { | ||
C: 10, | ||
}, | ||
ionization: { mf: 'Cl-', charge: -1, em: 0 }, | ||
}; | ||
expect(msemMatcher(entry, { minCharge: 0 })).toBe(false); | ||
expect(msemMatcher(entry, { minCharge: -1 }).ms.charge).toBe(-1); | ||
expect( | ||
msemMatcher(entry, { minCharge: 0, absoluteCharge: true }).ms.charge, | ||
).toBe(-1); | ||
expect( | ||
msemMatcher(entry, { minCharge: 0, maxCharge: 0, absoluteCharge: true }), | ||
).toBe(false); | ||
expect(msemMatcher(entry, { minCharge: 2, absoluteCharge: true })).toBe( | ||
false, | ||
); | ||
expect( | ||
msemMatcher(entry, { minCharge: 1, absoluteCharge: true }).ms.charge, | ||
).toBe(-1); | ||
}); | ||
it('forced ionization', () => { | ||
@@ -72,0 +101,0 @@ let entry = { |
@@ -13,2 +13,3 @@ import { unsaturationMatcher } from './unsaturationMatcher.js'; | ||
* @param {number} [options.maxCharge=+Infinity] - Maximal charge | ||
* @param {boolean} [options.absoluteCharge=false] - If true, the charge is absolute (so between 0 and +Infinity by default) | ||
* @param {object} [options.unsaturation={}] | ||
@@ -31,2 +32,3 @@ * @param {number} [options.unsaturation.min=-Infinity] - Minimal unsaturation | ||
maxCharge = Number.MAX_SAFE_INTEGER, | ||
absoluteCharge = false, | ||
unsaturation = {}, | ||
@@ -45,3 +47,4 @@ atoms, | ||
if (entry.charge !== undefined) { | ||
if (entry.charge < minCharge || entry.charge > maxCharge) return false; | ||
let charge = absoluteCharge ? Math.abs(entry.charge) : entry.charge; | ||
if (charge < minCharge || charge > maxCharge) return false; | ||
} | ||
@@ -48,0 +51,0 @@ |
@@ -20,2 +20,3 @@ import { getMsInfo } from 'mf-utilities'; | ||
* @param {number} [options.maxCharge=+Infinity] - Maximal charge | ||
* @param {boolean} [options.absoluteCharge=false] - If true, the charge is absolute (so between 0 and +Infinity by default) | ||
* @param {boolean} [options.allowNegativeAtoms=false] - Allow to have negative number of atoms | ||
@@ -43,2 +44,3 @@ * @param {object} [options.unsaturation={}] | ||
maxCharge = Number.MAX_SAFE_INTEGER, | ||
absoluteCharge = false, | ||
unsaturation = {}, | ||
@@ -74,4 +76,5 @@ targetMass, // if present we will calculate the errors | ||
if (entry.charge !== undefined) { | ||
if (ms.charge < minCharge || ms.charge > maxCharge) return false; | ||
if (ms.charge !== undefined) { | ||
let charge = absoluteCharge ? Math.abs(ms.charge) : ms.charge; | ||
if (charge < minCharge || charge > maxCharge) return false; | ||
} | ||
@@ -78,0 +81,0 @@ if (unsaturation !== undefined && entry.unsaturation !== undefined) { |
27222
720