From 97afbd5403c0d96dc2f45db43ecd2473e600d555 Mon Sep 17 00:00:00 2001 From: Jose Alejandro Bolanos Arroyave Date: Fri, 28 Jun 2024 10:32:35 -0500 Subject: [PATCH] fix: load raw bruker data (#52) * fix: remove possible black line in experiment * fix: load raw Bruker data * fix: extract nucleus from tag --- .../__tests__/nmredataToJSON.test.js | 12 ++++++++++ src/converter/nmredataToJSON.js | 4 ++-- src/converter/util/toJSON/getBrukerFiles.js | 23 +++++++++++++------ .../util/toJSON/getNucleusFromTag.js | 4 ++-- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/converter/__tests__/nmredataToJSON.test.js b/src/converter/__tests__/nmredataToJSON.test.js index 55b3428..1c3ba3e 100644 --- a/src/converter/__tests__/nmredataToJSON.test.js +++ b/src/converter/__tests__/nmredataToJSON.test.js @@ -50,4 +50,16 @@ describe('NMReData to nmrium', () => { 'AN-menthol/10/specpar', ]); }); + + it('1D data with more than one carbon spectra', async () => { + const nmrRecord = await readNmrRecord( + await getData('3,5-Bis(trifluoromethyl)aniline-sym.zip'), + ); + let jsonData = await nmrRecord.toJSON(); + + //dept135 is under tag #2 so it is what is testing. + expect( + jsonData.spectra.some((s) => s.experiment === 'dept135'), + ).toBeTruthy(); + }); }); diff --git a/src/converter/nmredataToJSON.js b/src/converter/nmredataToJSON.js index 0f629bc..67b6057 100644 --- a/src/converter/nmredataToJSON.js +++ b/src/converter/nmredataToJSON.js @@ -19,7 +19,7 @@ export async function nmredataToJSON(nmredata, options) { let spectra = data.spectra; let molecules = data.molecules; - if (nmredata.SMILES) { + if (nmredata.SMILES?.data.length > 0) { molecules[0].smiles = nmredata.SMILES.data[0].value; } @@ -48,7 +48,7 @@ export async function nmredataToJSON(nmredata, options) { nucleus, frequency: frequencyLine.value.larmor, experiment: pulseProgramLine - ? pulseProgramLine.value.pulseprogram + ? pulseProgramLine.value.pulseprogram.trim() : dimension, headComment: nmredata[tag].headComment, }; diff --git a/src/converter/util/toJSON/getBrukerFiles.js b/src/converter/util/toJSON/getBrukerFiles.js index 359fd09..952cf48 100644 --- a/src/converter/util/toJSON/getBrukerFiles.js +++ b/src/converter/util/toJSON/getBrukerFiles.js @@ -14,19 +14,18 @@ export async function getBrukerFiles(tag, options) { let relativePath = locationLine.value.spectrum_location; if (relativePath.match(/file:/s)) { - let pathSpectrum = root + relativePath.replace(/file:/s, ''); - let toCheck = pathSpectrum.replace(/(.*\w+\/[0-9]+\/)pdata\/.*/, '$1'); + let pathSpectrum = root + relativePath.replace(/file:[./]*/s, ''); + const regexRootPath = pathSpectrum.match(/[ser|fid]/s) + ? /([.*/]*\w+\/[0-9]+\/).*/ + : /(.*\w+\/[0-9]+\/)pdata\/.*/; + let toCheck = pathSpectrum.replace(regexRootPath, '$1'); + let toCheck2 = pathSpectrum.replace( /.*\/[0-9]+\/pdata\/([0-9]+)\/.*/, '$1', ); let brukerFolder = []; for (let file of fileCollection) { - if ( - toCheck !== file.relativePath.replace(/([.*/]*\w+\/[0-9]+\/).*/, '$1') - ) { - continue; - } if (file.relativePath.match('pdata')) { if ( toCheck2 !== @@ -35,8 +34,18 @@ export async function getBrukerFiles(tag, options) { continue; } } + + const path = file.relativePath.replace(/([.*/]*\w+\/[0-9]+\/).*/, '$1'); + if ( + toCheck !== path && + !['ser', 'fid'].some((e) => pathSpectrum === `${path}${e}`) + ) { + continue; + } + brukerFolder.push(file); } + sources.push({ type: 'brukerFiles', fileCollection: new FileCollection(brukerFolder), diff --git a/src/converter/util/toJSON/getNucleusFromTag.js b/src/converter/util/toJSON/getNucleusFromTag.js index 68a8818..1cf19f0 100644 --- a/src/converter/util/toJSON/getNucleusFromTag.js +++ b/src/converter/util/toJSON/getNucleusFromTag.js @@ -4,11 +4,11 @@ export function getNucleusFromTag(label) { if (dimensions === '1') { nucleus = label .substring(3, label.length) - .replace(/(?[0-9]+\w+)#\w+/g, '$nucleus'); + .replace(/(?[0-9]+\w+)#\w+/g, '$'); } else if (dimensions === '2') { let data = label.substring(12, label.length).split('_'); for (let i = 0; i < data.length; i += 2) { - nucleus.push(data[i].replace(/(?[0-9]+\w+)#\w+/g, '$nucleus')); + nucleus.push(data[i].replace(/(?[0-9]+\w+)#\w+/g, '$')); } } return nucleus;