-
Notifications
You must be signed in to change notification settings - Fork 10
/
utils.sh
59 lines (52 loc) · 1.59 KB
/
utils.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# ----------------------------------------------------------------------------
# Copyright (c) 2015--, The WGS-HGT Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
# ----------------------------------------------------------------------------
# usage: contains multiple functions used by other scripts
# get command-line arguments
function get_args() {
# convert arguments to --long-options
# (e.g., input_file => --input-file)
arg_str=$(IFS=,; echo "${args[*]/%/:}" | tr '_' '-')
# use GNU getopt to retrieve arguments
TEMP=`getopt -o "" -l "${arg_str}" -n "$0" -- "$@"`
eval set -- "$TEMP"
while true
do
case "$1" in
# convert --long-options back to variable_name
--?*) eval $(echo ${1:2} | tr '-' '_')=$2 ; shift 2 ;;
--) shift ; break ;;
*) echo "Internal error!" ; exit 1 ;;
esac
done
# manipulate arguments
for arg in ${args[@]}
do
# set undefined arguments to None
if [ -z "${!arg+x}" ]
then
eval $(echo $arg)=None
# convert files and directories to full paths
elif [[ "$arg" == *_fp || "$arg" == *_dir ]]
then
eval $(echo $arg)=$(readlink -m ${!arg})
fi
done
}
# launch job
function submit_job {
cmd=$1
tool=$2
if [ "${qsub_env}" == "true" ]
then
echo "source ${bash_config}; \
${cmd}" | qsub $qsub -N run_$tool; sleep 2
else
echo "${cmd}"
fi
}