ir-spectrum 3.1.0 → 3.2.0
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/package.json +15 -22
- package/src/from/fromJcamp.js +1 -1
- package/src/from/fromSPC.js +1 -1
- package/src/index.js +4 -4
- package/lib/index.js +0 -312
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ir-spectrum",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "3.2.0",
|
|
4
|
+
"description": "Package used to handle IR spectra in SciPeaks.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": "./src/index.js",
|
|
7
7
|
"files": [
|
|
8
|
-
"lib",
|
|
9
8
|
"src"
|
|
10
9
|
],
|
|
11
10
|
"scripts": {
|
|
@@ -13,12 +12,11 @@
|
|
|
13
12
|
"build-doc": "cheminfo doc",
|
|
14
13
|
"eslint": "eslint src",
|
|
15
14
|
"eslint-fix": "npm run eslint -- --fix",
|
|
16
|
-
"prepack": "rollup -c",
|
|
17
15
|
"prettier": "prettier --check src",
|
|
18
16
|
"prettier-write": "prettier --write src",
|
|
19
|
-
"test": "npm run test-
|
|
20
|
-
"test-
|
|
21
|
-
"test-
|
|
17
|
+
"test": "npm run test-only && npm run eslint && npm run prettier",
|
|
18
|
+
"test-only": "vitest run --coverage",
|
|
19
|
+
"test-import": "node -e \"import('file://' + process.cwd() + '/src/index.js').then(console.log)\""
|
|
22
20
|
},
|
|
23
21
|
"repository": {
|
|
24
22
|
"type": "git",
|
|
@@ -31,25 +29,20 @@
|
|
|
31
29
|
"url": "https://github.com/cheminfo/ir-spectrum/issues"
|
|
32
30
|
},
|
|
33
31
|
"homepage": "https://github.com/cheminfo/ir-spectrum#readme",
|
|
34
|
-
"jest": {
|
|
35
|
-
"testEnvironment": "node"
|
|
36
|
-
},
|
|
37
32
|
"devDependencies": {
|
|
38
|
-
"@babel/plugin-transform-modules-commonjs": "^7.
|
|
39
|
-
"@vitest/coverage-v8": "^2.
|
|
40
|
-
"cheminfo-build": "^1.2.
|
|
41
|
-
"
|
|
42
|
-
"eslint": "^
|
|
43
|
-
"eslint-config-cheminfo": "^12.0.1",
|
|
33
|
+
"@babel/plugin-transform-modules-commonjs": "^7.27.1",
|
|
34
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
35
|
+
"cheminfo-build": "^1.2.1",
|
|
36
|
+
"eslint": "^9.32.0",
|
|
37
|
+
"eslint-config-cheminfo": "^15.0.1",
|
|
44
38
|
"esm": "^3.2.25",
|
|
45
39
|
"jest-matcher-deep-close-to": "^3.0.2",
|
|
46
|
-
"prettier": "^3.
|
|
47
|
-
"
|
|
48
|
-
"vitest": "^2.1.5"
|
|
40
|
+
"prettier": "^3.6.2",
|
|
41
|
+
"vitest": "^3.2.4"
|
|
49
42
|
},
|
|
50
43
|
"dependencies": {
|
|
51
44
|
"common-spectrum": "2.12.0",
|
|
52
|
-
"ml-gsd": "^
|
|
45
|
+
"ml-gsd": "^13.0.1",
|
|
53
46
|
"spc-parser": "^1.0.0",
|
|
54
47
|
"uninstall": "^0.0.0"
|
|
55
48
|
},
|
package/src/from/fromJcamp.js
CHANGED
package/src/from/fromSPC.js
CHANGED
package/src/index.js
CHANGED
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
} from 'common-spectrum';
|
|
6
6
|
|
|
7
7
|
import { convertPeak } from './convertPeak.js';
|
|
8
|
-
import { getAnnotations } from './jsgraph/getAnnotations';
|
|
8
|
+
import { getAnnotations } from './jsgraph/getAnnotations.js';
|
|
9
9
|
|
|
10
|
-
export {
|
|
10
|
+
export { AnalysesManager, Analysis, toJcamp } from 'common-spectrum';
|
|
11
11
|
|
|
12
12
|
export function peakPicking(spectrum, target, options) {
|
|
13
13
|
const peak = originalPeakPicking(spectrum, target, options);
|
|
@@ -21,7 +21,7 @@ export function autoPeakPicking(spectrum, options) {
|
|
|
21
21
|
return peaks.map((peak) => convertPeak(peak, spectrum));
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export { fromJcamp } from './from/fromJcamp';
|
|
25
|
-
export { fromSPC } from './from/fromSPC';
|
|
24
|
+
export { fromJcamp } from './from/fromJcamp.js';
|
|
25
|
+
export { fromSPC } from './from/fromSPC.js';
|
|
26
26
|
|
|
27
27
|
export const JSGraph = { ...OriginalJSGraph, getAnnotations };
|
package/lib/index.js
DELETED
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var commonSpectrum = require('common-spectrum');
|
|
4
|
-
var spcParser = require('spc-parser');
|
|
5
|
-
|
|
6
|
-
function convertPeak(peak, spectrum) {
|
|
7
|
-
return {
|
|
8
|
-
wavenumber: peak.x,
|
|
9
|
-
absorbance: peak.a,
|
|
10
|
-
transmittance: peak.t / 100,
|
|
11
|
-
kind: getPeakKind(
|
|
12
|
-
peak.t,
|
|
13
|
-
spectrum.variables.t.min,
|
|
14
|
-
spectrum.variables.t.max,
|
|
15
|
-
),
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function getPeakKind(transmittance, minTransmittance, maxTransmittance) {
|
|
20
|
-
let position =
|
|
21
|
-
(maxTransmittance - transmittance) / (maxTransmittance - minTransmittance);
|
|
22
|
-
if (position < 0.33) {
|
|
23
|
-
return 'w';
|
|
24
|
-
} else if (position < 0.66) {
|
|
25
|
-
return 'm';
|
|
26
|
-
}
|
|
27
|
-
return 'S';
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @typedef {object} Peak
|
|
32
|
-
* @property {number} wavenumber
|
|
33
|
-
* @property {number} transmittance
|
|
34
|
-
* @property {number} absorbance
|
|
35
|
-
* @property {number} kind
|
|
36
|
-
* @property {number} assignment
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Creates annotations for jsgraph that allows to display the result of peak picking
|
|
41
|
-
* @param {Array<Peak>} peaks
|
|
42
|
-
* @param {object} [options={}]
|
|
43
|
-
* @param {string} [options.fillColor='green']
|
|
44
|
-
* @param {string} [options.strokeColor='red']
|
|
45
|
-
* @param {string} [options.showKind=true] - Display the kind, 'm', 'w', 'S'
|
|
46
|
-
* @param {string} [options.showAssignment=true] - Display the assignment
|
|
47
|
-
* @param {Function} [options.createFct] - (annotation, peak) => {}: callback allowing to add properties
|
|
48
|
-
* @param {string} [options.mode='t100'] - 't100'=transmittance in %, 't'=transmittance, 'a'=absorbance
|
|
49
|
-
* @returns array
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
function getAnnotations(peaks, options = {}) {
|
|
53
|
-
const {
|
|
54
|
-
fillColor = 'green',
|
|
55
|
-
strokeColor = 'red',
|
|
56
|
-
creationFct,
|
|
57
|
-
mode = 't100',
|
|
58
|
-
} = options;
|
|
59
|
-
let annotations = peaks.map((peak) => {
|
|
60
|
-
let annotation = {
|
|
61
|
-
line: 1,
|
|
62
|
-
type: 'rect',
|
|
63
|
-
strokeColor,
|
|
64
|
-
strokeWidth: 0,
|
|
65
|
-
fillColor,
|
|
66
|
-
};
|
|
67
|
-
if (creationFct) {
|
|
68
|
-
creationFct(annotation, peak);
|
|
69
|
-
}
|
|
70
|
-
switch (mode) {
|
|
71
|
-
case 'a':
|
|
72
|
-
annotationAbsorbance(annotation, peak, options);
|
|
73
|
-
break;
|
|
74
|
-
case 't':
|
|
75
|
-
annotationTransmittance(annotation, peak, 1, options);
|
|
76
|
-
break;
|
|
77
|
-
case 't100':
|
|
78
|
-
annotationTransmittance(annotation, peak, 100, options);
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
return annotation;
|
|
82
|
-
});
|
|
83
|
-
return annotations;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function annotationTransmittance(annotation, peak, factor = 1, options = {}) {
|
|
87
|
-
const { showKind = true, showAssignment = true } = options;
|
|
88
|
-
let labels = [];
|
|
89
|
-
let line = 0;
|
|
90
|
-
|
|
91
|
-
if (showKind) {
|
|
92
|
-
labels.push({
|
|
93
|
-
text: peak.kind,
|
|
94
|
-
size: '18px',
|
|
95
|
-
anchor: 'middle',
|
|
96
|
-
color: 'red',
|
|
97
|
-
position: {
|
|
98
|
-
x: peak.wavenumber,
|
|
99
|
-
y: peak.transmittance * factor,
|
|
100
|
-
dy: `${23 + line * 14}px`,
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
line++;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (showAssignment) {
|
|
107
|
-
labels.push({
|
|
108
|
-
text: peak.assignment,
|
|
109
|
-
size: '18px',
|
|
110
|
-
anchor: 'middle',
|
|
111
|
-
color: 'darkred',
|
|
112
|
-
position: {
|
|
113
|
-
x: peak.wavenumber,
|
|
114
|
-
y: peak.transmittance * factor,
|
|
115
|
-
dy: `${23 + line * 14}px`,
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
line++;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
annotation.labels = labels;
|
|
122
|
-
annotation.position = [
|
|
123
|
-
{
|
|
124
|
-
x: peak.wavenumber,
|
|
125
|
-
y: peak.transmittance * factor,
|
|
126
|
-
dy: '10px',
|
|
127
|
-
dx: '-1px',
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
x: peak.wavenumber,
|
|
131
|
-
y: peak.transmittance * factor,
|
|
132
|
-
dy: '5px',
|
|
133
|
-
dx: '1px',
|
|
134
|
-
},
|
|
135
|
-
];
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function annotationAbsorbance(annotation, peak, options = {}) {
|
|
139
|
-
const {
|
|
140
|
-
showKind = true,
|
|
141
|
-
showAssignment = true,
|
|
142
|
-
assignmentAngle = -45,
|
|
143
|
-
} = options;
|
|
144
|
-
let labels = [];
|
|
145
|
-
let line = 0;
|
|
146
|
-
|
|
147
|
-
if (showKind) {
|
|
148
|
-
labels.push({
|
|
149
|
-
text: peak.kind,
|
|
150
|
-
size: '18px',
|
|
151
|
-
anchor: 'middle',
|
|
152
|
-
color: 'red',
|
|
153
|
-
position: {
|
|
154
|
-
x: peak.wavenumber,
|
|
155
|
-
y: peak.absorbance,
|
|
156
|
-
dy: `${-15 - line * 14}px`,
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
line++;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (showAssignment) {
|
|
163
|
-
labels.push({
|
|
164
|
-
text: peak.assignment,
|
|
165
|
-
size: '18px',
|
|
166
|
-
angle: assignmentAngle,
|
|
167
|
-
anchor: 'left',
|
|
168
|
-
color: 'darkred',
|
|
169
|
-
position: {
|
|
170
|
-
x: peak.wavenumber,
|
|
171
|
-
y: peak.absorbance,
|
|
172
|
-
dy: `${-15 - line * 14}px`,
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
line++;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
annotation.labels = labels;
|
|
179
|
-
|
|
180
|
-
annotation.position = [
|
|
181
|
-
{
|
|
182
|
-
x: peak.wavenumber,
|
|
183
|
-
y: peak.absorbance,
|
|
184
|
-
dy: '-10px',
|
|
185
|
-
dx: '-1px',
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
x: peak.wavenumber,
|
|
189
|
-
y: peak.absorbance,
|
|
190
|
-
dy: '-5px',
|
|
191
|
-
dx: '1px',
|
|
192
|
-
},
|
|
193
|
-
];
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function spectrumCallback(variables) {
|
|
197
|
-
// we add missing absorbance / transmittance
|
|
198
|
-
// variable a = absorbance
|
|
199
|
-
// variable t = transmittance
|
|
200
|
-
let yVariable = variables.y;
|
|
201
|
-
let absorbance = true;
|
|
202
|
-
if (yVariable.label.toLowerCase().includes('trans')) {
|
|
203
|
-
absorbance = false;
|
|
204
|
-
}
|
|
205
|
-
if (absorbance) {
|
|
206
|
-
variables.a = { ...yVariable, symbol: 'a', data: yVariable.data.slice() };
|
|
207
|
-
variables.t = {
|
|
208
|
-
data: yVariable.data.map((absorbance) => 10 ** -absorbance * 100),
|
|
209
|
-
label: 'Transmittance (%)',
|
|
210
|
-
symbol: 't',
|
|
211
|
-
units: '',
|
|
212
|
-
};
|
|
213
|
-
} else {
|
|
214
|
-
const factor =
|
|
215
|
-
yVariable.label.includes('%') ||
|
|
216
|
-
yVariable.label.toLowerCase().includes('percent')
|
|
217
|
-
? 100
|
|
218
|
-
: 1;
|
|
219
|
-
|
|
220
|
-
variables.a = {
|
|
221
|
-
data: yVariable.data.map(
|
|
222
|
-
(transmittance) => -Math.log10(transmittance / factor),
|
|
223
|
-
),
|
|
224
|
-
symbol: 'a',
|
|
225
|
-
label: 'Absorbance',
|
|
226
|
-
units: '',
|
|
227
|
-
};
|
|
228
|
-
if (factor === 100) {
|
|
229
|
-
variables.t = { ...yVariable, symbol: 't' };
|
|
230
|
-
variables.t.data = variables.t.data.slice();
|
|
231
|
-
} else {
|
|
232
|
-
variables.t = {
|
|
233
|
-
units: '',
|
|
234
|
-
label: 'Transmittance (%)',
|
|
235
|
-
symbol: 't',
|
|
236
|
-
data: yVariable.data.map((transmittance) => transmittance * 100),
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Creates a new Analysis from a SPC buffer
|
|
244
|
-
* @param {ArrayBuffer|string} jcamp
|
|
245
|
-
* @param {object} [options={}]
|
|
246
|
-
* @param {string|number} [options.id=Math.random()]
|
|
247
|
-
* @param {string} [options.label=options.id] - human redeable label
|
|
248
|
-
* @param {string} [options.spectrumCallback] - a callback to apply on variables when creating spectrum. Default will add a and t
|
|
249
|
-
* @returns {Analysis} - New class element with the given data
|
|
250
|
-
*/
|
|
251
|
-
function fromJcamp(jcamp, options = {}) {
|
|
252
|
-
return commonSpectrum.fromJcamp(jcamp, { ...options, spectrumCallback });
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Creates a new Analysis from a SPC buffer
|
|
257
|
-
* @param {ArrayBuffer} buffer
|
|
258
|
-
* @param {object} [options={}]
|
|
259
|
-
* @param {object} [options.id=Math.random()]
|
|
260
|
-
* @param {string} [options.label=options.id] - human redeable label
|
|
261
|
-
* @param {string} [options.spectrumCallback] - a callback to apply on variables when creating spectrum. Default will add a and t
|
|
262
|
-
* @returns {Analysis} - New class element with the given data
|
|
263
|
-
*/
|
|
264
|
-
|
|
265
|
-
function fromSPC(buffer, options = {}) {
|
|
266
|
-
let analysis = new commonSpectrum.Analysis({ ...options, spectrumCallback });
|
|
267
|
-
let result = spcParser.parse(buffer);
|
|
268
|
-
|
|
269
|
-
if (result.meta) delete result.meta.parameters;
|
|
270
|
-
|
|
271
|
-
for (let spectrum of result.spectra) {
|
|
272
|
-
if (spectrum.meta) delete spectrum.meta.parameters;
|
|
273
|
-
analysis.pushSpectrum(spectrum.variables, {
|
|
274
|
-
dataType: 'IR SPECTRUM',
|
|
275
|
-
title: '',
|
|
276
|
-
meta: { ...result.meta, ...spectrum.meta },
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
return analysis;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function peakPicking(spectrum, target, options) {
|
|
283
|
-
const peak = commonSpectrum.peakPicking(spectrum, target, options);
|
|
284
|
-
if (!peak) return undefined;
|
|
285
|
-
return convertPeak(peak, spectrum);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
function autoPeakPicking(spectrum, options) {
|
|
289
|
-
const peaks = commonSpectrum.autoPeakPicking(spectrum, options);
|
|
290
|
-
if (!peaks) return [];
|
|
291
|
-
return peaks.map((peak) => convertPeak(peak, spectrum));
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const JSGraph = { ...commonSpectrum.JSGraph, getAnnotations };
|
|
295
|
-
|
|
296
|
-
Object.defineProperty(exports, "AnalysesManager", {
|
|
297
|
-
enumerable: true,
|
|
298
|
-
get: function () { return commonSpectrum.AnalysesManager; }
|
|
299
|
-
});
|
|
300
|
-
Object.defineProperty(exports, "Analysis", {
|
|
301
|
-
enumerable: true,
|
|
302
|
-
get: function () { return commonSpectrum.Analysis; }
|
|
303
|
-
});
|
|
304
|
-
Object.defineProperty(exports, "toJcamp", {
|
|
305
|
-
enumerable: true,
|
|
306
|
-
get: function () { return commonSpectrum.toJcamp; }
|
|
307
|
-
});
|
|
308
|
-
exports.JSGraph = JSGraph;
|
|
309
|
-
exports.autoPeakPicking = autoPeakPicking;
|
|
310
|
-
exports.fromJcamp = fromJcamp;
|
|
311
|
-
exports.fromSPC = fromSPC;
|
|
312
|
-
exports.peakPicking = peakPicking;
|