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