Skip to content

Commit 8e0188a

Browse files
authored
Merge pull request #1580 from HIP-infrastructure/fix/schema-option
FIX/FEAT: Use specific schema version
2 parents cf0c75e + 636f37e commit 8e0188a

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

bids-validator/validators/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function parseOptions(argumentOverride) {
7171
describe:
7272
'BIDS specification schema version to use for validation, e.g. "v1.6.0" (beta)',
7373
default: 'disable',
74-
choices: ['disable', 'v1.6.0', 'master'],
74+
choices: ['disable', 'v1.6.0', 'v1.7.0', 'master'],
7575
})
7676
.epilogue(
7777
'This tool checks if a dataset in a given directory is \

bids-validator/validators/schemaTypes.js

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,28 @@ async function loadYaml(base, path, local) {
5252
* @param {boolean} local Avoid any network access
5353
*/
5454
async function loadSchema(base, local = false) {
55-
const top = 'rules/top_level_files.yaml'
56-
const entities = 'rules/entities.yaml'
55+
// Define path prefix depending on the BIDS schema version
56+
const prefix_objects = base.includes('v1.6.0') ? '' : 'objects/'
57+
const prefix_rules = base.includes('v1.6.0') ? '' : 'rules/'
58+
const prefix_datatypes = prefix_rules + 'datatypes/'
59+
60+
// Define schema files for top level files and entities
61+
const top = prefix_rules + 'top_level_files.yaml'
62+
const entities = prefix_objects + 'entities.yaml'
63+
5764
return {
5865
top_level_files: await loadYaml(base, top, local),
5966
entities: await loadYaml(base, entities, local),
6067
datatypes: {
61-
anat: await loadYaml(base, `rules/datatypes/anat.yaml`, local),
62-
beh: await loadYaml(base, `rules/datatypes/beh.yaml`, local),
63-
dwi: await loadYaml(base, `rules/datatypes/dwi.yaml`, local),
64-
eeg: await loadYaml(base, `rules/datatypes/eeg.yaml`, local),
65-
fmap: await loadYaml(base, `rules/datatypes/fmap.yaml`, local),
66-
func: await loadYaml(base, `rules/datatypes/func.yaml`, local),
67-
ieeg: await loadYaml(base, 'rules/datatypes/ieeg.yaml', local),
68-
meg: await loadYaml(base, 'rules/datatypes/meg.yaml', local),
69-
pet: await loadYaml(base, 'rules/datatypes/pet.yaml', local),
68+
anat: await loadYaml(base, prefix_datatypes + 'anat.yaml', local),
69+
beh: await loadYaml(base, prefix_datatypes + 'beh.yaml', local),
70+
dwi: await loadYaml(base, prefix_datatypes + 'dwi.yaml', local),
71+
eeg: await loadYaml(base, prefix_datatypes + 'eeg.yaml', local),
72+
fmap: await loadYaml(base, prefix_datatypes + 'fmap.yaml', local),
73+
func: await loadYaml(base, prefix_datatypes + 'func.yaml', local),
74+
ieeg: await loadYaml(base, prefix_datatypes + 'ieeg.yaml', local),
75+
meg: await loadYaml(base, prefix_datatypes + 'meg.yaml', local),
76+
pet: await loadYaml(base, prefix_datatypes + 'pet.yaml', local),
7077
},
7178
}
7279
}
@@ -117,11 +124,14 @@ export async function generateRegex(schema, pythonRegex = false) {
117124

118125
for (const mod of modalities) {
119126
const modality_datatype_schema = schema.datatypes[mod]
120-
for (const datatype of modality_datatype_schema) {
127+
for (const datatype of Object.keys(modality_datatype_schema)) {
121128
let file_regex = `${regex.sub_ses_dirs}${mod}${regex.type_dir}${regex.sub_ses_entity}`
122-
for (const entity of Object.keys(schema.entities)) {
123-
const entityDefinion = schema.entities[entity]
124-
if (entity in datatype.entities) {
129+
let entities = Object.keys(schema.entities)
130+
for (const entity of Object.keys(
131+
modality_datatype_schema[datatype].entities,
132+
)) {
133+
if (entities.includes(entity)) {
134+
const entityDefinion = schema.entities[entity]
125135
// sub and ses entities in file name handled by directory pattern matching groups
126136
if (entity === 'subject' || entity === 'session') {
127137
continue
@@ -131,16 +141,18 @@ export async function generateRegex(schema, pythonRegex = false) {
131141
if (format) {
132142
// Limitation here is that if format is missing an essential entity may be skipped
133143
file_regex += `(?${P}<${entity}>_${entityKey}-${format})${
134-
regex[datatype.entities[entity]]
144+
regex[modality_datatype_schema[datatype].entities[entity]]
135145
}`
136146
}
137147
}
138148
}
139-
const suffix_regex = `_(?${P}<suffix>${datatype.suffixes.join('|')})`
149+
const suffix_regex = `_(?${P}<suffix>${modality_datatype_schema[
150+
datatype
151+
].suffixes.join('|')})`
140152
// Workaround v1.6.0 MEG extension "*"
141-
const wildcard_extensions = datatype.extensions.map((ext) =>
142-
ext === '*' ? '.*?' : ext,
143-
)
153+
const wildcard_extensions = modality_datatype_schema[
154+
datatype
155+
].extensions.map((ext) => (ext === '*' ? '.*?' : ext))
144156
const ext_regex = `(?${P}<ext>${wildcard_extensions.join('|')})`
145157
exportRegex.datatypes[mod].push(
146158
new RegExp(file_regex + suffix_regex + ext_regex + '$'),

0 commit comments

Comments
 (0)