Comparing version 1.1.6 to 1.1.7
@@ -6,4 +6,16 @@ # Change Log | ||
## [1.1.6](https://github.com/cheminfo/molecular-formula/compare/mf-finder@1.1.5...mf-finder@1.1.6) (2020-08-19) | ||
## 1.1.7 (2021-03-12) | ||
## 0.59.2 (2021-03-12) | ||
**Note:** Version bump only for package mf-finder | ||
## [1.1.6](https://github.com/cheminfo/mass-tools/compare/mf-finder@1.1.5...mf-finder@1.1.6) (2020-08-19) | ||
**Note:** Version bump only for package mf-finder |
{ | ||
"name": "mf-finder", | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"description": "Find a molecular formula from a monoisotopic mass", | ||
@@ -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,12 +18,12 @@ "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-finder#readme", | ||
"homepage": "https://github.com/cheminfo/mass-tools/tree/master/packages/mf-finder#readme", | ||
"dependencies": { | ||
"atom-sorter": "^1.1.5", | ||
"chemical-elements": "^1.1.5", | ||
"mf-parser": "^1.1.6", | ||
"mf-utilities": "^1.2.0" | ||
}, | ||
"gitHead": "cfb4dd864b00757572700c8751b620d500682476" | ||
"atom-sorter": "^1.1.6", | ||
"chemical-elements": "^1.1.6", | ||
"mf-matcher": "^1.1.7", | ||
"mf-parser": "^1.1.7", | ||
"mf-utilities": "^1.2.1" | ||
} | ||
} |
@@ -46,2 +46,29 @@ 'use strict'; | ||
it('basic case with advanced filtering (callback)', () => { | ||
let result = findMFs(12, { | ||
ranges: [ | ||
{ mf: 'C', min: 1, max: 10 }, | ||
{ mf: 'H', min: 1, max: 10 }, | ||
], | ||
precision: 1e8, | ||
ionizations: 'H+', | ||
filter: { | ||
callback: (entry) => entry.atoms.H === entry.atoms.C, | ||
}, | ||
}); | ||
expect(result.mfs).toHaveLength(10); | ||
}); | ||
it('basic case with limit', () => { | ||
let result = findMFs(24, { | ||
ranges: [{ mf: 'C', min: 1, max: 2 }], | ||
precision: 1e6, | ||
allowNeutral: true, | ||
ionizations: ',H+', | ||
limit: 1, | ||
}); | ||
expect(result.mfs).toHaveLength(1); | ||
expect(result.mfs[0].ms.ppm).toBe(0); | ||
}); | ||
it('basic case with double charge and extreme error', () => { | ||
@@ -92,5 +119,7 @@ let result = findMFs(24, { | ||
allowNeutral: true, | ||
unsaturation: { | ||
min: 0, | ||
max: 1, | ||
filter: { | ||
unsaturation: { | ||
min: 0, | ||
max: 1, | ||
}, | ||
}, | ||
@@ -110,6 +139,8 @@ }); | ||
allowNeutral: true, | ||
unsaturation: { | ||
min: 0, | ||
max: 1, | ||
onlyInteger: true, | ||
filter: { | ||
unsaturation: { | ||
min: 0, | ||
max: 1, | ||
onlyInteger: true, | ||
}, | ||
}, | ||
@@ -147,2 +178,13 @@ }); | ||
it('groups and atoms', () => { | ||
let result = findMFs(92.99814, { | ||
ranges: '(CH2)0-1C0-1', | ||
precision: 1e10, | ||
allowNeutral: true, | ||
}); | ||
expect(result.mfs[0].atoms).toStrictEqual({ C: 2, H: 2 }); | ||
expect(result.mfs[0].groups).toStrictEqual({ '(CH2)': 1 }); | ||
expect(result.mfs[2].atoms).toStrictEqual({ C: 1 }); | ||
expect(result.mfs[2].groups).toStrictEqual({}); | ||
}); | ||
it('simple combinations for polymers', () => { | ||
@@ -285,4 +327,2 @@ let result = findMFs(92.99814, { | ||
expect(result.mfs).toHaveLength(2); | ||
// expect(result.mfs).toHaveLength(0); | ||
}); | ||
@@ -311,4 +351,6 @@ | ||
precision: 1e5, | ||
maxCharge: 1, | ||
minCharge: 1, | ||
filter: { | ||
maxCharge: 1, | ||
minCharge: 1, | ||
}, | ||
}); | ||
@@ -315,0 +357,0 @@ expect(result.mfs).toHaveLength(1); |
'use strict'; | ||
const matcher = require('mf-matcher').msem; | ||
const atomSorter = require('atom-sorter'); | ||
@@ -10,18 +11,28 @@ const getMsInfo = require('mf-utilities/src/getMsInfo'); | ||
let targetMassCache; | ||
/** | ||
* Returns possible combinations | ||
* {number} [targetMass] | ||
* {object} [options={}] | ||
* {string} [options.ionizations=''] - comma separated list of ionizations | ||
* @return {} | ||
* @param {number} mass - Monoisotopic mass | ||
* @param {object} [options={}] | ||
* @param {number} [options.maxIterations=10000000] - Maximum number of iterations | ||
* @param {number} [options.limit=1000] - Maximum number of results | ||
* @param {string} [options.ionizations=''] - string containing a comma separated list of modifications | ||
* @param {string} [options.ranges='C0-100 H0-100 O0-100 N0-100'] - range of mfs to search | ||
* @param {number} [options.precision=100] - Allowed mass range based on precision | ||
* @param {number} [options.filter.minCharge=-Infinity] - Minimal charge | ||
* @param {number} [options.filter.maxCharge=+Infinity] - Maximal charge | ||
* @param {number} [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 | ||
*/ | ||
let targetMassCache; | ||
module.exports = function (targetMass, options = {}) { | ||
const { | ||
minCharge = Number.MIN_SAFE_INTEGER, | ||
maxCharge = Number.MAX_SAFE_INTEGER, | ||
unsaturation = {}, | ||
filter = {}, | ||
maxIterations = 1e8, | ||
limit = 1000, | ||
allowNeutral = true, // if there is no msem we use em ! | ||
@@ -36,2 +47,8 @@ ranges = [ | ||
const { | ||
minCharge = Number.MIN_SAFE_INTEGER, | ||
maxCharge = Number.MAX_SAFE_INTEGER, | ||
unsaturation = {}, | ||
} = filter; | ||
let filterUnsaturation = unsaturation ? true : false; | ||
@@ -52,2 +69,10 @@ // we calculate not the real unsaturation but the one before dividing by 2 + 1 | ||
let advancedFilter; | ||
if (filter.atoms || filter.callback) { | ||
advancedFilter = { | ||
atoms: filter.atoms, | ||
callback: filter.callback, | ||
}; | ||
} | ||
let result = { | ||
@@ -131,13 +156,22 @@ mfs: [], | ||
} | ||
if (isValid) { | ||
result.mfs.push( | ||
getResult( | ||
possibilities, | ||
targetMass, | ||
allowNeutral, | ||
ionization, | ||
orderMapping, | ||
), | ||
result.info.numberResults++; | ||
let newResult = getResult( | ||
possibilities, | ||
targetMass, | ||
allowNeutral, | ||
ionization, | ||
orderMapping, | ||
); | ||
result.info.numberResults++; | ||
if (advancedFilter) { | ||
isValid = matcher(newResult, advancedFilter) !== false; | ||
} | ||
if (isValid) { | ||
result.mfs.push(newResult); | ||
if (result.mfs.length > 2 * limit) { | ||
result.mfs.sort((a, b) => Math.abs(a.ms.ppm) - Math.abs(b.ms.ppm)); | ||
result.mfs.length = limit; | ||
} | ||
} | ||
} | ||
@@ -177,2 +211,5 @@ | ||
result.mfs.sort((a, b) => Math.abs(a.ms.ppm) - Math.abs(b.ms.ppm)); | ||
if (result.mfs.length > limit) { | ||
result.mfs.length = limit; | ||
} | ||
return result; | ||
@@ -207,2 +244,4 @@ }; | ||
ionization, | ||
atoms: {}, | ||
groups: {}, | ||
}; | ||
@@ -221,2 +260,7 @@ | ||
} | ||
if (result.groups[possibility.mf]) { | ||
result.groups[possibility.mf] += possibility.currentCount; | ||
} else { | ||
result.groups[possibility.mf] = possibility.currentCount; | ||
} | ||
} else { | ||
@@ -228,2 +272,11 @@ result.mf += possibility.mf; | ||
} | ||
for (let atom in possibility.atoms) { | ||
if (result.atoms[atom]) { | ||
result.atoms[atom] += | ||
possibility.atoms[atom] * possibility.currentCount; | ||
} else { | ||
result.atoms[atom] = | ||
possibility.atoms[atom] * possibility.currentCount; | ||
} | ||
} | ||
} | ||
@@ -230,0 +283,0 @@ } |
@@ -114,3 +114,6 @@ 'use strict'; | ||
: range.unsaturation; | ||
if (possibility.mf !== info.mf) possibility.isGroup = true; | ||
possibility.atoms = info.atoms; | ||
if (possibility.mf !== info.mf) { | ||
possibility.isGroup = true; | ||
} | ||
} | ||
@@ -117,0 +120,0 @@ possibilities = possibilities.filter( |
38455
1111
5
+ Addedmf-matcher@^1.1.7
+ Addedbinary-search@1.3.6(transitive)
+ Addedcheminfo-types@1.8.1(transitive)
+ Addedd3-array@0.7.1(transitive)
+ Addedfft.js@4.0.4(transitive)
+ Addedis-any-array@2.0.1(transitive)
+ Addedmf-matcher@1.3.0(transitive)
+ Addedml-array-max@1.2.4(transitive)
+ Addedml-array-min@1.2.3(transitive)
+ Addedml-array-rescale@1.3.7(transitive)
+ Addedml-matrix@6.12.0(transitive)
+ Addedml-spectra-processing@11.17.0(transitive)
+ Addedml-xsadd@2.0.0(transitive)
+ Addedspline-interpolator@1.0.0(transitive)
Updatedatom-sorter@^1.1.6
Updatedchemical-elements@^1.1.6
Updatedmf-parser@^1.1.7
Updatedmf-utilities@^1.2.1