ir-spectrum 1.1.0 → 3.0.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/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![NPM version][npm-image]][npm-url]
4
4
  [![Test coverage][codecov-image]][codecov-url]
5
5
  [![npm download][download-image]][download-url]
6
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5482831.svg)](https://doi.org/10.5281/zenodo.5482831)
6
7
 
7
8
  ## Installation
8
9
 
package/lib/index.js CHANGED
@@ -1,10 +1,32 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var commonSpectrum = require('common-spectrum');
6
4
  var spcParser = require('spc-parser');
7
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
+
8
30
  /**
9
31
  * @typedef {Object} Peak
10
32
  * @property {number} wavenumber
@@ -38,9 +60,9 @@ function getAnnotations(peaks, options = {}) {
38
60
  let annotation = {
39
61
  line: 1,
40
62
  type: 'rect',
41
- strokeColor: strokeColor,
63
+ strokeColor,
42
64
  strokeWidth: 0,
43
- fillColor: fillColor,
65
+ fillColor,
44
66
  };
45
67
  if (creationFct) {
46
68
  creationFct(annotation, peak);
@@ -180,13 +202,12 @@ function spectrumCallback(variables) {
180
202
  if (yVariable.label.toLowerCase().includes('trans')) {
181
203
  absorbance = false;
182
204
  }
183
-
184
205
  if (absorbance) {
185
- variables.a = { ...yVariable };
186
- variables.a.data = variables.a.data.slice();
206
+ variables.a = { ...yVariable, symbol: 'a', data: yVariable.data.slice() };
187
207
  variables.t = {
188
208
  data: yVariable.data.map((absorbance) => 10 ** -absorbance * 100),
189
209
  label: 'Transmittance (%)',
210
+ symbol: 't',
190
211
  units: '',
191
212
  };
192
213
  } else {
@@ -195,20 +216,23 @@ function spectrumCallback(variables) {
195
216
  yVariable.label.toLowerCase().includes('percent')
196
217
  ? 100
197
218
  : 1;
219
+
198
220
  variables.a = {
199
221
  data: yVariable.data.map(
200
222
  (transmittance) => -Math.log10(transmittance / factor),
201
223
  ),
224
+ symbol: 'a',
202
225
  label: 'Absorbance',
203
226
  units: '',
204
227
  };
205
228
  if (factor === 100) {
206
- variables.t = { ...yVariable };
229
+ variables.t = { ...yVariable, symbol: 't' };
207
230
  variables.t.data = variables.t.data.slice();
208
231
  } else {
209
232
  variables.t = {
210
233
  units: '',
211
234
  label: 'Transmittance (%)',
235
+ symbol: 't',
212
236
  data: yVariable.data.map((transmittance) => transmittance * 100),
213
237
  };
214
238
  }
@@ -219,7 +243,7 @@ function spectrumCallback(variables) {
219
243
  * Creates a new Analysis from a SPC buffer
220
244
  * @param {ArrayBuffer|string} jcamp
221
245
  * @param {object} [options={}]
222
- * @param {object} [options.id=Math.random()]
246
+ * @param {string|number} [options.id=Math.random()]
223
247
  * @param {string} [options.label=options.id] human redeable label
224
248
  * @param {string} [options.spectrumCallback] a callback to apply on variables when creating spectrum. Default will add a and t
225
249
  * @return {Analysis} - New class element with the given data
@@ -255,38 +279,34 @@ function fromSPC(buffer, options = {}) {
255
279
  return analysis;
256
280
  }
257
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
+
258
294
  const JSGraph = { ...commonSpectrum.JSGraph, getAnnotations };
259
295
 
260
296
  Object.defineProperty(exports, 'AnalysesManager', {
261
297
  enumerable: true,
262
- get: function () {
263
- return commonSpectrum.AnalysesManager;
264
- }
298
+ get: function () { return commonSpectrum.AnalysesManager; }
265
299
  });
266
300
  Object.defineProperty(exports, 'Analysis', {
267
301
  enumerable: true,
268
- get: function () {
269
- return commonSpectrum.Analysis;
270
- }
271
- });
272
- Object.defineProperty(exports, 'autoPeakPicking', {
273
- enumerable: true,
274
- get: function () {
275
- return commonSpectrum.autoPeakPicking;
276
- }
277
- });
278
- Object.defineProperty(exports, 'peakPicking', {
279
- enumerable: true,
280
- get: function () {
281
- return commonSpectrum.peakPicking;
282
- }
302
+ get: function () { return commonSpectrum.Analysis; }
283
303
  });
284
304
  Object.defineProperty(exports, 'toJcamp', {
285
305
  enumerable: true,
286
- get: function () {
287
- return commonSpectrum.toJcamp;
288
- }
306
+ get: function () { return commonSpectrum.toJcamp; }
289
307
  });
290
308
  exports.JSGraph = JSGraph;
309
+ exports.autoPeakPicking = autoPeakPicking;
291
310
  exports.fromJcamp = fromJcamp;
292
311
  exports.fromSPC = fromSPC;
312
+ exports.peakPicking = peakPicking;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ir-spectrum",
3
- "version": "1.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "module": "src/index.js",
@@ -13,7 +13,9 @@
13
13
  "build-doc": "cheminfo doc",
14
14
  "eslint": "eslint src",
15
15
  "eslint-fix": "npm run eslint -- --fix",
16
- "prepublishOnly": "rollup -c",
16
+ "prepack": "rollup -c",
17
+ "prettier": "prettier --check src",
18
+ "prettier-write": "prettier --write src",
17
19
  "test": "npm run test-coverage && npm run eslint",
18
20
  "test-coverage": "jest --coverage",
19
21
  "test-only": "jest"
@@ -33,25 +35,22 @@
33
35
  "testEnvironment": "node"
34
36
  },
35
37
  "devDependencies": {
36
- "@babel/plugin-transform-modules-commonjs": "^7.15.4",
37
- "@types/jest": "^27.0.1",
38
- "cheminfo-build": "^1.1.11",
38
+ "@babel/plugin-transform-modules-commonjs": "^7.22.5",
39
+ "@types/jest": "^29.5.3",
40
+ "cheminfo-build": "^1.2.0",
39
41
  "codecov": "^3.8.3",
40
- "eslint": "^7.32.0",
41
- "eslint-config-cheminfo": "^5.4.0",
42
- "eslint-plugin-import": "^2.24.2",
43
- "eslint-plugin-jest": "^24.4.0",
44
- "eslint-plugin-prettier": "^4.0.0",
42
+ "eslint": "^8.47.0",
43
+ "eslint-config-cheminfo": "^9.0.2",
45
44
  "esm": "^3.2.25",
46
- "jest": "^27.1.0",
47
- "jest-matcher-deep-close-to": "^2.0.1",
48
- "prettier": "^2.3.2",
49
- "rollup": "^2.56.3"
45
+ "jest": "^29.6.3",
46
+ "jest-matcher-deep-close-to": "^3.0.2",
47
+ "prettier": "^3.0.2",
48
+ "rollup": "^3.28.1"
50
49
  },
51
50
  "dependencies": {
52
- "common-spectrum": "0.40.0",
53
- "ml-gsd": "^6.7.0",
54
- "spc-parser": "^0.5.1"
51
+ "common-spectrum": "2.2.1",
52
+ "ml-gsd": "^12.1.3",
53
+ "spc-parser": "^0.7.2"
55
54
  },
56
55
  "info": {
57
56
  "logo": "https://raw.githubusercontent.com/cheminfo/font/master/src/ir/assignment.svg",
@@ -0,0 +1,23 @@
1
+ export function convertPeak(peak, spectrum) {
2
+ return {
3
+ wavenumber: peak.x,
4
+ absorbance: peak.a,
5
+ transmittance: peak.t / 100,
6
+ kind: getPeakKind(
7
+ peak.t,
8
+ spectrum.variables.t.min,
9
+ spectrum.variables.t.max,
10
+ ),
11
+ };
12
+ }
13
+
14
+ function getPeakKind(transmittance, minTransmittance, maxTransmittance) {
15
+ let position =
16
+ (maxTransmittance - transmittance) / (maxTransmittance - minTransmittance);
17
+ if (position < 0.33) {
18
+ return 'w';
19
+ } else if (position < 0.66) {
20
+ return 'm';
21
+ }
22
+ return 'S';
23
+ }
@@ -6,7 +6,7 @@ import { spectrumCallback } from './utils/spectrumCallback';
6
6
  * Creates a new Analysis from a SPC buffer
7
7
  * @param {ArrayBuffer|string} jcamp
8
8
  * @param {object} [options={}]
9
- * @param {object} [options.id=Math.random()]
9
+ * @param {string|number} [options.id=Math.random()]
10
10
  * @param {string} [options.label=options.id] human redeable label
11
11
  * @param {string} [options.spectrumCallback] a callback to apply on variables when creating spectrum. Default will add a and t
12
12
  * @return {Analysis} - New class element with the given data
@@ -7,13 +7,12 @@ export function spectrumCallback(variables) {
7
7
  if (yVariable.label.toLowerCase().includes('trans')) {
8
8
  absorbance = false;
9
9
  }
10
-
11
10
  if (absorbance) {
12
- variables.a = { ...yVariable };
13
- variables.a.data = variables.a.data.slice();
11
+ variables.a = { ...yVariable, symbol: 'a', data: yVariable.data.slice() };
14
12
  variables.t = {
15
13
  data: yVariable.data.map((absorbance) => 10 ** -absorbance * 100),
16
14
  label: 'Transmittance (%)',
15
+ symbol: 't',
17
16
  units: '',
18
17
  };
19
18
  } else {
@@ -22,20 +21,23 @@ export function spectrumCallback(variables) {
22
21
  yVariable.label.toLowerCase().includes('percent')
23
22
  ? 100
24
23
  : 1;
24
+
25
25
  variables.a = {
26
26
  data: yVariable.data.map(
27
27
  (transmittance) => -Math.log10(transmittance / factor),
28
28
  ),
29
+ symbol: 'a',
29
30
  label: 'Absorbance',
30
31
  units: '',
31
32
  };
32
33
  if (factor === 100) {
33
- variables.t = { ...yVariable };
34
+ variables.t = { ...yVariable, symbol: 't' };
34
35
  variables.t.data = variables.t.data.slice();
35
36
  } else {
36
37
  variables.t = {
37
38
  units: '',
38
39
  label: 'Transmittance (%)',
40
+ symbol: 't',
39
41
  data: yVariable.data.map((transmittance) => transmittance * 100),
40
42
  };
41
43
  }
package/src/index.js CHANGED
@@ -1,14 +1,25 @@
1
- import { JSGraph as OriginalJSGraph } from 'common-spectrum';
1
+ import {
2
+ JSGraph as OriginalJSGraph,
3
+ autoPeakPicking as originalAutoPeakPicking,
4
+ peakPicking as originalPeakPicking,
5
+ } from 'common-spectrum';
2
6
 
7
+ import { convertPeak } from './convertPeak.js';
3
8
  import { getAnnotations } from './jsgraph/getAnnotations';
4
9
 
5
- export {
6
- Analysis,
7
- AnalysesManager,
8
- toJcamp,
9
- peakPicking,
10
- autoPeakPicking,
11
- } from 'common-spectrum';
10
+ export { Analysis, AnalysesManager, toJcamp } from 'common-spectrum';
11
+
12
+ export function peakPicking(spectrum, target, options) {
13
+ const peak = originalPeakPicking(spectrum, target, options);
14
+ if (!peak) return undefined;
15
+ return convertPeak(peak, spectrum);
16
+ }
17
+
18
+ export function autoPeakPicking(spectrum, options) {
19
+ const peaks = originalAutoPeakPicking(spectrum, options);
20
+ if (!peaks) return [];
21
+ return peaks.map((peak) => convertPeak(peak, spectrum));
22
+ }
12
23
 
13
24
  export { fromJcamp } from './from/fromJcamp';
14
25
  export { fromSPC } from './from/fromSPC';
@@ -31,9 +31,9 @@ export function getAnnotations(peaks, options = {}) {
31
31
  let annotation = {
32
32
  line: 1,
33
33
  type: 'rect',
34
- strokeColor: strokeColor,
34
+ strokeColor,
35
35
  strokeWidth: 0,
36
- fillColor: fillColor,
36
+ fillColor,
37
37
  };
38
38
  if (creationFct) {
39
39
  creationFct(annotation, peak);
package/CHANGELOG.md DELETED
@@ -1,44 +0,0 @@
1
- # Changelog
2
-
3
- ## [1.1.0](https://www.github.com/cheminfo/ir-spectrum/compare/v1.0.3...v1.1.0) (2021-09-07)
4
-
5
-
6
- ### Features
7
-
8
- * add fromSPC ([d9eacf4](https://www.github.com/cheminfo/ir-spectrum/commit/d9eacf4cc3d4338ad630f7ee4798c3a168ead34f))
9
-
10
-
11
- ### Bug Fixes
12
-
13
- * remove compatibility with node 10.x ([08ed76c](https://www.github.com/cheminfo/ir-spectrum/commit/08ed76c47905625822272eb6e9831ba57f6b777f))
14
-
15
- ### [1.0.3](https://www.github.com/cheminfo/ir-spectrum/compare/v1.0.2...v1.0.3) (2021-07-06)
16
-
17
-
18
- ### Bug Fixes
19
-
20
- * dot in README ([dac6c63](https://www.github.com/cheminfo/ir-spectrum/commit/dac6c63f88399c1e87f10dd6dbb163b9c149e9b9))
21
- * iupac link for technique ([b67a76d](https://www.github.com/cheminfo/ir-spectrum/commit/b67a76d98e494655f037a43915aea29ad00eb5ff))
22
-
23
- ### [1.0.2](https://www.github.com/cheminfo/ir-spectrum/compare/v1.0.1...v1.0.2) (2021-04-14)
24
-
25
-
26
- ### Bug Fixes
27
-
28
- * double reverse because same variable (pointer) ([208bcf9](https://www.github.com/cheminfo/ir-spectrum/commit/208bcf9c04d1dcd5f9875d773f5bb201f26d2c56))
29
-
30
- ### [1.0.1](https://www.github.com/cheminfo/ir-spectrum/compare/v1.0.0...v1.0.1) (2021-03-29)
31
-
32
-
33
- ### Bug Fixes
34
-
35
- * use wavenumber and not wavelength ([66b6b51](https://www.github.com/cheminfo/ir-spectrum/commit/66b6b51a7c92c424183c4b34865bd21d0d714848))
36
-
37
- ## 1.0.0 (2021-03-26)
38
-
39
-
40
- ### Features
41
-
42
- * add getAnnotations ([e3f8b63](https://www.github.com/cheminfo/ir-spectrum/commit/e3f8b631f74fbb4bcdcebab7f1b6666e9695b722))
43
- * add peakPicking and autoPeakPicking ([a950e2d](https://www.github.com/cheminfo/ir-spectrum/commit/a950e2d7a4c02009f6b3c5c82f9f264193f25345))
44
- * fromJcamp adds a and t ([b3c8d77](https://www.github.com/cheminfo/ir-spectrum/commit/b3c8d77404d49415f594ec94ba92009877fc81a4))