From 2c00d261003adf9106ef4ec120bdf3b1b5f232b7 Mon Sep 17 00:00:00 2001 From: f-idiris Date: Fri, 8 Sep 2023 13:12:01 +0200 Subject: [PATCH 1/4] report fixed wavelength in emission spec --- src/__tests__/fixtures/emissions_jcamp.js | 24 +++++++++++++++------ src/__tests__/units/helpers/format.test.tsx | 2 +- src/helpers/chem.js | 4 ++++ src/helpers/format.js | 24 +++++++++++++++++++-- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/__tests__/fixtures/emissions_jcamp.js b/src/__tests__/fixtures/emissions_jcamp.js index 80610a34..e572ec20 100644 --- a/src/__tests__/fixtures/emissions_jcamp.js +++ b/src/__tests__/fixtures/emissions_jcamp.js @@ -1,10 +1,12 @@ const emissionsJcamp = ` -##TITLE= +##TITLE=Example of fluorescence measurement (4).1_bagit ##JCAMP-DX=5.0 ##DATA TYPE=LINK ##BLOCKS=1 + + $$ === CHEMSPECTRA SPECTRUM ORIG === -##TITLE= +##TITLE=Example of fluorescence measurement (4).1_bagit ##JCAMP-DX=5.00 ##DATA TYPE=Emissions ##DATA CLASS=XYDATA @@ -826,6 +828,7 @@ $$ === CHEMSPECTRA SPECTRUM ORIG === 800.0, 0.0258263 $$ === CHEMSPECTRA INTEGRALS AND MULTIPLETS === ##$OBSERVEDINTEGRALS= (X Y Z) + ##$OBSERVEDMULTIPLETS= ##$OBSERVEDMULTIPLETSPEAKS= $$ === CHEMSPECTRA SIMULATION === @@ -834,12 +837,12 @@ $$ === CHEMSPECTRA SIMULATION === $$ === CHEMSPECTRA PEAK TABLE EDIT === -##TITLE= +##TITLE=Example of fluorescence measurement (4).1_bagit ##JCAMP-DX=5.00 ##DATA TYPE=EmissionsPEAKTABLE ##DATA CLASS=PEAKTABLE ##$CSCATEGORY=EDIT_PEAK -##$CSTHRESHOLD=0.05 +##$CSTHRESHOLD=0.5 ##MAXX=800.0 ##MAXY=295.575 ##MINX=400.0 @@ -853,12 +856,12 @@ $$ === CHEMSPECTRA PEAK TABLE EDIT === $$ === CHEMSPECTRA PEAK TABLE AUTO === -##TITLE= +##TITLE=Example of fluorescence measurement (4).1_bagit ##JCAMP-DX=5.00 ##DATA TYPE=EmissionsPEAKTABLE ##DATA CLASS=PEAKTABLE ##$CSCATEGORY=AUTO_PEAK -##$CSTHRESHOLD=0.05 +##$CSTHRESHOLD=0.5 ##MAXX=800.0 ##MAXY=295.575 ##MINX=400.0 @@ -871,7 +874,16 @@ $$ === CHEMSPECTRA PEAK TABLE AUTO === 484.5, 190.807 ##END= + +$$ === CHEMSPECTRA AUTO METADATA === +##$CSAUTOMETADATA= +DATA CLASS=XYPOINTS +DATA TYPE=Emissions +XUNITS=wavelength (nm) +YUNITS=Intensity +FIXEDWAVELENGTH=380.0 ##END= +##END= `; export default emissionsJcamp; diff --git a/src/__tests__/units/helpers/format.test.tsx b/src/__tests__/units/helpers/format.test.tsx index bd8754d2..25e582c1 100644 --- a/src/__tests__/units/helpers/format.test.tsx +++ b/src/__tests__/units/helpers/format.test.tsx @@ -137,7 +137,7 @@ describe('Test format helper', () => { it('Get peaks for Emission layout', () => { params.layout = LIST_LAYOUT.EMISSIONS const body = Format.peaksBody(params) - expect(body).toEqual('2.0 nm (2.00 a.u.), 1.0 nm (1.00 a.u.)') + expect(body).toEqual('2.0, 1.0') }) diff --git a/src/helpers/chem.js b/src/helpers/chem.js index 3ad7fd94..99d0b5a1 100644 --- a/src/helpers/chem.js +++ b/src/helpers/chem.js @@ -751,6 +751,10 @@ const ExtractJcamp = (source) => { // : ((Format.isXRDLayout(layout) || Format.isCyclicVoltaLayout(layout)) // ? extrFeaturesXrd(jcamp, layout, peakUp) : extrFeaturesNi(jcamp, layout, peakUp, spectra)); + if (layout === LIST_LAYOUT.EMISSIONS) { + Format.extractFixedWavelength(source); + } + return { spectra, features, layout }; }; diff --git a/src/helpers/format.js b/src/helpers/format.js index b17f88cf..a5c726ed 100644 --- a/src/helpers/format.js +++ b/src/helpers/format.js @@ -1,5 +1,6 @@ /* eslint-disable no-mixed-operators, prefer-object-spread, function-paren-newline, no-unused-vars, default-param-last */ +import Jcampconverter from 'jcampconverter'; import { ToXY, IsSame } from './converter'; import { LIST_LAYOUT } from '../constants/list_layout'; import { calcMpyCenter } from './multiplicity_calc'; @@ -51,6 +52,22 @@ const toPeakStr = (peaks) => { return str; }; +let fixedWavelength = null; + +const extractFixedWavelength = (source) => { + const jcamp = Jcampconverter.convert( + source, + { + xy: true, + keepRecordsRegExp: /(CSAUTOMETADATA)/, + }, + ); + // eslint-disable-next-line prefer-destructuring + fixedWavelength = jcamp.info.$CSAUTOMETADATA.match(/FIXEDWAVELENGTH=([\d.]+)/)[1]; + + return { fixedWavelength }; +}; + const spectraOps = { [LIST_LAYOUT.PLAIN]: { head: '', tail: '.' }, [LIST_LAYOUT.H1]: { head: '1H', tail: '.' }, @@ -69,7 +86,6 @@ const spectraOps = { [LIST_LAYOUT.CYCLIC_VOLTAMMETRY]: { head: 'CYCLIC VOLTAMMETRY', tail: '.' }, [LIST_LAYOUT.CDS]: { head: 'CIRCULAR DICHROISM SPECTROSCOPY', tail: '.' }, [LIST_LAYOUT.SEC]: { head: 'SIZE EXCLUSION CHROMATOGRAPHY', tail: '.' }, - [LIST_LAYOUT.EMISSIONS]: { head: 'EMISSION', tail: '.' }, [LIST_LAYOUT.DLS_INTENSITY]: { head: 'DLS', tail: '.' }, }; @@ -189,7 +205,7 @@ const formatedEmissions = ( ordered = Object.keys(ordered).sort(sortFunc) .map((k) => ({ x: k, y: ordered[k] })); - return ordered.map((o) => `${o.x} nm (${fixDigit(o.y, 2)} a.u.)`).join(', '); + return ordered.map((o) => `${o.x}`).join(', '); }; const formatedDLSIntensity = ( @@ -324,6 +340,9 @@ const peaksWrapper = (layout, shift, atIndex = 0) => { return { head: '', tail: '' }; } + if (layout === LIST_LAYOUT.EMISSIONS) { + return { head: `EMISSION: λex = ${fixedWavelength} nm, λem = `, tail: ' nm' }; + } const ops = spectraOps[layout]; return { head: `${ops.head}${solvTxt} = `, tail: ops.tail }; }; @@ -459,6 +478,7 @@ const Format = { isAIFLayout, isDLSACFLayout, strNumberFixedDecimal, + extractFixedWavelength, }; export default Format; From 37b67dd3b0af7e56cfe3e5a70b1395167270ce65 Mon Sep 17 00:00:00 2001 From: f-idiris Date: Fri, 8 Sep 2023 14:33:04 +0200 Subject: [PATCH 2/4] yarn compile --- dist/helpers/chem.js | 3 +++ dist/helpers/format.js | 29 +++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/dist/helpers/chem.js b/dist/helpers/chem.js index c477abd9..1086556c 100644 --- a/dist/helpers/chem.js +++ b/dist/helpers/chem.js @@ -783,6 +783,9 @@ const ExtractJcamp = source => { // : ((Format.isXRDLayout(layout) || Format.isCyclicVoltaLayout(layout)) // ? extrFeaturesXrd(jcamp, layout, peakUp) : extrFeaturesNi(jcamp, layout, peakUp, spectra)); + if (layout === _list_layout.LIST_LAYOUT.EMISSIONS) { + _format.default.extractFixedWavelength(source); + } return { spectra, features, diff --git a/dist/helpers/format.js b/dist/helpers/format.js index e2eb4820..179bae42 100644 --- a/dist/helpers/format.js +++ b/dist/helpers/format.js @@ -1,9 +1,11 @@ "use strict"; +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; +var _jcampconverter = _interopRequireDefault(require("jcampconverter")); var _converter = require("./converter"); var _list_layout = require("../constants/list_layout"); var _multiplicity_calc = require("./multiplicity_calc"); @@ -58,6 +60,18 @@ const toPeakStr = peaks => { const str = arr.join('#'); return str; }; +let fixedWavelength = null; +const extractFixedWavelength = source => { + const jcamp = _jcampconverter.default.convert(source, { + xy: true, + keepRecordsRegExp: /(CSAUTOMETADATA)/ + }); + // eslint-disable-next-line prefer-destructuring + fixedWavelength = jcamp.info.$CSAUTOMETADATA.match(/FIXEDWAVELENGTH=([\d.]+)/)[1]; + return { + fixedWavelength + }; +}; const spectraOps = { [_list_layout.LIST_LAYOUT.PLAIN]: { head: '', @@ -127,10 +141,6 @@ const spectraOps = { head: 'SIZE EXCLUSION CHROMATOGRAPHY', tail: '.' }, - [_list_layout.LIST_LAYOUT.EMISSIONS]: { - head: 'EMISSION', - tail: '.' - }, [_list_layout.LIST_LAYOUT.DLS_INTENSITY]: { head: 'DLS', tail: '.' @@ -259,7 +269,7 @@ const formatedEmissions = function (peaks, maxY) { x: k, y: ordered[k] })); - return ordered.map(o => `${o.x} nm (${fixDigit(o.y, 2)} a.u.)`).join(', '); + return ordered.map(o => `${o.x}`).join(', '); }; const formatedDLSIntensity = function (peaks, maxY) { let decimal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; @@ -402,6 +412,12 @@ const peaksWrapper = function (layout, shift) { tail: '' }; } + if (layout === _list_layout.LIST_LAYOUT.EMISSIONS) { + return { + head: `EMISSION: λex = ${fixedWavelength} nm, λem = `, + tail: ' nm' + }; + } const ops = spectraOps[layout]; return { head: `${ops.head}${solvTxt} = `, @@ -526,7 +542,8 @@ const Format = { hasMultiCurves, isAIFLayout, isDLSACFLayout, - strNumberFixedDecimal + strNumberFixedDecimal, + extractFixedWavelength }; var _default = Format; exports.default = _default; \ No newline at end of file From 2cd7aa375b0b5851ffa3c774297296eeb77576a7 Mon Sep 17 00:00:00 2001 From: f-idiris Date: Fri, 8 Sep 2023 15:30:01 +0200 Subject: [PATCH 3/4] add check for autometadata --- dist/helpers/format.js | 21 +++++++++++++++------ src/helpers/format.js | 16 +++++++++++----- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/dist/helpers/format.js b/dist/helpers/format.js index 179bae42..98d0962a 100644 --- a/dist/helpers/format.js +++ b/dist/helpers/format.js @@ -60,14 +60,19 @@ const toPeakStr = peaks => { const str = arr.join('#'); return str; }; -let fixedWavelength = null; +let fixedWavelength = ''; const extractFixedWavelength = source => { const jcamp = _jcampconverter.default.convert(source, { xy: true, keepRecordsRegExp: /(CSAUTOMETADATA)/ }); - // eslint-disable-next-line prefer-destructuring - fixedWavelength = jcamp.info.$CSAUTOMETADATA.match(/FIXEDWAVELENGTH=([\d.]+)/)[1]; + if ('$CSAUTOMETADATA' in jcamp.info) { + const match = jcamp.info.$CSAUTOMETADATA.match(/FIXEDWAVELENGTH=([\d.]+)/); + if (match !== null) { + // eslint-disable-next-line prefer-destructuring + fixedWavelength = match[1]; + } + } return { fixedWavelength }; @@ -141,6 +146,10 @@ const spectraOps = { head: 'SIZE EXCLUSION CHROMATOGRAPHY', tail: '.' }, + [_list_layout.LIST_LAYOUT.EMISSIONS]: { + head: 'EMISSION', + tail: ' nm' + }, [_list_layout.LIST_LAYOUT.DLS_INTENSITY]: { head: 'DLS', tail: '.' @@ -412,13 +421,13 @@ const peaksWrapper = function (layout, shift) { tail: '' }; } + const ops = spectraOps[layout]; if (layout === _list_layout.LIST_LAYOUT.EMISSIONS) { return { - head: `EMISSION: λex = ${fixedWavelength} nm, λem = `, - tail: ' nm' + head: `${ops.head}${solvTxt}: λex = ${fixedWavelength} nm; λem = `, + tail: ops.tail }; } - const ops = spectraOps[layout]; return { head: `${ops.head}${solvTxt} = `, tail: ops.tail diff --git a/src/helpers/format.js b/src/helpers/format.js index a5c726ed..6b48204e 100644 --- a/src/helpers/format.js +++ b/src/helpers/format.js @@ -52,7 +52,7 @@ const toPeakStr = (peaks) => { return str; }; -let fixedWavelength = null; +let fixedWavelength = ''; const extractFixedWavelength = (source) => { const jcamp = Jcampconverter.convert( @@ -62,8 +62,13 @@ const extractFixedWavelength = (source) => { keepRecordsRegExp: /(CSAUTOMETADATA)/, }, ); - // eslint-disable-next-line prefer-destructuring - fixedWavelength = jcamp.info.$CSAUTOMETADATA.match(/FIXEDWAVELENGTH=([\d.]+)/)[1]; + if ('$CSAUTOMETADATA' in jcamp.info) { + const match = jcamp.info.$CSAUTOMETADATA.match(/FIXEDWAVELENGTH=([\d.]+)/); + if (match !== null) { + // eslint-disable-next-line prefer-destructuring + fixedWavelength = match[1]; + } + } return { fixedWavelength }; }; @@ -86,6 +91,7 @@ const spectraOps = { [LIST_LAYOUT.CYCLIC_VOLTAMMETRY]: { head: 'CYCLIC VOLTAMMETRY', tail: '.' }, [LIST_LAYOUT.CDS]: { head: 'CIRCULAR DICHROISM SPECTROSCOPY', tail: '.' }, [LIST_LAYOUT.SEC]: { head: 'SIZE EXCLUSION CHROMATOGRAPHY', tail: '.' }, + [LIST_LAYOUT.EMISSIONS]: { head: 'EMISSION', tail: ' nm' }, [LIST_LAYOUT.DLS_INTENSITY]: { head: 'DLS', tail: '.' }, }; @@ -340,10 +346,10 @@ const peaksWrapper = (layout, shift, atIndex = 0) => { return { head: '', tail: '' }; } + const ops = spectraOps[layout]; if (layout === LIST_LAYOUT.EMISSIONS) { - return { head: `EMISSION: λex = ${fixedWavelength} nm, λem = `, tail: ' nm' }; + return { head: `${ops.head}${solvTxt}: λex = ${fixedWavelength} nm; λem = `, tail: ops.tail }; } - const ops = spectraOps[layout]; return { head: `${ops.head}${solvTxt} = `, tail: ops.tail }; }; From 85d4718a8549011263ff1b5c7c909b8036071db3 Mon Sep 17 00:00:00 2001 From: f-idiris Date: Tue, 12 Sep 2023 10:05:12 +0200 Subject: [PATCH 4/4] update formatedEmissions --- dist/helpers/format.js | 8 +------- src/__tests__/units/helpers/format.test.tsx | 2 +- src/helpers/format.js | 6 ++---- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/dist/helpers/format.js b/dist/helpers/format.js index 98d0962a..1fbc58a7 100644 --- a/dist/helpers/format.js +++ b/dist/helpers/format.js @@ -278,7 +278,7 @@ const formatedEmissions = function (peaks, maxY) { x: k, y: ordered[k] })); - return ordered.map(o => `${o.x}`).join(', '); + return `λex = ${fixedWavelength} nm; λem = ${ordered.map(o => `${o.x}`).join(', ')}`; }; const formatedDLSIntensity = function (peaks, maxY) { let decimal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; @@ -422,12 +422,6 @@ const peaksWrapper = function (layout, shift) { }; } const ops = spectraOps[layout]; - if (layout === _list_layout.LIST_LAYOUT.EMISSIONS) { - return { - head: `${ops.head}${solvTxt}: λex = ${fixedWavelength} nm; λem = `, - tail: ops.tail - }; - } return { head: `${ops.head}${solvTxt} = `, tail: ops.tail diff --git a/src/__tests__/units/helpers/format.test.tsx b/src/__tests__/units/helpers/format.test.tsx index 25e582c1..a617e88f 100644 --- a/src/__tests__/units/helpers/format.test.tsx +++ b/src/__tests__/units/helpers/format.test.tsx @@ -137,7 +137,7 @@ describe('Test format helper', () => { it('Get peaks for Emission layout', () => { params.layout = LIST_LAYOUT.EMISSIONS const body = Format.peaksBody(params) - expect(body).toEqual('2.0, 1.0') + expect(body).toEqual('λex = nm; λem = 2.0, 1.0') }) diff --git a/src/helpers/format.js b/src/helpers/format.js index 6b48204e..e37ce8c2 100644 --- a/src/helpers/format.js +++ b/src/helpers/format.js @@ -211,7 +211,8 @@ const formatedEmissions = ( ordered = Object.keys(ordered).sort(sortFunc) .map((k) => ({ x: k, y: ordered[k] })); - return ordered.map((o) => `${o.x}`).join(', '); + return `λex = ${fixedWavelength} nm; λem = ${ordered.map((o) => `${o.x}`) + .join(', ')}`; }; const formatedDLSIntensity = ( @@ -347,9 +348,6 @@ const peaksWrapper = (layout, shift, atIndex = 0) => { } const ops = spectraOps[layout]; - if (layout === LIST_LAYOUT.EMISSIONS) { - return { head: `${ops.head}${solvTxt}: λex = ${fixedWavelength} nm; λem = `, tail: ops.tail }; - } return { head: `${ops.head}${solvTxt} = `, tail: ops.tail }; };