faylward / viralrecall

Detection of NCLDV signatures in 'omic data
30 stars 11 forks source link

Run from any directory #10

Open alephreish opened 2 years ago

alephreish commented 2 years ago

It's not an issue, but I just wanted to share an experience of making viralrecall run from any directory. The solution is straightforward and consists of having one additional wrapper script that converts relative paths to the input and the project into absolute ones and launches viralrecall.py from its location, e.g. /opt/viralrecall/:

$ cat /opt/viralrecall/viralrecall
#!/bin/bash

SCRIPT_DIR="$( cd "$( dirname "$( realpath "${BASH_SOURCE[0]}" )" )" &> /dev/null && pwd )"

args=()
while test $# -gt 0; do
    arg=$1
    args+=("$arg")
    case "$arg" in
        -i|--input|-p|--project)
            args+=("$(realpath -ms "$2")")
            shift
        ;;
    esac
    shift
done

cd "$SCRIPT_DIR"
python viralrecall.py "${args[@]}"

The wrapper can be soft-linked to a location on the PATH, and then viralrecall can be run intuitively as:

cd path/to/my/inputs/
viralrecall -i input.fasta -p project

One small problem is that viralrecall.py writes two files in the directory where it resides - err.txt and out.txt. To prevent this from happening in directories that are not supposed to have write permissions for regular users (and running viralrecall on different inputs compromises these files either way), they can be redirected preemptively to /dev/null:

$ readlink -f /opt/viralrecall/{out,err}.txt
/dev/null
/dev/null

although of course a more elegant solution would be to modify viralrecall.py to make it write those files relative to project.

faylward commented 2 years ago

Thanks for sharing! I will leave this open in case it can be useful for anyone else.