Skip to content

Commit fffc35c

Browse files
committed
Merge branches 'fix/expected_matches', 'enh/bval-values' and 'enh/phenotypes' into schema-provisional
4 parents 43a7117 + 0dc4691 + 173ecc2 + 9822199 commit fffc35c

File tree

5 files changed

+25
-30
lines changed

5 files changed

+25
-30
lines changed

bids-validator/src/deps/path.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ export {
99
parse,
1010
SEPARATOR,
1111
} from 'https://deno.land/[email protected]/path/mod.ts'
12+
export {
13+
globToRegExp,
14+
} from 'https://deno.land/[email protected]/path/glob_to_regexp.ts'

bids-validator/src/schema/associations.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ const associationLookup = {
8282
inherit: true,
8383
load: async (file: BIDSFile): Promise<ContextAssociations['bval']> => {
8484
const contents = await file.text()
85-
const columns = parseBvalBvec(contents)
85+
const rows = parseBvalBvec(contents)
8686
return {
8787
path: file.path,
88-
n_cols: columns ? columns[0].length : 0,
89-
n_rows: columns ? columns.length : 0,
88+
n_cols: rows ? rows[0].length : 0,
89+
n_rows: rows ? rows.length : 0,
90+
values: rows[0],
9091
}
9192
},
9293
},
@@ -96,11 +97,11 @@ const associationLookup = {
9697
inherit: true,
9798
load: async (file: BIDSFile): Promise<ContextAssociations['bvec']> => {
9899
const contents = await file.text()
99-
const columns = parseBvalBvec(contents)
100+
const rows = parseBvalBvec(contents)
100101
return {
101102
path: file.path,
102-
n_cols: columns ? columns[0].length : 0,
103-
n_rows: columns ? columns.length : 0,
103+
n_cols: rows ? rows[0].length : 0,
104+
n_rows: rows ? rows.length : 0,
104105
}
105106
},
106107
},

bids-validator/src/types/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface ContextAssociationsBval {
4444
path: string
4545
n_cols: number
4646
n_rows: number
47+
values: number[]
4748
}
4849
export interface ContextAssociationsBvec {
4950
path: string

bids-validator/src/validators/filenameIdentify.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Deno.test('test hasMatch', async (t) => {
7474
hasMatch(schema, context)
7575
})
7676

77-
await t.step('No match', async () => {
77+
await t.step('No match', async () => {
7878
const fileName = Deno.makeTempFileSync().split('/')[2]
7979
const file = new BIDSFileDeno('/tmp', fileName, ignore)
8080

@@ -87,7 +87,7 @@ Deno.test('test hasMatch', async (t) => {
8787
true,
8888
)
8989
})
90-
await t.step('1+ matched, datatype match', async () => {
90+
await t.step('2 matches, no pruning', async () => {
9191
const path = `${PATH}/../bids-examples/fnirs_automaticity`
9292
const fileName = 'events.json'
9393
const file = new BIDSFileDeno(path, fileName, ignore)
@@ -97,7 +97,6 @@ Deno.test('test hasMatch', async (t) => {
9797
'rules.files.raw.task.events__pet',
9898
]
9999
await hasMatch(schema, context)
100-
assertEquals(context.filenameRules.length, 1)
101-
assertEquals(context.filenameRules[0], 'rules.files.raw.task.events__mri')
100+
assertEquals(context.filenameRules.length, 2)
102101
})
103102
})

bids-validator/src/validators/filenameIdentify.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* object in the schema for reference.
1313
*/
1414
// @ts-nocheck
15-
import { SEPARATOR } from '../deps/path.ts'
15+
import { SEPARATOR, globToRegExp } from '../deps/path.ts'
1616
import { GenericSchema, Schema } from '../types/schema.ts'
1717
import { BIDSContext } from '../schema/context.ts'
1818
import { lookupModality } from '../schema/modalities.ts'
@@ -56,7 +56,7 @@ function findRuleMatches(schema, context) {
5656
export function _findRuleMatches(node, path, context) {
5757
if (
5858
('path' in node && context.file.name.endsWith(node.path)) ||
59-
('stem' in node && context.file.name.startsWith(node.stem)) ||
59+
('stem' in node && context.file.name.match(globToRegExp(node.stem + '*'))) ||
6060
('suffixes' in node && node.suffixes.includes(context.suffix))
6161
) {
6262
context.filenameRules.push(path)
@@ -74,27 +74,18 @@ export function _findRuleMatches(node, path, context) {
7474

7575
export async function datatypeFromDirectory(schema, context) {
7676
const subEntity = schema.objects.entities.subject.name
77-
const subFormat = schema.objects.formats[subEntity.format]
7877
const sesEntity = schema.objects.entities.session.name
79-
const sesFormat = schema.objects.formats[sesEntity.format]
8078
const parts = context.file.path.split(SEPARATOR)
81-
let datatypeIndex = 2
82-
if (parts[0] !== '') {
83-
// we assume paths have leading '/'
84-
}
85-
// Ignoring associated data for now
86-
const subParts = parts[1].split('-')
87-
if (!(subParts.length === 2 && subParts[0] === subEntity)) {
88-
// first directory must be subject
89-
}
90-
if (parts.length < 3) {
79+
let datatypeIndex = parts.length - 2
80+
if (datatypeIndex < 1) {
9181
return Promise.resolve()
9282
}
93-
const sesParts = parts[2].split('-')
94-
if (sesParts.length === 2 && sesParts[0] === sesEntity) {
95-
datatypeIndex = 3
96-
}
9783
const dirDatatype = parts[datatypeIndex]
84+
if (dirDatatype === 'phenotype') {
85+
// Phenotype is a pseudo-datatype for now.
86+
context.datatype = dirDatatype
87+
return Promise.resolve()
88+
}
9889
for (let key in schema.rules.modalities) {
9990
if (schema.rules.modalities[key].datatypes.includes(dirDatatype)) {
10091
context.modality = key
@@ -154,9 +145,9 @@ function entitiesExtensionsInRule(
154145
): boolean {
155146
const rule = schema[path]
156147
const fileEntities = Object.keys(context.entities)
157-
const ruleEntities = Object.keys(rule.entities).map((key) =>
148+
const ruleEntities = rule.entities ? Object.keys(rule.entities).map((key) =>
158149
lookupEntityLiteral(key, schema),
159-
)
150+
) : []
160151
const extInRule =
161152
!rule.extensions ||
162153
(rule.extensions && rule.extensions.includes(context.extension))

0 commit comments

Comments
 (0)