AFNI and BIDS

The zeitgeist for AFNI’s data layout and the zeitgeist for BIDS’ data layout aren’t well-matched. AFNI wants everything for the subject in one directory and BIDS wants each type of data in a separate directory. For example, for one subject, I currently have at least 6 relevant directories with the data:

sub-127608/ses-Session1/anat
sub-127608/ses-Session1/fmap
sub-127608/ses-Session1/func
derivatives/fmriprep/sub-127608/ses-Session1/anat
derivatives/fmriprep/sub-127608/ses-Session1/func
derivatives/bold/sub-127608/ses-Session1

My solution at the moment is to define a bash function (or use a shell-script) that uses find to help:


bsafni() {
  afni -DAFNI_SESSTRAIL=4 `find . -type d \( -wholename "*${1}*func" -o -wholename "*${1}*anat" -o -wholename "*${1}*fmap" -o -wholename "*derivatives/bold/*${1}*" \) | tr '\n' ' '`
}

so I can bsafni 127608 and then switch the session to “all datasets” (huge plus that feature!).

Are there other solutions people have out there to working with these two together?

Craig

We are working on BIDS-ification of AFNI scripts, but who knows when it will be ready?

The shadow? I’m sure the shadow knows…

Getting analysis scripts to be BIDSian is certainly a big step. The visualization / GUI aspects though are another. Certainly the “All Datasets” view is a massive help here and is really the only thing that makes it possible right now. AFNI expects a flat directory structure at the level of a subject and “All Datasets” lets you unflatten break that assumption. I guess what I’m wondering is if it’s worth putting in a BIDS-mode that, on startup would take the root BIDS directory, a subject, and a session as the startup parameters in the typical BIDS-ian fashion and then load all directories as if they were flat (instead of taking a subject directory). My function works a bit like this, leveraging off of ‘find’, but my guess is it could be done better.

Craig

Is there any update on “BIDS-ification of AFNI scripts”?

I’m adding a feature to the AFNI GUI to make it easier to collate all the datasets from a single subject into a “session”. The source code is in github now and the next binary build will have it incorporated.

As far as BIDS-ification of AFNI scripts, nothing to report on that battle front.

And “the next binary build” will be tonight.


  afni [options] [session_directory ...]

   -bysub       This new [01 Feb 2018] option allows you to have 'sessions'
                  made up from files scattered across multiple directories.
                  The purpose of this option is to gather all the datasets
                  corresponding to a single subject identifier, as is done
                  in the BIDS file hierarchy -- http://bids.neuroimaging.io/
               ** After '-bysub' you put one or more subject identifiers,
                  which are of the form 'sub-XXX' where 'XXX' is some
                  subject code (it does not have to be exactly 3 characters).
               ** If an identifier does NOT start with 'sub-', then that
                  4 letter string will be added to the front. This allows
                  you to specify your subjects by their numbers 'XXX' alone.
               ** The list of subject identifiers ends when an argument
                  on the command line starts with the '-' character.
                  That would be another option, or the '-' character
                  by itself if the next things on the command line
                  are the list of directories to scan for datasets.
               ** Each directory on the command line (after all options)
                  will be scanned recursively (down the file tree) for
                  subdirectories whose name matches the 'sub-XXX' identifier
                  exactly. All such subdirectories will have all their
                  datasets read in (recursively down the file tree) and
                  put into a single session for viewing in AFNI.
               ** Remember: if no directories are given on the command
                  line after the various options, then the current working
                  directory ('.' or 'echo $cwd') is used.
               ** If a directory on the command line does NOT have any
                  subdirectories that match any of the '-bysub' identifiers,
                  then that directory will be read in the normal way, with
                  all the datasets in that particular directory (but not
                  subdirectories) read into the session.
               ** Please note that '-bysub' sessions will NOT be rescanned
                  for new datasets that might get placed there after the
                  AFNI GUI starts, unlike normal (single directory) sessions.
               ** Example:
                    afni -bysub 10506 50073 - ~/data/OpenFMRI/ds000030
                  This will open the data for subjects 10506 and 50073 from
                  the data at the specified directory -- presumably the
                  data downloaded from https://openfmri.org/dataset/ds000030/
               ** If directory sub-10506 is found and has (say) sub-directories
                    anat beh dwi func
                  all AFNI-readable datasets from these sub-directories will
                  be input and collected into one session, to be easily
                  viewed together. In addition, if a sub-directory named
                    derivatives/sub-10506
                  is found underneath ~/data/OpenFMRI/ds000030, all the
                  datasets found underneath that will also be put into the
                  same session, so they can be viewed with the 'raw' data.
               ** In this context, 'dataset' also means .png and .jpg files
                  found in the sub-XXX directories. These images can be
                  opened in the AFNI GUI using the Axial image viewer.
                  (You might want to turn the AFNI crosshairs off!)
               ** If you do NOT want .png and .jpg files read into AFNI,
                  set UNIX environment variable AFNI_IMAGE_DATASETS to 'NO'.
               ** You can put multiple subject IDs after '-bysub', as
                  in the example above. You can also use the '-bysub' option
                  more than once, if you like. Each distinct subect ID will
                  get a distinct AFNI session.


Thanks Bob!

I must be being daft though…


stark@titan .../mridata3/Aaron_Sequence/BIDS $ ls -1
dataset_description.json
expert.opts
sourcedata
sub-121343A
sub-121615A
...


stark@titan .../mridata3/Aaron_Sequence/BIDS $ ls sub-121343A/
anat  dwi  func
stark@titan .../mridata3/Aaron_Sequence/BIDS $ ls sub-121343A/anat/
sub-121343A_T1w.json  sub-121343A_T1w.nii


afni -bysub sub-121343A - .
afni -bysub sub-121343A 
afni -bysub 121343A

All these say that no datasets are found. One clue is:

find: unknown predicate `-9’

Craig

Hmm. That looks like the ‘find’ common on your Unix isn’t compatible with the ‘find’ common on my Mac OS X. I use ‘find’ to search for subdirectories that match the subject ID, and in the ‘find’ command, use the predicate ‘-depth -9’ to limit the search to 9 levels of subdirectories (to avoid wandering through a vast cyberspace). Apparently, some versions of ‘find’ do not use this method for limiting the search depth, but use the ‘-maxdepth’ option instead. I will fix AFNI to use that and see how it goes. Stay tuned (after, it is Sunday, and I have personal things to do as well.)

Has there been any update on the -bysub option? I just updated to the latest AFNI version, and see “find: unknown predicate `-9’” when attempting this. At the (wonderful) AFNI bootcamp I heard that this issue had been fixed, but I may have misunderstood. I’m currently using AFNI in Ubuntu 16.04

Hi Bob,

Did this change ever make it to live AFNI? I just tried to use -BIDS for the first time on CentOS 7 and encountered what looks to be the same issue.


find: unknown predicate `-9'
find: warning: you have specified the -depth option after a non-option argument -type, but options are not positional (-depth affects tests specified before it as well as those specified after it).  Please specify options before other arguments.

Thank you!

Dillon