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;