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 2.1.2 to 3.0.0

2

bower.json
{
"name": "brukerconverter",
"version": "2.1.2",
"version": "3.0.0",
"main": "build/brukerconverter.js",

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

@@ -11,2 +11,55 @@ 'use strict';

/**
* Those functions should disappear if add2D becomes accessible in jcampconvert
* @param spectra
* @returns {{z: Array, minX: *, maxX: *, minY: *, maxY: *, minZ: *, maxZ: *, noise: number}}
*/
function convertTo3DZ(spectra) {
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 (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) {
noise +=
Math.abs(z[i][j] - z[i][j - 1]) + Math.abs(z[i][j] - z[i - 1][j]);
}
}
}
const firstX = spectra[0].data[0];
const lastX = spectra[0].data[spectra[0].data.length - 2]; // has to be -2 because it is a 1D array [x,y,x,y,...]
const firstY = spectra[0].pageValue;
const lastY = spectra[ySize - 1].pageValue;
// Because the min / max value are the only information about the matrix if we invert
// min and max we need to invert the array
if (firstX > lastX) {
for (let spectrum of z) {
spectrum.reverse();
}
}
if (firstY > lastY) {
z.reverse();
}
return {
z,
minX: Math.min(firstX, lastX),
maxX: Math.max(firstX, lastX),
minY: Math.min(firstY, lastY),
maxY: Math.max(firstY, lastY),
minZ: minZ,
maxZ: maxZ,
noise: noise / ((ySize - 1) * (xSize - 1) * 2),
};
}
function generateContourLines(zData) {

@@ -183,55 +236,2 @@ let noise = zData.noise;

/**
* Those functions should disappear if add2D becomes accessible in jcampconvert
* @param spectra
* @returns {{z: Array, minX: *, maxX: *, minY: *, maxY: *, minZ: *, maxZ: *, noise: number}}
*/
function convertTo3DZ(spectra) {
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 (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) {
noise +=
Math.abs(z[i][j] - z[i][j - 1]) + Math.abs(z[i][j] - z[i - 1][j]);
}
}
}
const firstX = spectra[0].data[0];
const lastX = spectra[0].data[spectra[0].data.length - 2]; // has to be -2 because it is a 1D array [x,y,x,y,...]
const firstY = spectra[0].pageValue;
const lastY = spectra[ySize - 1].pageValue;
// Because the min / max value are the only information about the matrix if we invert
// min and max we need to invert the array
if (firstX > lastX) {
for (let spectrum of z) {
spectrum.reverse();
}
}
if (firstY > lastY) {
z.reverse();
}
return {
z,
minX: Math.min(firstX, lastX),
maxX: Math.max(firstX, lastX),
minY: Math.min(firstY, lastY),
maxY: Math.max(firstY, lastY),
minZ: minZ,
maxZ: maxZ,
noise: noise / ((ySize - 1) * (xSize - 1) * 2),
};
}
const BINARY = 1;

@@ -283,2 +283,7 @@ const TEXT = 2;

);
let acqu2s = zip.file(name.replace(/pdata\/[0-9]+\//, 'acqu2s'));
if (acqu2s) {
promises.push('acqu2s');
promises.push(acqu2s.async('string'));
}
}

@@ -322,2 +327,27 @@ for (let j = 0; j < currFiles.length; ++j) {

}
//normalizing info
result.info.$DATE = parseFloat(result.info.$DATE);
if (result.info.$GRPDLY) {
result.info.$GRPDLY = parseFloat(result.info.$GRPDLY[0]);
result.info.$DSPFVS = parseFloat(result.info.$DSPFVS[0]);
result.info.$DECIM = parseFloat(result.info.$DECIM[0]);
}
for (let key in result.info) {
if (!Array.isArray(result.info[key])) continue;
if (key.indexOf('$') > -1) {
if (result.info[key].length === 1) {
result.info[key] = result.info[key][0];
} else if (
typeof result.info[key][0] === 'string' &&
result.info[key][0].indexOf('(0..') > -1
) {
result.info[key] = result.info[key][0];
}
} else {
result.info[key] = result.info[key][0];
}
}
if (result.twoD) {

@@ -365,10 +395,14 @@ add2D(result, 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 (!Object.keys(result).length) result = temp;
for (let key in result.info) {
result.info[key] = [result.info[key]];
}
for (let currKey in temp.info) {
if (result.info[currKey] === undefined) {
result.info[currKey] = temp.info[currKey];
result.info[currKey] = [temp.info[currKey]];
}
}
if (files['1r'] || files['1i']) {

@@ -389,40 +423,57 @@ if (files['1r']) {

function convert2D(files, options) {
let sf, swP, offset, result, temp;
if (files['2rr']) {
let sf, swP, offset, temp, temp2, result;
if (files.proc2s && files.procs) {
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) {
result.info[currKey] = temp.info[currKey];
temp = parseData(files.proc2s, options);
for (let key in temp.info) {
if (result.info[key]) {
if (!Array.isArray(result.info[key])) {
result.info[key] = [result.info[key]];
}
result.info[key].push(temp.info[key]);
} else if (result.info[key] === undefined) {
result.info[key] = [temp.info[key]];
}
}
temp = parseData(files.proc2s, options);
result.info.nbSubSpectra = temp.info.$SI = parseInt(temp.info.$SI, 10);
sf = temp.info.$SF = parseFloat(temp.info.$SF);
swP = temp.info.$SWP = parseFloat(temp.info.$SWP);
offset = temp.info.$OFFSET = parseFloat(temp.info.$OFFSET);
} else if (files.ser) {
result = parseData(files.acqus, options);
temp = parseData(files.acqu2s, options);
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']);
}
swP = temp.info.$SW;
temp = parseData(files.acqus, options);
temp2 = parseData(files.acqu2s, options);
for (let key in temp2.info) {
if (temp.info[key]) {
if (!Array.isArray(temp.info[key])) {
temp.info[key] = [temp.info[key]];
}
temp.info[key].push(temp2.info[key]);
} else if (temp.info[key] === undefined) {
temp.info[key] = [temp2.info[key]];
}
}
result.info.$SWP = result.info.$SWH;
result.info.$SF = parseFloat(temp.info.$SFO1);
result.info.$OFFSET = 0;
sf = temp.info.$SFO1 = parseFloat(temp.info.$SFO1);
offset = 0;
result.info.$AXNUC = result.info.$NUC1;
temp.info.$AXNUC = temp.info.$NUC1;
if (!result) result = temp;
for (let key in temp.info) {
if (result.info[key] === undefined) {
result.info[key] = temp.info[key];
}
}
for (let key in result.info) {
if (!Array.isArray(result.info[key])) {
result.info[key] = [result.info[key]];
}
}
result.info.nbSubSpectra = files['2rr']
? parseInt(result.info.$SI[1], 10)
: parseInt(result.info.$TD[1], 10);
if (result.info.$SWP) result.info.$SWP = result.info.$SWH;
if (!result.info.$SF) result.info.$SF = result.info.$SFO1;
if (!result.info.$OFFSET) result.info.$OFFSET = 0;
sf = parseFloat(result.info.$SF);
swP = parseFloat(result.info.$SWP || result.info.$SW);
offset = parseFloat(result.info.$OFFSET);
result.info.firstY = offset;
result.info.lastY = offset - swP / sf;
result.info.$BF2 = sf;
result.info.$SFO1 = sf;

@@ -444,6 +495,4 @@ let nbSubSpectra = result.info.nbSubSpectra;

// var dataType = files.ser ? 'TYPE_2DNMR_FID' : 'TYPE_2DNMR_SPECTRUM';
result.info['2D_Y_NUCLEUS'] = temp.info.$AXNUC;
result.info['2D_X_NUCLEUS'] = result.info.$AXNUC;
result.info['2D_Y_NUCLEUS'] = result.info.$NUC1[1];
result.info['2D_X_NUCLEUS'] = result.info.$NUC1[0];
result.info['2D_Y_FRECUENCY'] = sf;

@@ -453,5 +502,4 @@ result.info['2D_Y_OFFSET'] = offset;

result.info['2D_X_OFFSET'] = result.info.$OFFSET;
result.info.twoD = result.twoD = true;
result.twoD = true;
return result;

@@ -462,4 +510,4 @@ }

file = ensureIOBuffer(file);
let td = (spectra.info.$SI = parseInt(spectra.info.$SI, 10));
let td = parseInt(spectra.info.$SI[0], 10);
let swP = parseFloat(spectra.info.$SWP);

@@ -469,8 +517,5 @@ let sf = parseFloat(spectra.info.$SF);

// var BF = parseFloat(spectra.info["$BF1"]);
let offset = spectra.shiftOffsetVal || parseFloat(spectra.info.$OFFSET);
spectra.info.observeFrequency = sf;
spectra.info.$BF1 = bf;
spectra.info.$SFO1 = sf;
spectra.info.brukerReference = bf;

@@ -482,3 +527,2 @@ spectra.info.DATATYPE = 'NMR Spectrum';

// number of spectras
let nbSubSpectra = spectra.info.nbSubSpectra ? spectra.info.nbSubSpectra : 1;

@@ -541,3 +585,2 @@

});
return result.flatten.length === 0 ? {} : result.flatten[0];

@@ -548,8 +591,7 @@ }

file = ensureIOBuffer(file);
let td = (spectra.info.$TD = parseInt(spectra.info.$TD, 10));
let td = (spectra.info.$TD[0] = parseInt(spectra.info.$TD[0], 10));
let SW_H = (spectra.info.$SWH[0] = parseFloat(spectra.info.$SWH[0]));
let SW_H = (spectra.info.$SWH = parseFloat(spectra.info.$SWH));
let SF = (spectra.info.$SFO1 = parseFloat(spectra.info.$SFO1));
let BF = parseFloat(spectra.info.$BF1);
let SF = (spectra.info.$SFO1[0] = parseFloat(spectra.info.$SFO1[0]));
let BF = parseFloat(spectra.info.$BF1[0]);
spectra.info.$BF1 = BF;

@@ -600,5 +642,5 @@ spectra.info.DATATYPE = 'NMR FID';

yUnit: 'Arbitrary',
data: new Array(2 * td), // [{x:new Array(td),y:new Array(td)}],
data: new Array(2 * td),
isXYdata: true,
observeFrequency: SF,
directFrequency: SF,
title: spectra.info.TITLE,

@@ -605,0 +647,0 @@ deltaX: DW,

{
"name": "brukerconverter",
"version": "2.1.2",
"version": "3.0.0",
"description": "Parse and convert Bruker raw data",

@@ -35,15 +35,14 @@ "main": "lib/index.js",

"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.9.6",
"@types/jest": "^25.2.1",
"@babel/plugin-transform-modules-commonjs": "^7.10.4",
"@types/jest": "^25.2.3",
"cheminfo-build": "^1.1.1",
"cheminfo-tools": "1.23.3",
"eslint": "^6.8.0",
"eslint-config-cheminfo": "^3.0.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jest": "^23.8.2",
"eslint-plugin-prettier": "^3.1.3",
"jest": "^25.5.2",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^23.18.0",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^25.5.4",
"npm-run-all": "^4.1.5",
"prettier": "^2.0.5",
"rollup": "^2.7.3"
"rollup": "^2.19.0"
},

@@ -53,4 +52,4 @@ "dependencies": {

"jcampconverter": "^5.0.2",
"jszip": "^3.4.0"
"jszip": "^3.5.0"
}
}
import { IOBuffer } from 'iobuffer';
import { convert as convertJcamp } from 'jcampconverter';
import JSZip from 'jszip/dist/jszip';
import convertTo3DZ from './convertTo3DZ';
import generateContourLines from './generateContourLines';
import convertTo3DZ from './convertTo3DZ';

@@ -53,2 +54,7 @@ const BINARY = 1;

);
let acqu2s = zip.file(name.replace(/pdata\/[0-9]+\//, 'acqu2s'));
if (acqu2s) {
promises.push('acqu2s');
promises.push(acqu2s.async('string'));
}
}

@@ -92,2 +98,27 @@ for (let j = 0; j < currFiles.length; ++j) {

}
//normalizing info
result.info.$DATE = parseFloat(result.info.$DATE);
if (result.info.$GRPDLY) {
result.info.$GRPDLY = parseFloat(result.info.$GRPDLY[0]);
result.info.$DSPFVS = parseFloat(result.info.$DSPFVS[0]);
result.info.$DECIM = parseFloat(result.info.$DECIM[0]);
}
for (let key in result.info) {
if (!Array.isArray(result.info[key])) continue;
if (key.indexOf('$') > -1) {
if (result.info[key].length === 1) {
result.info[key] = result.info[key][0];
} else if (
typeof result.info[key][0] === 'string' &&
result.info[key][0].indexOf('(0..') > -1
) {
result.info[key] = result.info[key][0];
}
} else {
result.info[key] = result.info[key][0];
}
}
if (result.twoD) {

@@ -135,10 +166,14 @@ add2D(result, 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 (!Object.keys(result).length) result = temp;
for (let key in result.info) {
result.info[key] = [result.info[key]];
}
for (let currKey in temp.info) {
if (result.info[currKey] === undefined) {
result.info[currKey] = temp.info[currKey];
result.info[currKey] = [temp.info[currKey]];
}
}
if (files['1r'] || files['1i']) {

@@ -159,40 +194,57 @@ if (files['1r']) {

function convert2D(files, options) {
let sf, swP, offset, result, temp;
if (files['2rr']) {
let sf, swP, offset, temp, temp2, result;
if (files.proc2s && files.procs) {
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) {
result.info[currKey] = temp.info[currKey];
temp = parseData(files.proc2s, options);
for (let key in temp.info) {
if (result.info[key]) {
if (!Array.isArray(result.info[key])) {
result.info[key] = [result.info[key]];
}
result.info[key].push(temp.info[key]);
} else if (result.info[key] === undefined) {
result.info[key] = [temp.info[key]];
}
}
temp = parseData(files.proc2s, options);
result.info.nbSubSpectra = temp.info.$SI = parseInt(temp.info.$SI, 10);
sf = temp.info.$SF = parseFloat(temp.info.$SF);
swP = temp.info.$SWP = parseFloat(temp.info.$SWP);
offset = temp.info.$OFFSET = parseFloat(temp.info.$OFFSET);
} else if (files.ser) {
result = parseData(files.acqus, options);
temp = parseData(files.acqu2s, options);
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']);
}
swP = temp.info.$SW;
temp = parseData(files.acqus, options);
temp2 = parseData(files.acqu2s, options);
for (let key in temp2.info) {
if (temp.info[key]) {
if (!Array.isArray(temp.info[key])) {
temp.info[key] = [temp.info[key]];
}
temp.info[key].push(temp2.info[key]);
} else if (temp.info[key] === undefined) {
temp.info[key] = [temp2.info[key]];
}
}
result.info.$SWP = result.info.$SWH;
result.info.$SF = parseFloat(temp.info.$SFO1);
result.info.$OFFSET = 0;
sf = temp.info.$SFO1 = parseFloat(temp.info.$SFO1);
offset = 0;
result.info.$AXNUC = result.info.$NUC1;
temp.info.$AXNUC = temp.info.$NUC1;
if (!result) result = temp;
for (let key in temp.info) {
if (result.info[key] === undefined) {
result.info[key] = temp.info[key];
}
}
for (let key in result.info) {
if (!Array.isArray(result.info[key])) {
result.info[key] = [result.info[key]];
}
}
result.info.nbSubSpectra = files['2rr']
? parseInt(result.info.$SI[1], 10)
: parseInt(result.info.$TD[1], 10);
if (result.info.$SWP) result.info.$SWP = result.info.$SWH;
if (!result.info.$SF) result.info.$SF = result.info.$SFO1;
if (!result.info.$OFFSET) result.info.$OFFSET = 0;
sf = parseFloat(result.info.$SF);
swP = parseFloat(result.info.$SWP || result.info.$SW);
offset = parseFloat(result.info.$OFFSET);
result.info.firstY = offset;
result.info.lastY = offset - swP / sf;
result.info.$BF2 = sf;
result.info.$SFO1 = sf;

@@ -214,6 +266,4 @@ let nbSubSpectra = result.info.nbSubSpectra;

// var dataType = files.ser ? 'TYPE_2DNMR_FID' : 'TYPE_2DNMR_SPECTRUM';
result.info['2D_Y_NUCLEUS'] = temp.info.$AXNUC;
result.info['2D_X_NUCLEUS'] = result.info.$AXNUC;
result.info['2D_Y_NUCLEUS'] = result.info.$NUC1[1];
result.info['2D_X_NUCLEUS'] = result.info.$NUC1[0];
result.info['2D_Y_FRECUENCY'] = sf;

@@ -223,5 +273,4 @@ result.info['2D_Y_OFFSET'] = offset;

result.info['2D_X_OFFSET'] = result.info.$OFFSET;
result.info.twoD = result.twoD = true;
result.twoD = true;
return result;

@@ -232,4 +281,4 @@ }

file = ensureIOBuffer(file);
let td = (spectra.info.$SI = parseInt(spectra.info.$SI, 10));
let td = parseInt(spectra.info.$SI[0], 10);
let swP = parseFloat(spectra.info.$SWP);

@@ -239,8 +288,5 @@ let sf = parseFloat(spectra.info.$SF);

// var BF = parseFloat(spectra.info["$BF1"]);
let offset = spectra.shiftOffsetVal || parseFloat(spectra.info.$OFFSET);
spectra.info.observeFrequency = sf;
spectra.info.$BF1 = bf;
spectra.info.$SFO1 = sf;
spectra.info.brukerReference = bf;

@@ -252,3 +298,2 @@ spectra.info.DATATYPE = 'NMR Spectrum';

// number of spectras
let nbSubSpectra = spectra.info.nbSubSpectra ? spectra.info.nbSubSpectra : 1;

@@ -311,3 +356,2 @@

});
return result.flatten.length === 0 ? {} : result.flatten[0];

@@ -318,8 +362,7 @@ }

file = ensureIOBuffer(file);
let td = (spectra.info.$TD = parseInt(spectra.info.$TD, 10));
let td = (spectra.info.$TD[0] = parseInt(spectra.info.$TD[0], 10));
let SW_H = (spectra.info.$SWH[0] = parseFloat(spectra.info.$SWH[0]));
let SW_H = (spectra.info.$SWH = parseFloat(spectra.info.$SWH));
let SF = (spectra.info.$SFO1 = parseFloat(spectra.info.$SFO1));
let BF = parseFloat(spectra.info.$BF1);
let SF = (spectra.info.$SFO1[0] = parseFloat(spectra.info.$SFO1[0]));
let BF = parseFloat(spectra.info.$BF1[0]);
spectra.info.$BF1 = BF;

@@ -370,5 +413,5 @@ spectra.info.DATATYPE = 'NMR FID';

yUnit: 'Arbitrary',
data: new Array(2 * td), // [{x:new Array(td),y:new Array(td)}],
data: new Array(2 * td),
isXYdata: true,
observeFrequency: SF,
directFrequency: SF,
title: spectra.info.TITLE,

@@ -375,0 +418,0 @@ deltaX: DW,

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