Skip to content

Add command line interface

Support the following features:

  • getting individual filenames
  • iterating over placeholders (e.g., subjects). Potentially, support globbing to determine subject values.

Examples

Given a file-tree

sub-{subject}
  T1w.nii.gz
  T1w_bet.nii.gz

I want the following to work:

for FT_subject in A B ; do
  bet $(. file-tree get T1w) $(. file-tree get T1w_bet)
done

This should in effect call:

bet ./sub-A/T1w.nii.gz ./sub-A/T1w_bet.nii.gz
bet ./sub-B/T1w.nii.gz ./sub-B/T1w_bet.nii.gz

We should also support iteration.

call_bet() {
  bet $(. file-tree get T1w) $(. file-tree get T1w_bet)
}

. file-tree iter T1w call_bet --glob

This will call bet for any sub-*/T1w.nii.gz file.

Implementation

This will require file-tree to be a shell script, which is sourced from the pipeline script. It will internally call a python script called file-tree-helper, which will actually read and interpret the file-tree.

Getter

Implementation for file-tree get

ENVSTRING=$(file-tree-helper ENVSTRING)
echo $(eval $ENVSTRING file-tree-helper get $@)
  1. file-tree-helper ENVSTRING will return a string like: "FT_subject=$FT_subject FT_session=$FT_session" for a file-tree containing 2 placeholders (subject and session).
  2. file-tree-helper get will return the full filename using the environmental variables $FT_subject and $FT_session.

Iter

Implementation for file-tree iter:

for SETENV in $(file-tree-helper SETENV $1); do
  eval $SETENV $2
done

file-tree-helper SETENV <template> will return a string like: "FT_subject=A FT_session=01" presuming that the <template> depends on subject and session.

Edited by Michiel Cottaar