#!/bin/bash set -eu -o pipefail #------------------------------------------------------------ # parse command line options #------------------------------------------------------------ case $1 in --help) cat <&2 "$(basename 0): invalid option: $OPTARG"; exit 1;; esac done dida_cmd="$dida_cmd $dida_opt" shift $((OPTIND-1)) # dida-wrapper requires n >= 3 if [ $n -lt 3 ]; then n = 3 fi # default mpirun cmd, if none specified if [ -z "$mpirun" ]; then mpirun="mpirun -np $n" fi #------------------------------------------------------------ # parse command line arguments (query and target files) #------------------------------------------------------------ # Add file arguments to dida command. Convert all input file paths # to absolute, since we change to a temp dir below query=($(echo "$@" | xargs -n1 readlink -f)) target=${query[${#query[@]}-1]} unset query[${#query[@]}-1] #------------------------------------------------------------ # set up and switch to temp sandbox dir #------------------------------------------------------------ tmpdir=$(mktemp -d --tmpdir=.) pushd $tmpdir > /dev/null ln -s "$target" target_link="$(basename $target)" #------------------------------------------------------------ # run DIDA #------------------------------------------------------------ dida_cmd="$mpirun /bin/bash -c '$dida_cmd <(abyss-tofastq --interleave ${query[@]}) $target_link'" echo >&2 "$dida_cmd" # tricky: must use eval here to preserve nested quotes # (e.g. quotes in $mpirun command) eval "$dida_cmd" du=$(du -hsc * | tail -1 | awk '{print $1}') echo >&2 "dida-wrapper job used $du temp disk space" #------------------------------------------------------------ # clean up #------------------------------------------------------------ rm -f * popd > /dev/null rmdir $tmpdir