forked from miykael/nipype-beginner-s-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathANTSnormalizeFunc.sh
130 lines (103 loc) · 3.88 KB
/
ANTSnormalizeFunc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
#Define environment parameters
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#specify where ANTS is installed
export PATH=/software/ANTS:$PATH
export ANTSPATH=/software/ANTS/
#specify where FreeSurfer is installed
export FREESURFER_HOME=/software/Freesurfer/5.1.0
source $FREESURFER_HOME/SetUpFreeSurfer.sh
#Define experiment specific parameters
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#specify list of subjects
subjectList='subject1 subject2 subject3'
#specify list of contrasts. (empty = all contrasts will be normalized
contrastList=''
#specify folder names
experimentDir=~SOMEPATH/experiment #parent folder
inputDir=$experimentDir/result/vol_contrasts #folder containing functional images
templateName=$experimentDir/data/normtemp.nii.gz #path to and name of normtemplate
normAnatDir=$experimentDir/normAnat #outputdir of normalized T1 images
funcOutDir=$inputDir #outputdir of normalized functional images
#Do you want to overwrite existing output files? (1 = yes, 0 = no)
overwrite=0
#Write the main script
#~~~~~~~~~~~~~~~~~~~~~
#If not created yet, let's create a new output folder
if [ ! -d $funcOutDir ]
then
mkdir -p ${funcOutDir}
fi
#go through all subjects
for subj in $subjectList
do
#If not created yet, let's create a subject specific folder
if [ ! -d $funcOutDir/$subj ]
then
mkdir ${funcOutDir}/${subj}
fi
#If not created yet, let's create a folder for the normalized cons
if [ ! -d $funcOutDir/$subj/normcons ]
then
mkdir -p $funcOutDir/$subj/normcons
fi
#If not created yet, let's create a folder for the normalized spmTs
if [ ! -d $funcOutDir/$subj/normspmTs ]
then
mkdir -p $funcOutDir/$subj/normspmTs
fi
#checks if all necessary output of antsIntroduction.sh exists
if [ ! -e $normAnatDir/${subj}deformed.nii.gz ] || [ ! -e $normAnatDir/${subj}Warpxvec.nii.gz ] || [ ! -e $normAnatDir/${subj}Warpyvec.nii.gz ] || [ ! -e $normAnatDir/${subj}Warpzvec.nii.gz ] || [ ! -e $normAnatDir/${subj}Affine.txt ]
then
echo -e "NOTICE: A necessary ANTS output file of subject ${subj} was not found.\
Skipping to next subject."
continue
fi
#create a list that contains numbers of contrasts if not specified above
if [ $contrastList=='' ]
then
contrast=`ls $inputDir/$subj/con_*.img`
con_ID=''
for con in $contrast
do
length=${#con}
ID=`echo $con | cut -c $(($length-7))-$(($length-4))`
con_ID=${con_ID}' '$ID
done #con done
else
con_ID=$contrastList
fi
#go through all contrasts
for ID in $con_ID
do
#to normalize 'con' and 'spmT' files
for type in con spmT
do
#specify input image and name of normalized output image
InImg=$inputDir/$subj/${type}"_"${ID}.img
OutNii=$funcOutDir/$subj/norm${type}"s/ants_"${type}"_"${ID}.nii
#checks if input image exists
if [ ! -e $InImg ]
then
echo -e "NOTICE: Cannot find ${type}_${ID}.img of subject ${subj}"
continue
fi
#contrast will be normalized if contrast wasn't normalized yet
# or if overwrite was set to 1=yes
if [ ! -e $OutNii ] || [ $overwrite == 1 ]
then
#assemble the command for the conversion of img to nii
cmd1="mri_convert "${InImg}" "${OutNii}
#assemble the command for the normalization
cmd2="WarpImageMultiTransform 3 ${OutNii} ${OutNii} \
-R $normAnatDir/${subj}deformed.nii.gz \
$normAnatDir/${subj}Warp.nii.gz \
$normAnatDir/${subj}Affine.txt"
eval $cmd1 #execute cmd1
eval $cmd2 #execute cmd2
else
echo -e "NOTICE: ${OutNii} already exists. Skipping to next contrast."
fi
done #type done
done #ID done
done #subj done