AFNI Message Board

Dear AFNI users-

We are very pleased to announce that the new AFNI Message Board framework is up! Please join us at:

https://discuss.afni.nimh.nih.gov

Existing user accounts have been migrated, so returning users can login by requesting a password reset. New users can create accounts, as well, through a standard account creation process. Please note that these setup emails might initially go to spam folders (esp. for NIH users!), so please check those locations in the beginning.

The current Message Board discussion threads have been migrated to the new framework. The current Message Board will remain visible, but read-only, for a little while.

Sincerely, AFNI HQ

History of AFNI updates  

|
February 20, 2017 11:05AM
What you need to do is called "shell scripting" or "shell programming". An introduction for scripting with the C shell (the one we AFNI-oids prefer) is here:
http://www-cs.canisius.edu/ONLINESTUFF/UNIX/shellprogramming.html

For your particular problem as posed, one solution involves creating and using shell variables, in a loop.

For example

set flist = ( `cat subject.list.txt` )
foreach sub ( $flist )
  cd $sub
  3dROIstats -1DRformat -quiet -mask maskROI.nii stats.nii > ../${sub}.ROI.1D
  cd ..
end

Here, the first shell variable set is the array "flist" which contains the contents of the file "subject.list.txt" -- one string per entry in the array. This would be a file something like this:

FTX
FGY
FZN
FLQ
et cetera

where the code name for each subject is on a separate line.
For each subject, the script above assumes there is a directory with that name, and in that directory a dataset named "maskROI.nii" and one named "stats.nii".

The "foreach" command tells the shell to execute each of the commands, up to the "end", setting the shell variable "sub" to each of the entries in "flist" in turn. The "$" character is used to substitute the value of a shell variable onto the command line. Thus "cd $sub" will change directory into FTX the first time through the loop, to FGY the second time, and so on. Then the 3dROIstats command is executed in that directory, putting its output into the top level directory with a filename incorporating the subject identifier. Then the script changes directory back up one level and continues through the foreach loop until done.

You will have to understand this, and then adapt the script to the filenames and filename system that you actually use. Doing this requires using the general concepts of programming languages: variables, arrays, loops, variable setting, and variable usage.

If you don't know anything about programming at all, in any language, you will have a hard time. In which case, try the tutorial link above, and try to find help locally -- we won't be able to teach you programming remotely.
Subject Author Posted

Creating a script to execute a command for multiple participants simultaneously

Jparso February 19, 2017 08:28PM

Re: Creating a script to execute a command for multiple participants simultaneously

Bob Cox February 20, 2017 11:05AM

Re: Creating a script to execute a command for multiple participants simultaneously

Jparso February 21, 2017 02:22PM

Re: Creating a script to execute a command for multiple participants simultaneously

rick reynolds February 23, 2017 11:11AM

Re: Creating a script to execute a command for multiple participants simultaneously

Bob Cox February 24, 2017 09:19AM

Re: Creating a script to execute a command for multiple participants simultaneously

Jparso March 01, 2017 06:20PM