Monday, March 3, 2014

Resting State Analysis, Part III: Automating Your Analysis

Once you've set up a resting-state analysis script, either through uber_subject.py or following example #9 in the afni_proc.py documentation, I highly recommend that you set up some sort of higher-level script to automate running that script in each subject's directory. This is especially useful in the dataset we are using, since each individual analysis doesn't necessarily take that long, but we have a large number of subjects.

To begin, navigate to the downloaded KKI directory and use the following command to list each directory without trailing slashes:

ls -d */ | cut -f1 -d'/' > subjList.txt

You can then redirect this output to a text file, which can then be later edited at your leisure; in the above example, I used a redirect command to place all of the directories in a file called subjList.txt.

A for loop can then be used to do the analysis for each subject. (You can use any shell you want, but in this example I will use the t-shell.) Simply use the output of the text file as a variable, then use the for loop to execute the analysis for each subject, e.g.:

setenv subject `cat subjList.txt`
foreach subj ($subject)
cp RSproc.sh $subj/session_1
cd $subj/session_1
tcsh RSproc.sh $subj
cd ../..
end

The RSproc.sh script, generated from the uber_subject.py interface used in the last tutorial, can be found here. Note that I use a motion cutoff threshold of 0.3mm, which is slightly different from the standard 0.2mm cutoff; feel free to alter this if you like.

This should take care of all of your analyses while you go do something else, such as reading a book or shopping for tupperware and nosehair trimmers.* Of course, you will want to examine the output of your commands for any errors, but this menial task can usually be designated to one of your undergraduate RAs slated for resting-state data summoning immolation.




*Or maybe that's just me.

4 comments:

  1. Hi Andy,
    the link to RSproc.sh script is broken, would you happen to have another link or example ?
    thanks so much.

    ReplyDelete
    Replies
    1. Anonymous you can download
      https://drive.google.com/file/d/1QPmTIoxMdHELClpTXQcv8bxBJcQO_Dw6/view?usp=sharing from here change it's RSproc.sh name to proc.s061 and try. It seems good.

      Delete
  2. Hi Andy,

    I have this problem too. I saved script from uber_subject.py and tried with that something happened but not the true one. Can u give us RSproc.sh and tell me about it's logic.

    Best regards.

    ReplyDelete
  3. Thank you so much, Abdullah, really appreciate your help.
    best regards

    ReplyDelete