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

jcampconverter

Package Overview
Dependencies
Maintainers
5
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jcampconverter - npm Package Compare versions

Comparing version 2.7.0 to 2.8.0

30

package.json
{
"name": "jcampconverter",
"version": "2.7.0",
"version": "2.8.0",
"description": "Parse and convert JCAMP data",
"main": "./src/index.js",
"directories": {
"lib": "src",
"test": "test"
},
"files": [

@@ -14,3 +10,7 @@ "src"

"scripts": {
"test": "mocha --require should --reporter mocha-better-spec-reporter --recursive",
"eslint": "eslint src test",
"eslint-fix": "npm run eslint -- --fix",
"test": "run-s testonly eslint",
"test-travis": "eslint src && jest --coverage && codecov",
"testonly": "jest",
"build": "cheminfo build --root JcampConverter",

@@ -34,10 +34,16 @@ "benchmark": "node benchmark/benchmark.js",

},
"homepage": "https://github.com/cheminfo-js/jcampconverter",
"homepage": "https://github.com/cheminfo-js/jcampconverter#readme",
"jest": {
"testEnvironment": "node"
},
"devDependencies": {
"benchmark": "^2.1.0",
"cheminfo-tools": "^1.0.2",
"mocha": "^2.2.5",
"mocha-better-spec-reporter": "^2.1.1",
"should": "^7.0.2"
"benchmark": "^2.1.4",
"cheminfo-tools": "^1.19.2",
"codecov": "^2.3.0",
"eslint": "^4.4.1",
"eslint-config-cheminfo": "^1.8.0",
"eslint-plugin-no-only-tests": "^2.0.0",
"jest": "^20.0.4",
"npm-run-all": "^4.0.2"
}
}

14

README.md

@@ -5,6 +5,8 @@ # JCAMP converter

[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![npm download][download-image]][download-url]
Parse and convert JCAMP data
Parse and convert JCAMP data.
## Installation

@@ -38,3 +40,3 @@

* withoutXY - do not parse XYDATA or PEAKTABLE fields. Useful to only extract metadata fields (combine this option with `keepRecordsRegExp`)
* newGCMS - use the new GC/MS data format output (default: false)
* chromatogram - use the new GC/MS data format output (default: false)

@@ -85,3 +87,3 @@ 2D NMR options:

[MIT](./LICENSE)
[MIT](./LICENSE)

@@ -92,3 +94,7 @@ [npm-image]: https://img.shields.io/npm/v/jcampconverter.svg?style=flat-square

[travis-url]: https://travis-ci.org/cheminfo-js/jcampconverter
[codecov-image]: https://img.shields.io/codecov/c/github/cheminfo-js/jcampconverter.svg?style=flat-square
[codecov-url]: https://codecov.io/gh/cheminfo-js/jcampconverter
[david-image]: https://img.shields.io/david/cheminfo-js/jcampconverter.svg?style=flat-square
[david-url]: https://david-dm.org/cheminfo-js/jcampconverter
[download-image]: https://img.shields.io/npm/dm/jcampconverter.svg?style=flat-square
[download-url]: https://www.npmjs.com/package/jcampconverter
'use strict';
var parseXYDataRegExp = require('./parseXYData.js');
function getConverter() {
// the following RegExp can only be used for XYdata, some peakTables have values with a "E-5" ...
var ntuplesSeparator = /[, \t]{1,}/;
const ntuplesSeparator = /[, \t]+/;
const GC_MS_FIELDS = ['TIC', '.RIC', 'SCANNUMBER'];
var GC_MS_FIELDS = ['TIC', '.RIC', 'SCANNUMBER'];
function convertToFloatArray(stringArray) {

@@ -21,12 +16,19 @@ var l = stringArray.length;

}
function Spectrum() {
}
class Spectrum {}
const defaultOptions = {
keepRecordsRegExp: /^$/,
xy: false,
withoutXY: false,
chromatogram: false,
keepSpectra: false,
noContour: false,
nbContourLevels: 7,
noiseMultiplier: 5
};
function convert(jcamp, options) {
options = options || {};
options = Object.assign({}, defaultOptions, options);
var keepRecordsRegExp = /^$/;
if (options.keepRecordsRegExp) keepRecordsRegExp = options.keepRecordsRegExp;
var wantXY = !options.withoutXY;

@@ -36,8 +38,5 @@

var ntuples = {},
ldr,
dataLabel,
dataValue,
ldrs,
i, ii, position, endLine, infos;
var ntuples = {};
var ldr, dataLabel, dataValue, ldrs;
var i, ii, j, position, endLine, infos;

@@ -52,16 +51,21 @@ var result = {};

if (!(typeof jcamp === 'string')) return result;
// console.time('start');
if (!(typeof jcamp === 'string')) {
throw new TypeError('the JCAMP should be a string');
}
if (result.profiling) result.profiling.push({
action: 'Before split to LDRS',
time: Date.now() - start
});
if (result.profiling) {
result.profiling.push({
action: 'Before split to LDRS',
time: Date.now() - start
});
}
ldrs = jcamp.split(/[\r\n]+##/);
if (result.profiling) result.profiling.push({
action: 'Split to LDRS',
time: Date.now() - start
});
if (result.profiling) {
result.profiling.push({
action: 'Split to LDRS',
time: Date.now() - start
});
}

@@ -137,10 +141,6 @@ if (ldrs[0]) ldrs[0] = ldrs[0].replace(/^[\r\n ]*##/, '');

if (dataValue.match(/.*\+\+.*/)) {
if (options.fastParse === false) {
parseXYDataRegExp(spectrum, dataValue, result);
} else {
if (!spectrum.deltaX) {
spectrum.deltaX = (spectrum.lastX - spectrum.firstX) / (spectrum.nbPoints - 1);
}
fastParseXYData(spectrum, dataValue, result);
if (!spectrum.deltaX) {
spectrum.deltaX = (spectrum.lastX - spectrum.firstX) / (spectrum.nbPoints - 1);
}
fastParseXYData(spectrum, dataValue, result);
} else {

@@ -202,6 +202,6 @@ parsePeakTable(spectrum, dataValue, result);

} else if (dataLabel === '$OFFSET') { // OFFSET for Bruker spectra
} else if (dataLabel === '$OFFSET') { // OFFSET for Bruker spectra
result.shiftOffsetNum = 0;
if (!result.shiftOffsetVal) result.shiftOffsetVal = parseFloat(dataValue);
} else if (dataLabel === '$REFERENCEPOINT') { // OFFSET for Varian spectra
if (!result.shiftOffsetVal) result.shiftOffsetVal = parseFloat(dataValue);
} else if (dataLabel === '$REFERENCEPOINT') { // OFFSET for Varian spectra

@@ -243,3 +243,3 @@

spectrum.pageValue = parseFloat(dataValue.replace(/^.*=/, ''));
spectrum.pageSymbol = spectrum.page.replace(/=.*/, '');
spectrum.pageSymbol = spectrum.page.replace(/[=].*/, '');
var pageSymbolIndex = ntuples.symbol.indexOf(spectrum.pageSymbol);

@@ -258,3 +258,3 @@ var unit = '';

}
if (dataLabel.match(keepRecordsRegExp)) {
if (dataLabel.match(options.keepRecordsRegExp)) {
result.info[dataLabel] = dataValue.trim();

@@ -264,6 +264,8 @@ }

if (result.profiling) result.profiling.push({
action: 'Finished parsing',
time: Date.now() - start
});
if (result.profiling) {
result.profiling.push({
action: 'Finished parsing',
time: Date.now() - start
});
}

@@ -273,6 +275,6 @@ if (Object.keys(ntuples).length > 0) {

var keys = Object.keys(ntuples);
for (var i = 0; i < keys.length; i++) {
for (i = 0; i < keys.length; i++) {
var key = keys[i];
var values = ntuples[key];
for (var j = 0; j < values.length; j++) {
for (j = 0; j < values.length; j++) {
if (!newNtuples[j]) newNtuples[j] = {};

@@ -287,6 +289,8 @@ newNtuples[j][key] = values[j];

add2D(result, options);
if (result.profiling) result.profiling.push({
action: 'Finished countour plot calculation',
time: Date.now() - start
});
if (result.profiling) {
result.profiling.push({
action: 'Finished countour plot calculation',
time: Date.now() - start
});
}
if (!options.keepSpectra) {

@@ -297,4 +301,3 @@ delete result.spectra;

var isGCMS = (spectra.length > 1 && (!spectra[0].dataType || spectra[0].dataType.match(/.*mass.*/i)));
if (isGCMS && options.newGCMS) {
if (options.chromatogram) {
options.xy = true;

@@ -305,6 +308,6 @@ }

if (spectra.length > 0) {
for (var i = 0; i < spectra.length; i++) {
var spectrum = spectra[i];
for (i = 0; i < spectra.length; i++) {
spectrum = spectra[i];
if (spectrum.data.length > 0) {
for (var j = 0; j < spectrum.data.length; j++) {
for (j = 0; j < spectrum.data.length; j++) {
var data = spectrum.data[j];

@@ -329,12 +332,14 @@ var newData = {

// maybe it is a GC (HPLC) / MS. In this case we add a new format
if (isGCMS && wantXY) {
if (options.newGCMS) {
addNewGCMS(result);
if (options.chromatogram) {
if (result.spectra.length > 1) {
complexChromatogram(result);
} else {
addGCMS(result);
simpleChromatogram(result);
}
if (result.profiling) result.profiling.push({
action: 'Finished GCMS calculation',
time: Date.now() - start
});
if (result.profiling) {
result.profiling.push({
action: 'Finished chromatogram calculation',
time: Date.now() - start
});
}
}

@@ -361,12 +366,13 @@

function addNewGCMS(result) {
function complexChromatogram(result) {
var spectra = result.spectra;
var length = spectra.length;
var gcms = {
var chromatogram = {
times: new Array(length),
series: [{
name: 'ms',
dimension: 2,
data: new Array(length)
}]
series: {
ms: {
dimension: 2,
data: new Array(length)
}
}
};

@@ -380,7 +386,6 @@

existingGCMSFields.push(label);
gcms.series.push({
name: label,
chromatogram.series[label] = {
dimension: 1,
data: new Array(length)
});
};
}

@@ -391,41 +396,25 @@ }

var spectrum = spectra[i];
gcms.times[i] = spectrum.pageValue;
chromatogram.times[i] = spectrum.pageValue;
for (var j = 0; j < existingGCMSFields.length; j++) {
gcms.series[j + 1].data[i] = parseFloat(spectrum[existingGCMSFields[j]]);
chromatogram.series[existingGCMSFields[j]].data[i] = parseFloat(spectrum[existingGCMSFields[j]]);
}
if (spectrum.data) {
gcms.series[0].data[i] = [spectrum.data[0].x, spectrum.data[0].y];
chromatogram.series.ms.data[i] = [spectrum.data[0].x, spectrum.data[0].y];
}
}
result.gcms = gcms;
result.chromatogram = chromatogram;
}
function addGCMS(result) {
var spectra = result.spectra;
var existingGCMSFields = [];
var i;
for (i = 0; i < GC_MS_FIELDS.length; i++) {
var label = convertMSFieldToLabel(GC_MS_FIELDS[i]);
if (spectra[0][label]) {
existingGCMSFields.push(label);
function simpleChromatogram(result) {
var data = result.spectra[0].data[0];
result.chromatogram = {
times: data.x.slice(),
series: {
intensity: {
dimension: 1,
data: data.y.slice()
}
}
}
if (existingGCMSFields.length === 0) return;
var gcms = {};
gcms.gc = {};
gcms.ms = [];
for (i = 0; i < existingGCMSFields.length; i++) {
gcms.gc[existingGCMSFields[i]] = [];
}
for (i = 0; i < spectra.length; i++) {
var spectrum = spectra[i];
for (var j = 0; j < existingGCMSFields.length; j++) {
gcms.gc[existingGCMSFields[j]].push(spectrum.pageValue);
gcms.gc[existingGCMSFields[j]].push(parseFloat(spectrum[existingGCMSFields[j]]));
}
if (spectrum.data) gcms.ms[i] = spectrum.data[0];
}
result.gcms = gcms;
};
}

@@ -504,4 +493,2 @@

var z = zData.z;
var nbLevels = options.nbContourLevels || 7;
var noiseMultiplier = options.noiseMultiplier === undefined ? 5 : options.noiseMultiplier;
var povarHeight0, povarHeight1, povarHeight2, povarHeight3;

@@ -533,3 +520,3 @@ var isOver0, isOver1, isOver2, isOver3;

var iter = nbLevels * 2;
var iter = options.nbContourLevels * 2;
var contourLevels = new Array(iter);

@@ -541,7 +528,7 @@ var lineZValue;

var side = level % 2;
var factor = (maxZ - noiseMultiplier * noise) * Math.exp((level >> 1) - nbLevels);
var factor = (maxZ - options.noiseMultiplier * noise) * Math.exp((level >> 1) - options.nbContourLevels);
if (side === 0) {
lineZValue = factor + noiseMultiplier * noise;
lineZValue = factor + options.noiseMultiplier * noise;
} else {
lineZValue = (0 - factor) - noiseMultiplier * noise;
lineZValue = (0 - factor) - options.noiseMultiplier * noise;
}

@@ -663,4 +650,5 @@ var lines = [];

var endLine = false;
var ascii;
for (var i = 0; i < value.length; i++) {
var ascii = value.charCodeAt(i);
ascii = value.charCodeAt(i);
if (ascii === 13 || ascii === 10) {

@@ -685,3 +673,2 @@ endLine = true;

var decimalPosition = 0;
var ascii;
for (; i <= value.length; i++) {

@@ -861,4 +848,4 @@ if (i === value.length) ascii = 13;

var stamps = {},
worker;
var stamps = {};
var worker;

@@ -865,0 +852,0 @@ function postToWorker(input, options) {

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