FileDictionary

class FileDictionary(collection_name, file_list, key_indices=(0, 2), separator='_')[source]

A file dictionary keyed by entity pair indices.

Notes

  • The entities are identified as 0, 1, … depending on order in the base filename.

  • The entity key-value pairs are assumed separated by ‘_’ unless a separator is provided.

Methods

FileDictionary.__init__(collection_name, ...)

Create a dictionary with full paths as values.

FileDictionary.create_file_dict(file_list, ...)

Create new dict based on key indices.

FileDictionary.get_file_path(key)

Return file path corresponding to key.

FileDictionary.iter_files()

Iterator over the files in this dictionary.

FileDictionary.key_diffs(other_dict)

Return symmetric key difference with another dict.

FileDictionary.make_file_dict(file_list[, ...])

Return a dictionary of files using entity keys.

FileDictionary.make_key(key_string[, ...])

Create a key from specified entities.

FileDictionary.output_files([title, logger])

Return a string with the output of the list.

Attributes

FileDictionary.file_dict

Dictionary of path values in this dictionary.

FileDictionary.file_list

List of path values in this dictionary.

FileDictionary.key_list

Keys in this dictionary.

FileDictionary.name

Name of this dictionary.

FileDictionary.__init__(collection_name, file_list, key_indices=(0, 2), separator='_')[source]

Create a dictionary with full paths as values.

Parameters:
  • collection_name (str) – Name of the file collection for reference.

  • file_list (list, None) – List containing full paths of files of interest.

  • key_indices (tuple, None) – List of order of key-value pieces to assemble for the key.

  • separator (str) – Character used to separate pieces of key name.

Notes

  • This dictionary is used for cross listing BIDS style files for different studies.

Examples

If key_indices is (0, 2), the key generated for /tmp/sub-001_task-FaceCheck_run-01_events.tsv is sub_001_run-01.

FileDictionary.create_file_dict(file_list, key_indices, separator)[source]

Create new dict based on key indices.

Parameters:
  • file_list (list) – Paths of the files to include.

  • key_indices (tuple) – A tuple of integers representing order of entities for key.

  • separator (str) – The separator used between entities to form the key.

FileDictionary.get_file_path(key)[source]

Return file path corresponding to key.

Parameters:

key (str) – Key used to retrieve the file path.

Returns:

File path.

Return type:

str

FileDictionary.iter_files()[source]

Iterator over the files in this dictionary.

Yields:

- str – Key into the dictionary. - file: File path.

FileDictionary.key_diffs(other_dict)[source]

Return symmetric key difference with another dict.

Parameters:

other_dict (FileDictionary) –

Returns:

The symmetric difference of the keys in this dictionary and the other one.

Return type:

list

static FileDictionary.make_file_dict(file_list, key_indices=(0, 2), separator='_')[source]

Return a dictionary of files using entity keys.

Parameters:
  • file_list (list) – Paths to files to use.

  • key_indices (tuple) – Positions of entities to use for key.

  • separator (str) – Separator character used to construct key.

Returns:

Key is based on key indices and value is a full path.

Return type:

dict

static FileDictionary.make_key(key_string, indices=(0, 2), separator='_')[source]

Create a key from specified entities.

Parameters:
  • key_string (str) – The string from which to extract the key (usually a filename or path).

  • indices (tuple) – Positions of entity pairs to use as key.

  • separator (str) – Separator between entity pairs in the created key.

Returns:

The created key.

Return type:

str

FileDictionary.output_files(title=None, logger=None)[source]

Return a string with the output of the list.

Parameters:
  • title (None, str) – Optional title.

  • logger (HedLogger) – Optional HED logger for recording.

Returns:

The dictionary in string form.

Return type:

str

Notes

  • The logger is updated if available.

FileDictionary.file_dict

Dictionary of path values in this dictionary.

FileDictionary.file_list

List of path values in this dictionary.

FileDictionary.key_list

Keys in this dictionary.

FileDictionary.name

Name of this dictionary.