forked from lconcha/my_fba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_fba_build_template.sh
executable file
·140 lines (106 loc) · 3.02 KB
/
my_fba_build_template.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
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
source `which my_do_cmd`
help() {
echo "
`basename $0` [nSubjects]
"
}
for arg in "$@"
do
case "$arg" in
-h|-help)
help
exit 1
;;
esac
done
auto_nsubjs=0
if [ $1 -eq 0 ]
then
echo " [INFO] number of subjects for template not specified. Will use all available."
auto_nsubjs=1
nsubjs="XXX"
else
if [ -f $1 ]
then
nsubjs=$1
else
nsubjs=$1
echo " [INFO] Number of subjects explicitly set to $nsubjs"
fi
fi
# auto_nsubjs=0
# if [ "$#" -lt 2 ]; then
# echo " [INFO] number of subjects for template not specified. Will use all available."
# auto_nsubjs=1
# nsubjs="XXX"
# else
# nsubjs=$1
# fi
mkdir -p ${FBA_DIR}/logs/template
ln_fod_dir=${FBA_DIR}/logs/template/fods
ln_mask_dir=${FBA_DIR}/logs/template/masks
for d in $ln_fod_dir $ln_mask_dir
do
if [ ! -d $d ]
then
mkdir $d
fi
done
echo " [INFO] Making sure the template directories are empty"
rm ${ln_fod_dir}/*
rm ${ln_mask_dir}/*
subjects_file=${FBA_DIR}/logs/template/subjects_to_build_template_from.txt
if [ -f $nsubjs -a $auto_nsubjs -eq 0 ]
then
echo " [INFO] Taking the subjects to build template from file: $nsubjs"
cp $nsubjs $subjects_file
fi
available_subjects_file=${FBA_DIR}/logs/template/available_subjects_to_build_template_from.txt
ls ${FBA_DIR}/*/wm_fod.mif > $available_subjects_file
n_available_subjects=`wc -l $available_subjects_file | awk '{print $1}'`
if [ $n_available_subjects -eq 0 ]
then
echo " [ERROR] There are no FOD files to build template from. Bye."
exit 2
fi
if [ $auto_nsubjs -eq 1 ]
then
nsubjs=$n_available_subjects
fi
echo " [INFO] There are $n_available_subjects available subjects to build template from"
echo " [INFO] We will randomly take $nsubjs from these."
echo " [INFO] List of subjects written to $subjects_file"
shuf $available_subjects_file -n $nsubjs | sort > $subjects_file
while read fod;
do
ff=${fod#${FBA_DIR}/}
subj=${ff%%/*}
mask=${FBA_DIR}/$subj/mask_upsampled.mif
if [ ! -f $fod -a -f $mask ]
then
echo " [WARNING] Mismatch between FOD and mask of subject $subj (not including)"
continue
fi
ln_fod=${ln_fod_dir}/${subj}_fod.mif
ln_mask=${ln_mask_dir}/${subj}_mask.mif
ln -s $fod $ln_fod
ln -s $mask $ln_mask
done < <(cat $subjects_file)
echo " [INFO] Listing the FODs to use for template"
cat $subjects_file
echo " [INFO] End of FOD list"
echo " [INFO] It is best to run this step on an execution host.
Below is the command you should run.
If you want to run it on the cluster, prepend fsl_sub to the command.
* Also, your /tmp partition should be plentiful (several GB)
If it is not, then use the switch -tempdir \${FBA_DIR}/logs/template
in the following command.
"
my_do_cmd -fake population_template \
-mask_dir $ln_mask_dir \
-warp_dir ${FBA_DIR}/logs/template/warps \
-linear_transformations_dir ${FBA_DIR}/logs/template/xfms \
-template_mask ${FBA_DIR}/logs/template/template_mask.mif \
$ln_fod_dir \
${FBA_DIR}/template_fod.mif