| 1 |
#!/bin/bash |
| 2 |
set -eu |
| 3 |
|
| 4 |
case $1 in |
| 5 |
--help) |
| 6 |
cat <<EOF |
| 7 |
Usage: abyss-bwa [OPTION]... QUERY... TARGET |
| 8 |
Align the sequences of the files QUERY to those of the file |
| 9 |
TARGET using bwa. |
| 10 |
EOF |
| 11 |
exit |
| 12 |
;; |
| 13 |
--version) |
| 14 |
cat <<EOF |
| 15 |
abyss-bwa (ABySS) |
| 16 |
Written by Shaun Jackman. |
| 17 |
EOF |
| 18 |
bwa 2>&1 |head -n4 |
| 19 |
exit |
| 20 |
;; |
| 21 |
esac |
| 22 |
|
| 23 |
# Parse the command line. |
| 24 |
bwa_aln='bwa aln' |
| 25 |
bwa_index='bwa index -a bwtsw' |
| 26 |
while getopts :j:l:v opt; do |
| 27 |
case $opt in |
| 28 |
j) bwa_aln="$bwa_aln -t$OPTARG";; |
| 29 |
l) ;; |
| 30 |
v) ;; |
| 31 |
\?) echo >&2 "abyss-bwa: invalid option: $OPTARG"; exit 1;; |
| 32 |
esac |
| 33 |
done |
| 34 |
shift $((OPTIND-1)) |
| 35 |
|
| 36 |
query=("$@") |
| 37 |
target=${query[${#query[@]}-1]} |
| 38 |
unset query[${#query[@]}-1] |
| 39 |
index=$target.bwt |
| 40 |
|
| 41 |
# Build the index. |
| 42 |
if [ ! -r $index ]; then |
| 43 |
echo >&2 "Building the index $index..." |
| 44 |
echo >&2 $bwa_index $target $target |
| 45 |
$bwa_index $target $target 1>&2 |
| 46 |
elif [ $index -ot $target ]; then |
| 47 |
echo >&2 "The index $index is stale. Rebuilding the index..." |
| 48 |
echo >&2 $bwa_index $target $target |
| 49 |
$bwa_index $target $target 1>&2 |
| 50 |
else |
| 51 |
echo >&2 "The index $index is up to date." |
| 52 |
fi |
| 53 |
|
| 54 |
# Map the reads. |
| 55 |
echo >&2 $bwa_aln $target "${query[@]}" |
| 56 |
exec abyss-tofastq -i "${query[@]}" \ |
| 57 |
|$bwa_aln $target - \ |
| 58 |
|bwa samse $target - <(abyss-tofastq -i "${query[@]}") |