From d29aec62ffe14d93ca33a829651a1385e56d3da1 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Thu, 7 Nov 2024 14:29:19 -0500 Subject: [PATCH 1/3] fix: Flipped boolean for checking err.code --- src/files/deno.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/files/deno.ts b/src/files/deno.ts index b6fe4b13d..f3065a1f9 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}`) } } From ef6e4cd3a6a3356273671e813d95b8948e8c8b60 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Thu, 7 Nov 2024 14:52:36 -0500 Subject: [PATCH 2/3] fix(bval): Handle trailing whitespace without newlines --- src/files/dwi.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/files/dwi.ts b/src/files/dwi.ts index b7465b62a..481369456 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 } From f2ca92b63a48f70b08d21f80ad51589179bf38de Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Thu, 7 Nov 2024 15:45:30 -0500 Subject: [PATCH 3/3] test(dwi): Validate expected bval/bvec parses --- src/files/dwi.test.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/files/dwi.test.ts diff --git a/src/files/dwi.test.ts b/src/files/dwi.test.ts new file mode 100644 index 000000000..acb426a7e --- /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']]) + }) +}) +