diff --git a/src/files/deno.ts b/src/files/deno.ts index b6fe4b13..f3065a1f 100644 --- a/src/files/deno.ts +++ b/src/files/deno.ts @@ -159,7 +159,7 @@ export async function readFileTree(rootPath: string): Promise { ) ignore.add(await readBidsIgnore(ignoreFile)) } catch (err) { - if (err && typeof err === 'object' && !('code' in err && err.code !== 'ENOENT')) { + if (err && typeof err === 'object' && !('code' in err && err.code === 'ENOENT')) { logger.error(`Failed to read '.bidsignore' file with the following error:\n${err}`) } } diff --git a/src/files/dwi.test.ts b/src/files/dwi.test.ts new file mode 100644 index 00000000..acb426a7 --- /dev/null +++ b/src/files/dwi.test.ts @@ -0,0 +1,35 @@ +import { assertEquals } from '@std/assert' + +import { parseBvalBvec } from './dwi.ts' + +Deno.test('Test bval/bvec parsing', async (t) => { + await t.step('Load 3 bvals', async () => { + const bvals = parseBvalBvec('0 1 2 \n') // Typically ends with " \n" + assertEquals(bvals, [['0', '1', '2']]) + }) + await t.step('Load 3 bvals - missing newline', async () => { + const bvals = parseBvalBvec('0 1 2 ') + assertEquals(bvals, [['0', '1', '2']]) + }) + await t.step('Load 3 bvals - no spaces', async () => { + const bvals = parseBvalBvec('0 1 2') + assertEquals(bvals, [['0', '1', '2']]) + }) + await t.step('Load 3 bvecs', async () => { + const bvecs = parseBvalBvec('0 1 2 \n0 1 2 \n0 1 2 \n') + assertEquals(bvecs, [['0', '1', '2'], ['0', '1', '2'], ['0', '1', '2']]) + }) + await t.step('Load 3 bvals - missing newline', async () => { + const bvecs = parseBvalBvec('0 1 2 \n0 1 2 \n0 1 2 ') + assertEquals(bvecs, [['0', '1', '2'], ['0', '1', '2'], ['0', '1', '2']]) + }) + await t.step('Load 3 bvals - no spaces', async () => { + const bvecs = parseBvalBvec('0 1 2\n0 1 2\n0 1 2\n') + assertEquals(bvecs, [['0', '1', '2'], ['0', '1', '2'], ['0', '1', '2']]) + }) + await t.step('Load 3 bvals - no spaces, missing newline', async () => { + const bvecs = parseBvalBvec('0 1 2\n0 1 2\n0 1 2') + assertEquals(bvecs, [['0', '1', '2'], ['0', '1', '2'], ['0', '1', '2']]) + }) +}) + diff --git a/src/files/dwi.ts b/src/files/dwi.ts index b7465b62..48136945 100644 --- a/src/files/dwi.ts +++ b/src/files/dwi.ts @@ -10,7 +10,7 @@ export function parseBvalBvec(contents: string): string[][] { // BVAL files are a single row of numbers, and may contain // trailing whitespace return normalizeEOL(contents) - .split(/\s*\n/) // Split on newlines, ignoring trailing whitespace + .split(/\n/) // Split on newlines .filter((x) => x.match(/\S/)) // Remove empty lines - .map((row) => row.split(/\s+/)) + .map((row) => row.trimEnd().split(/\s+/)) // Split on whitespace, ignoring trailing }