-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuab_ngs_functions_v1.sh
107 lines (93 loc) · 2.38 KB
/
uab_ngs_functions_v1.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
#
# shared subroutine used by the qsub_* scripts in these subdirectories
#
# put positional params in vars specified in CMD_LINE_PARAM_LIST
cmd_line_params () {
for myvar in $CMD_LINE_PARAM_LIST ; do
eval $myvar=$1
export $myvar
echo -n "${myvar}="; eval echo \$$myvar
shift
done
return 0
}
print_cmd_line_params () {
for myvar in $CMD_LINE_PARAM_LIST; do
echo -n "$myvar="; eval echo \$$myvar
done
return 0
}
print_derived_params () {
for myvar in $DERIVED_VAR_LIST; do
echo -n "$myvar="; eval echo \$$myvar
done
return 0
}
# UTIL function
# exit from a qsub script adds unprintable chars to output
# send those chars to /dev/null
qsub_exit () { # ARGS: rc
RC=$1
exit $RC 2>&1 > /dev/null
return 0
}
run_cmd () { # ARGS: stdout_dest_or_- cmd [args]
TMPSTD=$1; shift # redirect for stdout
TMPERR=`mktemp`
if [[ -z "$TMPSTD" || "-" == "$TMPSTD" ]]; then
# stdout to stdout
echo "# CMD: $*"
eval $* 2>$TMPERR
else
# stdout to file
echo "# CMD: $* 1>$TMPSTD"
eval $* 2>$TMPERR 1>$TMPSTD
fi
RC=$?
if [ $RC != 0 ]; then
echo "ERROR: $*"
echo "ERROR: "`cat $TMPERR`
qsub_exit 1
fi
return $RC
}
#======================================================================
# UTIL FUNCTIONS
#======================================================================
run_step () { # ARGS: sample_name target_file step_name cmd_out cmd [cmd_args]
# args
RS_SAMPLE_NAME=$1; shift 1
RS_TARGET=$1; shift 1
RS_NAME=$1; shift 1
RS_STDOUT=$1; shift 1 # redirect for stdout
# log start/skip
if [[ ( -e "${RS_TARGET}" || -n "$DONE_ONLY" ) && ( -e "${RS_TARGET}.done" ) ]]; then
echo;echo `date`" TS SKIP ${RS_NAME} ${RS_SAMPLE_NAME}";
else
echo;echo `date`" TS START ${RS_NAME} ${RS_SAMPLE_NAME}";
# run the cmd
RS_TMPERR=`mktemp`
if [[ -z "$RS_STDOUT" || "-" == "$RS_STDOUT" ]]; then
# stdout to stdout
echo "# CMD: $*"
$* 2>$RS_TMPERR
else
# stdout to file
echo "# CMD: $* 1>$RS_STDOUT"
$* 2>$RS_TMPERR 1>$RS_STDOUT
fi
# handle errors
RC=$?
if [ $RC != 0 ]; then
echo "ERROR: $*"
echo "ERROR: "`cat $RS_TMPERR`
echo;echo `date`" TS ERROR ${RS_NAME} ${RS_SAMPLE_NAME}"
qsub_exit $RC
fi
# handle success
touch ${RS_TARGET}.done
echo;echo `date`" TS DONE ${RS_NAME} ${RS_SAMPLE_NAME}";
fi
return $RC
}