Skip to content

Commit

Permalink
fix: molfiles were not correctly placed
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed Apr 4, 2024
1 parent 91fc857 commit b0a67b8
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/createGeneralTOC.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ test('createGeneralTOC', async () => {
.map((file) => {
return statSync(file).size;
});
expect(sizes).toStrictEqual([2211, 404, 899, 483, 250]);
expect(sizes).toStrictEqual([1221, 384, 566, 483, 250]);
});
19 changes: 7 additions & 12 deletions src/__tests__/general/Data3/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,20 @@
},
"display": {
"name": "1h.jdx"
},
"molecules": [
{
"molfile": "\n ChemDraw05122111362D\n\n 9 9 0 0 0 0 0 0 0 0999 V2000\n -0.4125 -0.3572 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.4125 -0.3572 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.8250 0.3572 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.4125 1.0717 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.4125 1.0717 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.8250 0.3572 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.8250 -1.0717 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.4125 -1.7862 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.8250 1.7862 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 4 0 \n 2 3 4 0 \n 3 4 4 0 \n 4 5 4 0 \n 5 6 4 0 \n 6 1 4 0 \n 1 7 1 0 \n 7 8 1 0 \n 5 9 1 0 \nM END\n"
}
]
}
},
{
"source": {
"jcampURL": "./cosy.jdx"
},
"display": {
"name": "cosy.jdx"
},
"molecules": [
{
"molfile": "\n ChemDraw05122111362D\n\n 9 9 0 0 0 0 0 0 0 0999 V2000\n -0.4125 -0.3572 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.4125 -0.3572 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.8250 0.3572 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.4125 1.0717 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.4125 1.0717 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.8250 0.3572 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.8250 -1.0717 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.4125 -1.7862 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.8250 1.7862 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 4 0 \n 2 3 4 0 \n 3 4 4 0 \n 4 5 4 0 \n 5 6 4 0 \n 6 1 4 0 \n 1 7 1 0 \n 7 8 1 0 \n 5 9 1 0 \nM END\n"
}
]
}
}
],
"molecules": [
{
"molfile": "\n ChemDraw05122111362D\n\n 9 9 0 0 0 0 0 0 0 0999 V2000\n -0.4125 -0.3572 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.4125 -0.3572 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.8250 0.3572 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.4125 1.0717 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.4125 1.0717 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.8250 0.3572 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.8250 -1.0717 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.4125 -1.7862 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.8250 1.7862 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 4 0 \n 2 3 4 0 \n 3 4 4 0 \n 4 5 4 0 \n 5 6 4 0 \n 6 1 4 0 \n 1 7 1 0 \n 7 8 1 0 \n 5 9 1 0 \nM END\n"
}
]
}
12 changes: 6 additions & 6 deletions src/__tests__/general/Group1/Data1/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
{
"source": {
"jcampURL": "./1h.jdx"
},
"molecules": [
{
"molfile": "\n ChemDraw05122111372D\n\n 2 1 0 0 0 0 0 0 0 0999 V2000\n -0.3572 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.3572 0.2062 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 1 0 \nM END\n"
}
]
}
}
],
"molecules": [
{
"molfile": "\n ChemDraw05122111372D\n\n 2 1 0 0 0 0 0 0 0 0999 V2000\n -0.3572 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.3572 0.2062 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 1 0 \nM END\n"
}
]
}
19 changes: 7 additions & 12 deletions src/__tests__/general/Group1/Data2/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,20 @@
},
"display": {
"name": "13c.jdx"
},
"molecules": [
{
"molfile": "\n ChemDraw05122111372D\n\n 2 1 0 0 0 0 0 0 0 0999 V2000\n -0.3572 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.3572 0.2062 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 1 0 \nM END\n"
}
]
}
},
{
"source": {
"jcampURL": "./cosy.jdx"
},
"display": {
"name": "cosy.jdx"
},
"molecules": [
{
"molfile": "\n ChemDraw05122111372D\n\n 2 1 0 0 0 0 0 0 0 0999 V2000\n -0.3572 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.3572 0.2062 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 1 0 \nM END\n"
}
]
}
}
],
"molecules": [
{
"molfile": "\n ChemDraw05122111372D\n\n 2 1 0 0 0 0 0 0 0 0999 V2000\n -0.3572 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.3572 0.2062 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 1 0 \nM END\n"
}
]
}
2 changes: 1 addition & 1 deletion src/commands/createGeneralTOC.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { processGeneralFolder } from './toc/processGeneralFolder.js';
* Add the links based on all the available toc files
* @param {string} commandDir
* @param {object} [options={}]
* @param {boolean} [options.dataDir]
* @param {string} [options.dataDir]
*/
export async function createGeneralTOC(commandDir, options = {}) {
return createToc(commandDir, processGeneralFolder, options);
Expand Down
42 changes: 25 additions & 17 deletions src/commands/toc/processGeneralFolder.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { lstatSync, readFileSync, readdirSync, writeFileSync } from 'fs';
import { lstatSync, readFileSync, readdirSync, writeFileSync, existsSync } from 'fs';
import { join } from 'path';

import debugFct from 'debug';
import { hashElement } from 'folder-hash';
import { createTree } from 'jcampconverter';
import YAML from 'yaml';

const debug = debugFct('nmrium.general');

Expand All @@ -12,10 +13,23 @@ let dataCount = 0;

export async function processGeneralFolder(basename, folder, toc) {
const currentFolder = join(basename, folder);
const entries = readdirSync(currentFolder);
const molfileName = readdirSync(currentFolder).filter((file) =>

const folderConfigFilename = join(currentFolder, 'index.yml');
const folderConfig = existsSync(folderConfigFilename)
? YAML.parse(readFileSync(folderConfigFilename, 'utf8'))
: {};

// Loading all the molfiles
const molfileNames = readdirSync(currentFolder).filter((file) =>
file.toLowerCase().endsWith('.mol'),
)[0];
);
const molecules = [];
for (let molfileName of molfileNames) {
const molfile = readFileSync(join(currentFolder, molfileName), 'utf8');
molecules.push({ molfile });
}

const entries = readdirSync(currentFolder);
const spectra = [];
// we process only the folder if there is an answer (structure.mol)
const id = (
Expand All @@ -32,7 +46,6 @@ export async function processGeneralFolder(basename, folder, toc) {
const jcampText = readFileSync(join(currentFolder, filename));
const tree = createTree(jcampText, {});
const title = tree[0]?.title;

const spectrum = {
source: {
jcampURL: `./${filename}`,
Expand All @@ -45,25 +58,20 @@ export async function processGeneralFolder(basename, folder, toc) {
};
}

if (molfileName) {
const molfile = readFileSync(join(currentFolder, molfileName), 'utf8');
spectrum.molecules = [{ molfile }];
}
spectra.push(spectrum);
}

const targetPath = join(basename, folder, 'index.json');
debug(`Create: ${targetPath}`);

writeFileSync(targetPath, JSON.stringify({ spectra }, undefined, 2), 'utf8');
writeFileSync(targetPath, JSON.stringify({ spectra, molecules }, undefined, 2), 'utf8');

let title = folder
.replace(/^[^/]*\//, '')
.replace(/^[0-9]*$/, '')
.replace(/^[0-9]*_/, '');
if (!title) {
title = `Data ${++dataCount}`;
}
let title = folderConfig.menuLabel ||
folder
.replace(/^[^/]*\//, '')
.replace(/^[0-9]*$/, '')
.replace(/^[0-9]*_/, '') ||
`Data ${++dataCount}`;
const tocEntry = {
id,
file: `${URL_FOLDER}/${folder}/index.json`,
Expand Down

0 comments on commit b0a67b8

Please sign in to comment.