qsirecon.utils.bids module

exception qsirecon.utils.bids.BIDSError(message, bids_root)[source]

Bases: ValueError

exception qsirecon.utils.bids.BIDSWarning[source]

Bases: RuntimeWarning

qsirecon.utils.bids.clean_datasinks(workflow: Workflow, qsirecon_suffix: str | None) Workflow[source]

Overwrite the base_directory of Datasinks.

qsirecon.utils.bids.collect_anatomical_data(*, layout, subject_id, session_id, needs_t1w_transform, infant_mode=False, bids_filters=None)[source]

Gather any high-res anatomical data (images, transforms, segmentations) to use in recon workflows.

This function searches through input data to see what anatomical data is available. The anatomical data may be in a freesurfer directory.

Parameters:
  • layout (bids.layout.BIDSLayout) – BIDSLayout object

  • subject_id (str) – Single subject label

  • needs_t1w_transform (bool) – Whether a T1w transform is needed

  • bids_filters (dict, optional) – BIDS query filters

  • infant_mode (bool, optional) – Whether the subject is an infant

Returns:

  • anat_data (dict) – Dictionary of anatomical data

  • status (dict) – Dictionary of status flags

Notes

We’ll probably want to allow/collect multiple output space transforms in the future.

qsirecon.utils.bids.collect_participants(bids_dir, participant_label=None, strict=False, bids_validate=True)[source]

List the participants under the BIDS root and checks that participants designated with the participant_label argument exist in that folder.

Returns the list of participants to be finally processed.

Requesting all subjects in a BIDS directory root:

>>> collect_participants('ds114')
['01', '02', '03', '04', '05', '06', '07', '08', '09', '10']

Requesting two subjects, given their IDs:

>>> collect_participants('ds114', participant_label=['02', '04'])
['02', '04']

Requesting two subjects, given their IDs (works with ‘sub-’ prefixes):

>>> collect_participants('ds114', participant_label=['sub-02', 'sub-04'])
['02', '04']

Requesting two subjects, but one does not exist:

>>> collect_participants('ds114', participant_label=['02', '14'])
['02']
>>> collect_participants('ds114', participant_label=['02', '14'],
...                      strict=True)  
Traceback (most recent call last):
qsirecon.utils.bids.BIDSError:
...
qsirecon.utils.bids.get_entity(filename, entity)[source]

Extract a given entity from a BIDS filename via string manipulation.

Parameters:
  • filename (str) – Path to the BIDS file.

  • entity (str) – The entity to extract from the filename.

Returns:

entity_value – The BOLD file’s entity value associated with the requested entity.

Return type:

str or None

qsirecon.utils.bids.get_iterable_dwis_and_anats(layout)[source]

Look through the BIDS Layout for DWIs and their corresponding anats.

Returns:

dwis_and_anats – List of two-element tuples where the first element is a DWI scan and the second is the corresponding anatomical scan.

Return type:

list of tuple

qsirecon.utils.bids.validate_input_dir(exec_env, bids_dir, participant_label)[source]
qsirecon.utils.bids.write_atlas_dataset_description(atlas_dir)[source]

Write dataset_description.json file for Atlas derivatives.

Parameters:

atlas_dir (str) – Path to the output QSIRecon Atlases dataset.

qsirecon.utils.bids.write_bidsignore(deriv_dir)[source]
qsirecon.utils.bids.write_derivative_description(bids_dir, deriv_dir, dataset_links=None)[source]

Write dataset_description.json file for derivatives.

Parameters:
  • bids_dir (str) – Path to the BIDS derivative dataset being processed.

  • deriv_dir (str) – Path to the output QSIRecon dataset.

  • dataset_links (dict, optional) – Dictionary of dataset links to include in the dataset description.