{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# MRI pRF processing\n",
"Perform these steps after recombining the partial result-volumes that are returned by the cluster.
\n",
"Either use:
\n",
"`../Analysis_code/PostFit/matlab/ck_Combine_MRI_SliceChunks_cv.m`,
\n",
"or use a batch operation with:
\n",
"`../Analysis_code/PostFit/matlab/ck_BATCH_Combine_MRI_SliceChunks.m`.
\n",
"\n",
"If you have done that, there should be folders:
\n",
"`../FitResults/MRI///`
\n",
"with sets of results volumes:
\n",
"`../FitResults/MRI///Sess-.nii.gz` \n",
"\n",
"This notebook requires `fsl` to be installed."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Configure path and inclusion criteria"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"FitRes=../../../FitResults\n",
"ManMask=../../../Preprocessed_data/manual-masks\n",
"\n",
"# declare some arrays to cycle over \n",
"declare -a Monkeys=('M01' 'M02')\n",
"declare -a Models=(\\\n",
" 'csshrf_cv1_dhrf'\n",
" 'csshrf_cv1_mhrf'\n",
" 'doghrf_cv1_dhrf'\n",
" 'doghrf_cv1_mhrf'\n",
" 'linhrf_cv1_dhrf'\n",
" 'linhrf_cv1_mhrf'\n",
" 'linhrf_cv1_dhrf_neggain'\n",
" 'linhrf_cv1_mhrf_neggain')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Define a function to process"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"function MaskResults() {\n",
" MONKEY=$1\n",
" sess=$2\n",
" RTH=$3\n",
" FitRes=$4\n",
" ManMask=$5\n",
" \n",
" wp=$FitRes/MRI/$MONKEY/$sess\n",
" \n",
" brainmask=$ManMask/sub-${MONKEY}/func/sub-${MONKEY}_ref_func_mask_res-1x1x1.nii.gz\n",
" echo \"Masking results for\" $MONKEY $sess \"at mean xval R2 value of\" $RTH\n",
"\n",
" # Create the appropriate masks\n",
" fslmaths ${brainmask} -bin $wp/brainmask.nii.gz\n",
" fslmaths $wp/brainmask.nii.gz -sub 1 -mul -1 $wp/nonbrainmask.nii.gz\n",
" fslmaths $wp/nonbrainmask.nii.gz -mul -99 $wp/nanreplacement.nii.gz\n",
"\n",
" if [ ! -d \"$wp/org\" ]; then\n",
" mkdir -p $wp/org\n",
" cp $wp/Sess-*.nii.gz $wp/org/\n",
" else\n",
" cp $wp/org/Sess-*.nii.gz $wp/\n",
" fi\n",
" \n",
" # create average/max/min R2 values\n",
" fslmaths $wp/'Sess-'$sess'_R2_1.nii.gz' -nan $wp/'Sess-'$sess'_R2_1.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_R2_2.nii.gz' -nan $wp/'Sess-'$sess'_R2_2.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_R2_1.nii.gz' -min $wp/'Sess-'$sess'_R2_2.nii.gz' $wp/'Sess-'$sess'_minR2.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_R2_1.nii.gz' -max $wp/'Sess-'$sess'_R2_2.nii.gz' $wp/'Sess-'$sess'_maxR2.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_R2_1.nii.gz' -add $wp/'Sess-'$sess'_R2_2.nii.gz' -div 2 $wp/'Sess-'$sess'_meanR2.nii.gz'\n",
"\n",
" # create a mask volume based on mean R2\n",
" fslmaths $wp/'Sess-'$sess'_meanR2.nii.gz' -thr $RTH -bin $wp/'mask_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'mask_th'$RTH'.nii.gz' -sub 1 -mul -1 $wp/'invmask_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'mask_th'$RTH'.nii.gz' -sub 1 -mul 99 $wp/'negvalmask_th'$RTH'.nii.gz'\n",
"\n",
" # mask results\n",
" for part in 1 2; do\n",
" # echo 'Part ' ${part}\n",
" fslmaths $wp/'Sess-'$sess'_ang_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'ANG_'${part}'_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_ecc_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -div 10 -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'ECC_'${part}'_th'$RTH'.nii.gz'\n",
"\n",
" if [ ${sess:0:3} = css ]; then\n",
" fslmaths $wp/'Sess-'$sess'_expt_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'EXPT_'${part}'_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_exptsq_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'EXPTSQ_'${part}'_th'$RTH'.nii.gz'\n",
" fi\n",
"\n",
" fslmaths $wp/'Sess-'$sess'_imag_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'IMAG_'${part}'_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_real_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'REAL_'${part}'_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_FWHM_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -div 10 -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'FWHM_'${part}'_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_rfsize_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -div 10 -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'RFS_'${part}'_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_gain_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'GAIN_'${part}'_th'$RTH'.nii.gz'\n",
"\n",
" if [ ${sess:0:3} = dog ]; then\n",
" fslmaths $wp/'Sess-'$sess'_normamp_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'NAMP_'${part}'_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_sd2_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -div 10 -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'IRFS_'${part}'_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_sdratio_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'SDRATIO_'${part}'_th'$RTH'.nii.gz'\n",
" fi\n",
"\n",
" # ======\n",
"\n",
" fslmaths $wp/'Sess-'$sess'_ang_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz $wp/'Sess-'$sess'_ang_'${part}'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_ecc_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz $wp/'Sess-'$sess'_ecc_'${part}'.nii.gz'\n",
"\n",
" if [ ${sess:0:3} = css ]; then\n",
" fslmaths $wp/'Sess-'$sess'_expt_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_expt_'${part}'.nii.gz' \n",
" fslmaths $wp/'Sess-'$sess'_exptsq_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_exptsq_'${part}'.nii.gz' \n",
" fi\n",
"\n",
" fslmaths $wp/'Sess-'$sess'_imag_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_imag_'${part}'.nii.gz' \n",
" fslmaths $wp/'Sess-'$sess'_real_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_real_'${part}'.nii.gz' \n",
" fslmaths $wp/'Sess-'$sess'_FWHM_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_FWHM_'${part}'.nii.gz' \n",
" fslmaths $wp/'Sess-'$sess'_rfsize_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_rfsize_'${part}'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_gain_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_gain_'${part}'.nii.gz'\n",
"\n",
" if [ ${sess:0:3} = dog ]; then\n",
" fslmaths $wp/'Sess-'$sess'_normamp_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_normamp_'${part}'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_sd2_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_sd2_'${part}'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_sdratio_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_sdratio_'${part}'.nii.gz'\n",
" fi\n",
"\n",
" mkdir -p $wp/TH_$RTH\n",
" mv $wp/'ANG_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'ECC_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
"\n",
" if [ ${sess:0:3} = css ]; then\n",
" mv $wp/'EXPT_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'EXPTSQ_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" fi\n",
"\n",
" mv $wp/'IMAG_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'REAL_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'FWHM_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'RFS_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'GAIN_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
"\n",
" if [ ${sess:0:3} = dog ]; then\n",
" mv $wp/'NAMP_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'IRFS_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'SDRATIO_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" fi \n",
" done\n",
" mv $wp/'mask_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'invmask_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'negvalmask_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/nanreplacement.nii.gz $wp/TH_$RTH/\n",
"\n",
" wpth=$wp/TH_$RTH\n",
" \n",
" fslmaths $wpth/'FWHM_1_th'$RTH'.nii.gz' -add $wpth/'FWHM_2_th'$RTH'.nii.gz' -div 2 $wpth/'FWHM_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'RFS_1_th'$RTH'.nii.gz' -add $wpth/'RFS_2_th'$RTH'.nii.gz' -div 2 $wpth/'RFS_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'GAIN_1_th'$RTH'.nii.gz' -add $wpth/'GAIN_2_th'$RTH'.nii.gz' -div 2 $wpth/'GAIN_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'REAL_1_th'$RTH'.nii.gz' -add $wpth/'REAL_2_th'$RTH'.nii.gz' -div 2 $wpth/'REAL_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'IMAG_1_th'$RTH'.nii.gz' -add $wpth/'IMAG_2_th'$RTH'.nii.gz' -div 2 $wpth/'IMAG_th'$RTH'.nii.gz'\n",
" \n",
" if [ ${sess:0:3} = css ]; then\n",
" fslmaths $wpth/'EXPT_1_th'$RTH'.nii.gz' -add $wpth/'EXPT_2_th'$RTH'.nii.gz' -div 2 $wpth/'EXPT_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'EXPTSQ_1_th'$RTH'.nii.gz' -add $wpth/'EXPTSQ_2_th'$RTH'.nii.gz' -div 2 $wpth/'EXPTSQ_th'$RTH'.nii.gz'\n",
" fi\n",
" if [ ${sess:0:3} = dog ]; then\n",
" fslmaths $wpth/'NAMP_1_th'$RTH'.nii.gz' -add $wpth/'NAMP_2_th'$RTH'.nii.gz' -div 2 $wpth/'NAMP_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'IRFS_1_th'$RTH'.nii.gz' -add $wpth/'IRFS_2_th'$RTH'.nii.gz' -div 2 $wpth/'IRFS_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'SDRATIO_1_th'$RTH'.nii.gz' -add $wpth/'SDRATIO_2_th'$RTH'.nii.gz' -div 2 $wpth/'SDRATIO_th'$RTH'.nii.gz'\n",
" fi\n",
"\n",
" for xv in 1 2; do\n",
" fslmaths $wpth/'ANG_'${xv}'_th'$RTH'.nii.gz' -mul 0.0174533 -cos -mul \\\n",
" $wpth/'ECC_'${xv}'_th'$RTH'.nii.gz' $wpth/'X_'${xv}'_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'ANG_'${xv}'_th'$RTH'.nii.gz' -mul 0.0174533 -sin -mul \\\n",
" $wpth/'ECC_'${xv}'_th'$RTH'.nii.gz' $wpth/'Y_'${xv}'_th'$RTH'.nii.gz'\n",
" done\n",
"\n",
" fslmaths $wpth/'X_1_th'$RTH'.nii.gz' -add $wpth/'X_2_th'$RTH'.nii.gz' -div 2 -mas \\\n",
" $wpth/'mask_th'$RTH'.nii.gz' -add $wpth/'negvalmask_th'$RTH'.nii.gz' $wpth/'X_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'Y_1_th'$RTH'.nii.gz' -add $wpth/'Y_2_th'$RTH'.nii.gz' -div 2 -mas \\\n",
" $wpth/'mask_th'$RTH'.nii.gz' -add $wpth/'negvalmask_th'$RTH'.nii.gz' $wpth/'Y_th'$RTH'.nii.gz'\n",
"\n",
" fslmaths $wpth/'X_th'$RTH'.nii.gz' -sqr $wpth/'X2_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'Y_th'$RTH'.nii.gz' -sqr $wpth/'Y2_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'X2_th'$RTH'.nii.gz' -add $wpth/'Y2_th'$RTH'.nii.gz' -sqrt -mas $wpth/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wpth/'negvalmask_th'$RTH'.nii.gz' $wpth/'ECC_th'$RTH'.nii.gz'\n",
"\n",
" # calculate angle polar to cartesian\n",
" fslmaths $wpth/'X_th'$RTH'.nii.gz' -binv -mas $wpth/'mask_th'$RTH'.nii.gz' $wpth/'negX.nii.gz'\n",
" fslmaths $wpth/'Y_th'$RTH'.nii.gz' -binv -mas $wpth/'mask_th'$RTH'.nii.gz' $wpth/'negY.nii.gz'\n",
" fslmaths $wpth/'X_th'$RTH'.nii.gz' -bin -mas $wpth/'mask_th'$RTH'.nii.gz' $wpth/'posX.nii.gz'\n",
" fslmaths $wpth/'Y_th'$RTH'.nii.gz' -bin -mas $wpth/'mask_th'$RTH'.nii.gz' $wpth/'posY.nii.gz'\n",
" fslmaths $wpth/'negX.nii.gz' -mul $wpth/'posY.nii.gz' -mas $wpth/'mask_th'$RTH'.nii.gz' $wpth/'negXposY.nii.gz'\n",
" fslmaths $wpth/'negX.nii.gz' -mul $wpth/'negY.nii.gz' -mas $wpth/'mask_th'$RTH'.nii.gz' $wpth/'negXnegY.nii.gz'\n",
"\n",
" fslmaths $wpth/'Y_th'$RTH'.nii.gz' -div $wpth/'X_th'$RTH'.nii.gz' -atan -mul 57.2957795 $wpth/'rawANG.nii.gz'\n",
" # +X +Y >> atan(Y/X)\n",
" # do nothing\n",
" # -X -Y >> atan(Y/X) -180\n",
" fslmaths $wpth/'negXnegY.nii.gz' -mul -180 -add $wpth/'rawANG.nii.gz' $wpth/'raw2ANG.nii.gz'\n",
" # -X +Y >> atan(Y/X) +180\n",
" fslmaths $wpth/'negXposY.nii.gz' -mul 180 -add $wpth/'raw2ANG.nii.gz' -mas $wpth/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wpth/'negvalmask_th'$RTH'.nii.gz' $wpth/'raw3ANG.nii.gz'\n",
" fslmaths $wpth/'raw3ANG.nii.gz' -binv -mul 360 -add $wpth/'raw3ANG.nii.gz' -mas $wpth/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wpth/'negvalmask_th'$RTH'.nii.gz' $wpth/'ANG_th'$RTH'.nii.gz'\n",
"\n",
" # clean up, move some intermediate results to a separate folder\n",
" mkdir -p $wpth/'cv_r1' \n",
" mv $wpth/*_1_*.nii.gz $wpth/cv_r1/\n",
" mkdir -p $wpth/'cv_r2'\n",
" mv $wpth/*_2_*.nii.gz $wpth/cv_r2/\n",
" mkdir -p $wpth/'helper_vols'\n",
" mv $wpth/*pos*.nii.gz $wpth/helper_vols/\n",
" mv $wpth/*neg*.nii.gz $wpth/helper_vols/\n",
" mv $wpth/*raw*.nii.gz $wpth/helper_vols/\n",
" mv $wpth/*X2*.nii.gz $wpth/helper_vols/\n",
" mv $wpth/*Y2*.nii.gz $wpth/helper_vols/\n",
"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"function MaskResults_inAnat() {\n",
" MONKEY=$1\n",
" sess=$2\n",
" RTH=$3\n",
" FitRes=$4\n",
" ManMask=$5\n",
" \n",
" wp=$FitRes/MRI/$MONKEY/$sess\n",
" mkdir -p $wp/inAnat\n",
" \n",
" cp $ManMask/sub-${MONKEY}/anat/sub-${MONKEY}_ref* $wp/inAnat/\n",
" cp $ManMask/sub-${MONKEY}/warps/sub-${MONKEY}_func2* $wp/inAnat/\n",
" \n",
" for f in $wp/org/Sess-*.nii.gz; do\n",
" # applywarp fun2anat\n",
" f2=`basename $f .nii.gz`\n",
" flirt -applyxfm -init $wp/inAnat/sub-${MONKEY}_func2anat.mat -in $f \\\n",
" -ref $wp/inAnat/sub-${MONKEY}_ref_anat_res-1x1x1.nii.gz \\\n",
" -out $wp/inAnat/${f2}.nii -interp nearestneighbour\n",
" done\n",
" wp=$wp/inAnat\n",
" \n",
" brainmask=$ManMask/sub-${MONKEY}/anat/sub-${MONKEY}_ref_anat_mask_res-1x1x1.nii.gz\n",
"\n",
" echo \"Masking results for\" $MONKEY $sess \"at mean xval R2 value of\" $RTH\n",
"\n",
" # Create the appropriate masks\n",
" fslmaths ${brainmask} -bin $wp/brainmask.nii.gz\n",
" fslmaths $wp/brainmask.nii.gz -sub 1 -mul -1 $wp/nonbrainmask.nii.gz\n",
" fslmaths $wp/nonbrainmask.nii.gz -mul -99 $wp/nanreplacement.nii.gz\n",
"\n",
" if [ ! -d \"$wp/org\" ]; then\n",
" mkdir -p $wp/org\n",
" cp $wp/Sess-*.nii.gz $wp/org/\n",
" fi\n",
" \n",
" # create average/max/min R2 values\n",
" fslmaths $wp/'Sess-'$sess'_R2_1.nii.gz' -nan $wp/'Sess-'$sess'_R2_1.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_R2_2.nii.gz' -nan $wp/'Sess-'$sess'_R2_2.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_R2_1.nii.gz' -min $wp/'Sess-'$sess'_R2_2.nii.gz' $wp/'Sess-'$sess'_minR2.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_R2_1.nii.gz' -max $wp/'Sess-'$sess'_R2_2.nii.gz' $wp/'Sess-'$sess'_maxR2.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_R2_1.nii.gz' -add $wp/'Sess-'$sess'_R2_2.nii.gz' -div 2 $wp/'Sess-'$sess'_meanR2.nii.gz'\n",
"\n",
" # create a mask volume based on mean R2\n",
" fslmaths $wp/'Sess-'$sess'_meanR2.nii.gz' -thr $RTH -bin $wp/'mask_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'mask_th'$RTH'.nii.gz' -sub 1 -mul -1 $wp/'invmask_th'$RTH'.nii.gz'\n",
" # apply brainmask as well\n",
" fslmaths $wp/'mask_th'$RTH'.nii.gz' -mas $wp/brainmask.nii.gz $wp/'mask_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'invmask_th'$RTH'.nii.gz' -mas $wp/brainmask.nii.gz $wp/'invmask_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'mask_th'$RTH'.nii.gz' -sub 1 -mul 99 $wp/'negvalmask_th'$RTH'.nii.gz'\n",
" \n",
" # mask results\n",
" for part in 1 2; do\n",
" # echo 'Part ' ${part}\n",
" fslmaths $wp/'Sess-'$sess'_ang_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'ANG_'${part}'_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_ecc_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -div 10 -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'ECC_'${part}'_th'$RTH'.nii.gz'\n",
"\n",
" if [ ${sess:0:3} = css ]; then\n",
" fslmaths $wp/'Sess-'$sess'_expt_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'EXPT_'${part}'_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_exptsq_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'EXPTSQ_'${part}'_th'$RTH'.nii.gz'\n",
" fi\n",
"\n",
" fslmaths $wp/'Sess-'$sess'_imag_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'IMAG_'${part}'_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_real_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'REAL_'${part}'_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_FWHM_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -div 10 -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'FWHM_'${part}'_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_rfsize_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -div 10 -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'RFS_'${part}'_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_gain_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'GAIN_'${part}'_th'$RTH'.nii.gz'\n",
"\n",
" if [ ${sess:0:3} = dog ]; then\n",
" fslmaths $wp/'Sess-'$sess'_normamp_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'NAMP_'${part}'_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_sd2_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -div 10 -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'IRFS_'${part}'_th'$RTH'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_sdratio_'${part}'.nii.gz' -nan -mas $wp/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wp/'negvalmask_th'$RTH'.nii.gz' $wp/'SDRATIO_'${part}'_th'$RTH'.nii.gz'\n",
" fi\n",
"\n",
" # ======\n",
"\n",
" fslmaths $wp/'Sess-'$sess'_ang_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz $wp/'Sess-'$sess'_ang_'${part}'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_ecc_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz $wp/'Sess-'$sess'_ecc_'${part}'.nii.gz'\n",
"\n",
" if [ ${sess:0:3} = css ]; then\n",
" fslmaths $wp/'Sess-'$sess'_expt_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_expt_'${part}'.nii.gz' \n",
" fslmaths $wp/'Sess-'$sess'_exptsq_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_exptsq_'${part}'.nii.gz' \n",
" fi\n",
"\n",
" fslmaths $wp/'Sess-'$sess'_imag_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_imag_'${part}'.nii.gz' \n",
" fslmaths $wp/'Sess-'$sess'_real_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_real_'${part}'.nii.gz' \n",
" fslmaths $wp/'Sess-'$sess'_FWHM_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_FWHM_'${part}'.nii.gz' \n",
" fslmaths $wp/'Sess-'$sess'_rfsize_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_rfsize_'${part}'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_gain_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_gain_'${part}'.nii.gz'\n",
"\n",
" if [ ${sess:0:3} = dog ]; then\n",
" fslmaths $wp/'Sess-'$sess'_normamp_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_normamp_'${part}'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_sd2_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_sd2_'${part}'.nii.gz'\n",
" fslmaths $wp/'Sess-'$sess'_sdratio_'${part}'.nii.gz' -nan -add $wp/nanreplacement.nii.gz \\\n",
" $wp/'Sess-'$sess'_sdratio_'${part}'.nii.gz'\n",
" fi\n",
"\n",
" mkdir -p $wp/TH_$RTH\n",
" mv $wp/'ANG_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'ECC_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
"\n",
" if [ ${sess:0:3} = css ]; then\n",
" mv $wp/'EXPT_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'EXPTSQ_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" fi\n",
"\n",
" mv $wp/'IMAG_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'REAL_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'FWHM_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'RFS_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'GAIN_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
"\n",
" if [ ${sess:0:3} = dog ]; then\n",
" mv $wp/'NAMP_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'IRFS_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'SDRATIO_'${part}'_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" fi \n",
" done\n",
" mv $wp/'mask_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'invmask_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/'negvalmask_th'$RTH'.nii.gz' $wp/TH_$RTH/\n",
" mv $wp/nanreplacement.nii.gz $wp/TH_$RTH/\n",
"\n",
" wpth=$wp/TH_$RTH\n",
" \n",
" fslmaths $wpth/'FWHM_1_th'$RTH'.nii.gz' -add $wpth/'FWHM_2_th'$RTH'.nii.gz' -div 2 $wpth/'FWHM_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'RFS_1_th'$RTH'.nii.gz' -add $wpth/'RFS_2_th'$RTH'.nii.gz' -div 2 $wpth/'RFS_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'GAIN_1_th'$RTH'.nii.gz' -add $wpth/'GAIN_2_th'$RTH'.nii.gz' -div 2 $wpth/'GAIN_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'REAL_1_th'$RTH'.nii.gz' -add $wpth/'REAL_2_th'$RTH'.nii.gz' -div 2 $wpth/'REAL_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'IMAG_1_th'$RTH'.nii.gz' -add $wpth/'IMAG_2_th'$RTH'.nii.gz' -div 2 $wpth/'IMAG_th'$RTH'.nii.gz'\n",
" \n",
" if [ ${sess:0:3} = css ]; then\n",
" fslmaths $wpth/'EXPT_1_th'$RTH'.nii.gz' -add $wpth/'EXPT_2_th'$RTH'.nii.gz' -div 2 $wpth/'EXPT_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'EXPTSQ_1_th'$RTH'.nii.gz' -add $wpth/'EXPTSQ_2_th'$RTH'.nii.gz' -div 2 $wpth/'EXPTSQ_th'$RTH'.nii.gz'\n",
" fi\n",
" if [ ${sess:0:3} = dog ]; then\n",
" fslmaths $wpth/'NAMP_1_th'$RTH'.nii.gz' -add $wpth/'NAMP_2_th'$RTH'.nii.gz' -div 2 $wpth/'NAMP_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'IRFS_1_th'$RTH'.nii.gz' -add $wpth/'IRFS_2_th'$RTH'.nii.gz' -div 2 $wpth/'IRFS_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'SDRATIO_1_th'$RTH'.nii.gz' -add $wpth/'SDRATIO_2_th'$RTH'.nii.gz' -div 2 $wpth/'SDRATIO_th'$RTH'.nii.gz'\n",
" fi\n",
"\n",
" for xv in 1 2; do\n",
" fslmaths $wpth/'ANG_'${xv}'_th'$RTH'.nii.gz' -mul 0.0174533 -cos -mul \\\n",
" $wpth/'ECC_'${xv}'_th'$RTH'.nii.gz' $wpth/'X_'${xv}'_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'ANG_'${xv}'_th'$RTH'.nii.gz' -mul 0.0174533 -sin -mul \\\n",
" $wpth/'ECC_'${xv}'_th'$RTH'.nii.gz' $wpth/'Y_'${xv}'_th'$RTH'.nii.gz'\n",
" done\n",
"\n",
" fslmaths $wpth/'X_1_th'$RTH'.nii.gz' -add $wpth/'X_2_th'$RTH'.nii.gz' -div 2 -mas \\\n",
" $wpth/'mask_th'$RTH'.nii.gz' -add $wpth/'negvalmask_th'$RTH'.nii.gz' $wpth/'X_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'Y_1_th'$RTH'.nii.gz' -add $wpth/'Y_2_th'$RTH'.nii.gz' -div 2 -mas \\\n",
" $wpth/'mask_th'$RTH'.nii.gz' -add $wpth/'negvalmask_th'$RTH'.nii.gz' $wpth/'Y_th'$RTH'.nii.gz'\n",
"\n",
" fslmaths $wpth/'X_th'$RTH'.nii.gz' -sqr $wpth/'X2_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'Y_th'$RTH'.nii.gz' -sqr $wpth/'Y2_th'$RTH'.nii.gz'\n",
" fslmaths $wpth/'X2_th'$RTH'.nii.gz' -add $wpth/'Y2_th'$RTH'.nii.gz' -sqrt -mas $wpth/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wpth/'negvalmask_th'$RTH'.nii.gz' $wpth/'ECC_th'$RTH'.nii.gz'\n",
"\n",
" # calculate angle polar to cartesian\n",
" fslmaths $wpth/'X_th'$RTH'.nii.gz' -binv -mas $wpth/'mask_th'$RTH'.nii.gz' $wpth/'negX.nii.gz'\n",
" fslmaths $wpth/'Y_th'$RTH'.nii.gz' -binv -mas $wpth/'mask_th'$RTH'.nii.gz' $wpth/'negY.nii.gz'\n",
" fslmaths $wpth/'X_th'$RTH'.nii.gz' -bin -mas $wpth/'mask_th'$RTH'.nii.gz' $wpth/'posX.nii.gz'\n",
" fslmaths $wpth/'Y_th'$RTH'.nii.gz' -bin -mas $wpth/'mask_th'$RTH'.nii.gz' $wpth/'posY.nii.gz'\n",
" fslmaths $wpth/'negX.nii.gz' -mul $wpth/'posY.nii.gz' -mas $wpth/'mask_th'$RTH'.nii.gz' $wpth/'negXposY.nii.gz'\n",
" fslmaths $wpth/'negX.nii.gz' -mul $wpth/'negY.nii.gz' -mas $wpth/'mask_th'$RTH'.nii.gz' $wpth/'negXnegY.nii.gz'\n",
"\n",
" fslmaths $wpth/'Y_th'$RTH'.nii.gz' -div $wpth/'X_th'$RTH'.nii.gz' -atan -mul 57.2957795 $wpth/'rawANG.nii.gz'\n",
" # +X +Y >> atan(Y/X)\n",
" # do nothing\n",
" # -X -Y >> atan(Y/X) -180\n",
" fslmaths $wpth/'negXnegY.nii.gz' -mul -180 -add $wpth/'rawANG.nii.gz' $wpth/'raw2ANG.nii.gz'\n",
" # -X +Y >> atan(Y/X) +180\n",
" fslmaths $wpth/'negXposY.nii.gz' -mul 180 -add $wpth/'raw2ANG.nii.gz' -mas $wpth/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wpth/'negvalmask_th'$RTH'.nii.gz' $wpth/'raw3ANG.nii.gz'\n",
" fslmaths $wpth/'raw3ANG.nii.gz' -binv -mul 360 -add $wpth/'raw3ANG.nii.gz' -mas $wpth/'mask_th'$RTH'.nii.gz' \\\n",
" -add $wpth/'negvalmask_th'$RTH'.nii.gz' $wpth/'ANG_th'$RTH'.nii.gz'\n",
"\n",
" # clean up, move some intermediate results to a separate folder\n",
" mkdir -p $wpth/'cv_r1' \n",
" mv $wpth/*_1_*.nii.gz $wpth/cv_r1/\n",
" mkdir -p $wpth/'cv_r2'\n",
" mv $wpth/*_2_*.nii.gz $wpth/cv_r2/\n",
" mkdir -p $wpth/'helper_vols'\n",
" mv $wpth/*pos*.nii.gz $wpth/helper_vols/\n",
" mv $wpth/*neg*.nii.gz $wpth/helper_vols/\n",
" mv $wpth/*raw*.nii.gz $wpth/helper_vols/\n",
" mv $wpth/*X2*.nii.gz $wpth/helper_vols/\n",
" mv $wpth/*Y2*.nii.gz $wpth/helper_vols/\n",
"\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Run the masking function for all defined cases"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# cycle over monkeys, models, and R2-thresholds\n",
"for M in \"${Monkeys[@]}\"; do\n",
" for S in \"${Models[@]}\"; do\n",
" for rth in 0 1 2 3 4 5 10; do\n",
" MaskResults $M $S $rth $FitRes $ManMask\n",
" done\n",
" done\n",
"done "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Do it again with everything in anatomical space\n",
"Because we may want to look in volumetric space projected on anatomy"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# cycle over monkeys, models, and R2-thresholds\n",
"for M in \"${Monkeys[@]}\"; do\n",
" for S in \"${Models[@]}\"; do\n",
" for rth in 0 1 2 3 4 5 10; do\n",
" MaskResults_inAnat $M $S $rth $FitRes $ManMask\n",
" done\n",
" done\n",
"done "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Copy reference files to separate reference folders"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for M in \"${Monkeys[@]}\"; do\n",
" mkdir -p ${FitRes}/Reference/Volumes/func/${M}\n",
" cp -r ${ManMask}/sub-${M}/func/* ${FitRes}/Reference/Volumes/func/${M}/\n",
" mkdir -p ${FitRes}/Reference/Volumes/anat/${M}\n",
" cp -r ${ManMask}/sub-${M}/anat/* ${FitRes}/Reference/Volumes/anat/${M}/\n",
" mkdir -p ${FitRes}/Reference/Volumes/warps/${M}\n",
" cp -r ${ManMask}/sub-${M}/warps/* ${FitRes}/Reference/Volumes/warps/${M}/\n",
"done"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Copy atlas files to separate reference folders\n",
"Within the `manual-masks` folder there is a notebook `Atlas2ManualMasks` that will export the atlas data (D99) from the NMT template folders to the manual-masks folder. After that we can continue here for additional processing."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for M in \"${Monkeys[@]}\"; do\n",
" mkdir -p ${FitRes}/Reference/Volumes/atlas/${M}\n",
" cp -r ${ManMask}/sub-${M}/atlas/* ${FitRes}/Reference/Volumes/atlas/${M}/\n",
" # rm -r ${FitRes}/Reference/Volumes/atlas/${M}/atlas\n",
"done"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Adjust ROIs & warp to functional space\n",
"Do this in `manual-masks` so it will be generic. See the notebook `Customize_atlasses` in the `manual-masks/notebooks` folder. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Mask results with ROI \n",
"This will take the results in anatomical space and mask based on ROI so we can easily display"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"function MaskResults_inAnat_withROI () {\n",
" MONKEY=$1\n",
" MODEL=$2\n",
" ROI=$3\n",
" FitRes=$4\n",
"\n",
" echo \"Processing monkey ${MONKEY}\"\n",
" echo \"${MODEL} ${ROI}\" \n",
"\n",
" M_FLD=${FitRes}/MRI/${MONKEY}/${MODEL}/inAnat\n",
" ROI_FLD=${FitRes}/Reference/Volumes/atlas/${MONKEY}/ROI_manualadjust\n",
"\n",
" # do this for all existing thresholded subfolders \n",
" for sf in ${M_FLD}/TH_*; do\n",
" if [ -d ${sf} ]; then\n",
" #echo Processing $sf\n",
" \n",
" # mask averaged results with these ROIs\n",
" # NB! Use the filenames from ROI_manualadjust\n",
" # use specified ROI or this list\n",
"\n",
" if [ ${ROI} = 'allrois' ]; then \n",
" declare -a arr=(\"1-2\" \"3a_b\" \"5_(PE)\" \"5_(PEa)\" \"5_(PEc)\" \"7a_(Opt_PG)\" \"7b_(PFG_PF)\" \"7m\" \"7op\"\n",
" \"8Ad\" \"8Av\" \"8Bd\" \"8Bm\" \"8Bs\" \"9d\" \"9m\" \"10mc\" \"10mr\" \"10o\" \"11l\" \"11m\" \"12l\" \"12m\" \"12o\" \"12r\"\n",
" \"13a\" \"13b\" \"13l\" \"13m\" \"14c\" \"14r\" \"23a\" \"23b\" \"23c\" \"24a\" \"24a'\" \"24b\" \"24b'\" \"24c\" \"24c'\" \"25\"\n",
" \"29\" \"30\" \"31\" \"32\" \"35\" \"36c\" \"36p\" \"36r\" \"44\" \"45a\" \"45b\" \"46d\" \"46f\" \"46v\" \"A1\" \"AAA\" \"ABmc\"\n",
" \"ABpc\" \"AHA\" \"AIP\" \"AL\" \"AONd_m\" \"AONl\" \"Bi\" \"Bmc\" \"Bpc\" \"CA1\" \"CA2\" \"CA3\" \"CA4\" \"CE\" \"Cerebellum\"\n",
" \"CL\" \"Claustrum\" \"CM\" \"COa\" \"COp\" \"CPB\" \"DG\" \"DP\" \"EC\" \"ECL\" \"EI\" \"ELc\" \"ELr\" \"EO\" \"ER\" \"F1_(4)\"\n",
" \"F2_(6DR_6DC)\" \"F3\" \"F4\" \"F5_(6Va_6Vb)\" \"F6\" \"F7\" \"FST\" \"G\" \"GPe_GPi\" \"Ia\" \"Iai\" \"Ial\" \"Iam\" \"Iapl\"\n",
" \"Iapm\" \"Id\" \"Ig\" \"IPa\" \"Ld\" \"LGNm\" \"LGNp\" \"LIPd\" \"LIPv\" \"LOP\" \"Lv\" \"MDdc\" \"MDpc\" \"ME\" \"MGad\" \"MGmc\"\n",
" \"MGpd\" \"MGv\" \"MGz\" \"MIP\" \"ML\" \"MN\" \"MST\" \"MT\" \"NLOT\" \"OT\" \"PAC2\" \"PAC3\" \"PACo_Pir\" \"PACs\" \"paraS\"\n",
" \"PEci\" \"PGa\" \"Pi\" \"PIP\" \"Pir\" \"PL\" \"PL'\" \"PM\" \"PrCO\" \"preS\" \"proS\" \"R\" \"RM\" \"RPB\" \"RT\" \"RTL\" \"RTp\"\n",
" \"SII\" \"SNr_c\" \"STGr\" \"STN\" \"Striatum\" \"Sub\" \"TAa\" \"TEa\" \"TEad\" \"TEav\" \"TEm\" \"TEO\" \"TEpd\" \"TEpv\"\n",
" \"TF\" \"TFO\" \"TGa\" \"TGdd\" \"TGdg\" \"TGsts\" \"TGvd\" \"TGvg\" \"TH\" \"TPO\" \"Tpt\" \"TTv\" \"v23a\" \"v23b\" \"v23b?\"\n",
" \"V1\" \"V2\" \"V2?\" \"V2_or_v23b\" \"V3A\" \"V3d\" \"V3v\" \"V4\" \"V4t\" \"V4v\" \"V6\" \"V6Ad\" \"V6Av\" \"VIP\")\n",
" else\n",
" declare -a arr=(${ROI})\n",
" fi\n",
"\n",
" for roi in \"${arr[@]}\"; do\n",
" echo ${roi}\n",
" \n",
" mkdir -p ${sf}/mROI/${roi}\n",
" mkdir -p ${ROI_FLD}/1mm\n",
" \n",
" # resample roi to 1 mm\n",
" mri_convert ${ROI_FLD}/${roi}.nii.gz ${ROI_FLD}/1mm/${roi}.nii.gz -vs 1 1 1\n",
" \n",
" fslmaths ${ROI_FLD}/1mm/${roi}.nii.gz -sub 1 -mul 99 ${ROI_FLD}/1mm/${roi}_SUB.nii.gz\n",
" # mask with roi file\n",
" for file in ${sf}/*.nii.gz; do\n",
" #echo Masking ${file}\n",
" #echo With ${ROI_FLD}/1mm/${roi}.nii.gz\n",
" fslmaths ${file} -mas ${ROI_FLD}/1mm/${roi}.nii.gz ${sf}/mROI/${roi}/$(basename \"$file\")\n",
" fslmaths ${sf}/mROI/${roi}/$(basename \"$file\") -add ${ROI_FLD}/1mm/${roi}_SUB.nii.gz \\\n",
" ${sf}/mROI/${roi}/$(basename \"$file\")\n",
" done\n",
" done\n",
" fi\n",
" done\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# cycle over monkeys, models, and R2-thresholds\n",
"declare -a ROIs=('V1' 'V2' 'V3d' 'V3v' 'V3A' 'V4' 'V4t' 'V4v' 'MT' 'MST' \n",
" 'TEO' 'TAa' 'Tpt' 'TPO' 'FST' 'VIP' 'LIPv' 'LIPd' \n",
" '1-2' 'PL' 'PM' 'LGNm' 'LGNp' 'Striatum' '3a_b' 'SII' \n",
" 'F2_(6DR_6DC)' 'F4' 'F5_(6Va_6Vb)' 'F7' '8Av' '8Ad' '8Bs' '8Bd' '46v' '46d' \n",
" '12r' '12m' '13l' 'Id' 'Iai' '32' '24c' 'ML' '10mr')\n",
"\n",
"for M in \"${Monkeys[@]}\"; do\n",
" for S in \"${Models[@]}\"; do\n",
" for R in \"${ROIs[@]}\"; do\n",
" MaskResults_inAnat_withROI $M $S $R $FitRes\n",
" done\n",
" done\n",
"done "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Bash",
"language": "bash",
"name": "bash"
},
"language_info": {
"codemirror_mode": "shell",
"file_extension": ".sh",
"mimetype": "text/x-sh",
"name": "bash"
}
},
"nbformat": 4,
"nbformat_minor": 4
}