Debian Codegraph @

bin/abyss-bwasw

raw
1 #!/bin/bash
2 set -eu
3
4 case $1 in
5 --help)
6 cat <<EOF
7 Usage: abyss-bwasw [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-bwasw (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 bwasw='bwa bwasw'
25 bwa_index='bwa index -a bwtsw'
26 while getopts :j:l:v opt; do
27 case $opt in
28 j) bwasw="$bwasw -t$OPTARG";;
29 l) ;;
30 v) ;;
31 \?) echo >&2 "abyss-bwasw: 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 $bwasw $target "${query[@]}"
56 exec abyss-tofastq -i "${query[@]}" \
57 |$bwasw $target - \
58 |awk '
59 BEGIN {
60 OFS = "\t"
61 }
62 /^@/ { print; next }
63 $1 == x { next }
64 { x = $1 }
65 sub("/1$", "", $1) > 0 {
66 $2 = or($2, 0x41)
67 print; next
68 }
69 sub("/[23]$", "", $1) > 0 {
70 $2 = or($2, 0x81)
71 print; next
72 }
73 { print }
74 '