Comparing version 2.0.1 to 2.1.0
@@ -0,1 +1,5 @@ | ||
# [2.1.0](https://github.com/cheminfo-js/mzData/compare/v2.0.1...v2.1.0) (2020-04-20) | ||
## [2.0.1](https://github.com/cheminfo-js/mzData/compare/v1.1.0...v2.0.1) (2020-02-28) | ||
@@ -2,0 +6,0 @@ |
102
lib/index.js
@@ -205,2 +205,103 @@ 'use strict'; | ||
function parseCvParam$2(cvParam) { | ||
let result = {}; | ||
if (!cvParam) return result; | ||
let cvParams; | ||
if (Array.isArray(cvParam)) { | ||
cvParams = cvParam; | ||
} else { | ||
cvParams = [cvParam]; | ||
} | ||
for (let param of cvParams) { | ||
if (param.precision) { | ||
result = { | ||
precision: param.precision, | ||
byteOrder: param.byteOrder, | ||
contentType: param.contentType, | ||
pairOrder: param.pairOrder, | ||
}; | ||
} | ||
} | ||
return result; | ||
} | ||
function parseBinaryDataArray$1(node) { | ||
let data = node.peaks; | ||
let attr = node._attr; | ||
let cvParam = parseCvParam$2(data._attr); | ||
if (!data || !attr) return []; | ||
let buffer = decoder$1(data._data, cvParam); | ||
let kind = ''; | ||
if (cvParam.contentType) { | ||
kind = cvParam.contentType; | ||
} else if (cvParam.pairOrder) { | ||
kind = cvParam.pairOrder; | ||
} else { | ||
throw new Error('unknown binary data type'); | ||
} | ||
// console.log(buffer) | ||
if (cvParam.precision === 64) { | ||
let result = {}; | ||
result.data = new Float64Array(buffer.buffer); | ||
result.kind = kind; | ||
return result; | ||
} else if (cvParam.precision === 32) { | ||
let result = {}; | ||
result.data = new Float32Array(buffer); | ||
result.kind = kind; | ||
return result; | ||
} | ||
throw new Error(`unknown precision in decoder: ${attr.precision}`); | ||
} | ||
function decoder$1(base64Encoded, cvParams = {}) { | ||
if (cvParams.compressionType === 'zlib') { | ||
return pako.inflate(base64Js.toByteArray(base64Encoded)); | ||
} else { | ||
return base64Js.toByteArray(base64Encoded); | ||
} | ||
} | ||
function processSpectrumList$2(parsed, msData) { | ||
if (!parsed.msRun.scan) return; | ||
let scanList = parsed.msRun.scan; | ||
if (Array.isArray(scanList) === false) scanList = [scanList]; | ||
if (scanList[0]._attr) { | ||
msData.info = []; | ||
} | ||
for (let scan of scanList) { | ||
if (typeof scan !== 'object') continue; | ||
if (Array.isArray(scan)) { | ||
throw new Error('processSpectrumList: scan may not be an array'); | ||
} | ||
let dataArray = parseBinaryDataArray$1(scan); | ||
let first = new Float64Array(dataArray.data.length / 2); | ||
let second = new Float64Array(dataArray.data.length / 2); | ||
for (let i = 0; i < dataArray.data.length / 2; i++) { | ||
first[i] = dataArray.data[i * 2]; | ||
second[i] = dataArray.data[i * 2 + 1]; | ||
} | ||
msData.data.push([first, second]); | ||
msData.info.push(scan._attr); | ||
} | ||
} | ||
function processMZXML(topLevel, result) { | ||
processSpectrumList$2(topLevel, result.series.ms); | ||
let offset = topLevel.index.offset; | ||
for (let i = 0; i < offset.length; i++) { | ||
let index = offset[i]._attr.id; | ||
let data = offset[i]._data; | ||
result.times[index - 1] = data; | ||
} | ||
result.metadata = { | ||
msManufacturer: topLevel.msRun.msInstrument.msManufacturer._attr, | ||
msModel: topLevel.msRun.msInstrument.msModel._attr, | ||
msIonisation: topLevel.msRun.msInstrument.msIonisation._attr, | ||
msMassAnalyzer: topLevel.msRun.msInstrument.msMassAnalyzer._attr, | ||
msDetector: topLevel.msRun.msInstrument.msDetector._attr, | ||
software: topLevel.msRun.msInstrument.software._attr, | ||
}; | ||
} | ||
function ensureText(data, options = {}) { | ||
@@ -271,2 +372,3 @@ const { encoding = 'utf8' } = options; | ||
case 'mzxml': | ||
processMZXML(topLevel.mzxml, result); | ||
break; | ||
@@ -273,0 +375,0 @@ default: |
{ | ||
"name": "mzdata", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Read and explore mzData v1.05 files", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -5,2 +5,3 @@ import { parse } from 'fast-xml-parser'; | ||
import { processMZML } from './mzml/process'; | ||
import { processMZXML } from './mzxml/process'; | ||
import { ensureText } from './util/ensureText'; | ||
@@ -50,2 +51,3 @@ import { searchObjectKey } from './util/searchObjectKey'; | ||
case 'mzxml': | ||
processMZXML(topLevel.mzxml, result); | ||
break; | ||
@@ -52,0 +54,0 @@ default: |
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
35588
27
951
3