Hello! I have been using pybids to work with a dataset of raw fMRI data. I am aiming to preprocess the data with a custom pipeline and create files corresponding to each raw file in a derivatives folder. I’d like to use the BIDSLayout.build_path() function to help name my files to assure I’m doing things properly BIDS-ified (Still getting the hang of the spec).
I’m having trouble with the description / desc entitiy. I’m trying to rely on the files created by fmriprep as examples. For example, in the fmriprep-generated outputs, I have a file named:
<experiment base>/derivatives_fmriprep/sub-ABCses-A/anat/sub-ABC_ses-A_desc-brain_mask.nii.gz'
This is presumably created according to the BIDS spec.
I parse this file with:
bl = bids.BIDSLayout(‘’, derivatives=‘/derivatives_fmriprep/’)
ee = bl.get(subject=‘ABC’, scope=‘derivatives’, desc=‘brain’, extension=‘.nii.gz’)[0].get_entities()
and I get the following entities out:
{'datatype': 'anat',
'desc': 'brain',
'extension': '.nii.gz',
'session': 'A',
'subject': 'ABC',
'suffix': 'mask'}
So far so good. But when I try to create a path from these entities (not because I want an identically named file, just as a test), with code:
test_path = bl.build_path(ee)
I get:
BIDSValidationError: Built path sub-ABC/ses-A/anat/sub-ABC_ses-A_desc-brain_mask.nii.gz is not a valid BIDS filename. Please make sure all provided entity values are spec-compliant.
Same story for:
test_path = bl_f.build_path(ee, scope='derivatives')
# and
test_path = bl_f.derivatives['derivatives_fmriprep'].build_path(ee)
I can work around this by just creating file strings, as pybids doesn’t seem to have a problem parsing file names in the form of my example, but I’m worried that I’m misunderstanding something fundamental about how I’m supposed to be structuring things or working with the derivatives scope.
The error comes from BIDSValidator, which doesn’t seem to like the ‘desc’ field nor the specific value for the ‘suffix’ field. It seems like the BIDS validator may be pitching a fit because it doesn’t have the right regexes loaded? I’ve dug into the code a bit, and I think there are supposed to be different regexes for derivatives and for raw files, but I haven’t yet found exactly how and where that is handled and I’m looking for some help.
Any indication what I’m doing wrong? Please and thanks!
I’m working with pybids 0.19.0