qsiprep.interfaces.bids module

Interfaces for handling BIDS-like neuroimaging structures

Fetch some example data:

>>> import os
>>> from niworkflows import data
>>> data_root = data.get_bids_examples(variant='BIDS-examples-1-enh-ds054')
>>> os.chdir(data_root)

Disable warnings:

>>> from nipype import logging
>>> logging.getLogger('nipype.interface').setLevel('ERROR')
class qsiprep.interfaces.bids.BIDSDataGrabber(*args, **kwargs)[source]

Bases: SimpleInterface

Collect files from a BIDS directory structure

>>> from qsiprep.interfaces import BIDSDataGrabber
>>> from qsiprep.utils.bids import collect_data
>>> bids_src = BIDSDataGrabber(anat_only=False)
>>> bids_src.inputs.subject_data = collect_data('ds114', '01')[0]
>>> bids_src.inputs.subject_id = 'ds114'
>>> res = bids_src.run()
>>> res.outputs.t1w  
['.../ds114/sub-01/ses-retest/anat/sub-01_ses-retest_T1w.nii.gz',
 '.../ds114/sub-01/ses-test/anat/sub-01_ses-test_T1w.nii.gz']
Optional Inputs:
  • subject_data (a dictionary with keys which are a string and with values which are any value)

  • subject_id (a string)

Outputs:
  • bold (a list of items which are any value) – Output functional images.

  • dwi (a list of items which are any value) – Output DWI images.

  • flair (a list of items which are any value) – Output FLAIR images.

  • fmap (a list of items which are any value) – Output fieldmaps.

  • out_dict (a dictionary with keys which are any value and with values which are any value) – Output data structure.

  • roi (a list of items which are any value) – Output ROI images.

  • sbref (a list of items which are any value) – Output sbrefs.

  • t1w (a list of items which are any value) – Output T1w images.

  • t2w (a list of items which are any value) – Output T2w images.

class qsiprep.interfaces.bids.BIDSInfo(from_file=None, resource_monitor=None, **inputs)[source]

Bases: SimpleInterface

Extract metadata from a BIDS-conforming filename

This interface uses only the basename, not the path, to determine the subject, session, task, run, acquisition or reconstruction.

Mandatory Inputs:

in_file (a pathlike object or string representing a file) – Input file, part of a BIDS tree.

Outputs:
  • acq_id (a string)

  • rec_id (a string)

  • run_id (a string)

  • session_id (a string)

  • subject_id (a string)

  • task_id (a string)

class qsiprep.interfaces.bids.DerivativesDataSink(out_path_base=None, **inputs)[source]

Bases: SimpleInterface

Saves the in_file into a BIDS-Derivatives folder provided by base_directory, given the input reference source_file.

>>> from pathlib import Path
>>> import tempfile
>>> from qsiprep.utils.bids import collect_data
>>> tmpdir = Path(tempfile.mkdtemp())
>>> tmpfile = tmpdir / 'a_temp_file.nii.gz'
>>> tmpfile.open('w').close()  # "touch" the file
>>> dsink = DerivativesDataSink(base_directory=str(tmpdir))
>>> dsink.inputs.in_file = str(tmpfile)
>>> dsink.inputs.source_file = collect_data('ds114', '01')[0]['t1w'][0]
>>> dsink.inputs.keep_dtype = True
>>> dsink.inputs.suffix = 'target-mni'
>>> res = dsink.run()
>>> res.outputs.out_file  
'.../qsiprep/sub-01/ses-retest/anat/sub-01_ses-retest_target-mni_T1w.nii.gz'
>>> bids_dir = tmpdir / 'bidsroot' / 'sub-02' / 'ses-noanat' / 'func'
>>> bids_dir.mkdir(parents=True, exist_ok=True)
>>> tricky_source = bids_dir / 'sub-02_ses-noanat_task-rest_run-01_bold.nii.gz'
>>> tricky_source.open('w').close()
>>> dsink = DerivativesDataSink(base_directory=str(tmpdir))
>>> dsink.inputs.in_file = str(tmpfile)
>>> dsink.inputs.source_file = str(tricky_source)
>>> dsink.inputs.keep_dtype = True
>>> dsink.inputs.desc = 'preproc'
>>> res = dsink.run()
>>> res.outputs.out_file  
'.../qsiprep/sub-02/ses-noanat/func/sub-02_ses-noanat_task-rest_run-01_desc-preproc_bold.nii.gz'
Mandatory Inputs:
  • in_file (a string or os.PathLike object referring to an existing directory or a list of items which are a pathlike object or string representing an existing file) – The object to be saved.

  • source_file (a pathlike object or string representing a file) – The original file or name of merged files.

Optional Inputs:
  • base_directory (a string or os.PathLike object) – Path to the base directory for storing data.

  • bundle (a string) – Label for bundle field. (Nipype default value: "")

  • compress (a boolean) – Force compression (True) or uncompression (False) of the output file (default: same as input).

  • desc (a string) – Label for description field. (Nipype default value: "")

  • extension (a string)

  • extra_values (a list of items which are a string)

  • keep_dtype (a boolean) – Keep datatype suffix. (Nipype default value: False)

  • space (a string) – Label for space field. (Nipype default value: "")

  • suffix (a string) – Suffix appended to source_file. (Nipype default value: "")

Outputs:
  • compression (a list of items which are a boolean) – Whether in_file was compressed/uncompressed or `it was copied directly.

  • out_file (a string or os.PathLike object referring to an existing directory or a list of items which are a pathlike object or string representing an existing file) – Written file path.

out_path_base = 'qsiprep'
class qsiprep.interfaces.bids.DerivativesMaybeDataSink(out_path_base=None, **inputs)[source]

Bases: DerivativesDataSink

Mandatory Inputs:

source_file (a pathlike object or string representing a file) – The original file or name of merged files.

Optional Inputs:
  • base_directory (a string or os.PathLike object) – Path to the base directory for storing data.

  • bundle (a string) – Label for bundle field. (Nipype default value: "")

  • compress (a boolean) – Force compression (True) or uncompression (False) of the output file (default: same as input).

  • desc (a string) – Label for description field. (Nipype default value: "")

  • extension (a string)

  • extra_values (a list of items which are a string)

  • in_file (a string or os.PathLike object referring to an existing directory or a list of items which are a pathlike object or string representing an existing file) – The object to be saved.

  • keep_dtype (a boolean) – Keep datatype suffix. (Nipype default value: False)

  • space (a string) – Label for space field. (Nipype default value: "")

  • suffix (a string) – Suffix appended to source_file. (Nipype default value: "")

Outputs:
  • compression (a list of items which are a boolean) – Whether in_file was compressed/uncompressed or `it was copied directly.

  • out_file (a string or os.PathLike object referring to an existing directory or a list of items which are a pathlike object or string representing an existing file) – Written file path.

exception qsiprep.interfaces.bids.FileNotFoundError[source]

Bases: OSError

class qsiprep.interfaces.bids.ReadSidecarJSON(from_file=None, resource_monitor=None, **inputs)[source]

Bases: SimpleInterface

A utility to find and read JSON sidecar files of a BIDS tree

Mandatory Inputs:

in_file (a pathlike object or string representing an existing file) – The input nifti file.

Optional Inputs:

fields (a list of items which are a string) – Get only certain fields.

Outputs:
  • acq_id (a string)

  • out_dict (a dictionary with keys which are any value and with values which are any value)

  • rec_id (a string)

  • run_id (a string)

  • session_id (a string)

  • subject_id (a string)

  • task_id (a string)

expr = re.compile('^sub-(?P<subject_id>[a-zA-Z0-9]+)(_ses-(?P<session_id>[a-zA-Z0-9]+))?(_task-(?P<task_id>[a-zA-Z0-9]+))?(_acq-(?P<acq_id>[a-zA-Z0-9]+))?(_rec-(?P<rec_id>[a-zA-Z0-9]+))?(_run-(?P<run_id>[a-zA-Z0-9]+))?)[source]
class qsiprep.interfaces.bids.ReconDerivativesDataSink(out_path_base=None, **inputs)[source]

Bases: DerivativesDataSink

Mandatory Inputs:
  • in_file (a string or os.PathLike object referring to an existing directory or a list of items which are a pathlike object or string representing an existing file) – The object to be saved.

  • source_file (a pathlike object or string representing a file) – The original file or name of merged files.

Optional Inputs:
  • atlas (a string) – Label for label field. (Nipype default value: "")

  • base_directory (a string or os.PathLike object) – Path to the base directory for storing data.

  • bundle (a string) – Label for bundle field. (Nipype default value: "")

  • bundles (a string) – Label for bundles field. (Nipype default value: "")

  • compress (a boolean) – Force compression (True) or uncompression (False) of the output file (default: same as input).

  • desc (a string) – Label for description field. (Nipype default value: "")

  • extension (a string)

  • extra_values (a list of items which are a string)

  • fit (a string) – Label for fit field. (Nipype default value: "")

  • keep_dtype (a boolean) – Keep datatype suffix. (Nipype default value: False)

  • label (a string) – Label for label field. (Nipype default value: "")

  • mdp (a string) – Label for model derived parameter field. (Nipype default value: "")

  • mfp (a string) – Label for model fit parameter field. (Nipype default value: "")

  • model (a string) – Label for model field. (Nipype default value: "")

  • qsirecon_suffix (a string) – Name appended to qsirecon- in the derivatives. (Nipype default value: "")

  • space (a string) – Label for space field. (Nipype default value: "")

  • suffix (a string) – Suffix appended to source_file. (Nipype default value: "")

Outputs:
  • compression (a list of items which are a boolean) – Whether in_file was compressed/uncompressed or `it was copied directly.

  • out_file (a string or os.PathLike object referring to an existing directory or a list of items which are a pathlike object or string representing an existing file) – Written file path.

out_path_base = 'qsirecon'
qsiprep.interfaces.bids.get_bids_params(fullpath)[source]
qsiprep.interfaces.bids.get_metadata_for_nifti(in_file)[source]

Fetch metadata for a given nifti file

qsiprep.interfaces.bids.get_recon_output_name(base_dir, source_file, derivative_file, qsirecon_suffix, output_bids_entities, use_ext=True)[source]