bids.BIDSLayout.build_path() removes dir- label from dwi images

I am using bids.BIDSLayout.build_path() to build valid BIDS-paths for images that I am saving. When I try to build a path using modified entities for a DWI image, bids.BIDSLayout.build_path() discards the provided dir- label.

E.g.

import bids

layout = bids.BIDSLayout('./')

dwis = layout.get(suffix='dwi', extension=['nii', 'nii.gz'])

ent = dwis[0].entities
ent.update({'acquisition': 'new'})

print(dwis[0].filename)
# 'sub-01_ses-01_dir-AP_dwi.nii.gz'

print(layout.build_path(ent))
# 'sub-01_ses-1_acq-new_dwi.nii.gz'

Do I need to use non-default path_patterns?

You have to modify the default_path_patterns, adding this entry (or replacing the dwi entry with it):

'sub-{subject}[/ses-{session}]/dwi/sub-{subject}[_ses-{session}][_acq-{acquisition}][_dir-{direction}]_{suffix<dwi>}.{extension<bval|bvec|json|nii.gz|nii>|nii.gz}'

This looks like a bug, and perhaps we should update the default path patterns.

Can you submit an issue to the pybids repo? Issues · bids-standard/pybids · GitHub

1 Like

Thank you! Bug report has been submitted…