qsirecon.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 qsirecon.interfaces.bids.CopyAtlas(from_file=None, resource_monitor=None, **inputs)[source]

Bases: SimpleInterface

Copy atlas file to output directory.

Parameters:
  • source_file (str) – The source name of the atlas file.

  • in_file (str) – The atlas file to copy.

  • out_dir (str) – The output directory.

  • atlas (str) – The name of the atlas.

Returns:

out_file – The path to the copied atlas file.

Return type:

str

Notes

I can’t use DerivativesDataSink because it has a problem with dlabel CIFTI files. It gives the following error: “AttributeError: ‘Cifti2Header’ object has no attribute ‘set_data_dtype’”

I can’t override the CIFTI atlas’s data dtype ahead of time because setting it to int8 or int16 somehow converts all of the values in the data array to weird floats. This could be a version-specific nibabel issue.

I’ve also updated this function to handle JSON and TSV files as well.

Mandatory Inputs:
  • atlas (a string) – The atlas name.

  • in_file (a pathlike object or string representing an existing file) – The atlas file to copy.

  • out_dir (a pathlike object or string representing an existing directory) – The output directory.

Optional Inputs:
  • Sources (a list of items which are a string) – List of sources for the atlas.

  • meta_dict (a dictionary with keys which are any value and with values which are any value or None) – The atlas metadata dictionary.

  • source_file (a string) – The source file’s name.

Outputs:

out_file (a pathlike object or string representing an existing file) – The copied atlas file.

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

Bases: DerivativesDataSink

Store derivative files.

A child class of the niworkflows DerivativesDataSink, using QSIRecon’s configuration files.

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

  • source_file (a list of items which are a pathlike object or string representing a file) – The source file(s) to extract entities from.

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

  • check_hdr (a boolean) – Fix headers of NIfTI outputs. (Nipype default value: True)

  • compress (a list of items which are a boolean or None) – Whether in_file should be compressed (True), uncompressed (False) or left unmodified (None, default). (Nipype default value: [])

  • data_dtype (a string) – NumPy datatype to coerce NIfTI data to, or source to match the input file dtype.

  • dismiss_entities (a list of items which are a string or None) – A list entities that will not be propagated from the source file. (Nipype default value: [])

  • meta_dict (a dictionary with keys which are a string and with values which are any value) – An input dictionary containing metadata.

Outputs:
  • compression (a list of items which are a boolean or None) – Whether in_file should be compressed (True), uncompressed (False) or left unmodified (None).

  • fixed_hdr (a list of items which are a boolean) – Whether derivative header was fixed.

  • out_file (a list of items which are a pathlike object or string representing an existing file)

  • out_meta (a list of items which are a pathlike object or string representing an existing file)

out_path_base = ''
class qsirecon.interfaces.bids.ReconDerivativesDataSink(allowed_entities=None, 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 list of items which are a pathlike object or string representing a file) – The source file(s) to extract entities from.

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: "")

  • check_hdr (a boolean) – Fix headers of NIfTI outputs. (Nipype default value: True)

  • compress (a list of items which are a boolean or None) – Whether in_file should be compressed (True), uncompressed (False) or left unmodified (None, default). (Nipype default value: [])

  • data_dtype (a string) – NumPy datatype to coerce NIfTI data to, or source to match the input file dtype.

  • dismiss_entities (a list of items which are a string or None) – A list entities that will not be propagated from the source file. (Nipype default value: [])

  • extension (a string) – Extension (will be ignored). (Nipype default value: "")

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

  • meta_dict (a dictionary with keys which are a string and with values which are any value) – An input dictionary containing metadata.

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

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

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

Outputs:
  • compression (a list of items which are a boolean or None) – Whether in_file should be compressed (True), uncompressed (False) or left unmodified (None).

  • fixed_hdr (a list of items which are a boolean) – Whether derivative header was fixed.

  • out_file (a string) – The output file/folder.

  • out_meta (a list of items which are a pathlike object or string representing an existing file)

out_path_base = 'qsirecon'
qsirecon.interfaces.bids.get_bids_params(fullpath)[source]
qsirecon.interfaces.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.interfaces.bids.get_recon_output_name(base_dir, source_file, derivative_file, output_bids_entities, use_ext=True, qsirecon_suffix=None, dismiss_entities=None)[source]