forked from azroger/cyverse_agave_apps
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclustalw_test.sh
103 lines (81 loc) · 2.76 KB
/
clustalw_test.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
# 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
# the cmd and module loading is hard-coded here:
cmd=clustalw2
prog=`basename $cmd`
# modules should be preloaded
# module load irods
# module load clustalw2/2.1
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 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="-OUTPUT=FASTA -OUTORDER=ALIGNED $arguments"
# set the input
if [ -n "${stdin}" ]
then
filter "${stdin}" || 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/;
# local copy has appended process id for corner case where input file
# is same name as the output file name
localInput="$(basename "${stdin}").$$"
iget -fIT "${stdin}" "$localInput"
# bail on failure to stage local copy of input file
test -r "$localInput" || { error "irods failure: cannot copy input file to staging area; job failed"; return 1; }
stdinStr="-INFILE=$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
stdout=clustalw2.fa
if [ -n "${stdout}" ]
then
filter "${stdout}" || return 1
stdoutStr="-OUTFILE=${stdout} >$prog.$$.out"
else
stdoutStr="-OUTFILE=clustalw2.fa >$prog.$$.out"
fi
# set the error stream
if [ -n "${stderr}" ]
then
filter "${stderr}" || return 1
stderrStr="2>${stderr}"
else
stderrStr="2>$prog.$$.err"
fi
# echo cmd string to this script's stdout (but not the program's redirection, if any)
set -x # xtrace: print expansions
# execute the cmd
eval $cmd $arguments $stdinStr $stdoutStr $stderrStr
return $?
}
main