Skip to content

Commit

Permalink
fix: load raw bruker data (#52)
Browse files Browse the repository at this point in the history
* fix: remove possible black line in experiment

* fix: load raw Bruker data

* fix: extract nucleus from tag
  • Loading branch information
jobo322 authored Jun 28, 2024
1 parent 41fd4a3 commit 97afbd5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
12 changes: 12 additions & 0 deletions src/converter/__tests__/nmredataToJSON.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
4 changes: 2 additions & 2 deletions src/converter/nmredataToJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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,
};
Expand Down
23 changes: 16 additions & 7 deletions src/converter/util/toJSON/getBrukerFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]+\/).*/

Check warning on line 19 in src/converter/util/toJSON/getBrukerFiles.js

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Capture group '([.*/]*\w+\/[0-9]+\/)' should be converted to a named or non-capturing group
: /(.*\w+\/[0-9]+\/)pdata\/.*/;

Check warning on line 20 in src/converter/util/toJSON/getBrukerFiles.js

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Capture group '(.*\w+\/[0-9]+\/)' should be converted to a named or non-capturing group
let toCheck = pathSpectrum.replace(regexRootPath, '$1');

let toCheck2 = pathSpectrum.replace(
/.*\/[0-9]+\/pdata\/([0-9]+)\/.*/,

Check warning on line 24 in src/converter/util/toJSON/getBrukerFiles.js

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Capture group '([0-9]+)' should be converted to a named or non-capturing group
'$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 !==
Expand All @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/converter/util/toJSON/getNucleusFromTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ export function getNucleusFromTag(label) {
if (dimensions === '1') {
nucleus = label
.substring(3, label.length)
.replace(/(?<nucleus>[0-9]+\w+)#\w+/g, '$nucleus');
.replace(/(?<nucleus>[0-9]+\w+)#\w+/g, '$<nucleus>');
} 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(/(?<nucleus>[0-9]+\w+)#\w+/g, '$nucleus'));
nucleus.push(data[i].replace(/(?<nucleus>[0-9]+\w+)#\w+/g, '$<nucleus>'));
}
}
return nucleus;
Expand Down

0 comments on commit 97afbd5

Please sign in to comment.