mf-utilities
Advanced tools
Comparing version 0.8.0 to 0.9.1
{ | ||
"name": "mf-utilities", | ||
"version": "0.8.0", | ||
"version": "0.9.1", | ||
"description": "Small utilities dealing with molecular formula", | ||
@@ -21,5 +21,6 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"chemical-elements": "^0.7.0", | ||
"mf-parser": "^0.8.0" | ||
"chemical-elements": "^0.9.1", | ||
"chemical-groups": "^0.9.1", | ||
"mf-parser": "^0.9.1" | ||
} | ||
} |
@@ -5,60 +5,61 @@ 'use strict'; | ||
test('getMsInfo', () => { | ||
let mf = { | ||
mf: 'C10', | ||
em: 120, | ||
charge: 0 | ||
}; | ||
expect(getMsInfo(mf).ms).toMatchObject({ | ||
ionization: '', | ||
em: 0, | ||
charge: 0 | ||
}); | ||
let mf = { | ||
mf: 'C10', | ||
em: 120, | ||
charge: 0 | ||
}; | ||
expect(getMsInfo(mf)).toMatchObject({ | ||
ionization: '', | ||
em: 0, | ||
charge: 0 | ||
}); | ||
expect(getMsInfo(mf, { allowNeutralMolecules: true }).ms).toMatchObject({ | ||
ionization: '', | ||
em: 120, | ||
charge: 0 | ||
}); | ||
expect(getMsInfo(mf, { allowNeutralMolecules: true })).toMatchObject({ | ||
ionization: '', | ||
em: 120, | ||
charge: 0 | ||
}); | ||
expect(getMsInfo(mf, { ionization: { mf: 'H+', charge: 1, em: 1 } })).toMatchObject({ | ||
ionization: 'H+', | ||
em: 120.99945142009094, | ||
charge: 1 | ||
}); | ||
expect( | ||
getMsInfo(mf, { ionization: { mf: 'H+', charge: 1, em: 1 } }).ms | ||
).toMatchObject({ | ||
ionization: 'H+', | ||
em: 120.99945142009094, | ||
charge: 1 | ||
}); | ||
}); | ||
test('getMsInfo with targetMass', () => { | ||
let mf = { | ||
mf: 'C10', | ||
em: 120, | ||
charge: 0 | ||
}; | ||
let mf = { | ||
mf: 'C10', | ||
em: 120, | ||
charge: 0, | ||
}; | ||
expect( | ||
getMsInfo(mf, { | ||
allowNeutralMolecules: true, | ||
targetMass: 120 | ||
}).ms | ||
).toMatchObject({ | ||
ionization: '', | ||
em: 120, | ||
charge: 0, | ||
ppm: 0, | ||
delta: 0 | ||
}); | ||
expect(getMsInfo(mf, { | ||
allowNeutralMolecules: true, | ||
targetMass: 120, | ||
})).toMatchObject({ | ||
ionization: '', | ||
em: 120, | ||
charge: 0, | ||
ppm: 0, | ||
delta: 0 | ||
}); | ||
expect(getMsInfo(mf, { | ||
ionization: { mf: 'H+', charge: 1, em: 1 }, // we use one as exact mass to test | ||
targetMass: 121, | ||
})).toMatchObject({ | ||
ionization: 'H+', | ||
em: 120.99945142009094, | ||
charge: 1, | ||
ppm: 4.5337182567354, | ||
delta: -0.0005485799090649834, | ||
}); | ||
expect( | ||
getMsInfo(mf, { | ||
ionization: { mf: 'H+', charge: 1, em: 1 }, // we use one as exact mass to test | ||
targetMass: 121 | ||
}).ms | ||
).toMatchObject({ | ||
ionization: 'H+', | ||
em: 120.99945142009094, | ||
charge: 1, | ||
ppm: 4.5337182567354, | ||
delta: -0.0005485799090649834 | ||
}); | ||
}); |
@@ -6,8 +6,8 @@ 'use strict'; | ||
describe('preprocessIonizations', () => { | ||
it('check ionizations', () => { | ||
let ionizations = preprocessIonizations('H+,Na+,(H+)2, K+'); | ||
expect(ionizations).toHaveLength(4); | ||
expect(ionizations[0]).toMatchObject({ mf: 'H+', em: 1.00782503223, charge: 1 }); | ||
expect(ionizations[2]).toMatchObject({ mf: '(H+)2', em: 2.01565006446, charge: 2 }); | ||
}); | ||
it('check ionizations', () => { | ||
let ionizations = preprocessIonizations('H+,Na+,(H+)2, K+'); | ||
expect(ionizations).toHaveLength(4); | ||
expect(ionizations[0]).toMatchObject({ mf: 'H+', em: 1.00782503223, charge: 1 }); | ||
expect(ionizations[2]).toMatchObject({ mf: '(H+)2', em: 2.01565006446, charge: 2 }); | ||
}); | ||
}); |
@@ -6,9 +6,9 @@ 'use strict'; | ||
module.exports = function getMsem(em, charge) { | ||
if (charge > 0) { | ||
return em / charge - ELECTRON_MASS; | ||
} else if (charge < 0) { | ||
return em / (charge * -1) + ELECTRON_MASS; | ||
} else { | ||
return 0; | ||
} | ||
if (charge > 0) { | ||
return em / charge - ELECTRON_MASS; | ||
} else if (charge < 0) { | ||
return em / (charge * -1) + ELECTRON_MASS; | ||
} else { | ||
return 0; | ||
} | ||
}; |
@@ -6,34 +6,39 @@ 'use strict'; | ||
/** | ||
* Adds a field 'ms' to an object containing em, charge and ioniwation | ||
* Returns an object containing: | ||
* {ms: {em, charge, ionization}, ionization: {}} | ||
* We return the ionization in order to know which one has been selected | ||
*/ | ||
module.exports = function getMsInfo(entry, options = {}) { | ||
const { | ||
allowNeutralMolecules, | ||
ionization = { mf: '', em: 0, charge: 0 }, | ||
forceIonization = false, | ||
targetMass | ||
} = options; | ||
const { | ||
allowNeutralMolecules, | ||
ionization = { mf: '', em: 0, charge: 0 }, | ||
forceIonization = false, | ||
targetMass | ||
} = options; | ||
let realIonization = ionization; | ||
if (!forceIonization && entry.ionization) { | ||
realIonization = entry.ionization; | ||
} | ||
let realIonization = ionization; | ||
if (!forceIonization && entry.ionization && entry.ionization.mf !== '') { | ||
realIonization = entry.ionization; | ||
} | ||
let result = { | ||
ionization: realIonization.mf, | ||
em: 0, | ||
charge: entry.charge + realIonization.charge | ||
}; | ||
let ms = { | ||
ionization: realIonization.mf, | ||
em: 0, | ||
charge: entry.charge + realIonization.charge | ||
}; | ||
if (result.charge !== 0) { | ||
result.em = getMsem(entry.em + realIonization.em, result.charge); | ||
} else if (allowNeutralMolecules) { | ||
result.em = entry.em + realIonization.em; | ||
} | ||
if (targetMass) { | ||
result.delta = result.em - targetMass; | ||
result.ppm = Math.abs(((targetMass - result.em) / targetMass) * 1e6); | ||
} | ||
return result; | ||
if (ms.charge !== 0) { | ||
ms.em = getMsem(entry.em + realIonization.em, ms.charge); | ||
} else if (allowNeutralMolecules) { | ||
ms.em = entry.em + realIonization.em; | ||
} | ||
if (targetMass) { | ||
ms.delta = ms.em - targetMass; | ||
ms.ppm = Math.abs(((targetMass - ms.em) / targetMass) * 1e6); | ||
} | ||
return { | ||
ms, | ||
ionization: realIonization | ||
}; | ||
}; |
@@ -6,10 +6,13 @@ 'use strict'; | ||
module.exports = function preprocessIonizations(ionizationsString = '') { | ||
let ionizations = ionizationsString.split(/ *[.,;\t\r\n]+ */).map((mf) => ({ mf })); | ||
for (let ionization of ionizations) { | ||
let info = new MF(ionization.mf).getInfo(); | ||
ionization.em = info.monoisotopicMass; | ||
ionization.charge = info.charge; | ||
} | ||
if (Array.isArray(ionizationsString)) return ionizationsString; | ||
let ionizations = ionizationsString | ||
.split(/ *[.,;\t\r\n]+ */) | ||
.map((mf) => ({ mf })); | ||
for (let ionization of ionizations) { | ||
let info = new MF(ionization.mf).getInfo(); | ||
ionization.em = info.monoisotopicMass; | ||
ionization.charge = info.charge; | ||
} | ||
return ionizations; | ||
return ionizations; | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8991
12
250
3
+ Addedchemical-groups@^0.9.1
+ Addedatom-sorter@0.9.1(transitive)
+ Addedchemical-elements@0.9.1(transitive)
+ Addedchemical-groups@0.9.1(transitive)
+ Addedmf-parser@0.9.1(transitive)
- Removedatom-sorter@0.8.0(transitive)
- Removedchemical-elements@0.7.0(transitive)
- Removedchemical-groups@0.8.0(transitive)
- Removedmf-parser@0.8.0(transitive)
Updatedchemical-elements@^0.9.1
Updatedmf-parser@^0.9.1