This script will generate text/ascii tables of freesurfer aseg stats data, aseg.stats. This can then be easily imported into a spreadsheet and/or stats program.


Converts a subcortical stats file created by recon-all and/or mri_segstats (eg, aseg.stats) into a table in which each line is a subject and each column is a segmentation ( there is an option to transpose that). The values are the volume of the segmentation in mm3 or the mean intensity over the structure. The first row is a list of the segmentation names. The first column is the subject name. If the measure is volume, then the estimated intracranial volume (eTIV) is printed as the 2nd to last column (if present in the input), and BrainSegVol is the last column.

The subjects list can be specified in one of four ways:

  1. Specify each subject after -s
    • -s subject1 -s subject2 ..
  2. specify all subjects after --subjects.
    • --subjects does not have to be the last argument. Eg:
      • --subjects subject1 subject2 ...
  3. Specify each input file after -i
    • -i subject1/stats/aseg.stats -i subject2/stat/aseg.stats ..
  4. Specify all the input stat files after --inputs. --inputs does not have
    • to be the last argument. Eg:
      • --inputs subject1/stats/aseg.stats subject2/stats/aseg.stats ...

The first two methods assume the freesurfer directory structure. The last two are general and can be used with any file produced by mri_segstats regardless of whether it was created with recon-all or not, however, the subject name is not printed in the file (just the row number). Note that the first two and last two are mutually exclusive. i.e don't specify --subjects when you are providing --inputs and vice versa.

By default, the volume (mm3) of each segmentation is reported. This can be changed with '--meas measure', where measure can be volume or mean. If mean, it reports the mean intensity value from the 6th column.

By default, all segmentations found in the input stats file are reported. This can be changed by specifying the maximum segmentation number with --maxsegno. This can be convenient for removing segmentations that are always empty.

With methods 1 and 2 above uses stats/aseg.stats by default. This can be changed to subdir/statsfile with `--subdir subdir --stats statsfile`.

The --segno option outputs only the segmentations requested. This is useful because if the number of segmentations is large, the table becomes huge.

The --no-segno options doesn't output the segmentations. This can be convenient for removing segs that are always empty.

The --transpose flag writes the transpose of the table. This might be a useful way to see the table when the number of subjects is relatively less than the number of segmentations.

The --delimiter option controls what character comes between the measures in the table. Valid options are tab (default), comma, space and semicolon.

The --skip option skips if it can't find a .stats file. Default behavior is exit the program.

The '-qdec and -qdec-long' flags can pass a qdec table for subject selection

Sample Command line

asegstats2table --subjects bert ernie fred margaret --meas volume --tablefile aseg_stats.txt

This will combine the aseg.stats file for the subjects bert, ernie, fred, and margaret to generate one table, aseg_stats.txt, that will report the volumes of all the structures labeled in aseg.mgz. The resulting file can be imported into any spreadsheet program.

asegstats2table (last edited 2012-12-03 11:36:04 by MaritzaEbling)