Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mf-parser

Package Overview
Dependencies
Maintainers
6
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mf-parser - npm Package Compare versions

Comparing version 0.5.11 to 0.5.12

8

package.json
{
"name": "mf-parser",
"version": "0.5.11",
"version": "0.5.12",
"description": "",

@@ -21,6 +21,6 @@ "main": "src/index.js",

"dependencies": {
"atom-sorter": "^0.5.11",
"chemical-elements": "^0.5.11",
"mf-utilities": "^0.5.11"
"atom-sorter": "^0.5.12",
"chemical-elements": "^0.5.12",
"mf-utilities": "^0.5.12"
}
}

@@ -9,7 +9,3 @@ 'use strict';

expect(parts).toEqual(
[[
{ kind: 'atom', value: 'C', multiplier: 1 },
]]
);
expect(parts).toEqual([[{ kind: 'atom', value: 'C', multiplier: 1 }]]);

@@ -42,12 +38,13 @@ var newMF = mf.toMF();

expect(parts).toEqual(
[[
expect(parts).toEqual([
[
{ kind: 'atom', value: 'C', multiplier: 6 },
{ kind: 'atom', value: 'H', multiplier: 15 },
{ kind: 'atom', value: 'N', multiplier: 1 }
], [
],
[
{ kind: 'atom', value: 'H', multiplier: 1 },
{ kind: 'atom', value: 'Cl', multiplier: 1 }
]]
);
]
]);

@@ -63,20 +60,26 @@ var newMF = mf.toMF();

let info = mf.getInfo();
expect(info).toEqual({ parts:
[{ mass: 101.19022990269394,
monoisotopicMass: 101.12044948788001,
charge: 0,
mf: 'C6H15N',
unsaturation: 0,
atoms: { C: 6, H: 15, N: 1 } },
{ mass: 36.460878336663775,
monoisotopicMass: 35.97667771423,
charge: 0,
mf: 'HCl',
unsaturation: 0,
atoms: { H: 1, Cl: 1 } }],
monoisotopicMass: 137.09712720211002,
mass: 137.6511082393577,
charge: 0,
mf: 'C6H15N.HCl' }
);
expect(info).toEqual({
parts: [
{
mass: 101.19022990269394,
monoisotopicMass: 101.12044948788001,
charge: 0,
mf: 'C6H15N',
unsaturation: 0,
atoms: { C: 6, H: 15, N: 1 }
},
{
mass: 36.460878336663775,
monoisotopicMass: 35.97667771423,
charge: 0,
mf: 'HCl',
unsaturation: 0,
atoms: { H: 1, Cl: 1 }
}
],
monoisotopicMass: 137.09712720211002,
mass: 137.6511082393577,
charge: 0,
mf: 'C6H15N.HCl'
});
});

@@ -88,4 +91,4 @@

expect(parts).toEqual(
[[
expect(parts).toEqual([
[
{ kind: 'atom', value: 'C', multiplier: 3 },

@@ -95,6 +98,5 @@ { kind: 'atom', value: 'H', multiplier: 3 },

{ kind: 'atom', value: 'N', multiplier: 1 }
]]
]
]);
);
var newMF = mf.toMF();

@@ -104,12 +106,10 @@ expect(newMF).toBe('C3H3Me6N');

let info = mf.getInfo();
expect(info).toEqual(
{
mass: 143.27008211723435,
monoisotopicMass: 143.16739968126,
charge: 0,
mf: 'C3H3Me6N',
unsaturation: 0,
atoms: { C: 3, H: 3, Me: 6, N: 1 }
}
);
expect(info).toEqual({
mass: 143.27008211723435,
monoisotopicMass: 143.16739968126,
charge: 0,
mf: 'C3H3Me6N',
unsaturation: 0,
atoms: { C: 3, H: 3, Me: 6, N: 1 }
});
});

@@ -121,9 +121,9 @@

expect(parts).toEqual(
[[
expect(parts).toEqual([
[
{ kind: 'atom', value: 'C', multiplier: 9 },
{ kind: 'atom', value: 'H', multiplier: 21 },
{ kind: 'atom', value: 'N', multiplier: 1 }
]]
);
]
]);

@@ -134,12 +134,10 @@ var newMF = mf.toMF();

let info = mf.getInfo();
expect(info).toEqual(
{
mass: 143.27008211723435,
monoisotopicMass: 143.16739968126,
charge: 0,
mf: 'C9H21N',
unsaturation: 0,
atoms: { C: 9, H: 21, N: 1 }
}
);
expect(info).toEqual({
mass: 143.27008211723435,
monoisotopicMass: 143.16739968126,
charge: 0,
mf: 'C9H21N',
unsaturation: 0,
atoms: { C: 9, H: 21, N: 1 }
});
});

@@ -151,9 +149,9 @@

expect(parts).toEqual(
[[
expect(parts).toEqual([
[
{ kind: 'atom', value: 'O', multiplier: 4 },
{ kind: 'atom', value: 'S', multiplier: 1 },
{ kind: 'charge', value: -2 },
]]
);
{ kind: 'charge', value: -2 }
]
]);

@@ -175,15 +173,15 @@ var newMF = mf.toMF();

unsaturation: 4,
atoms: { O: 4, S: 1 } }
);
atoms: { O: 4, S: 1 }
});
});
test('test unsaturation with charges', () => {
expect((new MF('CH4')).getInfo().unsaturation).toBe(0);
expect((new MF('C10H22O')).getInfo().unsaturation).toBe(0);
expect((new MF('H+')).getInfo().unsaturation).toBe(0);
expect((new MF('CO3(--)')).getInfo().unsaturation).toBe(3);
expect((new MF('HO(-)')).getInfo().unsaturation).toBe(1);
expect((new MF('F(-)')).getInfo().unsaturation).toBe(1);
expect((new MF('Na+')).getInfo().unsaturation).toBe(0);
expect((new MF('NH4+')).getInfo().unsaturation).toBe(-1);
expect(new MF('CH4').getInfo().unsaturation).toBe(0);
expect(new MF('C10H22O').getInfo().unsaturation).toBe(0);
expect(new MF('H+').getInfo().unsaturation).toBe(0);
expect(new MF('CO3(--)').getInfo().unsaturation).toBe(3);
expect(new MF('HO(-)').getInfo().unsaturation).toBe(1);
expect(new MF('F(-)').getInfo().unsaturation).toBe(1);
expect(new MF('Na+').getInfo().unsaturation).toBe(0);
expect(new MF('NH4+').getInfo().unsaturation).toBe(-1);
});

@@ -194,10 +192,18 @@

var parts = mf.toParts();
expect(parts).toEqual(
[[
expect(parts).toEqual([
[
{ kind: 'atom', value: 'C', multiplier: 1 },
{ kind: 'isotope', value: { atom: 'C', isotope: 13 }, multiplier: 1 },
{
kind: 'isotope',
value: { atom: 'C', isotope: 13 },
multiplier: 1
},
{ kind: 'atom', value: 'N', multiplier: 4 },
{ kind: 'isotope', value: { atom: 'N', isotope: 15 }, multiplier: 2 },
]]
);
{
kind: 'isotope',
value: { atom: 'N', isotope: 15 },
multiplier: 2
}
]
]);

@@ -211,3 +217,3 @@ let info = mf.getInfo();

unsaturation: 6,
atoms: { C: 2, N: 6 },
atoms: { C: 2, N: 6 }
});

@@ -219,12 +225,38 @@

test('MF of DNA HODampDtmpDcmpDgmpH ', () => {
var mf = new MF('HODampDtmpDgmpDcmpH');
var info = mf.getInfo();
expect(info).toEqual({ mass: 1253.8043977028433,
monoisotopicMass: 1253.21310019311,
charge: 0,
mf: 'C39H51N15O25P4',
atoms: { C: 39, H: 51, N: 15, O: 25, P: 4 },
unsaturation: 24 });
});
test('MF of RNA HOAmpUmpH ', () => {
var mf = new MF('HOAmpUmpH');
var info = mf.getInfo();
expect(info).toEqual({ mass: 653.388021231099,
monoisotopicMass: 653.08838712715,
charge: 0,
mf: 'C19H25N7O15P2',
atoms: { C: 19, H: 25, N: 7, O: 15, P: 2 },
unsaturation: 12 });
});
test('MF of CC{50,50}H', () => {
var mf = new MF('HC{50,50}C');
var parts = mf.toParts();
expect(parts).toEqual(
[[
expect(parts).toEqual([
[
{ kind: 'atom', value: 'C', multiplier: 1 },
{ kind: 'isotopeRatio', value: { atom: 'C', ratio: [50, 50] }, multiplier: 1 },
{
kind: 'isotopeRatio',
value: { atom: 'C', ratio: [50, 50] },
multiplier: 1
},
{ kind: 'atom', value: 'H', multiplier: 1 }
]]
);
]
]);

@@ -235,12 +267,10 @@ var newMF = mf.toMF();

let info = mf.getInfo();
expect(info).toEqual(
{
monoisotopicMass: 25.00782503223,
mass: 25.520354068326025,
charge: 0,
mf: 'CC{50,50}H',
unsaturation: 2.5,
atoms: { C: 2, H: 1 }
}
);
expect(info).toEqual({
monoisotopicMass: 25.00782503223,
mass: 25.520354068326025,
charge: 0,
mf: 'CC{50,50}H',
unsaturation: 2.5,
atoms: { C: 2, H: 1 }
});
});

@@ -13,3 +13,2 @@ 'use strict';

/**

@@ -21,7 +20,7 @@ *

module.exports = function getInfo(parts, options = {}) {
let {
customUnsaturations = {}
} = options;
let { customUnsaturations = {} } = options;
if (parts.length === 0) return {};
if (parts.length === 1) return getProcessedPart(parts[0], customUnsaturations);
if (parts.length === 1) {
return getProcessedPart(parts[0], customUnsaturations);
}

@@ -67,2 +66,3 @@ var result = {

element = groups[line.value];
if (!element) throw Error(`Unknown element: ${line.value}`);
if (!customUnsaturations[line.value]) {

@@ -74,3 +74,4 @@ customUnsaturations[line.value] = element.unsaturation;

if (!element) throw new Error(`Unknown element: ${line.value}`);
currentPart.monoisotopicMass += element.monoisotopicMass * line.multiplier;
currentPart.monoisotopicMass +=
element.monoisotopicMass * line.multiplier;
currentPart.mass += element.mass * line.multiplier;

@@ -82,3 +83,9 @@ break;

let isotope = isotopes[line.value.isotope + line.value.atom];
if (!isotope) throw new Error(`Unknown isotope: ${line.value.isotope}${line.value.atom}`);
if (!isotope) {
throw new Error(
`Unknown isotope: ${line.value.isotope}${
line.value.atom
}`
);
}
currentPart.monoisotopicMass += isotope.mass * line.multiplier;

@@ -91,3 +98,4 @@ currentPart.mass += isotope.mass * line.multiplier;

let isotopeRatioInfo = getIsotopeRatioInfo(line.value);
currentPart.monoisotopicMass += isotopeRatioInfo.monoisotopicMass * line.multiplier;
currentPart.monoisotopicMass +=
isotopeRatioInfo.monoisotopicMass * line.multiplier;
currentPart.mass += isotopeRatioInfo.mass * line.multiplier;

@@ -107,3 +115,4 @@ break;

if (customUnsaturations[currentElement] !== undefined) {
unsaturation += customUnsaturations[currentElement] * line.multiplier;
unsaturation +=
customUnsaturations[currentElement] * line.multiplier;
} else if (unsaturations[currentElement] !== undefined) {

@@ -119,3 +128,6 @@ unsaturation += unsaturations[currentElement] * line.multiplier;

if (currentPart.charge) {
currentPart.observedMonoisotopicMass = (currentPart.monoisotopicMass - currentPart.charge * ELECTRON_MASS) / Math.abs(currentPart.charge);
currentPart.observedMonoisotopicMass =
(currentPart.monoisotopicMass -
currentPart.charge * ELECTRON_MASS) /
Math.abs(currentPart.charge);
}

@@ -128,3 +140,2 @@ if (validUnsaturation) {

function getIsotopeRatioInfo(value) {

@@ -141,3 +152,7 @@ let result = {

if (ratios.length > isotopesArray.length) {
throw new Error(`the number of specified ratios is bigger that the number of stable isotopes: ${value.atom}`);
throw new Error(
`the number of specified ratios is bigger that the number of stable isotopes: ${
value.atom
}`
);
}

@@ -157,2 +172,1 @@ for (let i = 0; i < ratios.length; i++) {

}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc