-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into rf/json-validator
- Loading branch information
Showing
21 changed files
with
201 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { isCompressed, readHeader } from 'https://esm.sh/[email protected]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { BIDSFile } from '../types/file.ts' | ||
import { BIDSFile } from '../types/filetree.ts' | ||
import { default as ignore } from 'npm:[email protected]' | ||
import type { Ignore } from 'npm:[email protected]' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { BIDSFile, FileTree } from '../types/filetree.ts' | ||
import { Context } from '../types/context.ts' | ||
import { readEntities } from '../schema/entities.ts' | ||
|
||
export function* walkBack( | ||
source: BIDSFile, | ||
inherit: boolean = true, | ||
targetExtensions: string[] = ['.json'], | ||
targetSuffix?: string, | ||
): Generator<BIDSFile> { | ||
const sourceParts = readEntities(source.name) | ||
|
||
targetSuffix = targetSuffix || sourceParts.suffix | ||
|
||
let fileTree = source.parent | ||
while (fileTree) { | ||
const candidates = fileTree.files.filter((file) => { | ||
const { suffix, extension, entities } = readEntities(file.name) | ||
return ( | ||
targetExtensions.includes(extension) && | ||
suffix === targetSuffix && | ||
Object.keys(entities).every((entity) => entities[entity] === sourceParts.entities[entity]) | ||
) | ||
}) | ||
if (candidates.length > 1) { | ||
const exactMatch = candidates.find((file) => { | ||
const { suffix, extension, entities } = readEntities(file.name) | ||
return Object.keys(sourceParts.entities).every((entity) => | ||
entities[entity] === sourceParts.entities[entity] | ||
) | ||
}) | ||
if (exactMatch) { | ||
yield exactMatch | ||
} else { | ||
console.warn(` | ||
Multiple candidates detected for '${source.path}' | ||
${candidates.map((file) => `* ${file.path}`).join('\n')} | ||
`) | ||
} | ||
} else if (candidates.length === 1) { | ||
yield candidates[0] | ||
} | ||
if (!inherit) break | ||
fileTree = fileTree.parent | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { assert } from '../deps/asserts.ts' | ||
import { FileIgnoreRules } from './ignore.ts' | ||
import { BIDSFileDeno } from './deno.ts' | ||
|
||
import { loadHeader } from './nifti.ts' | ||
|
||
Deno.test('Test loading nifti header', async (t) => { | ||
const ignore = new FileIgnoreRules([]) | ||
await t.step('Load header from compressed file', async () => { | ||
const path = "sub-01/func/sub-01_task-rhymejudgment_bold.nii.gz" | ||
const root = "./tests/data/valid_headers" | ||
const file = new BIDSFileDeno(root, path, ignore) | ||
const header = await loadHeader(file) | ||
assert(header !== undefined) | ||
assert(header['pixdim'].length === 8) | ||
}) | ||
await t.step('Fail on non-nifti file', async () => { | ||
const path = "sub-01/func/sub-01_task-rhymejudgment_events.tsv" | ||
const root = "./tests/data/valid_headers" | ||
const file = new BIDSFileDeno(root, path, ignore) | ||
const header = await loadHeader(file) | ||
assert(header !== undefined) | ||
assert(header === null) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.