Using aparcstats2table program in Freesurfer to extract the stats data for multiple subjects

Hi all
I’m trying to extract the statical data for multiple subjects using the aparcstats2table program in freesurfer.
I used this command to extract the statical data for one subject.

aparcstats2table --subjects /fefs1/fcit/ezahamalyoubi/freesurfer/subjects/MCI_Female_Subjects/I4688/ --hemi lh --meas volume --parc=aparc --tablefile=I4688_lh_volume.txt

how can I edit this command to work for many subjects and store the statical data in one txt file?

Any clarification will help


Hi Esraa,

The --subjects argument of the command can take multiple subjects, delimited by spaces, e.g. --subject SUB01 SUB02...

As long as your Freesurfer subjects directory is pointed to your Freesurfer outputs (e.g. setenv SUBJECTS_DIR (full path to subject dir), you can just supply the subject IDs in the --subjects argument.

For example,
1, Go to your freesurfer directory: cd $SUBJECTS_DIR
2. Get all subjects: subjects=$(ls sub*) - that assumes that all subject folders begin with sub, but you can change it to work with your data.
3. Run your command, with --subjects ${subjects[@]}


Thanks for your response, Steven.
actually, I have four folders inside my subjects directory. each folder has different subjects. and I’m aiming to extract the stats data for each folder in a single excel file.

Is there a way to do that?

You can make a new folder that contains symlinks/shortcuts to the subject data in the different folders (see the ln -s command). Then set the subject directory environment variable to the folder that contains these shortcuts.

1- I created a symbolic link of CN_Male_Subjetcs

ln -s  /fefs1/fcit/ezahamalyoubi/freesurfer/subject_two/CN_Male_Subjects CN_Male_Subjects

2- I changed the SUBJECTS_DIR to subjects_two

export SUBJECTS_DIR=/fefs1/fcit/ezahamalyoubi/freesurfer/subject_two/

3- I entered subject_two and created subjects variable to get all subjects.

subjects=$(ls ADN*)

4- when I run this command I got the below error

the command

aparcstats2table --subjects ${subjects[@]} --hemi lh --meas volume --parc=aparc --parcs-from-file= --tablefile=CN_Male_volume_lh.txt

the error i got

[ezahamalyoubi@klogin2 subject_two]$ aparcstats2table --subjects ${subjects[@]} --hemi lh --meas volume --parc=aparc --parcs-from-file= --tablefile=CN_Male_volume_lh.txt
ERROR: cannot read
SUBJECTS_DIR : /fefs1/fcit/ezahamalyoubi/freesurfer/subject_two/
Parsing the .stats files

ERROR: Cannot find stats file /fefs1/fcit/ezahamalyoubi/freesurfer/subject_two/ls/stats/lh.aparc.stats

It looks like $subjects is not being defined correctly, as FreeSurfer is looking for a folder called ls.

Try this subjects=($(ls ADN* -d)), then make sure it looks right with echo ${subjects[@]}

[ezahamalyoubi@kcn061 subject_two]$ subjects=$(ls ADN*)
ls: cannot access ADN*: No such file or directory
[ezahamalyoubi@kcn061 subject_two]$ subjects=$(ls)
[ezahamalyoubi@kcn061 subject_two]$ echo ${subjects[@]}
CN_Female_Subjects_link CN_Male_Subjects MCI_Female_Subjects MCI_Male_Subjects
[ezahamalyoubi@kcn061 subject_two]$ subjects=$(ls CN_Female_Subjects_link*)
[ezahamalyoubi@kcn061 subject_two]$ echo ${subjects[@]}

(those are the links for the four folders)
how can I access the subjects inside the links? I think freesurfer could not collect them in the subjects variable

You should create a single folder that contains the links to the subjects contained in all of those four folders. So, looking at subjects in CN_Male_Subjects, for example, you should send a shortcut of each of the subject folders to your final directory where you want to have all subjects represented, and the repeat for the other 3 bigger folders. See more about the ln command here:

thanks for your help, Steven.