Using mri_extract_label program in freesurfer to extract entorhinal cortex area for multiple subjects

Hi NeuroStarts,

I’m aiming to extract the entorhinal cortex area for multiple subjects using Freesurfer.
I used mri_extract_label to do that. but I’m facing a challenge to extract the area for all the subjects in one command. since I have more than 700 subjects.

this is the command that I used to extract the area from one subject.

mri_extract_label /fefs1/fcit/ezahamalyoubi/freesurfer/subjects/130146/mri/aparc.DKTatlas+aseg.mgz 1006 2006 /fefs1/fcit/ezahamalyoubi/freesurfer/subjects/130146/mri/130146LeftandRightERC.mgz

Any help?

-Esraa

Hi Esraa and welcome to NeuroStars!

Would something like a for-loop help?

for subjectfolder in /fefs1/fcit/ezahamalyoubi/freesurfer/subjects/*;
do mri_extract_label $subjectfolder/mri/aparc.DKTatlas+aseg.mgz 1006 2006 \
$subjectfolder/mri/LeftandRightERC.mgz;
done

Best,
Steven

Thanks Steven for your help.
really appreciated

After doing this process and extract the area for all the subjects. how can I collect all the extracted areas for each subject and save them in one folder?

I am not sure I can help best because I do not know which Freesurfer commands do that, but if you meant just moving the outputs from the previous command, then you can just change the last argument of the code above to put outputs somewhere more central instead of in the $subjectfolder.

Best,
Steven

sounds great.
so if I want to collect all the areas in CN_Male folder, I could edit the code this way, right?

for subjectfolder in /fefs1/fcit/ezahamalyoubi/freesurfer/subjects/*;
do mri_extract_label $subjectfolder/mri/aparc.DKTatlas+aseg.mgz 1006 2006 \
CN_Male/$subjectfolder/mri/LeftandRightERC.mgz;

No,

$subjectfolder is an absolute path (that is, fully defined, begins with /); $subjectfolder is the same as /fefs1/fcit/ezahamalyoubi/freesurfer/subjects/(ONE_OF_YOUR_SUBJECTS).

I don’t know where CN_Male is on your system, but if you do not specify the path beginning with a /, then it is a relative path, and assumes that CN_Male is a folder that exists in whereever your code terminal is running.

Best,
Steven

This is the path for CN_Male : /fefs1/fcit/ezahamalyoubi/freesurfer
How can I edit the code so each extracted area will be saved in CN_Male folder with the name of the subject?

pushd /fefs1/fcit/ezahamalyoubi/freesurfer/subjects/;
for subject in *;
do mri_extract_label $subject/mri/aparc.DKTatlas+aseg.mgz 1006 2006 \
 /fefs1/fcit/ezahamalyoubi/freesurfer/CN_Male/${subject}_LeftandRightERC.mgz;
done
popd
1 Like

All clear now,
Thanks so much Steven for the time and effort