-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsequence_accessories
More file actions
executable file
·413 lines (401 loc) · 15 KB
/
sequence_accessories
File metadata and controls
executable file
·413 lines (401 loc) · 15 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#!/bin/bash
set -eo pipefail
# Usage message
function Usage() {
echo -e "\
Usage: $(basename $0) <accessory> \n\
Where: <accessory> is one of: \n\
ListGenerator \n\
SummarizeStats \n\
DumpFastq \n\
SRADownloader \n\
MergeBAM \n\
SimpleCoverage \n\
AddBAMLane \n\
FreeBayes_SNP_Calls \n\
SubsampleFastq \n\
UG100_filter \n\ PanDepthCoverage \" >&2
exit 1
}
# Export the function
export -f Usage
# A function to say invalid argument
function invalid() {
local arg="$1"
echo -e "\nParameter error: ${arg%=*} not recognized\n" >&2
}
# Export the function
export -f invalid
# A function to check a sample list
function checkSampleList() {
local sampleList=$1
[[ -f "${sampleList}" ]] || (echo "Failed to find ${sampleList}, exiting..." >&2; exit 1)
for sample in $(<"${sampleList}")
do
[[ -f "${sample}" ]] || (echo "Failed to find sample ${sample}, exiting..." >&2; exit 1)
done
}
# Export the function
export -f checkSampleList
# A function to check dependencies
function checkDependency() {
local dependency=$1
$(command -v ${dependency} > /dev/null 2> /dev/null) || ( echo "Failed to find ${dependency}, exiting..." >&2; exit 1)
}
# Export the function
export -f checkDependency
# Some checks
SEQ_ACC=$(pwd -P)
ACC_DIR="${SEQ_ACC}/Accessories"
[[ -d "${ACC_DIR}" ]] || (echo "Cannot find the Accessories! Please leave this script in the 'sequence_accessories' directory" >&2; exit 1)
# Figure out which accessory we're working with and remove it from the argument list
[[ "$#" -lt 1 ]] && Usage
ACCESSORY="$1"
shift
# Run sequence_accessories
case "${ACCESSORY}" in
ListGenerator)
echo "$(basename $0): Creating a sample list..." >&2
echo "ListGenerator is not yet ready, exiting..." >&2; exit 8
source "${ACC_DIR}/ListGenerator.sh"
# Check dependencies
for prog in "${list_deps[@]}"; do checkDependency "${prog}"; done
# Check to make sure we have arguments
[[ "$#" -lt 1 ]] && ListUsage
# Parse arguments
for arg in "$@"; do
case "${arg}" in
--sample-directory=*)
DIRECTORY="${arg#*=}"
shift
;;
--output-list=*)
OUTPUT_LIST="${arg#*=}"
shift
;;
--extension=*)
EXTENSION="${arg#*=}"
shift
;;
--append-list=*)
APPEND_LIST="${ARG#*=}"
shift
;;
--follow-tree)
FOLLOW=true
shift
;;
*)
ListUsage
;;
esac
done
# Validate arguments
# ([ -z "${OUTPUT_LIST+zzz}" ] || [ -z "${APPEND+zzz}" ]) || (echo "Cannot add and append, please choose one or the other" >&2; exit 1)
if ! ([ -z "${OUTPUT_LIST}" ] || [ -z "${APPEND_LIST}" ]); then
# If we were given OUTPUT_LIST and APPEND_LIST
echo "Cannot add and append, please choose one or the other" >&2
exit 1 # That's not allowed
elif ([ -z "${OUTPUT_LIST}" ] && ! [ -z "${APPEND_LIST}" ]); then
# If we have OUTPUT_LIST instead of APPEND_LIST, use APPEND_LIST and append
MY_LIST="${APPEND_LIST}"; APPEND=true
elif (! [ -z "${OUTPUT_LIST}" ] && [ -z "${APPEND_LIST}" ]); then
# If we have OUTPUT_LIST instead of APPEND_LIST, use OUTPUT_LIST and don't append
MY_LIST="${OUTPUT_LIST}"; APPEND=false
else
# If we have neither OUTPUT_LIST nor APPEND_LIST, use OUT_DEFAULT and don't append
MY_LIST="${OUT_DEFAULT}"; APPEND=false
fi
;;
SummarizeStats)
echo "$(basename $0): Generating summary statistics..." >&2
source "${ACC_DIR}/SummarizeStats.sh"
# Check our dependencies for SummarizeStats
for prog in "${idx_deps[@]}"; do checkDependency "${prog}"; done
# Check to make sure we have arguments for SummarizeStats
[[ "$#" -lt 1 ]] && idxUsage # If not, exit with usage message
# Parse arguments
for arg in "$@" # For every argument in our argument list
do
case "${arg}" in # Use a case statment to figure out what argument we have
# Use the #*= do delete everything up to and including the '=' from the argument (arg value)
# Use the %=* to delete everything beyond the '=' from the argument (arg param)
--sample-list=*) # Sample list
SAMPLE_LIST="${arg#*=}"
shift
;;
--project=*)
PROJECT="${arg#*=}"
shift
;;
*)
invalid "${arg}"; idxUsage
;;
esac
done
# Set a default project parameter
[[ -z "${PROJECT}" ]] && PROJECT="${PROJECT_DEFAULT}"
# Validate our sample list
checkSampleList "${SAMPLE_LIST}"
# Run SummarizeStats
SummarizeStats "${SAMPLE_LIST}" "${PROJECT}"
;;
DumpFastq)
echo "$(basename $0): Dumping SRA files to FastQ files..." >&2
source "${ACC_DIR}/DumpFastq.sh"
# Check our dependencies for DumpFastq
for prog in "${dump_deps[@]}"; do checkDependency "${prog}"; done
# Check to make sure we have arguments for DumpFastq
[[ "$#" -lt 1 ]] && dumpUsage # If not, exit with usage message
# Parse arguments
for arg in "$@"
do
case "${arg}" in
--sample-list=*)
SAMPLE_LIST="${arg#*=}"
shift
;;
--outdirectory=*)
OUTDIRECTORY="${arg#*=}"
shift
;;
--paired)
PAIRED=true
;;
*)
invalid "${arg}"; dumpUsage
;;
esac
done
# Set defaults
[[ -z "${PAIRED}" ]] && PAIRED=false # Assume not paired if not specified on the command line
[[ -z "${OUTDIRECTORY}" ]] && OUTDIRECTORY="${OUTPUT_DEFAULT}"
# Validate our sample list
checkSampleList "${SAMPLE_LIST}"
# Run DumpFastq
DumpFastq "${SAMPLE_LIST}" "${OUTDIRECTORY}" "${PAIRED}"
;;
SRADownloader)
echo "$(basename $0): Downloading from the SRA..." >&2
source "${ACC_DIR}/SRADownloader.sh"
# Check our dependencies for SRADownloader
for prog in "${sra_deps[@]}"; do checkDependency "${prog}"; done
# Check to make sure we have arguments for SRADownloader
[[ "$#" -lt 1 ]] && SRAUsage
# Parse arguments
for arg in "$@"
do
case "${arg}" in
--sample-list=*)
SAMPLE_LIST="${arg#*=}"
shift
;;
--sample-type=*)
TYPE="${arg#*=}"
shift
;;
--outdirectory=*)
OUTDIRECTORY="${arg#*=}"
shift
;;
--validate)
VALIDATE=true
shift
;;
*)
invalid "${arg}"; SRAUsage
;;
esac
done
# Set some defaults
[[ "${VALIDATE}" ]] && checkDependency vdb-validate || VALIDATE=false
[[ -z "${OUTDIRECTORY}" ]] && OUTDIRECTORY="${OUTPUT_DEFAULT}"
[[ -z "${TYPE}" ]] && (echo "Missing --sample-type, please choose from: ${SRATYPES[*]}"; exit 1)
# Check our inputs
valid_type=false
for sra_type in "${SRATYPES[@]}"; do
if [[ "${sra_type}" == "${TYPE}" ]]; then
valid_type=true
break
fi
done
[[ "${valid_type}" == true ]] || (echo -e "\nInvalid type: ${TYPE}\nChoose from: ${SRATYPES[*]}\n" >&2; exit 1)
[[ -f "${SAMPLE_LIST}" ]] || (echo "Failed to find ${SAMPLE_LIST}, exiting..."; exit 1)
# Run SRADownloader
SRADownloader "${SAMPLE_LIST}" "${TYPE}" "${OUTDIRECTORY}" "${VALIDATE}"
;;
MergeBAM)
echo "$(basename $0): Merging BAM files..." >&2
source "${ACC_DIR}/MergeBAM.sh"
# Check our dependencies for MergeBAM
for prog in "${merge_deps[@]}"; do checkDependency "${prog}"; done
# Check to make sure we have arguments for MergeBAM
[[ "$#" -lt 1 ]] && MergeUsage
for arg in "$@"
do
case "${arg}" in
--sample-list=*)
SAMPLE_LIST="${arg#*=}"
shift
;;
--name-table=*)
TABLE="${arg#*=}"
shift
;;
--outdirectory=*#)
OUTDIRECTORY="${arg#*=}"
shift
;;
*)
invalid "${arg}"; MergeUsage
;;
esac
done
# Set some defaults
[[ -z "${OUTDIRECTORY}" ]] && OUTDIRECTORY="${OUT_DEFAULT}"
# Check our inputs
checkSampleList "${SAMPLE_LIST}"
[[ -f "${TABLE}" ]] || (echo "Cannot find ${TABLE}, exiting..." >&2; exit 1)
# Make our output directory
mkdir -p "${OUTDIRECTORY}"
# Read our sample names into an associative array
declare -A SAMPLE_NAMES
while read LINE
do
# Get the first value (merged sample name) from the list
# Convert any spaces on this line to single spaces
# Then condense all repeated spaces to a single space
NAME=$(echo "${LINE}" | tr '[:space:]' ' ' | tr -s ' '| cut -f 1 -d ' ')
# If the first value starts with a '#', skip the rest of the line
[[ "${NAME:0:1}" == '#' ]] && continue
# Make the name the key in our associative array, with the value being a all the old names
SAMPLE_NAMES["${NAME}"]="$(echo ${LINE} | tr '[:space:]' ${SAMPLE_DELIMITER} | cut -f 2- -d ${SAMPLE_DELIMITER})"
done < "${TABLE}"
parallel --verbose --xapply "MergeBAM ${SAMPLE_LIST} {1} ${OUTDIRECTORY} {2}" ::: "${!SAMPLE_NAMES[@]}" ::: "${SAMPLE_NAMES[@]}"
;;
SimpleCoverage)
echo "$(basename $0): Calculating simple coverage estimations..." >&2
source "${ACC_DIR}/SimpleCoverage.sh"
# Check our dependencies
for prog in "${cov_deps[@]}"; do checkDependency "${prog}"; done
# Check to make sure we have arguments for SimpleCoverage
[[ "$#" -lt 1 ]] && covUsage
# Parse arguments
for arg in "$@"; do
case "${arg}" in
--sample-list=*)
SAMPLE_LIST="${arg#*=}"
shift
;;
--genome-size=*)
TARGET="${arg#*=}"
shift
;;
--outdirectory=*)
OUTDIRECTORY="${arg#*=}"
shift
;;
--project=*)
PROJECT="${arg#=*}"
shift
;;
*)
invalid "${arg}"; covUsage
;;
esac
done
# Set some defaults
[[ -z "${OUTDIRECTORY}" ]] && OUTDIRECTORY="${OUTPUT_DEFAULT}"
[[ -z "${PROJECT}" ]] && PROJECT="${PROJECT_DEFAULT}"
# Check our arguments
checkSampleList "${SAMPLE_LIST}"
# isInteger "${TARGET}"
# Make our output directory
mkdir -p "${OUTDIRECTORY}"
SimpleCoverage "${SAMPLE_LIST}" "${OUTDIRECTORY}" "${PROJECT}" "${TARGET}"
;;
AddBAMLane)
echo "$(basename $0): Running AddBAMLane..." >&2
bash "${ACC_DIR}/AddBAMLane.sh" "$@"
;;
FreeBayes_SNP_Calls)
echo "$(basename $0): Running FreeBayes_SNP_Calls..." >&2
bash "${ACC_DIR}/FreeBayes_SNP_Calls.sh" "$@"
;;
SubsampleFastq)
echo "$(basename $0): Running SubsampleFastq..." >&2
bash "${ACC_DIR}/SubsampleFastq.sh" "$@"
;;
UG100_filter)
echo "$(basename $0): Running UG100_filter..." >&2
bash "${ACC_DIR}/UG100_filter.sh" "$@"
;;
PanDepthCoverage)
echo "$(basename $0): Calculating coverage with PanDepth..." >&2
source "${ACC_DIR}/PanDepthCoverage.sh"
# Check dependencies
for prog in "${pandepth_deps[@]}"; do checkDependency "${prog}"; done
# Check for required arguments
[[ "$#" -lt 1 ]] && pandepthUsage
# Parse arguments
GFF=''; BED=''; WINDOW=''; MIN_MAPQ=''; PD_THREADS=''
for arg in "$@"; do
case "${arg}" in
--sample-list=*)
SAMPLE_LIST="${arg#*=}"
shift
;;
--gff=*)
GFF="${arg#*=}"
shift
;;
--bed=*)
BED="${arg#*=}"
shift
;;
--window-size=*)
WINDOW="${arg#*=}"
shift
;;
--feature=*)
FEATURE="${arg#*=}"
shift
;;
--min-mapq=*)
MIN_MAPQ="${arg#*=}"
shift
;;
--threads=*)
PD_THREADS="${arg#*=}"
shift
;;
--outdirectory=*)
OUTDIRECTORY="${arg#*=}"
shift
;;
--project=*)
PROJECT="${arg#*=}"
shift
;;
*)
invalid "${arg}"; pandepthUsage
;;
esac
done
# Set defaults
[[ -z "${OUTDIRECTORY:-}" ]] && OUTDIRECTORY="${OUTPUT_DEFAULT}"
[[ -z "${PROJECT:-}" ]] && PROJECT="${PROJECT_DEFAULT}"
[[ -z "${FEATURE:-}" ]] && FEATURE="${FEATURE_DEFAULT}"
[[ -z "${MIN_MAPQ:-}" ]] && MIN_MAPQ='0'
[[ -z "${PD_THREADS:-}" ]] && PD_THREADS="${THREADS_DEFAULT}"
# Validate target mode
validateTargetMode "${GFF}" "${BED}" "${WINDOW}"
# Validate sample list
checkSampleList "${SAMPLE_LIST}"
# Run PanDepthCoverage
PanDepthCoverage "${SAMPLE_LIST}" "${OUTDIRECTORY}" "${PROJECT}" "${GFF}" "${BED}" "${WINDOW}" "${FEATURE}" "${MIN_MAPQ}" "${PD_THREADS}"
;;
* )
Usage
;;
esac