bids-specification icon indicating copy to clipboard operation
bids-specification copied to clipboard

[SCHEMA] Proposal: Add selectors to file rules

Open effigies opened this issue 10 months ago • 1 comments

We could consider putting selectors in filename rules to achieve this. Something like:

stimuli_default:
  selectors:
    - '!exists("stimuli/stimuli.tsv", "dataset")'
  datatypes:
    - stimuli
  stem:
    - '*'
  extensions:
    - '*'

audio:
  selectors:
    - exists("stimuli/stimuli.tsv", "dataset")
  suffixes:
    - audio
  extensions:
    - .wav
    - .mp3
    - .aac
    - .ogg
  datatypes:
    - stimuli
  entities:
    - stim: required
    - part: optional

...

Originally posted by @effigies in #1828

The above proposal considers the case where the contents of stimuli/ may be free-form or structured, depending on a condition. This is necessary to preserve backwards compatibility while extending BIDS principles into previously un-managed areas.

This is also the basic problem we had with derivatives, which we resolved by creating the rules.files.derivatives branch. With this proposal, we could use dataset.description.DatasetType != 'raw' (or similar) to indicate rules that are invalid in raw but permissible in derivative datasets.

cc @rwblair @nellh @tsalo @bids-standard/schema-users

effigies avatar Feb 13 '25 15:02 effigies

This seems workable. To capture non audio files when stimuli.tsv exists the first selector could be modified with:

stimuli_default:
  selectors:
    - '!exists("stimuli/stimuli.tsv", "dataset")' || suffix != "audio"
  datatypes:
    - stimuli
  stem:
    - '*'
  extensions:
    - '*'

audio:
  selectors:
    - exists("stimuli/stimuli.tsv", "dataset")
  suffixes:
    - audio
  extensions:
    - .wav
    - .mp3
    - .aac
    - .ogg
  datatypes:
    - stimuli
  entities:
    - stim: required
    - part: optional

With respect to the JS validator we could apply the selectors in filenameIdentify.ts findRuleMatches, this is where we currently filter out derivative rules from the schema for raw datasets. I believe the context will be sufficiently populated by this time to handle any variables that can be used in selectors.

We could imagine folding all path, stem and suffixes entries into the selectors, this is how the JS validator makes its initial guess at what potential rules might apply to a given filename. (then making the other entries into traditional checks?) I don't think we should do this, I'm not seeing the immediate benefit other that conceptual harmony among all rules.

rwblair avatar Feb 13 '25 17:02 rwblair