Skip to content

Commit dd8a5b3

Browse files
authored
Merge pull request #92 from effigies/fix/bval-bvec
fix(bval): Handle trailing whitespace without newlines
2 parents 4223800 + f2ca92b commit dd8a5b3

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/files/deno.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export async function readFileTree(rootPath: string): Promise<FileTree> {
159159
)
160160
ignore.add(await readBidsIgnore(ignoreFile))
161161
} catch (err) {
162-
if (err && typeof err === 'object' && !('code' in err && err.code !== 'ENOENT')) {
162+
if (err && typeof err === 'object' && !('code' in err && err.code === 'ENOENT')) {
163163
logger.error(`Failed to read '.bidsignore' file with the following error:\n${err}`)
164164
}
165165
}

src/files/dwi.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { assertEquals } from '@std/assert'
2+
3+
import { parseBvalBvec } from './dwi.ts'
4+
5+
Deno.test('Test bval/bvec parsing', async (t) => {
6+
await t.step('Load 3 bvals', async () => {
7+
const bvals = parseBvalBvec('0 1 2 \n') // Typically ends with " \n"
8+
assertEquals(bvals, [['0', '1', '2']])
9+
})
10+
await t.step('Load 3 bvals - missing newline', async () => {
11+
const bvals = parseBvalBvec('0 1 2 ')
12+
assertEquals(bvals, [['0', '1', '2']])
13+
})
14+
await t.step('Load 3 bvals - no spaces', async () => {
15+
const bvals = parseBvalBvec('0 1 2')
16+
assertEquals(bvals, [['0', '1', '2']])
17+
})
18+
await t.step('Load 3 bvecs', async () => {
19+
const bvecs = parseBvalBvec('0 1 2 \n0 1 2 \n0 1 2 \n')
20+
assertEquals(bvecs, [['0', '1', '2'], ['0', '1', '2'], ['0', '1', '2']])
21+
})
22+
await t.step('Load 3 bvals - missing newline', async () => {
23+
const bvecs = parseBvalBvec('0 1 2 \n0 1 2 \n0 1 2 ')
24+
assertEquals(bvecs, [['0', '1', '2'], ['0', '1', '2'], ['0', '1', '2']])
25+
})
26+
await t.step('Load 3 bvals - no spaces', async () => {
27+
const bvecs = parseBvalBvec('0 1 2\n0 1 2\n0 1 2\n')
28+
assertEquals(bvecs, [['0', '1', '2'], ['0', '1', '2'], ['0', '1', '2']])
29+
})
30+
await t.step('Load 3 bvals - no spaces, missing newline', async () => {
31+
const bvecs = parseBvalBvec('0 1 2\n0 1 2\n0 1 2')
32+
assertEquals(bvecs, [['0', '1', '2'], ['0', '1', '2'], ['0', '1', '2']])
33+
})
34+
})
35+

src/files/dwi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function parseBvalBvec(contents: string): string[][] {
1010
// BVAL files are a single row of numbers, and may contain
1111
// trailing whitespace
1212
return normalizeEOL(contents)
13-
.split(/\s*\n/) // Split on newlines, ignoring trailing whitespace
13+
.split(/\n/) // Split on newlines
1414
.filter((x) => x.match(/\S/)) // Remove empty lines
15-
.map((row) => row.split(/\s+/))
15+
.map((row) => row.trimEnd().split(/\s+/)) // Split on whitespace, ignoring trailing
1616
}

0 commit comments

Comments
 (0)