#!/bin/bash

###List of folders
folders=("mgh_1026" \
"mgh_1004" \
"mgh_1010" \
"mgh_1012" \
"mgh_1025" \
"mgh_1001" \
"mgh_1008" \
"mgh_1015" \
"mgh_1022" \
"mgh_1029" \
"mgh_1002" \
"mgh_1009" \
"mgh_1016" \
"mgh_1023" \
"mgh_1030" \
"mgh_1003" \
"mgh_1017" \
"mgh_1024" \
"mgh_1031" \
"mgh_1011" \
"mgh_1018" \
"mgh_1032" \
"mgh_1005" \
"mgh_1019" \
"mgh_1033" \
"mgh_1006" \
"mgh_1013" \
"mgh_1027" \
"mgh_1034" \
"mgh_1007" \
"mgh_1014" \
"mgh_1021" \
"mgh_1028")

###List of ROIs
rois=("resliced_native_AV_L_FS_DTI_coreg.nii.gz" \
"resliced_native_AV_L_FS_T1_coreg.nii.gz" \
"resliced_native_AV_L_HT_New_coreg.nii.gz" \
"resliced_native_AV_L_FS_DTI_coreg.nii.gz" \
"resliced_native_AV_L_FS_T1_coreg.nii.gz" \
"resliced_native_AV_L_HT_New_coreg.nii.gz" \
"resliced_native_CeM_L_FS_DTI_coreg.nii.gz" \
"resliced_native_CeM_L_FS_T1_coreg.nii.gz" \
"resliced_native_CL_L_FS_DTI_coreg.nii.gz" \
"resliced_native_CL_L_FS_T1_coreg.nii.gz" \
"resliced_native_CL_L_HT_New_coreg.nii.gz" \
"resliced_native_CM_L_FS_DTI_coreg.nii.gz" \
"resliced_native_CM_L_FS_T1_coreg.nii.gz" \
"resliced_native_CM_L_HT_New_coreg.nii.gz" \
"resliced_native_LD_L_FS_DTI_coreg.nii.gz" \
"resliced_native_LD_L_FS_T1_coreg.nii.gz" \
"resliced_native_LGN_L_FS_DTI_coreg.nii.gz" \
"resliced_native_LGN_L_FS_T1_coreg.nii.gz" \
"resliced_native_LGN_L_HT_New_coreg.nii.gz" \
"resliced_native_LSg_L_FS_DTI_coreg.nii.gz" \
"resliced_native_LSg_L_FS_T1_coreg.nii.gz" \
"resliced_native_LP_L_FS_DTI_coreg.nii.gz" \
"resliced_native_LP_L_FS_T1_coreg.nii.gz" \
"resliced_native_MDm_L_FS_DTI_coreg.nii.gz" \
"resliced_native_MDm_L_FS_T1_coreg.nii.gz" \
"resliced_native_MDl_L_FS_DTI_coreg.nii.gz" \
"resliced_native_MDl_L_FS_T1_coreg.nii.gz" \
"resliced_native_MGN_L_FS_DTI_coreg.nii.gz" \
"resliced_native_MGN_L_FS_T1_coreg.nii.gz" \
"resliced_native_MGN_L_HT_New_coreg.nii.gz" \
"resliced_native_MD_Pf_L_FS_DTI_comb_coreg.nii.gz" \
"resliced_native_MD_Pf_L_FS_T1_comb_coreg.nii.gz" \
"resliced_native_MD_Pf_L_HT_New_coreg.nii.gz" \
"resliced_native_Pf_L_FS_DTI_coreg.nii.gz" \
"resliced_native_Pf_L_FS_T1_coreg.nii.gz" \
"resliced_native_Pf_L_FS_DTI_coreg.nii.gz" \
"resliced_native_Pf_L_FS_T1_coreg.nii.gz" \
"resliced_native_PuA_L_FS_DTI_coreg.nii.gz" \
"resliced_native_PuA_L_FS_T1_coreg.nii.gz" \
"resliced_native_PuI_L_FS_DTI_coreg.nii.gz" \
"resliced_native_PuI_L_FS_T1_coreg.nii.gz" \
"resliced_native_PuL_L_FS_DTI_coreg.nii.gz" \
"resliced_native_PuL_L_FS_T1_coreg.nii.gz" \
"resliced_native_PuM_L_FS_DTI_comb_coreg.nii.gz" \
"resliced_native_PuM_L_FS_T1_coreg.nii.gz" \
"resliced_native_Pu_L_FS_DTI_comb_coreg.nii.gz" \
"resliced_native_Pu_L_FS_T1_comb_coreg.nii.gz" \
"resliced_native_Pul_L_HT_New_coreg.nii.gz" \
"resliced_native_VA_L_FS_DTI_comb_coreg.nii.gz" \
"resliced_native_VA_L_FS_T1_comb_coreg.nii.gz" \
"resliced_native_VA_L_HT_New_coreg.nii.gz" \
"resliced_native_VAmc_L_FS_DTI_coreg.nii.gz" \
"resliced_native_Vamc_L_FS_T1_coreg.nii.gz" \
"resliced_native_VA_L_FS_DTI_coreg.nii.gz" \
"resliced_native_VA_L_FS_T1_coreg.nii.gz" \
"resliced_native_VA_L_HT_New_coreg.nii.gz" \
"resliced_native_VLa_L_FS_DTI_coreg.nii.gz" \
"resliced_native_VLa_L_FS_T1_coreg.nii.gz" \
"resliced_native_Vla_L_HT_New_coreg.nii.gz" \
"resliced_native_VLp_L_FS_DTI_coreg.nii.gz" \
"resliced_native_VLp_L_FS_T1_coreg.nii.gz" \
"resliced_native_VLp_L_HT_New_coreg.nii.gz" \
"resliced_native_VPL_L_FS_DTI_coreg.nii.gz" \
"resliced_native_VPL_L_FS_T1_coreg.nii.gz" \
"resliced_native_VPL_L_HT_New_coreg.nii.gz" \
"resliced_native_AV_R_FS_DTI_coreg.nii.gz" \
"resliced_native_AV_R_FS_T1_coreg.nii.gz" \
"resliced_native_AV_R_HT_New_coreg.nii.gz" \
"resliced_native_AV_R_FS_DTI_coreg.nii.gz" \
"resliced_native_AV_R_FS_T1_coreg.nii.gz" \
"resliced_native_AV_R_HT_New_coreg.nii.gz" \
"resliced_native_CeM_R_FS_DTI_coreg.nii.gz" \
"resliced_native_CeM_R_FS_T1_coreg.nii.gz" \
"resliced_native_CL_R_FS_DTI_coreg.nii.gz" \
"resliced_native_CL_R_FS_T1_coreg.nii.gz" \
"resliced_native_CL_R_HT_New_coreg.nii.gz" \
"resliced_native_CM_R_FS_DTI_coreg.nii.gz" \
"resliced_native_CM_R_FS_T1_coreg.nii.gz" \
"resliced_native_CM_R_HT_New_coreg.nii.gz" \
"resliced_native_LD_R_FS_DTI_coreg.nii.gz" \
"resliced_native_LD_R_FS_T1_coreg.nii.gz" \
"resliced_native_LGN_R_FS_DTI_coreg.nii.gz" \
"resliced_native_LGN_R_FS_T1_coreg.nii.gz" \
"resliced_native_LGN_R_HT_New_coreg.nii.gz" \
"resliced_native_LSg_R_FS_DTI_coreg.nii.gz" \
"resliced_native_LSg_R_FS_T1_coreg.nii.gz" \
"resliced_native_LP_R_FS_DTI_coreg.nii.gz" \
"resliced_native_LP_R_FS_T1_coreg.nii.gz" \
"resliced_native_MDm_R_FS_DTI_coreg.nii.gz" \
"resliced_native_MDm_R_FS_T1_coreg.nii.gz" \
"resliced_native_MDl_R_FS_DTI_coreg.nii.gz" \
"resliced_native_MDl_R_FS_T1_coreg.nii.gz" \
"resliced_native_MGN_R_FS_DTI_coreg.nii.gz" \
"resliced_native_MGN_R_FS_T1_coreg.nii.gz" \
"resliced_native_MGN_R_HT_New_coreg.nii.gz" \
"resliced_native_MD_Pf_R_FS_DTI_comb_coreg.nii.gz" \
"resliced_native_MD_Pf_R_FS_T1_comb_coreg.nii.gz" \
"resliced_native_MD_Pf_R_HT_New_coreg.nii.gz" \
"resliced_native_Pf_R_FS_DTI_coreg.nii.gz" \
"resliced_native_Pf_R_FS_T1_coreg.nii.gz" \
"resliced_native_Pf_R_FS_DTI_coreg.nii.gz" \
"resliced_native_Pf_R_FS_T1_coreg.nii.gz" \
"resliced_native_PuA_R_FS_DTI_coreg.nii.gz" \
"resliced_native_PuA_R_FS_T1_coreg.nii.gz" \
"resliced_native_PuI_R_FS_DTI_coreg.nii.gz" \
"resliced_native_PuI_R_FS_T1_coreg.nii.gz" \
"resliced_native_PuL_R_FS_DTI_coreg.nii.gz" \
"resliced_native_PuL_R_FS_T1_coreg.nii.gz" \
"resliced_native_PuM_R_FS_DTI_comb_coreg.nii.gz" \
"resliced_native_PuM_R_FS_T1_coreg.nii.gz" \
"resliced_native_Pu_R_FS_DTI_comb_coreg.nii.gz" \
"resliced_native_Pu_R_FS_T1_comb_coreg.nii.gz" \
"resliced_native_Pul_R_HT_New_coreg.nii.gz" \
"resliced_native_VA_R_FS_DTI_comb_coreg.nii.gz" \
"resliced_native_VA_R_FS_T1_comb_coreg.nii.gz" \
"resliced_native_VA_R_HT_New_coreg.nii.gz" \
"resliced_native_VAmc_R_FS_DTI_coreg.nii.gz" \
"resliced_native_Vamc_R_FS_T1_coreg.nii.gz" \
"resliced_native_VA_R_FS_DTI_coreg.nii.gz" \
"resliced_native_VA_R_FS_T1_coreg.nii.gz" \
"resliced_native_VA_R_HT_New_coreg.nii.gz" \
"resliced_native_VLa_R_FS_DTI_coreg.nii.gz" \
"resliced_native_VLa_R_FS_T1_coreg.nii.gz" \
"resliced_native_Vla_R_HT_New_coreg.nii.gz" \
"resliced_native_VLp_R_FS_DTI_coreg.nii.gz" \
"resliced_native_VLp_R_FS_T1_coreg.nii.gz" \
"resliced_native_VLp_R_HT_New_coreg.nii.gz" \
"resliced_native_VPL_R_FS_DTI_coreg.nii.gz" \
"resliced_native_VPL_R_FS_T1_coreg.nii.gz" \
"resliced_native_VPL_R_HT_New_coreg.nii.gz" \
"resliced_native_MVRe_L_FS_DTI_coreg.nii.gz" \
"resliced_native_MVRe_L_FS_T1_coreg.nii.gz" \
"resliced_native_MVRe_R_FS_DTI_coreg.nii.gz" \
"resliced_native_MVRe_R_FS_T1_coreg.nii.gz")


for folder in "${folders[@]}"; do
	cd /mnt/d/HCP35/unzipped/${folder}/anat/T1/

    echo "Processing $folder"

	# Apply inverse warp to ROI (e.g., ROI in MNI space) using nearest neighbour
	echo "Applying the warp for $folder"
	for roi in "${rois[@]}"; do
		roi_name="${roi/_coreg.nii.gz/}"
		applywarp \
			--in="$roi" \
			--ref=$FSLDIR/data/standard/MNI152_T1_1mm.nii.gz \
			--warp=anat2mni_warp.nii.gz \
			--out="${roi_name}_MNI.nii.gz" \
			--interp=nn
	done

done
