Debian Codegraph @

bin/abyss-dida

raw
1 #!/bin/bash
2 set -eu -o pipefail
3
4 #------------------------------------------------------------
5 # parse command line options
6 #------------------------------------------------------------
7
8 case $1 in
9 --help)
10 cat <<EOF
11 Usage: abyss-dida [OPTION]... QUERY... TARGET
12
13 Options:
14
15 --help this help message
16 -d STRING additional command line opts for DIDA
17 -j number of threads [1]
18 -m path of 'mpirun' executable [mpirun]
19 -n number of ranks in DIDA MPI job [3]
20 -x VAR=value set environment variable for MPI job
21 --version print version info and exit
22
23 Align the sequences of the files QUERY to those of the file
24 TARGET using DIDA.
25 EOF
26 exit
27 ;;
28 --version)
29 cat <<EOF
30 abyss-dida (ABySS)
31 Written by Ben Vandervalk.
32 EOF
33 dida-wrapper --version
34 exit
35 ;;
36 esac
37
38 n=3
39 mpirun=''
40 dida_cmd='dida-wrapper'
41 dida_opt='--no-clean --se'
42 while getopts :d:j:l:m:n:v:x: opt; do
43 case $opt in
44 d) dida_opt="$dida_opt $OPTARG";;
45 j) dida_cmd="$dida_cmd -j$OPTARG";;
46 l) dida_cmd="$dida_cmd -l$OPTARG";;
47 m) mpirun="$OPTARG";;
48 n) n=$OPTARG;;
49 v) ;;
50 x) export "$OPTARG";;
51 \?) echo >&2 "$(basename 0): invalid option: $OPTARG"; exit 1;;
52 esac
53 done
54 dida_cmd="$dida_cmd $dida_opt"
55 shift $((OPTIND-1))
56
57 # dida-wrapper requires n >= 3
58 if [ $n -lt 3 ]; then
59 n = 3
60 fi
61
62 # default mpirun cmd, if none specified
63 if [ -z "$mpirun" ]; then
64 mpirun="mpirun -np $n"
65 fi
66
67 #------------------------------------------------------------
68 # parse command line arguments (query and target files)
69 #------------------------------------------------------------
70
71 # Add file arguments to dida command. Convert all input file paths
72 # to absolute, since we change to a temp dir below
73
74 query=($(echo "$@" | xargs -n1 readlink -f))
75 target=${query[${#query[@]}-1]}
76 unset query[${#query[@]}-1]
77
78 #------------------------------------------------------------
79 # set up and switch to temp sandbox dir
80 #------------------------------------------------------------
81
82 tmpdir=$(mktemp -d --tmpdir=.)
83 pushd $tmpdir > /dev/null
84
85 ln -s "$target"
86 target_link="$(basename $target)"
87
88 #------------------------------------------------------------
89 # run DIDA
90 #------------------------------------------------------------
91
92 dida_cmd="$mpirun /bin/bash -c '$dida_cmd <(abyss-tofastq --interleave ${query[@]}) $target_link'"
93 echo >&2 "$dida_cmd"
94 # tricky: must use eval here to preserve nested quotes
95 # (e.g. quotes in $mpirun command)
96 eval "$dida_cmd"
97
98 du=$(du -hsc * | tail -1 | awk '{print $1}')
99 echo >&2 "dida-wrapper job used $du temp disk space"
100
101 #------------------------------------------------------------
102 # clean up
103 #------------------------------------------------------------
104
105 rm -f *
106 popd > /dev/null
107 rmdir $tmpdir