ir-spectrum 3.0.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 CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "ir-spectrum",
3
- "version": "3.0.0",
4
- "description": "",
5
- "main": "lib/index.js",
6
- "module": "src/index.js",
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-coverage && npm run eslint",
20
- "test-coverage": "jest --coverage",
21
- "test-only": "jest"
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,26 +29,22 @@
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.22.5",
39
- "@types/jest": "^29.5.3",
40
- "cheminfo-build": "^1.2.0",
41
- "codecov": "^3.8.3",
42
- "eslint": "^8.47.0",
43
- "eslint-config-cheminfo": "^9.0.2",
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
- "jest": "^29.6.3",
46
39
  "jest-matcher-deep-close-to": "^3.0.2",
47
- "prettier": "^3.0.2",
48
- "rollup": "^3.28.1"
40
+ "prettier": "^3.6.2",
41
+ "vitest": "^3.2.4"
49
42
  },
50
43
  "dependencies": {
51
- "common-spectrum": "2.2.1",
52
- "ml-gsd": "^12.1.3",
53
- "spc-parser": "^0.7.2"
44
+ "common-spectrum": "2.12.0",
45
+ "ml-gsd": "^13.0.1",
46
+ "spc-parser": "^1.0.0",
47
+ "uninstall": "^0.0.0"
54
48
  },
55
49
  "info": {
56
50
  "logo": "https://raw.githubusercontent.com/cheminfo/font/master/src/ir/assignment.svg",
@@ -1,15 +1,15 @@
1
1
  import { fromJcamp as commonFromJcamp } from 'common-spectrum';
2
2
 
3
- import { spectrumCallback } from './utils/spectrumCallback';
3
+ import { spectrumCallback } from './utils/spectrumCallback.js';
4
4
 
5
5
  /**
6
6
  * Creates a new Analysis from a SPC buffer
7
7
  * @param {ArrayBuffer|string} jcamp
8
8
  * @param {object} [options={}]
9
9
  * @param {string|number} [options.id=Math.random()]
10
- * @param {string} [options.label=options.id] human redeable label
11
- * @param {string} [options.spectrumCallback] a callback to apply on variables when creating spectrum. Default will add a and t
12
- * @return {Analysis} - New class element with the given data
10
+ * @param {string} [options.label=options.id] - human redeable label
11
+ * @param {string} [options.spectrumCallback] - a callback to apply on variables when creating spectrum. Default will add a and t
12
+ * @returns {Analysis} - New class element with the given data
13
13
  */
14
14
  export function fromJcamp(jcamp, options = {}) {
15
15
  return commonFromJcamp(jcamp, { ...options, spectrumCallback });
@@ -1,16 +1,16 @@
1
1
  import { Analysis } from 'common-spectrum';
2
2
  import { parse } from 'spc-parser';
3
3
 
4
- import { spectrumCallback } from './utils/spectrumCallback';
4
+ import { spectrumCallback } from './utils/spectrumCallback.js';
5
5
 
6
6
  /**
7
7
  * Creates a new Analysis from a SPC buffer
8
8
  * @param {ArrayBuffer} buffer
9
9
  * @param {object} [options={}]
10
10
  * @param {object} [options.id=Math.random()]
11
- * @param {string} [options.label=options.id] human redeable label
12
- * @param {string} [options.spectrumCallback] a callback to apply on variables when creating spectrum. Default will add a and t
13
- * @return {Analysis} - New class element with the given data
11
+ * @param {string} [options.label=options.id] - human redeable label
12
+ * @param {string} [options.spectrumCallback] - a callback to apply on variables when creating spectrum. Default will add a and t
13
+ * @returns {Analysis} - New class element with the given data
14
14
  */
15
15
 
16
16
  export function fromSPC(buffer, options = {}) {
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 { Analysis, AnalysesManager, toJcamp } from 'common-spectrum';
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 };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @typedef {Object} Peak
2
+ * @typedef {object} Peak
3
3
  * @property {number} wavenumber
4
4
  * @property {number} transmittance
5
5
  * @property {number} absorbance
@@ -9,14 +9,14 @@
9
9
 
10
10
  /**
11
11
  * Creates annotations for jsgraph that allows to display the result of peak picking
12
- * @param {array<Peak>} peaks
12
+ * @param {Array<Peak>} peaks
13
13
  * @param {object} [options={}]
14
14
  * @param {string} [options.fillColor='green']
15
15
  * @param {string} [options.strokeColor='red']
16
- * @param {string} [options.showKind=true] Display the kind, 'm', 'w', 'S'
17
- * @param {string} [options.showAssignment=true] Display the assignment
18
- * @param {function} [options.createFct] (annotation, peak) => {}: callback allowing to add properties
19
- * @param {string} [options.mode='t100'] 't100'=transmittance in %, 't'=transmittance, 'a'=absorbance
16
+ * @param {string} [options.showKind=true] - Display the kind, 'm', 'w', 'S'
17
+ * @param {string} [options.showAssignment=true] - Display the assignment
18
+ * @param {Function} [options.createFct] - (annotation, peak) => {}: callback allowing to add properties
19
+ * @param {string} [options.mode='t100'] - 't100'=transmittance in %, 't'=transmittance, 'a'=absorbance
20
20
  * @returns array
21
21
  */
22
22
 
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
- * @return {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
- * @return {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;