Description
I'm not sure how feasible this is, given how little I know about SQL, but it seems like file collections should be gathered by get_associations
.
For example, I tested on a single-subject multi-echo dataset (https://openneuro.org/datasets/ds002156):
from bids.layout import BIDSLayout, BIDSLayoutIndexer
dset_dir = "/path/to/ds002156"
indexer = BIDSLayoutIndexer(validate=False, index_metadata=True, ignore=["derivatives/"])
layout = BIDSLayout(dset_dir, derivatives=False, indexer=indexer)
me_files = layout.get(suffix="bold", extension="nii.gz")
me_file = me_files[0]
me_file.get_associations()
What I get is:
[<BIDSImageFile filename='/path/to/ds002156/sub-23638/ses-01/fmap/sub-23638_ses-01_acq-rest_dir-match_run-1_epi.nii.gz'>,
<BIDSImageFile filename='/path/to/ds002156/sub-23638/ses-01/fmap/sub-23638_ses-01_acq-rest_dir-opp_run-1_epi.nii.gz'>,
<BIDSJSONFile filename='/path/to/ds002156/sub-23638/ses-01/func/sub-23638_ses-01_task-rest_run-1_echo-1_bold.json'>,
<BIDSDataFile filename='/path/to/ds002156/sub-23638/ses-01/func/sub-23638_ses-01_task-rest_run-1_physio.tsv.gz'>]
I would expect to see the other three echoes from that run in the list of associated files.
I know that the definition of a file collection can be a little ambiguous in BIDS. Most file collections share a suffix and vary along specific entities (e.g., echo, flip, inv, mt, and part), though some will have different suffixes (e.g., phase-difference field maps, which typically have a _phasediff
map, a _magnitude1
map, and a _magnitude2
map). PyBIDS might need specific rules for the latter case.