-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathrun_ica.sh
executable file
·157 lines (130 loc) · 3.64 KB
/
run_ica.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
set -e
function usage {
printf "\nUsage: run_ica.sh [ARGS] FILE\n"
printf "\n"
printf "Arguments\n"
printf " -i|--iter <n_iter> Number of random restarts (default: 100)\n"
printf " -t|--tolerance <tol> Tolerance (default: 1e-7)\n"
printf " -n|--n-cores <n_cores> Number of cores to use (default: 8)\n"
printf " -d|--max-dim <max_dim> Maximum dimensionality for search (default: n_samples)\n"
printf " -m|--min-dim <min_dim> Minimum dimensionality for search (default: 20)\n"
printf " -s|--step-size <step_size> Dimensionality step size (default: n_samples/25)\n"
printf " -o|--outdir <path> Output directory for files (default: current directory)\n"
printf " -l|--logfile Name of log file to use if verbose is off (default: ica.log)\n"
printf " -v|--verbose Send output to stdout rather than writing to file\n"
printf " -h|--help Display help information\n"
printf "\n"
exit 1
}
# Handle arguments
OUTDIR=$(pwd)
TOL="1e-7"
ITER=100
STEP=0
MAXDIM=0
MINDIM=20
CORES=8
VERBOSE=false
LOGFILE="ica.log"
POSITIONAL=()
while [[ $# -gt 0 ]]; do
case $1 in
-i|--iter)
ITER=$2
shift;
shift;;
-o|--out)
OUTDIR=$2
shift;
shift;;
-t|--tolerance)
TOL=$2
shift;
shift;;
-m|--min-dim)
MINDIM=$2
shift;
shift;;
-d|--max-dim)
MAXDIM=$2
shift;
shift;;
-s|--step-size)
STEP=$2
shift;
shift;;
-n|--n-cores)
CORES=$2
shift;
shift;;
-l|--logfile)
LOGFILE=$2
shift;
shift;;
-v|--verbose)
VERBOSE=true
shift;;
-h|--help)
usage;;
--)
shift;
break;;
*)
POSITIONAL+=("$1")
shift;;
esac
done
set -- "${POSITIONAL[@]}"
FILE="$1"
# Error checking
if [ "$FILE" = "" ]; then
printf "Filename for expression data is required\n"
usage
fi
if [ ! -f $FILE ]; then
printf "ERROR: $FILE does not exist\n"
exit 1
fi
# Get number of samples in file
n_samples=$(head -1 $FILE | sed 's/[^,]//g' | tr -d '\n' | wc -c)
if [ "$MAXDIM" -eq 0 ]; then
MAXDIM=$n_samples
fi
if [ "$STEP" -eq 0 ]; then
STEP=$((($n_samples / 250 + 1) * 10))
fi
# Verbosity wrapper
redirect_cmd() {
# if verbose, write to std and log else only write to log
if [ "$VERBOSE" = true ]; then
"$@" | tee -a $LOGFILE
else
"$@" >> $LOGFILE 2>&1
fi
}
echo "" > $LOGFILE
# Run code
for dim in $(seq $MINDIM $STEP $MAXDIM); do
bar="############################${dim//[0-9]/'#'}${MAXDIM//[0-9]/'#'}"
# Make output subdirectory
outsubdir=$OUTDIR/ica_runs/$dim
if [ ! -f $outsubdir ]; then
mkdir -p $outsubdir
fi
redirect_cmd echo ""
redirect_cmd echo $bar
redirect_cmd echo "# Computing dimension $dim of $MAXDIM #"
redirect_cmd echo $bar
redirect_cmd echo ""
redirect_cmd mpiexec -n $CORES python -u random_restart_ica.py -f $FILE -i $ITER -o $outsubdir -t $TOL -d $dim 2>&1
redirect_cmd mpiexec -n $CORES python -u compute_distance.py -i $ITER -o $outsubdir 2>&1
redirect_cmd mpiexec -n $CORES python -u cluster_components.py -i $ITER -o $outsubdir 2>&1
redirect_cmd echo ""
done
# Identify best dimension
if [ "$VERBOSE" = true ]; then
python get_dimension.py -o $OUTDIR 2>&1
else
python get_dimension.py -o $OUTDIR >> $LOGFILE 2>&1
fi