Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run from any directory #10

Open
alephreish opened this issue Oct 27, 2021 · 1 comment
Open

Run from any directory #10

alephreish opened this issue Oct 27, 2021 · 1 comment

Comments

@alephreish
Copy link

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants