isotopic-distribution
Advanced tools
Comparing version 1.1.1 to 1.1.2
{ | ||
"name": "isotopic-distribution", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Calculate the isotopic distribution of a molecular formula", | ||
@@ -21,8 +21,8 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"chemical-elements": "^1.1.1", | ||
"mf-parser": "^1.1.1", | ||
"mf-utilities": "^1.1.1", | ||
"chemical-elements": "^1.1.2", | ||
"mf-parser": "^1.1.2", | ||
"mf-utilities": "^1.1.2", | ||
"spectrum-generator": "^3.2.1" | ||
}, | ||
"gitHead": "6b2d07885895d1eb6ffdbb51bbccdf15cc8d0aec" | ||
"gitHead": "03f4aca58a117f78aaceffce4b968507cd964b74" | ||
} |
@@ -7,3 +7,17 @@ 'use strict'; | ||
it('create distribution of CH0', () => { | ||
let isotopicDistribution = new IsotopicDistribution('CH0'); | ||
let isotopicDistribution = new IsotopicDistribution('CH00'); | ||
expect(isotopicDistribution.getTable()).toStrictEqual([ | ||
{ x: 12, y: 0.9893 }, | ||
{ x: 13.00335483507, y: 0.0107 }, | ||
]); | ||
expect( | ||
isotopicDistribution.getTable({ xLabel: 'mz', yLabel: 'intensity' }), | ||
).toStrictEqual([ | ||
{ mz: 12, intensity: 0.9893 }, | ||
{ mz: 13.00335483507, intensity: 0.0107 }, | ||
]); | ||
expect(isotopicDistribution.getTable({ maxValue: 100 })).toStrictEqual([ | ||
{ x: 12, y: 100 }, | ||
{ x: 13.00335483507, y: 1.0815728292732234 }, | ||
]); | ||
let distribution = isotopicDistribution.getDistribution(); | ||
@@ -10,0 +24,0 @@ expect(distribution.array[0].x).toBe(12); |
@@ -6,4 +6,4 @@ 'use strict'; | ||
const MF = require('mf-parser').MF; | ||
const getMsInfo = require('mf-utilities/src/getMsInfo'); | ||
const preprocessIonizations = require('mf-utilities/src/preprocessIonizations'); | ||
const getMsInfo = require('mf-utilities/src/getMsInfo'); | ||
@@ -167,14 +167,27 @@ const Distribution = require('./Distribution'); | ||
getCSV() { | ||
return this.getText(','); | ||
return this.getText({ delimiter: ', ' }); | ||
} | ||
getTSV() { | ||
return this.getText('\t'); | ||
return this.getText({ delimiter: '\t' }); | ||
} | ||
getTable() { | ||
return this.getDistribution().array; | ||
getTable(options = {}) { | ||
const { maxValue, xLabel = 'x', yLabel = 'y' } = options; | ||
let points = this.getDistribution().array; | ||
let factor = 1; | ||
if (maxValue) { | ||
let maxY = this.getMaxY(points); | ||
factor = maxValue / maxY; | ||
} | ||
return points.map((point) => { | ||
let newPoint = {}; | ||
newPoint[xLabel] = point.x; | ||
newPoint[yLabel] = point.y * factor; | ||
return newPoint; | ||
}); | ||
} | ||
getText(delimiter = '\t') { | ||
getText(options = {}) { | ||
const { delimiter = '\t', numberDecimals = 3 } = options; | ||
let points = this.getDistribution().array; | ||
@@ -184,3 +197,5 @@ let csv = []; | ||
csv.push( | ||
`${point.x.toFixed(5)}${delimiter}${(point.y * 100).toFixed(3)}`, | ||
`${point.x.toFixed(5)}${delimiter}${(point.y * 100).toFixed( | ||
numberDecimals, | ||
)}`, | ||
); | ||
@@ -191,2 +206,10 @@ } | ||
getMaxY(points) { | ||
let maxY = points[0].y; | ||
for (let point of points) { | ||
if (point.y > maxY) maxY = point.y; | ||
} | ||
return maxY; | ||
} | ||
/** | ||
@@ -202,6 +225,3 @@ * Returns the isotopic distirubtion | ||
if (maxValue) { | ||
let maxY = points[0].y; | ||
for (let point of points) { | ||
if (point.y > maxY) maxY = point.y; | ||
} | ||
let maxY = this.getMaxY(points); | ||
factor = maxY / maxValue; | ||
@@ -208,0 +228,0 @@ } |
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
36025
952
Updatedchemical-elements@^1.1.2
Updatedmf-parser@^1.1.2
Updatedmf-utilities@^1.1.2