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

brukerconverter

Package Overview
Dependencies
Maintainers
4
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

brukerconverter - npm Package Compare versions

Comparing version 1.1.2 to 2.0.0

.prettierrc

2

bower.json
{
"name": "brukerconverter",
"version": "1.1.2",
"version": "2.0.0",
"main": "build/brukerconverter.js",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/cheminfo-js/brukerconverter",

{
"name": "brukerconverter",
"version": "1.1.2",
"version": "2.0.0",
"description": "Parse and convert Bruker raw data",

@@ -30,15 +30,17 @@ "main": "./src/brukerconverter.js",

"cheminfo-tools": "1.23.3",
"eslint": "^5.16.0 ",
"eslint-config-cheminfo": "^1.20.1",
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-jest": "^22.6.4",
"jest": "^21.0.0",
"npm-run-all": "^4.1.5"
"eslint": "^6.8.0",
"eslint-config-cheminfo": "^2.0.4",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jest": "^23.7.0",
"eslint-plugin-prettier": "^3.1.2",
"jest": "^25.1.0",
"npm-run-all": "^4.1.5",
"prettier": "^1.19.1"
},
"dependencies": {
"@babel/preset-env": "^7.4.5",
"iobuffer": "^4.0.1",
"jcampconverter": "^3.0.2",
"jszip": "^3.2.1"
"@babel/preset-env": "^7.8.4",
"iobuffer": "^5.0.2",
"jcampconverter": "^5.0.2",
"jszip": "^3.2.2"
}
}

@@ -22,5 +22,6 @@ const Converter = require('jcampconverter');

'1i': BINARY,
'2rr': BINARY
'2rr': BINARY,
};
let folders = zip.filter(function (relativePath) {
let folders = zip.filter(function(relativePath) {
if (relativePath.match('__MACOSX')) return false;
if (

@@ -36,11 +37,11 @@ relativePath.endsWith('ser') ||

});
var spectra = new Array(folders.length);
let spectra = new Array(folders.length);
for (let i = 0; i < folders.length; ++i) {
var promises = [];
var name = folders[i].name;
let promises = [];
let name = folders[i].name;
name = name.substr(0, name.lastIndexOf('/') + 1);
promises.push(name);
var currFolder = zip.folder(name);
var currFiles = currFolder.filter(function (relativePath) {
let currFolder = zip.folder(name);
let currFiles = currFolder.filter(function(relativePath) {
return files[relativePath] ? true : false;

@@ -51,8 +52,8 @@ });

promises.push(
zip.file(name.replace(/pdata\/[0-9]+\//, 'acqus')).async('string')
zip.file(name.replace(/pdata\/[0-9]+\//, 'acqus')).async('string'),
);
}
for (var j = 0; j < currFiles.length; ++j) {
var idx = currFiles[j].name.lastIndexOf('/');
var name = currFiles[j].name.substr(idx + 1);
for (let j = 0; j < currFiles.length; ++j) {
let idx = currFiles[j].name.lastIndexOf('/');
name = currFiles[j].name.substr(idx + 1);
promises.push(name);

@@ -67,5 +68,5 @@ if (files[name] === BINARY) {

let brukerFiles = {};
for (let i = 1; i < result.length; i += 2) {
let name = result[i];
brukerFiles[name] = result[i + 1];
for (let k = 1; k < result.length; k += 2) {
name = result[k];
brukerFiles[name] = result[k + 1];
}

@@ -81,4 +82,4 @@ return { filename: result[0], value: convert(brukerFiles, options) };

options = options || {};
var start = new Date();
var result;
let start = new Date();
let result;
if (brukerFiles.ser || brukerFiles['2rr']) {

@@ -91,3 +92,2 @@ result = convert2D(brukerFiles, options);

}
if (result.twoD && !options.noContours) {

@@ -98,3 +98,3 @@ add2D(result);

action: 'Finished countour plot calculation',
time: new Date() - start
time: new Date() - start,
});

@@ -107,21 +107,19 @@ }

var spectra = result.spectra;
let spectra = result.spectra;
if (options.xy) {
// the spectraData should not be a oneD array but an object with x and y
//the spectraData should not be a oneD array but an object with x and y
if (spectra.length > 0) {
for (var i = 0; i < spectra.length; i++) {
var spectrum = spectra[i];
if (spectrum.data.length > 0) {
for (var j = 0; j < spectrum.data.length; j++) {
var data = spectrum.data[j];
var newData = {
x: new Array(data.length / 2),
y: new Array(data.length / 2)
};
for (var k = 0; k < data.length; k = k + 2) {
newData.x[k / 2] = data[k];
newData.y[k / 2] = data[k + 1];
}
spectrum.data[j] = newData;
for (let i = 0; i < spectra.length; i++) {
let spectrum = spectra[i];
if (spectrum.data.length) {
let data = spectrum.data;
let newData = {
x: new Array(data.length / 2),
y: new Array(data.length / 2),
};
for (let k = 0; k < data.length; k = k + 2) {
newData.x[k / 2] = data[k];
newData.y[k / 2] = data[k + 1];
}
spectrum.data = newData;
}

@@ -136,8 +134,8 @@ }

function convert1D(files, options) {
var result = parseData(files.procs || '', options);
var temp = parseData(files.acqus || '', options);
var keys = Object.keys(temp.info);
for (var i = 0; i < keys.length; i++) {
var currKey = keys[i];
let result = parseData(files.procs || '', options);
let temp = parseData(files.acqus || '', options);
let keys = Object.keys(temp.info || {});
if (!result.info) result = temp;
for (let i = 0; i < keys.length; i++) {
let currKey = keys[i];
if (result.info[currKey] === undefined) {

@@ -147,3 +145,2 @@ result.info[currKey] = temp.info[currKey];

}
if (files['1r'] || files['1i']) {

@@ -164,10 +161,9 @@ if (files['1r']) {

function convert2D(files, options) {
var sf, swP, offset;
let sf, swP, offset, result, temp;
if (files['2rr']) {
var result = parseData(files.procs, options);
var temp = parseData(files.acqus, options);
var keys = Object.keys(temp.info);
for (var i = 0; i < keys.length; i++) {
var currKey = keys[i];
result = parseData(files.procs, options);
temp = parseData(files.acqus, options);
let keys = Object.keys(temp.info);
for (let i = 0; i < keys.length; i++) {
let currKey = keys[i];
if (result.info[currKey] === undefined) {

@@ -177,5 +173,4 @@ result.info[currKey] = temp.info[currKey];

}
temp = parseData(files.proc2s, options);
result.info.nbSubSpectra = temp.info.$SI = parseInt(temp.info.$SI);
result.info.nbSubSpectra = temp.info.$SI = parseInt(temp.info.$SI, 10);
sf = temp.info.$SF = parseFloat(temp.info.$SF);

@@ -187,4 +182,4 @@ swP = temp.info.$SWP = parseFloat(temp.info.$SWP);

temp = parseData(files.acqu2s, options);
result.info.nbSubSpectra = temp.info.$SI = parseInt(temp.info.$TD);
result.info.$SI = parseInt(result.info.$TD);
result.info.nbSubSpectra = temp.info.$SI = parseInt(temp.info.$TD, 10);
result.info.$SI = parseInt(result.info.$TD, 10);
// SW_p = temp.info['$SWH'] = parseFloat(temp.info['$SWH']);

@@ -209,5 +204,5 @@

var nbSubSpectra = result.info.nbSubSpectra;
var pageValue = result.info.firstY;
var deltaY = (result.info.lastY - result.info.firstY) / (nbSubSpectra - 1);
let nbSubSpectra = result.info.nbSubSpectra;
let pageValue = result.info.firstY;
let deltaY = (result.info.lastY - result.info.firstY) / (nbSubSpectra - 1);

@@ -241,10 +236,10 @@ if (files['2rr']) {

file = ensureIOBuffer(file);
var td = (spectra.info.$SI = parseInt(spectra.info.$SI));
let td = (spectra.info.$SI = parseInt(spectra.info.$SI, 10));
var swP = parseFloat(spectra.info.$SWP);
var sf = parseFloat(spectra.info.$SF);
var bf = sf;
let swP = parseFloat(spectra.info.$SWP);
let sf = parseFloat(spectra.info.$SF);
let bf = sf;
// var BF = parseFloat(spectra.info["$BF1"]);
var offset = spectra.shiftOffsetVal || parseFloat(spectra.info.$OFFSET);
let offset = spectra.shiftOffsetVal || parseFloat(spectra.info.$OFFSET);

@@ -255,8 +250,9 @@ spectra.info.observeFrequency = sf;

spectra.info.brukerReference = bf;
spectra.info.DATATYPE = 'NMR Spectrum';
var endian = parseInt(spectra.info.$BYTORDP);
let endian = parseInt(spectra.info.$BYTORDP, 10);
endian = endian ? 0 : 1;
// number of spectras
var nbSubSpectra = spectra.info.nbSubSpectra ? spectra.info.nbSubSpectra : 1;
let nbSubSpectra = spectra.info.nbSubSpectra ? spectra.info.nbSubSpectra : 1;

@@ -269,4 +265,4 @@ if (endian) {

for (var i = 0; i < nbSubSpectra; i++) {
var toSave = {
for (let i = 0; i < nbSubSpectra; i++) {
let toSave = {
dataType: 'NMR Spectrum',

@@ -279,21 +275,18 @@ dataTable: '(X++(R..R))',

yUnit: 'Arbitrary',
data: [new Array(td * 2)], // [{x:new Array(td),y:new Array(td)}],
data: new Array(td * 2), // [{x:new Array(td),y:new Array(td)}],
isXYdata: true,
observeFrequency: sf,
title: spectra.info.TITLE,
deltaX: -(swP / sf) / (td - 1)
deltaX: -(swP / sf) / (td - 1),
};
var x = offset;
var deltaX = toSave.deltaX;
let x = offset;
let deltaX = toSave.deltaX;
if (real) {
for (var k = 0; k < td; ++k) {
toSave.data[0][2 * k] = x;
toSave.data[0][2 * k + 1] = file.readInt32();
if (
toSave.data[0][2 * k + 1] === null ||
isNaN(toSave.data[0][2 * k + 1])
) {
toSave.data[0][2 * k + 1] = 0;
for (let k = 0; k < td; ++k) {
toSave.data[2 * k] = x;
toSave.data[2 * k + 1] = file.readInt32();
if (toSave.data[2 * k + 1] === null || isNaN(toSave.data[2 * k + 1])) {
toSave.data[2 * k + 1] = 0;
}

@@ -303,10 +296,7 @@ x += deltaX;

} else {
for (k = td - 1; k >= 0; --k) {
toSave.data[0][2 * k] = x;
toSave.data[0][2 * k + 1] = file.readInt32();
if (
toSave.data[0][2 * k + 1] === null ||
isNaN(toSave.data[0][2 * k + 1])
) {
toSave.data[0][2 * k + 1] = 0;
for (let k = td - 1; k >= 0; --k) {
toSave.data[2 * k] = x;
toSave.data[2 * k + 1] = file.readInt32();
if (toSave.data[2 * k + 1] === null || isNaN(toSave.data[2 * k + 1])) {
toSave.data[2 * k + 1] = 0;
}

@@ -322,7 +312,9 @@ x += deltaX;

function parseData(file, options) {
var keepRecordsRegExp = /.*/;
let keepRecordsRegExp = /.*/;
if (options.keepRecordsRegExp) keepRecordsRegExp = options.keepRecordsRegExp;
return Converter.convert(file, {
keepRecordsRegExp: keepRecordsRegExp
let result = Converter.convert(file, {
keepRecordsRegExp: keepRecordsRegExp,
});
return result.flatten.length === 0 ? {} : result.flatten[0];
}

@@ -332,16 +324,17 @@

file = ensureIOBuffer(file);
var td = (spectra.info.$TD = parseInt(spectra.info.$TD));
let td = (spectra.info.$TD = parseInt(spectra.info.$TD, 10));
var SW = (spectra.info.$SW = parseFloat(spectra.info.$SW));
let SW = (spectra.info.$SW = parseFloat(spectra.info.$SW));
var SF = (spectra.info.$SFO1 = parseFloat(spectra.info.$SFO1));
var BF = parseFloat(spectra.info.$BF1);
let SF = (spectra.info.$SFO1 = parseFloat(spectra.info.$SFO1));
let BF = parseFloat(spectra.info.$BF1);
spectra.info.$BF1 = BF;
spectra.info.DATATYPE = 'NMR FID';
// var DW = 1 / (2 * SW_h);
// var AQ = td * DW;
var AQ = SW;
var DW = AQ / (td - 1);
let AQ = SW;
let DW = AQ / (td - 1);
var endian = parseInt(spectra.info.$BYTORDP);
let endian = parseInt(spectra.info.$BYTORDP, 10);
endian = endian ? 0 : 1;

@@ -355,7 +348,7 @@

var nbSubSpectra = spectra.info.nbSubSpectra ? spectra.info.nbSubSpectra : 1;
let nbSubSpectra = spectra.info.nbSubSpectra ? spectra.info.nbSubSpectra : 1;
spectra.spectra = new Array(nbSubSpectra);
for (var j = 0; j < nbSubSpectra / 2; j++) {
var toSave = {
for (let j = 0; j < nbSubSpectra / 2; j++) {
let toSave = {
dataType: 'NMR FID',

@@ -373,3 +366,3 @@ dataTable: '(X++(R..R))',

title: spectra.info.TITLE,
deltaX: DW
deltaX: DW,
};

@@ -387,13 +380,13 @@ spectra.spectra[j * 2] = toSave;

yUnit: 'Arbitrary',
data: [new Array(2 * td)], // [{x:new Array(td),y:new Array(td)}],
data: new Array(2 * td), // [{x:new Array(td),y:new Array(td)}],
isXYdata: true,
observeFrequency: SF,
title: spectra.info.TITLE,
deltaX: DW
deltaX: DW,
};
spectra.spectra[j * 2 + 1] = toSave;
var x = 0;
var y;
for (var i = 0; file.available(8) && i < td; i++, x = i * DW) {
let x = 0;
let y, i;
for (i = 0; file.available(8) && i < td; i++, x = i * DW) {
y = file.readInt32();

@@ -403,4 +396,4 @@ if (y === null || isNaN(y)) {

}
spectra.spectra[j * 2].data[0][2 * i + 1] = y;
spectra.spectra[j * 2].data[0][2 * i] = x;
spectra.spectra[j * 2].data[2 * i + 1] = y;
spectra.spectra[j * 2].data[2 * i] = x;
y = file.readInt32();

@@ -410,11 +403,11 @@ if (y === null || isNaN(y)) {

}
spectra.spectra[j * 2 + 1].data[0][2 * i + 1] = y;
spectra.spectra[j * 2 + 1].data[0][2 * i] = x;
spectra.spectra[j * 2 + 1].data[2 * i + 1] = y;
spectra.spectra[j * 2 + 1].data[2 * i] = x;
}
for (; i < td; i++, x = i * DW) {
spectra.spectra[j * 2].data[0][2 * i + 1] = 0;
spectra.spectra[j * 2].data[0][2 * i] = x;
spectra.spectra[j * 2 + 1].data[0][2 * i + 1] = 0;
spectra.spectra[j * 2 + 1].data[0][2 * i] = x;
spectra.spectra[j * 2].data[2 * i + 1] = 0;
spectra.spectra[j * 2].data[2 * i] = x;
spectra.spectra[j * 2 + 1].data[2 * i + 1] = 0;
spectra.spectra[j * 2 + 1].data[2 * i] = x;
}

@@ -431,14 +424,14 @@ }

function convertTo3DZ(spectra) {
var noise = 0;
var minZ = spectra[0].data[0][0];
var maxZ = minZ;
var ySize = spectra.length;
var xSize = spectra[0].data[0].length / 2;
var z = new Array(ySize);
for (var i = 0; i < ySize; i++) {
let noise = 0;
let minZ = spectra[0].data[0];
let maxZ = minZ;
let ySize = spectra.length;
let xSize = spectra[0].data.length / 2;
let z = new Array(ySize);
for (let i = 0; i < ySize; i++) {
z[i] = new Array(xSize);
for (var j = 0; j < xSize; j++) {
z[i][j] = spectra[i].data[0][j * 2 + 1];
if (z[i][j] < minZ) minZ = spectra[i].data[0][j * 2 + 1];
if (z[i][j] > maxZ) maxZ = spectra[i].data[0][j * 2 + 1];
for (let j = 0; j < xSize; j++) {
z[i][j] = spectra[i].data[j * 2 + 1];
if (z[i][j] < minZ) minZ = spectra[i].data[j * 2 + 1];
if (z[i][j] > maxZ) maxZ = spectra[i].data[j * 2 + 1];
if (i !== 0 && j !== 0) {

@@ -452,4 +445,4 @@ noise +=

z: z,
minX: spectra[0].data[0][0],
maxX: spectra[0].data[0][spectra[0].data[0].length - 2],
minX: spectra[0].data[0],
maxX: spectra[0].data[spectra[0].data.length - 2],
minY: spectra[0].pageValue,

@@ -459,3 +452,3 @@ maxY: spectra[ySize - 1].pageValue,

maxZ: maxZ,
noise: noise / ((ySize - 1) * (xSize - 1) * 2)
noise: noise / ((ySize - 1) * (xSize - 1) * 2),
};

@@ -465,3 +458,3 @@ }

function add2D(result) {
var zData = convertTo3DZ(result.spectra);
let zData = convertTo3DZ(result.spectra);
result.contourLines = generateContourLines(zData);

@@ -473,20 +466,20 @@ delete zData.z;

function generateContourLines(zData) {
var noise = zData.noise;
var z = zData.z;
var contourLevels = [];
var nbLevels = 7;
var povarHeight = new Float32Array(4);
var isOver = [];
var nbSubSpectra = z.length;
var nbPovars = z[0].length;
var pAx, pAy, pBx, pBy;
let noise = zData.noise;
let z = zData.z;
let contourLevels = [];
let nbLevels = 7;
let povarHeight = new Float32Array(4);
let isOver = [];
let nbSubSpectra = z.length;
let nbPovars = z[0].length;
let pAx, pAy, pBx, pBy;
var x0 = zData.minX;
var xN = zData.maxX;
var dx = (xN - x0) / (nbPovars - 1);
var y0 = zData.minY;
var yN = zData.maxY;
var dy = (yN - y0) / (nbSubSpectra - 1);
var minZ = zData.minZ;
var maxZ = zData.maxZ;
let x0 = zData.minX;
let xN = zData.maxX;
let dx = (xN - x0) / (nbPovars - 1);
let y0 = zData.minY;
let yN = zData.maxY;
let dy = (yN - y0) / (nbSubSpectra - 1);
let minZ = zData.minZ;
let maxZ = zData.maxZ;

@@ -504,8 +497,8 @@ // System.out.prvarln('y0 '+y0+' yN '+yN);

var lineZValue;
for (var level = 0; level < nbLevels * 2; level++) {
let lineZValue;
for (let level = 0; level < nbLevels * 2; level++) {
// multiply by 2 for positif and negatif
var contourLevel = {};
let contourLevel = {};
contourLevels.push(contourLevel);
var side = level % 2;
let side = level % 2;
if (side === 0) {

@@ -518,3 +511,3 @@ lineZValue =

}
var lines = [];
let lines = [];
contourLevel.zValue = lineZValue;

@@ -525,4 +518,4 @@ contourLevel.lines = lines;

for (var iSubSpectra = 0; iSubSpectra < nbSubSpectra - 1; iSubSpectra++) {
for (var povar = 0; povar < nbPovars - 1; povar++) {
for (let iSubSpectra = 0; iSubSpectra < nbSubSpectra - 1; iSubSpectra++) {
for (let povar = 0; povar < nbPovars - 1; povar++) {
povarHeight[0] = z[iSubSpectra][povar];

@@ -533,3 +526,3 @@ povarHeight[1] = z[iSubSpectra][povar + 1];

for (var i = 0; i < 4; i++) {
for (let i = 0; i < 4; i++) {
isOver[i] = povarHeight[i] > lineZValue;

@@ -554,3 +547,3 @@ }

pBx * dx + x0,
pBy * dy + y0
pBy * dy + y0,
);

@@ -573,3 +566,3 @@ }

pBx * dx + x0,
pBy * dy + y0
pBy * dy + y0,
);

@@ -596,3 +589,3 @@ }

pBx * dx + x0,
pBy * dy + y0
pBy * dy + y0,
);

@@ -610,3 +603,3 @@ }

pBx * dx + x0,
pBy * dy + y0
pBy * dy + y0,
);

@@ -623,3 +616,3 @@ }

pBx * dx + x0,
pBy * dy + y0
pBy * dy + y0,
);

@@ -636,3 +629,3 @@ }

pBx * dx + x0,
pBy * dy + y0
pBy * dy + y0,
);

@@ -650,3 +643,3 @@ }

maxY: zData.maxY,
segments: contourLevels
segments: contourLevels,
};

@@ -667,3 +660,3 @@ }

convertZip: readZIP,
convertFolder: convert
convertFolder: convert,
};
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