-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-pgap
executable file
·195 lines (158 loc) · 4.58 KB
/
run-pgap
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#! /bin/bash
set -e
BACKEND=singularity
# ------------------------------------------------------------------------
OUT_DIR=pgap_out
function usage {
echo 1>&2 "Usage: $0 [options] genome1.fna [...] [-- pgap.py args]"
echo 1>&2 "-O ORGANISM_NAME"
echo 1>&2 "-S STRAIN_NAME (required)"
echo 1>&2 "-U - update PGAP, then exit"
echo 1>&2 "-h - this message"
echo 1>&2 "-k - keep temporary files"
echo 1>&2 "-o OUT_DIR - Output directory [$OUT_DIR]"
echo 1>&2 "-p PGAP_INPUT_DIR - Directory containing PGAP. Will download if not specified."
echo 1>&2 "-s SUBMOL_YAML - submol.yaml to use instead of PGAP generated"
echo 1>&2 "-u - update PGAP before running"
echo 1>&2 ''
echo 1>&2 "Exactly one of '-O', '-U', or '-s' option must be specified"
exit "$@"
}
while getopts 'O:S:V:Uhko:p:s:u' opt ; do
case "$opt" in
O) ORGANISM_NAME="$OPTARG" ;;
S) STRAIN_NAME="$OPTARG" ;;
U) UPDATE_PGAP=1 ; THEN_EXIT=1 ;;
h) DISPLAY_HELP=1 ;;
k) KEEP_FILES=1 ;;
o) OUT_DIR="$OPTARG" ;;
p) PGAP_INPUT_DIR="$OPTARG" ;;
s) SUBMOL_YAML="$OPTARG" ;;
u) UPDATE_PGAP=1 ;;
\?) usage 1 ;;
*) echo "Can't happen" ; exit 1 ;;
esac
done
shift $((OPTIND-1))
if [ "$DISPLAY_HELP" ] ; then
usage
fi
ARG_COUNT=
if [ "$SUBMOD_YAML" ] ; then ARG_COUNT+=1 ; fi
if [ "$ORGANISM_NAME" ] ; then ARG_COUNT+=1 ; fi
if [ "$THEN_EXIT" ] ; then ARG_COUNT+=1 ; fi
if [ "$ARG_COUNT" != 1 ] ; then
echo 1>&2 "Exactly one of '-O', '-U', or '-s' option must be specified"
exit 1
fi
if [ -z "$THEN_EXIT" ] ; then
if [ -z "$1" -o x"$1"x = x--x ] ; then
echo 1>&2 "Missing genome file."
exit 1
fi
fi
# ------------------------------------------------------------------------
function run {
echo 1>&2 + "$@"
"$@"
}
if [ "$PGAP_INPUT_DIR" ] ; then
if [ ! -e "$PGAP_INPUT_DIR" ] ; then
echo 1>&2 "$PGAP_INPUT_DIR does not exist"
exit 1
fi
export PGAP_INPUT_DIR
elif [ -d $HOME/scratch/pgap ] ; then
export PGAP_INPUT_DIR=$HOME/scratch/pgap
else
export PGAP_INPUT_DIR=${OUT_DIR}/pgap_dist
echo "# Downloading PGAP to ${PGAP_INPUT_DIR}"
(
mkdir -p ${PGAP_INPUT_DIR}
run cd ${PGAP_INPUT_DIR}
run wget -q https://github.com/ncbi/pgap/raw/prod/scripts/pgap.py
run chmod +x pgap.py
run ./pgap.py -D ${BACKEND} --update --taxcheck
)
UPDATE_PGAP= # skip updating again
fi
# ------------------------------------------------------------------------
if [ "$UPDATE_PGAP" ] ; then
(
run cd ${PGAP_INPUT_DIR}
run rm -f pgap.py
run wget -q https://github.com/ncbi/pgap/raw/prod/scripts/pgap.py
run chmod +x pgap.py
run ./pgap.py -D ${BACKEND} --update --taxcheck
)
fi
if [ "$THEN_EXIT" ] ; then
exit
fi
# ------------------------------------------------------------------------
TEMP_PATH=$(mktemp -d ${PGAP_INPUT_DIR}/tmp.XXXXXXXX)
TEMP_DIR=$(basename $TEMP_PATH)
mkdir -p ${TEMP_PATH}/input
while [ -n "$1" -a x"$1"x != x--x ] ; do
cat "$1" >> ${TEMP_PATH}/input/genome.fasta
shift 1
done
if [ x"$1"x == x--x ] ; then
shift 1
fi
if [ "$SUBMOL_YAML" ] ; then
cp --archive "$SUBMOL_YAML" ${TEMP_PATH}/input/submol.yaml
else
cat <<EOF > ${TEMP_PATH}/input/submol.yaml
organism:
genus_species: ${ORGANISM_NAME}
EOF
fi
cat <<EOF > ${TEMP_PATH}/input/input.yaml
fasta:
class: File
location: genome.fasta
submol:
class: File
location: submol.yaml
EOF
# ------------------------------------------------------------------------
(
run cd ${PGAP_INPUT_DIR}
ulimit -n 8192
(
set +e # keep going even if pgap.py fails
run ./pgap.py -D ${BACKEND} --output ${TEMP_DIR}/output "$@" \
--report-usage-false --no-internet --taxcheck \
${TEMP_DIR}/input/input.yaml
true # keep going even if pgap.py fails
)
)
# ------------------------------------------------------------------------
if [ ! -e ${TEMP_PATH}/output/annot.gbk ] ; then
echo 2>&1 '# ***********************'
echo 2>&1 '# * !!! PGAP Failed !!! *'
echo 2>&1 '# ***********************'
echo 2>&1 '#'
echo 2>&1 '# Output can be found:' ${TEMP_PATH}/output
if [ -e ${TEMP_PATH}/output/calls.tab ] ; then
echo 2>&1 '# Head of:' ${TEMP_PATH}/output/calls.tab
head ${TEMP_PATH}/output/calls.tab
fi
exit 1
fi
# ------------------------------------------------------------------------
mkdir -p ${OUT_DIR}
cp --archive ${TEMP_PATH}/output/* ${OUT_DIR}
if [ "$SUBMOL_YAML" ] ; then
cp --archive ${TEMP_PATH}/input/*.yaml ${OUT_DIR}
fi
if [ -z "$KEEP_FILES" ] ; then
(
set +e
# set -x
chmod -R u+w ${TEMP_PATH}
rm -rf ${TEMP_PATH}
)
fi
# ------------------------------------------------------------------------