forked from azroger/cyverse_agave_apps
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfasttree_wrapper.sh
127 lines (98 loc) · 3.23 KB
/
fasttree_wrapper.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# no #!/bin/bash directive
# Constraints:
# * must not use the single word 'c o m m a n d' (no spaces); post-processing substitutes token
# * must not exit(); post-processing statements are inserted
# * must write all output files to "this" directory (no subdirectories)
# * must set executable permissions on any executables copied via iget
# * API does not support output ids
# run a cmd with 'arguments,' 'stdin,' 'stdout,' and 'stderr'
# and other variables passed in from the environment
# module loading is hard-coded here:
# modules should be preloaded
# module load irods
# there is no module for fasttree; it is a binary packaged as part of the deployed zip
# set the default program version
defaultVersion=2.1.4
error() {
echo "$0: $1" >&2
return 1
}
filter() {
# we'll not allow certain characters
# this is not offered as tight security; just a catch on disallowed chars
# must contain at least one of these chars ...
expr "$1" : '.*[[:alnum:]_./=+-].*' >/dev/null || { error "input does not contain a single valid character; job rejected"; return 1; }
# ... and only these chars
expr "$1" : '.*[^[:alnum:][:space:]_./=+-].*' >/dev/null && { error "invalid characters in input; job rejected"; return 1; }
return 0
}
main() {
# tighten the environment
set -f # noglob: no filename expansion
# set the version
if [ -n "${version}" ]
then
filter "${version}" || return 1
version="${version}"
else
version=$defaultVersion
fi
# set the command line
case "$version" in
2.1.4 ) cmd=fasttree ;;
* ) { error "unsupported version: $version"; return 1; } ;;
esac
# set program name
prog=`basename $cmd`
# set the arguments
if [ -n "${arguments}" ]
then
filter "${arguments}" || return 1
arguments="${arguments}"
fi
# insert these options
# should be set as default values in apps.json
#arguments="" # no default arguments
# set the input
if [ -n "${inFasta}" ]
then
filter "${inFasta}" || return 1
# use irods to get the data from the source into "this" staging area;
# file name must start with irods root: e.g., /iplant/home/ or ? /iplant/home/<login>/;
# local copy has appended process id for corner case where input file
# is same name as the output file name
localInput="$(basename ${inFasta})"
# iget -fIT "${inFasta}" "$localInput"
# bail on failure to stage local copy of input file
test -r "$localInput" || { error "Where's the input file?? Job failed!"; return 1; }
stdinStr="$localInput"
else
error "$prog requires an input file; none specified"; return 1
fi
# set the output
# not supported by API; hard-code and coord w/ RDG
outTree=fasttree.nwk
if [ -n "${outTree}" ]
then
filter "${outTree}" || return 1
stdoutStr=">${outTree}"
else
stdoutStr=">$prog.$$.out"
fi
# set the error stream
if [ -n "${stderr}" ]
then
filter "${stderr}" || return 1
stderrStr="2>${stderr}"
else
stderrStr="2>$prog.$$.err"
fi
# set execute permissions because they are lost on staging local executable
chmod a+x $cmd # no glob, so no shell expansion
# echo cmd string to this script's outTree (but not the program's redirection, if any)
set -x # xtrace: print expansions
# execute the cmd
eval $cmd "${model}" $arguments $stdinStr $stdoutStr $stderrStr
return $?
}
main