Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: load raw bruker data #52

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 All @@ -37,7 +37,7 @@

let nucleus = getNucleusFromTag(tag);

let dimension = ctag.replace(/([1|2]d)_.*/, '$1');

Check warning on line 40 in src/converter/nmredataToJSON.js

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Capture group '([1|2]d)' should be converted to a named or non-capturing group
let signalProcessor =
dimension === '2d' ? getSignalData2D : getSignalData1D;

Expand All @@ -48,7 +48,7 @@
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 @@

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 @@
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
Loading