Newer
Older
#!/bin/sh
# Copyright (C) 2004 University of Oxford
#
# SHCOPYRIGHT
if [ "x$SGE_ROOT" = "x" ] ; then
if [ -f /usr/local/share/sge-6.0/default/common/settings.sh ] ; then
. /usr/local/share/sge-6.0/default/common/settings.sh
else if [ -f /usr/local/sge-6/default/common/settings.sh ] ; then
. /usr/local/sge-6/default/common/settings.sh
else
echo "bedpost: Couldn\'t locate SGE_ROOT\!"
exit 255
fi
fi
echo "Usage: bedpostX <subject directory> "
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
echo ""
echo "expects to find bvals and bvecs in subject directory"
echo "expects to find data nodif_brain_mask nodif in subject directory"
echo ""
exit
}
make_absolute(){
dir=$1;
if [ -d ${dir} ]; then
OLDWD=`pwd`
cd ${dir}
dir_all=`pwd`
cd $OLDWD
else
dir_all=${dir}
fi
echo ${dir_all}
}
[ "$1" = "" ] && Usage
subjdir=`make_absolute $1`
subjdir=`echo $subjdir | sed 's/\/$/$/g'`
echo subjectdir is $subjdir
#check that all required files exist
if [ ! -d $subjdir ]; then
echo "subject directory $1 not found"
fi
if [ ! -e ${subjdir}/bvecs ]; then
echo "${subjdir}/bvecs not found"
fi
if [ ! -e ${subjdir}/bvals ]; then
echo "${subjdir}/bvals not found"
fi
if [ `${FSLDIR}/bin/imtest ${subjdir}/data` -eq 0 ]; then
echo "${subjdir}/data not found"
fi
if [ `${FSLDIR}/bin/imtest ${subjdir}/nodif` -eq 0 ]; then
echo "${subjdir}/nodif not found"
fi
if [ `${FSLDIR}/bin/imtest ${subjdir}/nodif_brain_mask` -eq 0 ]; then
echo "${subjdir}/nodif_brain_mask not found"
fi
echo Making bedpost directory structure
mkdir -p ${subjdir}.bedpost/
mkdir -p ${subjdir}.bedpost/diff_slices
mkdir -p ${subjdir}.bedpost/logs
mkdir -p ${subjdir}.bedpost/logs/pid_${$}
mkdir -p ${subjdir}.bedpost/xfms
mailto=`whoami`@fmrib.ox.ac.uk
echo Queuing preprocessing stages
preprocid=`qsub -M $mailto -V -q short.q \
-o ${subjdir}.bedpost/logs -e ${subjdir}.bedpost/logs \
${FSLDIR}/bin/bedpostX_preproc.sh ${subjdir} | \
awk '{print $3}'`
echo Queuing parallel processing stage
nslices=`avwval ${subjdir}/data dim3`
bedpostid=`qsub -M $mailto -hold_jid $preprocid -V -q long.q -t 1-$nslices \
-o ${subjdir}.bedpost/logs -e ${subjdir}.bedpost/logs \
${FSLDIR}/bin/bedpostX_single_slice.sh $subjdir | \
awk '{print $3}' | awk -F. '{print $1}'`
echo Queuing post processing stage
mergeid=`qsub -M $mailto -hold_jid $bedpostid -V -q short.q \
-o ${subjdir}.bedpost/logs -e ${subjdir}.bedpost/logs \
${FSLDIR}/bin/bedpostX_postproc.sh $subjdir | \
awk '{print $3}'`
echo
echo Type ${subjdir}.bedpost/monitor to show progress.
cat <<EOM > ${subjdir}.bedpost/monitor
#!/bin/sh
finished=0
logdir=${subjdir}.bedpost/logs
while [ \$finished -eq 0 ] ; do
nfin=0
if [ -f \$logdir/bedpost.o$bedpostid.1 ] ; then
nfin=\`cat \$logdir/bedpost.o$bedpostid.* |\
grep Done | wc -w | awk '{print \$1}'\`
fi
if [ \$nfin -eq $nslices ] ; then
finished=1
fi
echo "\$nfin slices processed"
sleep 600;
done
EOM
chmod +x ${subjdir}.bedpost/monitor
echo Type ${subjdir}.bedpost/cancel to terminate the task.
cat <<EOC > ${subjdir}.bedpost/cancel
#!/bin/sh
qdel $mergeid $bedpostid $preprocid
EOC
chmod +x ${subjdir}.bedpost/cancel
echo
echo You will get an email at the end of the post-processing stage.
echo