-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmaster_blaster.sh
More file actions
executable file
·262 lines (221 loc) · 5 KB
/
Copy pathmaster_blaster.sh
File metadata and controls
executable file
·262 lines (221 loc) · 5 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/bin/bash
#SBATCH --job-name=split_blast
#SBATCH --time=1:00:00
#SBATCH --chdir=.
module load python
module load anaconda
module load blast+/2.7.1
# Constants used by parts of the script
BLASTSCRIPT=split_blast.py
SPLIT_SCRIPT=split_fastas.py
DEFAULT_TEMP=temp
KEEPOUT=0
combine_file="combine_outputs.sh"
working_dir="$PWD"
time="5:00"
mem="1G"
sub_args=()
POSITIONAL=()
args=()
# make sure MASTER_BLASTER_PATH is defined
# or non-empty
if [[ -z "$MASTER_BLASTER_PATH" ]]; then
echo MASTER_BLASTER_PATH must be defined, please refer to
echo the 'install.sh' script.
exit 1
fi
# Run through all of the arguments provided from command line
while [[ $# -gt 0 ]]
do
key="$1"
if ! [[ -z "$key" ]]; then
args+=("$1")
args+=("$2")
fi
case $key in
-q|--query)
QUERY="$2"
shift # past argument
shift # past value
;;
--ns|--nucSubject)
NUCSUBJECT="$2"
sub_args+=("$1")
sub_args+=("$2")
shift # past argument
shift # past value
;;
--ps|--protSubject)
PROTSUBJECT="$2"
sub_args+=("$1")
sub_args+=("$2")
shift # past argument
shift # past value
;;
--withColor)
WITHCOLOR="$2"
shift # past value
;;
-n|--numProcs)
NUMPROCS="$2"
sub_args+=("$1")
sub_args+=("$2")
shift
shift
;;
-t|--temp)
TEMP="$2"
sub_args+=("$1")
sub_args+=("$2")
shift
shift
;;
-b|--blastType)
BLASTTYPE="$2"
sub_args+=("$1")
sub_args+=("$2")
shift
shift
;;
--dontIndex)
DONTINDEX="$1"
sub_args+=("$1")
shift
;;
-k|--keepOut)
KEEPOUT=1
sub_args+=("$1")
shift
shift
;;
--blastFull)
BLASTFULL="$2"
sub_args+=("$1")
shift
;;
--task)
TASK="$2"
sub_args+=("$1")
sub_args+=("$2")
shift
shift
;;
--evalue)
EVALUE="$2"
sub_args+=("$1")
sub_args+=("$2")
shift
shift
;;
--outFmt)
OUTFMT="$2"
sub_args+=("$1")
sub_args+=("$2")
shift
shift
;;
--numHits)
NUMHITS="$2"
sub_args+=("$1")
sub_args+=("$2")
shift
shift
;;
--numHsps)
NUMHSPS="$2"
sub_args+=("$1")
sub_args+=("$2")
shift
shift
;;
--goodHit)
GOODHIT="$2"
sub_args+=("$1")
sub_args+=("$2")
shift
shift
;;
--orfSize)
ORFSIZE="$2"
sub_args+=("$1")
sub_args+=("$2")
shift
shift
;;
-h|--help)
python $BLASTSCRIPT -h
echo '--time the amount of time to give jobs submitted to slurm.'
echo '--mem the amount of memory to allocate for jobs submitted to slurm.'
shift
shift
exit 1
;;
--time)
time="$2"
shift
shift
;;
--mem)
mem="$2"
shift
shift
;;
*)
POSITIONAL+=("$1")
shift
;;
esac
done
if [ "$OUTFMT" = "" ]; then
OUTFMT=5
fi
if [ -z "$TEMP" ]; then
TEMP=$DEFAULT_TEMP
fi
# Read all of the command-line arguments into a variable
# Split the query file into multiple temporary files for blasting
if [ "$QUERY" ]; then
srun $SPLIT_SCRIPT -q $(pwd)/$QUERY -t "$workign_dir$TEMP" --numProcs $NUMPROCS
else
srun echo "Fasta query file must be provided for script to execute."
exit 1
fi
# Get the number of files created by split_fastas
num_files= ls "$working_dir/$TEMP" | wc -l
output=0
# Call split_blast on the rest of the files in the directory
# with the args passed in
jobnumber=()
sub_args=($(echo "${sub_args[@]}" |tr ' ' '\n' | uniq | tr '\n' ' '))
shopt -s nullglob
for file in "$TEMP"/*
do
# Create a file to run the blast, save its jobnumber
echo '#!/bin/sh' >> "$file.sh"
echo '#SBATCH --time='$time >> "$file.sh"
echo '#SBATCH --mem='$mem >> "$file.sh"
echo '#SBATCH --output=pyoutput' >> $file.sh
# We don't want to recreate the database for each blast, so only do it on the first
if [[ -z "$jobnumber" ]] ; then
echo ${sub_args[@]}
echo module load python >> "$file.sh"
echo module load anaconda >> "$file.sh"
echo module load blast+/2.7.1 >> "$file.sh"
echo python $MASTER_BLASTER_PATH/$BLASTSCRIPT -q $file ${sub_args[@]} >> "$file.sh"
else
# only depend on the first job, the one that created the db
echo "#SBATCH --dependency=afterok"${jobnumber[0]} >> "$file.sh"
echo module load python >> "$file.sh"
echo module load anaconda >> "$file.sh"
echo module load blast+/2.7.1 >> "$file.sh"
echo python $MASTER_BLASTER_PATH/$BLASTSCRIPT -q $file ${sub_args[@]} --dontIndex >> "$file.sh"
fi
output=$( sbatch "$file.sh" )
echo $output
jobnumber+=(:"$( echo $output | cut -d ' ' -f 4 )")
done
# Combine files after the last blast has been completed
query_no_path=$(echo "$QUERY" | rev | cut -d '/' -f 1 | rev | cut -d '.' -f 1 )
echo "$query_no_path"
all_jobs=$(echo "${jobnumber[@]}" | tr -d '[:space:]')
sbatch --dependency=afterok$all_jobs $MASTER_BLASTER_PATH/$combine_file -t $TEMP $KEEPOUT "$query_no_path"