From 722ecadb1a03ceeb27145fbfb120f2d1ecf72849 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Thu, 25 Apr 2024 16:59:50 -0400 Subject: [PATCH 1/3] Enable stems to be globs --- bids-validator/src/deps/path.ts | 3 +++ bids-validator/src/validators/filenameIdentify.ts | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bids-validator/src/deps/path.ts b/bids-validator/src/deps/path.ts index a19d88058..de21eb5e6 100644 --- a/bids-validator/src/deps/path.ts +++ b/bids-validator/src/deps/path.ts @@ -9,3 +9,6 @@ export { parse, SEPARATOR, } from 'https://deno.land/std@0.217.0/path/mod.ts' +export { + globToRegExp, +} from 'https://deno.land/std@0.217.0/path/glob_to_regexp.ts' diff --git a/bids-validator/src/validators/filenameIdentify.ts b/bids-validator/src/validators/filenameIdentify.ts index 5cfbdc6cc..c3a0ac060 100644 --- a/bids-validator/src/validators/filenameIdentify.ts +++ b/bids-validator/src/validators/filenameIdentify.ts @@ -12,7 +12,7 @@ * object in the schema for reference. */ // @ts-nocheck -import { SEPARATOR } from '../deps/path.ts' +import { SEPARATOR, globToRegExp } from '../deps/path.ts' import { GenericSchema, Schema } from '../types/schema.ts' import { BIDSContext } from '../schema/context.ts' import { lookupModality } from '../schema/modalities.ts' @@ -56,7 +56,7 @@ function findRuleMatches(schema, context) { export function _findRuleMatches(node, path, context) { if ( ('path' in node && context.file.name.endsWith(node.path)) || - ('stem' in node && context.file.name.startsWith(node.stem)) || + ('stem' in node && context.file.name.match(globToRegExp(node.stem + '*'))) || ('suffixes' in node && node.suffixes.includes(context.suffix)) ) { context.filenameRules.push(path) From 2e84f817fa89aba6c951e9296cdd862f85ccbf4a Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Thu, 25 Apr 2024 21:11:40 -0400 Subject: [PATCH 2/3] feat: Accept phenotype as a pseudo-datatype --- .../src/validators/filenameIdentify.ts | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/bids-validator/src/validators/filenameIdentify.ts b/bids-validator/src/validators/filenameIdentify.ts index c3a0ac060..e19754205 100644 --- a/bids-validator/src/validators/filenameIdentify.ts +++ b/bids-validator/src/validators/filenameIdentify.ts @@ -74,27 +74,18 @@ export function _findRuleMatches(node, path, context) { export async function datatypeFromDirectory(schema, context) { const subEntity = schema.objects.entities.subject.name - const subFormat = schema.objects.formats[subEntity.format] const sesEntity = schema.objects.entities.session.name - const sesFormat = schema.objects.formats[sesEntity.format] const parts = context.file.path.split(SEPARATOR) - let datatypeIndex = 2 - if (parts[0] !== '') { - // we assume paths have leading '/' - } - // Ignoring associated data for now - const subParts = parts[1].split('-') - if (!(subParts.length === 2 && subParts[0] === subEntity)) { - // first directory must be subject - } - if (parts.length < 3) { + let datatypeIndex = parts.length - 2 + if (datatypeIndex < 1) { return Promise.resolve() } - const sesParts = parts[2].split('-') - if (sesParts.length === 2 && sesParts[0] === sesEntity) { - datatypeIndex = 3 - } const dirDatatype = parts[datatypeIndex] + if (dirDatatype === 'phenotype') { + // Phenotype is a pseudo-datatype for now. + context.datatype = dirDatatype + return Promise.resolve() + } for (let key in schema.rules.modalities) { if (schema.rules.modalities[key].datatypes.includes(dirDatatype)) { context.modality = key From 9822199eecfb85cd9751d9cfa373a6e14c524752 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Thu, 25 Apr 2024 21:46:50 -0400 Subject: [PATCH 3/3] fix: Check if rule.entities exists before accessing keys --- bids-validator/src/validators/filenameIdentify.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bids-validator/src/validators/filenameIdentify.ts b/bids-validator/src/validators/filenameIdentify.ts index e19754205..0816cf638 100644 --- a/bids-validator/src/validators/filenameIdentify.ts +++ b/bids-validator/src/validators/filenameIdentify.ts @@ -145,9 +145,9 @@ function entitiesExtensionsInRule( ): boolean { const rule = schema[path] const fileEntities = Object.keys(context.entities) - const ruleEntities = Object.keys(rule.entities).map((key) => + const ruleEntities = rule.entities ? Object.keys(rule.entities).map((key) => lookupEntityLiteral(key, schema), - ) + ) : [] const extInRule = !rule.extensions || (rule.extensions && rule.extensions.includes(context.extension))