# Neuroimaging Data Processing/Processing/Tools/AFNI
## Structure

AFNI is a command line based tool, i.e. all the processing steps are defined in a script, using commands and methods built-in to afni, which is then run on the data. You can but don't have to put up your scripts from scratch, afni_proc.py and uber-subject.py (see below) are helpful tools to help you putting together your processing script. Afni does have a graphical viewer for images and graphs. Once you have installed AFNI (check tutorial below or) and entered AFNI environment by typing AFNI, you can call this GUI by typing
to you terminal. It will try to find and open Afni or Nifti format datasets in your current folder and otherwise open on a default anatomical image. The tutorial mentioned below gives a good introduction to how you can use the viewer to inspect you data before, during and after processing.

#### What is afni_proc.py?

a command line program used to generate processing scripts (proc. scripts) for single subject analysis. Generated scripts are in tcsh syntax and written to be easily read and modified. Learn about the syntax you need here, where you find a full list of all the possible building blocks and options along with very helpful example scripts. You get the same output when typing (in AFNI environment):
In the AFNI part of the implementation in each subsection of this wikibook there is some very basic information on respective proc.py commands you need for each step. Also the tutorial mentioned below is a good introduction to proc.py. One thing I find helpful to know is how to includ non-default processing blocks in proc.py (if you read the help on proc.py it will become clearer what that means): you can include single blocks in their default position by
followed by the name of the block. If you want to include the processing blocks in a specific order use
followed by the blocks in their respective order.

#### What is uber_subject.py?

a graphical user interface to afni_proc.py, for creating processing scripts and running the analysis. When starting with AFNI it might be easiest to create scripts using uber_subject and then explore the generated scripts and modulate them if you wish. However this tool is still rather new and might not be fully developed.
The uber_subject GUI is quite self-explanatory. You can find some help here or just open and explore it using this command (given AFNI is installed and AFNI environment is active)

## Data formats

AFNI can handle nifti files (nii and nii.gz). However, the native data format is .HEAD and .BRIK files (see Afni) and when using nifti files it seems there can be problems with the header information. To import dicom data into head/brik use the to3d command.
For example for functional data with TR 2300 ms, 257 volumes, 37 slices acquired in z direction and then in time (zt), in interleaved order (alt+z):
INPUTFILES should be all dicoms, i.e. using a wildcard like data/func/run001/*.dcm and for anatomical
Make sure in both cases that INPUTFILES refers to all dicoms, i.e. using a wildcard like path_to_data/*.dcm

## Oblique data in AFNI

If you data was acquired oblique this information will be stored in the dicom header. Afni recognizes this and will complain. You should apply 3dWarp to the oblique data (to both anatomical AND functional in case both are oblique). See also
Otherwise, probably due to different mosaic centers, your coregistration may end up looking something like this:

## Documentation, tutorials, links

Documentation on the single commands http://afni.nimh.nih.gov/pub/dist/doc/program_help//index.html
A tutorial with sample data is provided here: http://afni.nimh.nih.gov/pub/dist/edu/data/CD.expanded/AFNI_data6/FT_analysis/tutorial/
The same tutorial, each step documented in a video: http://andysbrainblog.blogspot.de/2013/08/afni-start-to-finish-playlist.html
This is a really helpful "what you need to know when you are absolutely new to AFNI": http://afni.nimh.nih.gov/pub/dist/doc/program_help/README.afnigui.html
And a ppt presentation which you might also find helpful as a start: http://ngp.usc.edu/files/2013/06/Gimbel_AFNI.pdf

## References

* ↑ http://afni.nimh.nih.gov/pub/dist/HOWTO/howto/ht00_inst/html/
* ↑ http://afni.nimh.nih.gov/pub/dist/doc/program_help/afni_proc.py.html
* ↑ http://afni.nimh.nih.gov/pub/dist/doc/program_help/uber_subject.py.html
* ↑ http://afni.nimh.nih.gov/pub/dist/doc/program_help/to3d.html
* ↑ http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dWarp.htm
* ↑ http://afni.nimh.nih.gov/sscc/dglen/Obliquity