Skip to content

Instantly share code, notes, and snippets.

@ilkayisik
Last active May 9, 2019 13:49
Show Gist options
  • Save ilkayisik/3a229c48737198fe52e806f165552c50 to your computer and use it in GitHub Desktop.
Save ilkayisik/3a229c48737198fe52e806f165552c50 to your computer and use it in GitHub Desktop.
Map volume (.nii) files to surface (.mgh) using mrivol2surf command from freesurfer
bash_root=/Users/ilkay.isik/project_folder_temp/fc_content/MRI_data/lscp_data/derivatives
# simple version
for hemi in lh rh; do
src_file=${bash_root}/analysis/video/odata_prmtc_inMNI/level_2.gfeat/cope3.feat/thresh_zstat1.nii.gz
src_name=${src_file##*/} # take everything after the last /
out_file=${bash_root}/analysis/video/odata_prmtc_inMNI/level_2.gfeat/cope3.feat/${hemi}_${src_name%.nii*}.mgh #remove .nii.gz
echo ${src_file} ${out_file}
mri_vol2surf --src ${src_file} \
--out ${out_file} \
--trgsubject fsaverage \
--regheader fsaverage \
--hemi ${hemi} \
--fwhm 5
done
old_ext=nii.gz
new_ext=mgh
for sub in {01..26}; do # loop over subjects
subj=sub-${sub}
for map_name in cope1 cope2 cope3; do # loops over nii files
for hemi in lh rh; do
# create a directory to save the created mgh files
mkdir ${bash_root}/analysis/${subj}/task/level_2.gfeat/stats/fs
echo ${subj} ${map_name} ${hemi}
src_file=${bash_root}/analysis/${subj}/task/level_2.gfeat/stats/${map_name}.${old_ext}
out_file=${bash_root}/analysis/${subj}/task/level_2.gfeat/stats/fs/${hemi}.${map_name}.${new_ext}
echo ${src_file} ${out_file}
mri_vol2surf --src ${src_file} \
#--trgsubject fsaverage \ # only if output space is wanted to be fsaverage
--out ${out_file} \
--regheader ${subj} \
--hemi ${hemi} \
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment