jcampconverter 8.2.2 → 8.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/2d/add2D.d.ts +2 -0
- package/lib/2d/add2D.d.ts.map +1 -0
- package/lib/2d/add2D.js +17 -0
- package/lib/2d/add2D.js.map +1 -0
- package/lib/2d/convertTo3DZ.d.ts +11 -0
- package/lib/2d/convertTo3DZ.d.ts.map +1 -0
- package/lib/2d/convertTo3DZ.js +59 -0
- package/lib/2d/convertTo3DZ.js.map +1 -0
- package/lib/2d/generateContourLines.d.ts +8 -0
- package/lib/2d/generateContourLines.d.ts.map +1 -0
- package/lib/2d/generateContourLines.js +163 -0
- package/lib/2d/generateContourLines.js.map +1 -0
- package/lib/complexChromatogram.d.ts +4 -0
- package/lib/complexChromatogram.d.ts.map +1 -0
- package/lib/complexChromatogram.js +49 -0
- package/lib/complexChromatogram.js.map +1 -0
- package/lib/convert.d.ts +139 -0
- package/lib/convert.d.ts.map +1 -0
- package/lib/convert.js +383 -0
- package/lib/convert.js.map +1 -0
- package/lib/convertToFloatArray.d.ts +2 -0
- package/lib/convertToFloatArray.d.ts.map +1 -0
- package/lib/convertToFloatArray.js +11 -0
- package/lib/convertToFloatArray.js.map +1 -0
- package/lib/createTree.d.ts +29 -0
- package/lib/createTree.d.ts.map +1 -0
- package/lib/createTree.js +98 -0
- package/lib/createTree.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +8 -1214
- package/lib/index.js.map +1 -0
- package/lib/parse/fastParseXYData.d.ts +2 -0
- package/lib/parse/fastParseXYData.d.ts.map +1 -0
- package/lib/parse/fastParseXYData.js +192 -0
- package/lib/parse/fastParseXYData.js.map +1 -0
- package/lib/parse/parsePeakTable.d.ts +2 -0
- package/lib/parse/parsePeakTable.d.ts.map +1 -0
- package/lib/parse/parsePeakTable.js +67 -0
- package/lib/parse/parsePeakTable.js.map +1 -0
- package/lib/parse/parseXYA.d.ts +2 -0
- package/lib/parse/parseXYA.d.ts.map +1 -0
- package/lib/parse/parseXYA.js +17 -0
- package/lib/parse/parseXYA.js.map +1 -0
- package/lib/postProcessing.d.ts +2 -0
- package/lib/postProcessing.d.ts.map +1 -0
- package/lib/postProcessing.js +50 -0
- package/lib/postProcessing.js.map +1 -0
- package/lib/postProcessingNMR.d.ts +2 -0
- package/lib/postProcessingNMR.d.ts.map +1 -0
- package/lib/postProcessingNMR.js +94 -0
- package/lib/postProcessingNMR.js.map +1 -0
- package/lib/prepareNtuplesDatatable.d.ts +2 -0
- package/lib/prepareNtuplesDatatable.d.ts.map +1 -0
- package/lib/prepareNtuplesDatatable.js +87 -0
- package/lib/prepareNtuplesDatatable.js.map +1 -0
- package/lib/prepareSpectrum.d.ts +2 -0
- package/lib/prepareSpectrum.d.ts.map +1 -0
- package/lib/prepareSpectrum.js +10 -0
- package/lib/prepareSpectrum.js.map +1 -0
- package/lib/profiling.d.ts +2 -0
- package/lib/profiling.d.ts.map +1 -0
- package/lib/profiling.js +12 -0
- package/lib/profiling.js.map +1 -0
- package/lib/simpleChromatogram.d.ts +2 -0
- package/lib/simpleChromatogram.d.ts.map +1 -0
- package/lib/simpleChromatogram.js +16 -0
- package/lib/simpleChromatogram.js.map +1 -0
- package/lib-esm/2d/add2D.d.ts +2 -0
- package/lib-esm/2d/add2D.d.ts.map +1 -0
- package/lib-esm/2d/add2D.js +11 -0
- package/lib-esm/2d/add2D.js.map +1 -0
- package/lib-esm/2d/convertTo3DZ.d.ts +11 -0
- package/lib-esm/2d/convertTo3DZ.d.ts.map +1 -0
- package/lib-esm/2d/convertTo3DZ.js +53 -0
- package/lib-esm/2d/convertTo3DZ.js.map +1 -0
- package/lib-esm/2d/generateContourLines.d.ts +8 -0
- package/lib-esm/2d/generateContourLines.d.ts.map +1 -0
- package/lib-esm/2d/generateContourLines.js +160 -0
- package/lib-esm/2d/generateContourLines.js.map +1 -0
- package/lib-esm/complexChromatogram.d.ts +4 -0
- package/lib-esm/complexChromatogram.d.ts.map +1 -0
- package/lib-esm/complexChromatogram.js +43 -0
- package/lib-esm/complexChromatogram.js.map +1 -0
- package/lib-esm/convert.d.ts +139 -0
- package/lib-esm/convert.d.ts.map +1 -0
- package/lib-esm/convert.js +376 -0
- package/lib-esm/convert.js.map +1 -0
- package/lib-esm/convertToFloatArray.d.ts +2 -0
- package/lib-esm/convertToFloatArray.d.ts.map +1 -0
- package/lib-esm/convertToFloatArray.js +8 -0
- package/lib-esm/convertToFloatArray.js.map +1 -0
- package/lib-esm/createTree.d.ts +29 -0
- package/lib-esm/createTree.d.ts.map +1 -0
- package/lib-esm/createTree.js +94 -0
- package/lib-esm/createTree.js.map +1 -0
- package/lib-esm/index.d.ts +3 -0
- package/lib-esm/index.d.ts.map +1 -0
- package/lib-esm/index.js +3 -0
- package/lib-esm/index.js.map +1 -0
- package/lib-esm/parse/fastParseXYData.d.ts +2 -0
- package/lib-esm/parse/fastParseXYData.d.ts.map +1 -0
- package/lib-esm/parse/fastParseXYData.js +189 -0
- package/lib-esm/parse/fastParseXYData.js.map +1 -0
- package/lib-esm/parse/parsePeakTable.d.ts +2 -0
- package/lib-esm/parse/parsePeakTable.d.ts.map +1 -0
- package/lib-esm/parse/parsePeakTable.js +64 -0
- package/lib-esm/parse/parsePeakTable.js.map +1 -0
- package/lib-esm/parse/parseXYA.d.ts +2 -0
- package/lib-esm/parse/parseXYA.d.ts.map +1 -0
- package/lib-esm/parse/parseXYA.js +14 -0
- package/lib-esm/parse/parseXYA.js.map +1 -0
- package/lib-esm/postProcessing.d.ts +2 -0
- package/lib-esm/postProcessing.d.ts.map +1 -0
- package/lib-esm/postProcessing.js +44 -0
- package/lib-esm/postProcessing.js.map +1 -0
- package/lib-esm/postProcessingNMR.d.ts +2 -0
- package/lib-esm/postProcessingNMR.d.ts.map +1 -0
- package/lib-esm/postProcessingNMR.js +91 -0
- package/lib-esm/postProcessingNMR.js.map +1 -0
- package/lib-esm/prepareNtuplesDatatable.d.ts +2 -0
- package/lib-esm/prepareNtuplesDatatable.d.ts.map +1 -0
- package/lib-esm/prepareNtuplesDatatable.js +84 -0
- package/lib-esm/prepareNtuplesDatatable.js.map +1 -0
- package/lib-esm/prepareSpectrum.d.ts +2 -0
- package/lib-esm/prepareSpectrum.d.ts.map +1 -0
- package/lib-esm/prepareSpectrum.js +7 -0
- package/lib-esm/prepareSpectrum.js.map +1 -0
- package/lib-esm/profiling.d.ts +2 -0
- package/lib-esm/profiling.d.ts.map +1 -0
- package/lib-esm/profiling.js +9 -0
- package/lib-esm/profiling.js.map +1 -0
- package/lib-esm/simpleChromatogram.d.ts +2 -0
- package/lib-esm/simpleChromatogram.d.ts.map +1 -0
- package/lib-esm/simpleChromatogram.js +13 -0
- package/lib-esm/simpleChromatogram.js.map +1 -0
- package/package.json +22 -17
- package/src/convert.js +57 -13
- package/src/createTree.js +16 -3
- package/CHANGELOG.md +0 -427
package/lib/convert.js
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.convert = void 0;
|
|
7
|
+
const dynamic_typing_1 = require("dynamic-typing");
|
|
8
|
+
const ensure_string_1 = require("ensure-string");
|
|
9
|
+
const complexChromatogram_1 = require("./complexChromatogram");
|
|
10
|
+
const convertToFloatArray_1 = __importDefault(require("./convertToFloatArray"));
|
|
11
|
+
const fastParseXYData_1 = __importDefault(require("./parse/fastParseXYData"));
|
|
12
|
+
const parsePeakTable_1 = __importDefault(require("./parse/parsePeakTable"));
|
|
13
|
+
const parseXYA_1 = __importDefault(require("./parse/parseXYA"));
|
|
14
|
+
const postProcessing_1 = __importDefault(require("./postProcessing"));
|
|
15
|
+
const prepareNtuplesDatatable_1 = __importDefault(require("./prepareNtuplesDatatable"));
|
|
16
|
+
const prepareSpectrum_1 = __importDefault(require("./prepareSpectrum"));
|
|
17
|
+
const profiling_1 = __importDefault(require("./profiling"));
|
|
18
|
+
// the following RegExp can only be used for XYdata, some peakTables have values with a "E-5" ...
|
|
19
|
+
const ntuplesSeparatorRegExp = /[ \t]*,[ \t]*/;
|
|
20
|
+
class Spectrum {
|
|
21
|
+
}
|
|
22
|
+
const defaultOptions = {
|
|
23
|
+
keepRecordsRegExp: /^$/,
|
|
24
|
+
canonicDataLabels: true,
|
|
25
|
+
canonicMetadataLabels: false,
|
|
26
|
+
dynamicTyping: true,
|
|
27
|
+
withoutXY: false,
|
|
28
|
+
chromatogram: false,
|
|
29
|
+
keepSpectra: false,
|
|
30
|
+
noContour: false,
|
|
31
|
+
nbContourLevels: 7,
|
|
32
|
+
noiseMultiplier: 5,
|
|
33
|
+
profiling: false,
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @typedef {object} ConvertOptions
|
|
38
|
+
* @property {RegExp} [options.keepRecordsRegExp=/^$/] - By default we don't keep meta information.
|
|
39
|
+
* @property {boolean} [options.canonicDataLabels=true] - Canonize the Labels (uppercase without symbol).
|
|
40
|
+
* @property {boolean} [options.canonicMetadataLabels=false] - Canonize the metadata Labels (uppercase without symbol).
|
|
41
|
+
* @property {boolean} [options.dynamicTyping=false] - Convert numbers to Number.
|
|
42
|
+
* @property {boolean} [options.withoutXY=false] - Remove the XY data.
|
|
43
|
+
* @property {boolean} [options.chromatogram=false] - Special post-processing for GC / HPLC / MS.
|
|
44
|
+
* @property {boolean} [options.keepSpectra=false] - Force to keep the spectra in case of 2D.
|
|
45
|
+
* @property {boolean} [options.noContour=false] - Don't calculate countour in case of 2D.
|
|
46
|
+
* @property {number} [options.nbContourLevels=7] - Number of positive / negative contour levels to calculate.
|
|
47
|
+
* @property {number} [options.noiseMultiplier=5] - Define for 2D the level as 5 times the median as default.
|
|
48
|
+
* @property {boolean} [options.profiling=false] - Add profiling information.
|
|
49
|
+
*/
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @typedef {object} Ntuples
|
|
53
|
+
* @property {string[]} [varname]
|
|
54
|
+
* @property {string[]} [symbol]
|
|
55
|
+
* @property {string[]} [vartype]
|
|
56
|
+
* @property {string[]} [varform]
|
|
57
|
+
* @property {number[]} [vardim]
|
|
58
|
+
* @property {string[]} [units]
|
|
59
|
+
* @property {number[]} [factor]
|
|
60
|
+
* @property {number[]} [first]
|
|
61
|
+
* @property {number[]} [last]
|
|
62
|
+
* @property {number[]} [min]
|
|
63
|
+
* @property {number[]} [max]
|
|
64
|
+
* @property {string[]} [nucleus]
|
|
65
|
+
*/
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @typedef { object } Entry
|
|
69
|
+
* @property {Spectrum[]} spectra
|
|
70
|
+
* @property {Ntuples} ntuples
|
|
71
|
+
* @property {object} meta
|
|
72
|
+
* @property {object} tmp
|
|
73
|
+
* @property {string} [title]
|
|
74
|
+
* @property {string} [dataType]
|
|
75
|
+
* @property {string} [dataClass]
|
|
76
|
+
* @property {boolean} [twoD]
|
|
77
|
+
*/
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @typedef { object } ConvertResult
|
|
81
|
+
* @property { object[] | boolean } profiling
|
|
82
|
+
* @property { string[] } logs
|
|
83
|
+
* @property { object[] } entries
|
|
84
|
+
* @property { Entry[] } flatten
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* Parse a jcamp.
|
|
88
|
+
*
|
|
89
|
+
* @param {string|ArrayBuffer|Uint8Array} jcamp
|
|
90
|
+
* @param {ConvertOptions} [options]
|
|
91
|
+
* @returns {ConvertResult}
|
|
92
|
+
*/
|
|
93
|
+
function convert(jcamp, options = {}) {
|
|
94
|
+
jcamp = (0, ensure_string_1.ensureString)(jcamp);
|
|
95
|
+
options = { ...defaultOptions, ...options };
|
|
96
|
+
options.wantXY = !options.withoutXY;
|
|
97
|
+
options.start = Date.now();
|
|
98
|
+
let entriesFlat = [];
|
|
99
|
+
let result = {
|
|
100
|
+
profiling: options.profiling ? [] : false,
|
|
101
|
+
logs: [],
|
|
102
|
+
entries: [],
|
|
103
|
+
};
|
|
104
|
+
let tmpResult = { children: [] };
|
|
105
|
+
let currentEntry = tmpResult;
|
|
106
|
+
let parentsStack = [];
|
|
107
|
+
let spectrum = new Spectrum();
|
|
108
|
+
if (typeof jcamp !== 'string') {
|
|
109
|
+
throw new TypeError('the JCAMP should be a string');
|
|
110
|
+
}
|
|
111
|
+
(0, profiling_1.default)(result, 'Before split to LDRS', options);
|
|
112
|
+
let ldrs = jcamp.replace(/[\r\n]+##/g, '\n##').split('\n##');
|
|
113
|
+
(0, profiling_1.default)(result, 'Split to LDRS', options);
|
|
114
|
+
if (ldrs[0])
|
|
115
|
+
ldrs[0] = ldrs[0].replace(/^[\r\n ]*##/, '');
|
|
116
|
+
for (let ldr of ldrs) {
|
|
117
|
+
// This is a new LDR
|
|
118
|
+
let position = ldr.indexOf('=');
|
|
119
|
+
let dataLabel = position > 0 ? ldr.substring(0, position) : ldr;
|
|
120
|
+
let dataValue = position > 0 ? ldr.substring(position + 1).trim() : '';
|
|
121
|
+
let canonicDataLabel = dataLabel.replace(/[_ -]/g, '').toUpperCase();
|
|
122
|
+
if (canonicDataLabel === 'DATATABLE') {
|
|
123
|
+
let endLine = dataValue.indexOf('\n');
|
|
124
|
+
if (endLine === -1)
|
|
125
|
+
endLine = dataValue.indexOf('\r');
|
|
126
|
+
if (endLine > 0) {
|
|
127
|
+
// ##DATA TABLE= (X++(I..I)), XYDATA
|
|
128
|
+
// We need to find the variables
|
|
129
|
+
let infos = dataValue.substring(0, endLine).split(/[ ,;\t]+/);
|
|
130
|
+
(0, prepareNtuplesDatatable_1.default)(currentEntry, spectrum, infos[0]);
|
|
131
|
+
spectrum.datatable = infos[0];
|
|
132
|
+
if (infos[1] && infos[1].indexOf('PEAKS') > -1) {
|
|
133
|
+
canonicDataLabel = 'PEAKTABLE';
|
|
134
|
+
}
|
|
135
|
+
else if (infos[1] &&
|
|
136
|
+
(infos[1].indexOf('XYDATA') || infos[0].indexOf('++') > 0)) {
|
|
137
|
+
canonicDataLabel = 'XYDATA';
|
|
138
|
+
spectrum.deltaX =
|
|
139
|
+
(spectrum.lastX - spectrum.firstX) / (spectrum.nbPoints - 1);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (canonicDataLabel === 'XYDATA') {
|
|
144
|
+
if (options.wantXY) {
|
|
145
|
+
(0, prepareSpectrum_1.default)(spectrum);
|
|
146
|
+
// well apparently we should still consider it is a PEAK TABLE if there are no '++' after
|
|
147
|
+
if (dataValue.match(/.*\+\+.*/)) {
|
|
148
|
+
// ex: (X++(Y..Y))
|
|
149
|
+
spectrum.deltaX =
|
|
150
|
+
(spectrum.lastX - spectrum.firstX) / (spectrum.nbPoints - 1);
|
|
151
|
+
(0, fastParseXYData_1.default)(spectrum, dataValue, result);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
(0, parsePeakTable_1.default)(spectrum, dataValue, result);
|
|
155
|
+
}
|
|
156
|
+
currentEntry.spectra.push(spectrum);
|
|
157
|
+
spectrum = new Spectrum();
|
|
158
|
+
}
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
else if (canonicDataLabel === 'PEAKTABLE') {
|
|
162
|
+
if (options.wantXY) {
|
|
163
|
+
(0, prepareSpectrum_1.default)(spectrum);
|
|
164
|
+
(0, parsePeakTable_1.default)(spectrum, dataValue, result);
|
|
165
|
+
currentEntry.spectra.push(spectrum);
|
|
166
|
+
spectrum = new Spectrum();
|
|
167
|
+
}
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (canonicDataLabel === 'PEAKASSIGNMENTS') {
|
|
171
|
+
if (options.wantXY) {
|
|
172
|
+
if (dataValue.match(/.*(XYA).*/)) {
|
|
173
|
+
// ex: (XYA)
|
|
174
|
+
(0, parseXYA_1.default)(spectrum, dataValue);
|
|
175
|
+
}
|
|
176
|
+
currentEntry.spectra.push(spectrum);
|
|
177
|
+
spectrum = new Spectrum();
|
|
178
|
+
}
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (canonicDataLabel === 'TITLE') {
|
|
182
|
+
let parentEntry = currentEntry;
|
|
183
|
+
if (!parentEntry.children) {
|
|
184
|
+
parentEntry.children = [];
|
|
185
|
+
}
|
|
186
|
+
currentEntry = {
|
|
187
|
+
spectra: [],
|
|
188
|
+
ntuples: {},
|
|
189
|
+
info: {},
|
|
190
|
+
meta: {},
|
|
191
|
+
tmp: {}, // tmp information we need to keep for postprocessing
|
|
192
|
+
};
|
|
193
|
+
parentEntry.children.push(currentEntry);
|
|
194
|
+
parentsStack.push(parentEntry);
|
|
195
|
+
entriesFlat.push(currentEntry);
|
|
196
|
+
currentEntry.title = dataValue;
|
|
197
|
+
}
|
|
198
|
+
else if (canonicDataLabel === 'DATATYPE') {
|
|
199
|
+
currentEntry.dataType = dataValue;
|
|
200
|
+
if (dataValue.match(/(^nd|\snd\s)/i)) {
|
|
201
|
+
currentEntry.twoD = true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else if (canonicDataLabel === 'NTUPLES') {
|
|
205
|
+
if (dataValue.match(/(^nd|\snd\s)/i)) {
|
|
206
|
+
currentEntry.twoD = true;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
else if (canonicDataLabel === 'DATACLASS') {
|
|
210
|
+
currentEntry.dataClass = dataValue;
|
|
211
|
+
}
|
|
212
|
+
else if (canonicDataLabel === 'XUNITS') {
|
|
213
|
+
spectrum.xUnits = dataValue;
|
|
214
|
+
}
|
|
215
|
+
else if (canonicDataLabel === 'YUNITS') {
|
|
216
|
+
spectrum.yUnits = dataValue;
|
|
217
|
+
}
|
|
218
|
+
else if (canonicDataLabel === 'FIRSTX') {
|
|
219
|
+
spectrum.firstX = Number(dataValue);
|
|
220
|
+
}
|
|
221
|
+
else if (canonicDataLabel === 'LASTX') {
|
|
222
|
+
spectrum.lastX = Number(dataValue);
|
|
223
|
+
}
|
|
224
|
+
else if (canonicDataLabel === 'FIRSTY') {
|
|
225
|
+
spectrum.firstY = Number(dataValue);
|
|
226
|
+
}
|
|
227
|
+
else if (canonicDataLabel === 'LASTY') {
|
|
228
|
+
spectrum.lastY = Number(dataValue);
|
|
229
|
+
}
|
|
230
|
+
else if (canonicDataLabel === 'NPOINTS') {
|
|
231
|
+
spectrum.nbPoints = Number(dataValue);
|
|
232
|
+
}
|
|
233
|
+
else if (canonicDataLabel === 'XFACTOR') {
|
|
234
|
+
spectrum.xFactor = Number(dataValue);
|
|
235
|
+
}
|
|
236
|
+
else if (canonicDataLabel === 'YFACTOR') {
|
|
237
|
+
spectrum.yFactor = Number(dataValue);
|
|
238
|
+
}
|
|
239
|
+
else if (canonicDataLabel === 'MAXX') {
|
|
240
|
+
spectrum.maxX = Number(dataValue);
|
|
241
|
+
}
|
|
242
|
+
else if (canonicDataLabel === 'MINX') {
|
|
243
|
+
spectrum.minX = Number(dataValue);
|
|
244
|
+
}
|
|
245
|
+
else if (canonicDataLabel === 'MAXY') {
|
|
246
|
+
spectrum.maxY = Number(dataValue);
|
|
247
|
+
}
|
|
248
|
+
else if (canonicDataLabel === 'MINY') {
|
|
249
|
+
spectrum.minY = Number(dataValue);
|
|
250
|
+
}
|
|
251
|
+
else if (canonicDataLabel === 'DELTAX') {
|
|
252
|
+
spectrum.deltaX = Number(dataValue);
|
|
253
|
+
}
|
|
254
|
+
else if (canonicDataLabel === '.OBSERVEFREQUENCY' ||
|
|
255
|
+
canonicDataLabel === '$SFO1') {
|
|
256
|
+
if (!spectrum.observeFrequency) {
|
|
257
|
+
spectrum.observeFrequency = Number(dataValue);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
else if (canonicDataLabel === '.OBSERVENUCLEUS') {
|
|
261
|
+
if (!spectrum.xType) {
|
|
262
|
+
currentEntry.xType = dataValue.replace(/[^a-zA-Z0-9]/g, '');
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
else if (canonicDataLabel === '$OFFSET') {
|
|
266
|
+
// OFFSET for Bruker spectra
|
|
267
|
+
currentEntry.shiftOffsetNum = 0;
|
|
268
|
+
if (!spectrum.shiftOffsetVal) {
|
|
269
|
+
spectrum.shiftOffsetVal = Number(dataValue);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
else if (canonicDataLabel === '$REFERENCEPOINT') {
|
|
273
|
+
// OFFSET for Varian spectra
|
|
274
|
+
// if we activate this part it does not work for ACD specmanager
|
|
275
|
+
// } else if (canonicDataLabel=='.SHIFTREFERENCE') { // OFFSET FOR Bruker Spectra
|
|
276
|
+
// var parts = dataValue.split(/ *, */);
|
|
277
|
+
// currentEntry.shiftOffsetNum = parseInt(parts[2].trim());
|
|
278
|
+
// spectrum.shiftOffsetVal = Number(parts[3].trim());
|
|
279
|
+
}
|
|
280
|
+
else if (canonicDataLabel === 'VARNAME') {
|
|
281
|
+
currentEntry.ntuples.varname = dataValue.split(ntuplesSeparatorRegExp);
|
|
282
|
+
}
|
|
283
|
+
else if (canonicDataLabel === 'SYMBOL') {
|
|
284
|
+
currentEntry.ntuples.symbol = dataValue.split(ntuplesSeparatorRegExp);
|
|
285
|
+
}
|
|
286
|
+
else if (canonicDataLabel === 'VARTYPE') {
|
|
287
|
+
currentEntry.ntuples.vartype = dataValue.split(ntuplesSeparatorRegExp);
|
|
288
|
+
}
|
|
289
|
+
else if (canonicDataLabel === 'VARFORM') {
|
|
290
|
+
currentEntry.ntuples.varform = dataValue.split(ntuplesSeparatorRegExp);
|
|
291
|
+
}
|
|
292
|
+
else if (canonicDataLabel === 'VARDIM') {
|
|
293
|
+
currentEntry.ntuples.vardim = (0, convertToFloatArray_1.default)(dataValue.split(ntuplesSeparatorRegExp));
|
|
294
|
+
}
|
|
295
|
+
else if (canonicDataLabel === 'UNITS') {
|
|
296
|
+
currentEntry.ntuples.units = dataValue.split(ntuplesSeparatorRegExp);
|
|
297
|
+
}
|
|
298
|
+
else if (canonicDataLabel === 'FACTOR') {
|
|
299
|
+
currentEntry.ntuples.factor = (0, convertToFloatArray_1.default)(dataValue.split(ntuplesSeparatorRegExp));
|
|
300
|
+
}
|
|
301
|
+
else if (canonicDataLabel === 'FIRST') {
|
|
302
|
+
currentEntry.ntuples.first = (0, convertToFloatArray_1.default)(dataValue.split(ntuplesSeparatorRegExp));
|
|
303
|
+
}
|
|
304
|
+
else if (canonicDataLabel === 'LAST') {
|
|
305
|
+
currentEntry.ntuples.last = (0, convertToFloatArray_1.default)(dataValue.split(ntuplesSeparatorRegExp));
|
|
306
|
+
}
|
|
307
|
+
else if (canonicDataLabel === 'MIN') {
|
|
308
|
+
currentEntry.ntuples.min = (0, convertToFloatArray_1.default)(dataValue.split(ntuplesSeparatorRegExp));
|
|
309
|
+
}
|
|
310
|
+
else if (canonicDataLabel === 'MAX') {
|
|
311
|
+
currentEntry.ntuples.max = (0, convertToFloatArray_1.default)(dataValue.split(ntuplesSeparatorRegExp));
|
|
312
|
+
}
|
|
313
|
+
else if (canonicDataLabel === '.NUCLEUS') {
|
|
314
|
+
if (currentEntry.ntuples) {
|
|
315
|
+
currentEntry.ntuples.nucleus = dataValue.split(ntuplesSeparatorRegExp);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
else if (canonicDataLabel === 'PAGE') {
|
|
319
|
+
spectrum.page = dataValue.trim();
|
|
320
|
+
spectrum.pageValue = Number(dataValue.replace(/^.*=/, ''));
|
|
321
|
+
spectrum.pageSymbol = spectrum.page.replace(/[=].*/, '');
|
|
322
|
+
}
|
|
323
|
+
else if (canonicDataLabel === 'RETENTIONTIME') {
|
|
324
|
+
spectrum.pageValue = Number(dataValue);
|
|
325
|
+
}
|
|
326
|
+
else if ((0, complexChromatogram_1.isMSField)(canonicDataLabel)) {
|
|
327
|
+
spectrum[(0, complexChromatogram_1.convertMSFieldToLabel)(canonicDataLabel)] = dataValue;
|
|
328
|
+
}
|
|
329
|
+
else if (canonicDataLabel === 'SAMPLEDESCRIPTION') {
|
|
330
|
+
spectrum.sampleDescription = dataValue;
|
|
331
|
+
}
|
|
332
|
+
else if (canonicDataLabel.startsWith('$NUC')) {
|
|
333
|
+
if (!currentEntry.tmp[canonicDataLabel] && !dataValue.includes('off')) {
|
|
334
|
+
currentEntry.tmp[canonicDataLabel] = dataValue.replace(/[<>]/g, '');
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
else if (canonicDataLabel === 'END') {
|
|
338
|
+
currentEntry = parentsStack.pop();
|
|
339
|
+
}
|
|
340
|
+
if (currentEntry &&
|
|
341
|
+
currentEntry.info &&
|
|
342
|
+
currentEntry.meta &&
|
|
343
|
+
canonicDataLabel.match(options.keepRecordsRegExp)) {
|
|
344
|
+
let value = dataValue.trim();
|
|
345
|
+
let target, label;
|
|
346
|
+
if (dataLabel.startsWith('$')) {
|
|
347
|
+
label = options.canonicMetadataLabels
|
|
348
|
+
? canonicDataLabel.substring(1)
|
|
349
|
+
: dataLabel.substring(1);
|
|
350
|
+
target = currentEntry.meta;
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
label = options.canonicDataLabels ? canonicDataLabel : dataLabel;
|
|
354
|
+
target = currentEntry.info;
|
|
355
|
+
}
|
|
356
|
+
if (options.dynamicTyping) {
|
|
357
|
+
value = (0, dynamic_typing_1.parseString)(value);
|
|
358
|
+
}
|
|
359
|
+
if (target[label]) {
|
|
360
|
+
if (!Array.isArray(target[label])) {
|
|
361
|
+
target[label] = [target[label]];
|
|
362
|
+
}
|
|
363
|
+
target[label].push(value);
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
target[label] = value;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
(0, profiling_1.default)(result, 'Finished parsing', options);
|
|
371
|
+
(0, postProcessing_1.default)(entriesFlat, result, options);
|
|
372
|
+
(0, profiling_1.default)(result, 'Total time', options);
|
|
373
|
+
/*
|
|
374
|
+
if (result.children && result.children.length>0) {
|
|
375
|
+
result = { ...result, ...result.children[0] };
|
|
376
|
+
}
|
|
377
|
+
*/
|
|
378
|
+
result.entries = tmpResult.children;
|
|
379
|
+
result.flatten = entriesFlat;
|
|
380
|
+
return result;
|
|
381
|
+
}
|
|
382
|
+
exports.convert = convert;
|
|
383
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../src/convert.js"],"names":[],"mappings":";;;;;;AAAA,mDAA6C;AAC7C,iDAA6C;AAE7C,+DAAyE;AACzE,gFAAwD;AACxD,8EAAsD;AACtD,4EAAoD;AACpD,gEAAwC;AACxC,sEAA8C;AAC9C,wFAAgE;AAChE,wEAAgD;AAChD,4DAAoC;AAEpC,iGAAiG;AACjG,MAAM,sBAAsB,GAAG,eAAe,CAAC;AAE/C,MAAM,QAAQ;CAAG;AAEjB,MAAM,cAAc,GAAG;IACrB,iBAAiB,EAAE,IAAI;IACvB,iBAAiB,EAAE,IAAI;IACvB,qBAAqB,EAAE,KAAK;IAC5B,aAAa,EAAE,IAAI;IACnB,SAAS,EAAE,KAAK;IAChB,YAAY,EAAE,KAAK;IACnB,WAAW,EAAE,KAAK;IAClB,SAAS,EAAE,KAAK;IAChB,eAAe,EAAE,CAAC;IAClB,eAAe,EAAE,CAAC;IAClB,SAAS,EAAE,KAAK;CACjB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;GAWG;AAEH;;;;;;;GAOG;AAEH;;;;;;GAMG;AAEH,SAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,EAAE;IACzC,KAAK,GAAG,IAAA,4BAAY,EAAC,KAAK,CAAC,CAAC;IAC5B,OAAO,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,EAAE,CAAC;IAC5C,OAAO,CAAC,MAAM,GAAG,C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IAAA,mBAAS,EAAC,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;IAEzC;;;;MAIE;IACF,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC;IACpC,MAAM,CAAC,OAAO,GAAG,WAAW,CAAC;IAE7B,OAAO,MAAM,CAAC;AAChB,CAAC;AA5RD,0BA4RC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertToFloatArray.d.ts","sourceRoot":"","sources":["../src/convertToFloatArray.js"],"names":[],"mappings":"AAAA,wEAMC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function convertToFloatArray(stringArray) {
|
|
4
|
+
let floatArray = [];
|
|
5
|
+
for (let i = 0; i < stringArray.length; i++) {
|
|
6
|
+
floatArray.push(Number(stringArray[i]));
|
|
7
|
+
}
|
|
8
|
+
return floatArray;
|
|
9
|
+
}
|
|
10
|
+
exports.default = convertToFloatArray;
|
|
11
|
+
//# sourceMappingURL=convertToFloatArray.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertToFloatArray.js","sourceRoot":"","sources":["../src/convertToFloatArray.js"],"names":[],"mappings":";;AAAA,SAAwB,mBAAmB,CAAC,WAAW;IACrD,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC3C,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KACzC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAND,sCAMC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @typedef {object} CreateTreeOptions
|
|
4
|
+
* @property {boolean} [flatten=false]
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @typedef {object} Tree
|
|
9
|
+
* @property {string} title
|
|
10
|
+
* @property {string} jcamp
|
|
11
|
+
* @property {Tree[]} [children]
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Parse the jcamp to extract the structure as a tree.
|
|
15
|
+
*
|
|
16
|
+
* @param {string|ArrayBuffer|Uint8Array} jcamp
|
|
17
|
+
* @param {CreateTreeOptions} [options={}]
|
|
18
|
+
* @returns {Tree[]}
|
|
19
|
+
*/
|
|
20
|
+
export function createTree(jcamp: string | ArrayBuffer | Uint8Array, options?: CreateTreeOptions | undefined): Tree[];
|
|
21
|
+
export type CreateTreeOptions = {
|
|
22
|
+
flatten?: boolean | undefined;
|
|
23
|
+
};
|
|
24
|
+
export type Tree = {
|
|
25
|
+
title: string;
|
|
26
|
+
jcamp: string;
|
|
27
|
+
children?: Tree[] | undefined;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=createTree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTree.d.ts","sourceRoot":"","sources":["../src/createTree.js"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,kCAJW,MAAM,GAAC,WAAW,GAAC,UAAU,4CAE3B,IAAI,EAAE,CA2ElB;;;;;WArFa,MAAM;WACN,MAAM"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTree = void 0;
|
|
4
|
+
const ensure_string_1 = require("ensure-string");
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @typedef {object} CreateTreeOptions
|
|
8
|
+
* @property {boolean} [flatten=false]
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @typedef {object} Tree
|
|
13
|
+
* @property {string} title
|
|
14
|
+
* @property {string} jcamp
|
|
15
|
+
* @property {Tree[]} [children]
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Parse the jcamp to extract the structure as a tree.
|
|
19
|
+
*
|
|
20
|
+
* @param {string|ArrayBuffer|Uint8Array} jcamp
|
|
21
|
+
* @param {CreateTreeOptions} [options={}]
|
|
22
|
+
* @returns {Tree[]}
|
|
23
|
+
*/
|
|
24
|
+
function createTree(jcamp, options = {}) {
|
|
25
|
+
jcamp = (0, ensure_string_1.ensureString)(jcamp);
|
|
26
|
+
const { flatten = false } = options;
|
|
27
|
+
if (typeof jcamp !== 'string') {
|
|
28
|
+
throw new TypeError('the JCAMP should be a string');
|
|
29
|
+
}
|
|
30
|
+
let lines = jcamp.split(/[\r\n]+/);
|
|
31
|
+
let flat = [];
|
|
32
|
+
let stack = [];
|
|
33
|
+
let result = [];
|
|
34
|
+
let current;
|
|
35
|
+
let ntupleLevel = 0;
|
|
36
|
+
let spaces = jcamp.includes('## ');
|
|
37
|
+
for (let i = 0; i < lines.length; i++) {
|
|
38
|
+
let line = lines[i];
|
|
39
|
+
let labelLine = spaces ? line.replace(/ /g, '') : line;
|
|
40
|
+
if (labelLine.substring(0, 9) === '##NTUPLES') {
|
|
41
|
+
ntupleLevel++;
|
|
42
|
+
}
|
|
43
|
+
if (labelLine.substring(0, 7) === '##TITLE') {
|
|
44
|
+
let title = [labelLine.substring(8).trim()];
|
|
45
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
46
|
+
if (lines[j].startsWith('##')) {
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
title.push(lines[j].trim());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
stack.push({
|
|
54
|
+
title: title.join('\n'),
|
|
55
|
+
jcamp: `${line}\n`,
|
|
56
|
+
children: [],
|
|
57
|
+
});
|
|
58
|
+
current = stack[stack.length - 1];
|
|
59
|
+
flat.push(current);
|
|
60
|
+
}
|
|
61
|
+
else if (labelLine.substring(0, 5) === '##END' && ntupleLevel === 0) {
|
|
62
|
+
current.jcamp += `${line}\n`;
|
|
63
|
+
let finished = stack.pop();
|
|
64
|
+
if (stack.length !== 0) {
|
|
65
|
+
current = stack[stack.length - 1];
|
|
66
|
+
current.children.push(finished);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
current = undefined;
|
|
70
|
+
result.push(finished);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (current && current.jcamp) {
|
|
74
|
+
current.jcamp += `${line}\n`;
|
|
75
|
+
let match = labelLine.match(/^##(.*?)=(.+)/);
|
|
76
|
+
if (match) {
|
|
77
|
+
let canonicDataLabel = match[1].replace(/[ _-]/g, '').toUpperCase();
|
|
78
|
+
if (canonicDataLabel === 'DATATYPE') {
|
|
79
|
+
current.dataType = match[2].trim();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (labelLine.substring(0, 5) === '##END' && ntupleLevel > 0) {
|
|
84
|
+
ntupleLevel--;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (flatten) {
|
|
88
|
+
flat.forEach((entry) => {
|
|
89
|
+
entry.children = undefined;
|
|
90
|
+
});
|
|
91
|
+
return flat;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.createTree = createTree;
|
|
98
|
+
//# sourceMappingURL=createTree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTree.js","sourceRoot":"","sources":["../src/createTree.js"],"names":[],"mappings":";;;AAAA,iDAA6C;AAE7C;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,EAAE;IAC5C,KAAK,GAAG,IAAA,4BAAY,EAAC,KAAK,CAAC,CAAC;IAC5B,MAAM,EAAE,OAAO,G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