Mercurial > repos > pjbriggs > pal_finder
comparison pal_finder_wrapper.sh @ 9:b3ca3ece8a8b draft
WIP detect/trap "bad primer product range" errors.
author | pjbriggs |
---|---|
date | Fri, 16 Jun 2017 09:12:09 -0400 |
parents | 67ab365c29a7 |
children | 84613d5f1713 |
comparison
equal
deleted
inserted
replaced
8:67ab365c29a7 | 9:b3ca3ece8a8b |
---|---|
51 echo $* | 51 echo $* |
52 # | 52 # |
53 # Maximum size reporting log file contents | 53 # Maximum size reporting log file contents |
54 MAX_LINES=500 | 54 MAX_LINES=500 |
55 # | 55 # |
56 # Get helper functions | |
57 . $(dirname $0)/pal_finder_wrapper_utils.sh | |
58 # | |
56 # Initialise locations of scripts, data and executables | 59 # Initialise locations of scripts, data and executables |
57 # | 60 # |
58 # Set these in the environment to overide at execution time | 61 # Set these in the environment to overide at execution time |
59 : ${PALFINDER_SCRIPT_DIR:=/usr/bin} | 62 : ${PALFINDER_SCRIPT_DIR:=/usr/bin} |
60 : ${PALFINDER_DATA_DIR:=/usr/share/pal_finder_v0.02.04} | 63 : ${PALFINDER_DATA_DIR:=/usr/share/pal_finder_v0.02.04} |
61 : ${PRIMER3_CORE_EXE:=primer3_core} | 64 : ${PRIMER3_CORE_EXE:=primer3_core} |
62 # | 65 # |
63 # Filter script is in the same directory as this script | 66 # Filter script is in the same directory as this script |
64 PALFINDER_FILTER=$(dirname $0)/pal_filter.py | 67 PALFINDER_FILTER=$(dirname $0)/pal_filter.py |
65 if [ ! -f $PALFINDER_FILTER ] ; then | 68 if [ ! -f $PALFINDER_FILTER ] ; then |
66 echo No $PALFINDER_FILTER script >&2 | 69 fatal No $PALFINDER_FILTER script |
67 exit 1 | |
68 fi | 70 fi |
69 # | 71 # |
70 # Check that we have all the components | 72 # Check that we have all the components |
71 function have_program() { | |
72 local program=$1 | |
73 local got_program=$(which $program 2>&1 | grep "no $(basename $program) in") | |
74 if [ -z "$got_program" ] ; then | |
75 echo yes | |
76 else | |
77 echo no | |
78 fi | |
79 } | |
80 if [ "$(have_program $PRIMER3_CORE_EXE)" == "no" ] ; then | 73 if [ "$(have_program $PRIMER3_CORE_EXE)" == "no" ] ; then |
81 echo "ERROR primer3_core missing: ${PRIMER3_CORE_EXE} not found" >&2 | 74 fatal "primer3_core missing: ${PRIMER3_CORE_EXE} not found" |
82 exit 1 | |
83 fi | 75 fi |
84 if [ ! -f "${PALFINDER_DATA_DIR}/config.txt" ] ; then | 76 if [ ! -f "${PALFINDER_DATA_DIR}/config.txt" ] ; then |
85 echo "ERROR pal_finder config.txt not found in ${PALFINDER_DATA_DIR}" >&2 | 77 fatal "pal_finder config.txt not found in ${PALFINDER_DATA_DIR}" |
86 exit 1 | |
87 fi | 78 fi |
88 if [ ! -f "${PALFINDER_SCRIPT_DIR}/pal_finder_v0.02.04.pl" ] ; then | 79 if [ ! -f "${PALFINDER_SCRIPT_DIR}/pal_finder_v0.02.04.pl" ] ; then |
89 echo "ERROR pal_finder_v0.02.04.pl not found in ${PALFINDER_SCRIPT_DIR}" >&2 | 80 fatal "pal_finder_v0.02.04.pl not found in ${PALFINDER_SCRIPT_DIR}" |
90 exit 1 | |
91 fi | 81 fi |
92 # | 82 # |
93 # Initialise parameters used in the config.txt file | 83 # Initialise parameters used in the config.txt file |
94 PRIMER_PREFIX="test" | 84 PRIMER_PREFIX="test" |
95 MIN_2_MER_REPS=6 | 85 MIN_2_MER_REPS=6 |
116 # | 106 # |
117 # Collect command line arguments | 107 # Collect command line arguments |
118 if [ $# -lt 2 ] ; then | 108 if [ $# -lt 2 ] ; then |
119 echo "Usage: $0 FASTQ_R1 FASTQ_R2 MICROSAT_SUMMARY PAL_SUMMARY [OPTIONS]" | 109 echo "Usage: $0 FASTQ_R1 FASTQ_R2 MICROSAT_SUMMARY PAL_SUMMARY [OPTIONS]" |
120 echo " $0 --454 FASTA MICROSAT_SUMMARY PAL_SUMMARY [OPTIONS]" | 110 echo " $0 --454 FASTA MICROSAT_SUMMARY PAL_SUMMARY [OPTIONS]" |
121 exits | 111 fatal "Bad command line" |
122 fi | 112 fi |
123 if [ "$1" == "--454" ] ; then | 113 if [ "$1" == "--454" ] ; then |
124 PLATFORM="454" | 114 PLATFORM="454" |
125 FNA=$2 | 115 FNA=$2 |
126 else | 116 else |
233 done | 223 done |
234 # | 224 # |
235 # Check that primer3_core is available | 225 # Check that primer3_core is available |
236 got_primer3=`which $PRIMER3_CORE_EXE 2>&1 | grep -v "no primer3_core in"` | 226 got_primer3=`which $PRIMER3_CORE_EXE 2>&1 | grep -v "no primer3_core in"` |
237 if [ -z "$got_primer3" ] ; then | 227 if [ -z "$got_primer3" ] ; then |
238 echo ERROR primer3_core not found >&2 | 228 fatal "primer3_core not found" |
239 exit 1 | |
240 fi | 229 fi |
241 # | 230 # |
242 # Set up the working dir | 231 # Set up the working dir |
243 if [ "$PLATFORM" == "Illumina" ] ; then | 232 if [ "$PLATFORM" == "Illumina" ] ; then |
244 # Paired end Illumina data as input | 233 # Paired end Illumina data as input |
245 if [ $FASTQ_R1 == $FASTQ_R2 ] ; then | 234 if [ $FASTQ_R1 == $FASTQ_R2 ] ; then |
246 echo ERROR R1 and R2 fastqs are the same file >&2 | 235 fatal ERROR R1 and R2 fastqs are the same file |
247 exit 1 | |
248 fi | 236 fi |
249 ln -s $FASTQ_R1 | 237 ln -s $FASTQ_R1 |
250 ln -s $FASTQ_R2 | 238 ln -s $FASTQ_R2 |
251 fastq_r1=$(basename $FASTQ_R1) | 239 fastq_r1=$(basename $FASTQ_R1) |
252 fastq_r2=$(basename $FASTQ_R2) | 240 fastq_r2=$(basename $FASTQ_R2) |
262 # Copy in the default config.txt file | 250 # Copy in the default config.txt file |
263 echo "### Creating config.txt file for pal_finder run ###" | 251 echo "### Creating config.txt file for pal_finder run ###" |
264 /bin/cp $PALFINDER_DATA_DIR/config.txt . | 252 /bin/cp $PALFINDER_DATA_DIR/config.txt . |
265 # | 253 # |
266 # Update the config.txt file with new values | 254 # Update the config.txt file with new values |
267 function set_config_value() { | |
268 local key=$1 | |
269 local value=$2 | |
270 local config_txt=$3 | |
271 if [ -z "$value" ] ; then | |
272 echo "No value for $key, left as default" | |
273 else | |
274 echo Setting "$key" to "$value" | |
275 sed -i 's,^'"$key"' .*,'"$key"' '"$value"',' $config_txt | |
276 fi | |
277 } | |
278 # Input files | 255 # Input files |
279 set_config_value platform $PLATFORM config.txt | 256 set_config_value platform $PLATFORM config.txt |
280 if [ "$PLATFORM" == "Illumina" ] ; then | 257 if [ "$PLATFORM" == "Illumina" ] ; then |
281 set_config_value inputFormat fastq config.txt | 258 set_config_value inputFormat fastq config.txt |
282 set_config_value pairedEnd 1 config.txt | 259 set_config_value pairedEnd 1 config.txt |
297 set_config_value 5merMinReps $MIN_5_MER_REPS config.txt | 274 set_config_value 5merMinReps $MIN_5_MER_REPS config.txt |
298 set_config_value 6merMinReps $MIN_6_MER_REPS config.txt | 275 set_config_value 6merMinReps $MIN_6_MER_REPS config.txt |
299 # Primer3 settings | 276 # Primer3 settings |
300 set_config_value primer3input Output/pr3in.txt config.txt | 277 set_config_value primer3input Output/pr3in.txt config.txt |
301 set_config_value primer3output Output/pr3out.txt config.txt | 278 set_config_value primer3output Output/pr3out.txt config.txt |
279 set_config_value keepPrimer3files 1 config.txt | |
302 set_config_value primer3executable $PRIMER3_CORE_EXE config.txt | 280 set_config_value primer3executable $PRIMER3_CORE_EXE config.txt |
303 set_config_value prNamePrefix ${PRIMER_PREFIX}_ config.txt | 281 set_config_value prNamePrefix ${PRIMER_PREFIX}_ config.txt |
304 set_config_value PRIMER_MISPRIMING_LIBRARY "$PRIMER_MISPRIMING_LIBRARY" config.txt | 282 set_config_value PRIMER_MISPRIMING_LIBRARY "$PRIMER_MISPRIMING_LIBRARY" config.txt |
305 set_config_value PRIMER_OPT_SIZE "$PRIMER_OPT_SIZE" config.txt | 283 set_config_value PRIMER_OPT_SIZE "$PRIMER_OPT_SIZE" config.txt |
306 set_config_value PRIMER_MIN_SIZE "$PRIMER_MIN_SIZE" config.txt | 284 set_config_value PRIMER_MIN_SIZE "$PRIMER_MIN_SIZE" config.txt |
327 fi | 305 fi |
328 tail -$MAX_LINES pal_finder.log | 306 tail -$MAX_LINES pal_finder.log |
329 # | 307 # |
330 # Check that log ends with "Done!!" message | 308 # Check that log ends with "Done!!" message |
331 if [ -z "$(tail -n 1 pal_finder.log | grep Done!!)" ] ; then | 309 if [ -z "$(tail -n 1 pal_finder.log | grep Done!!)" ] ; then |
332 echo ERROR pal_finder failed to complete successfully >&2 | 310 fatal ERROR pal_finder failed to complete successfully |
333 exit 1 | 311 fi |
312 echo "### pal_finder finished ###" | |
313 # | |
314 # Check for errors in pal_finder output | |
315 echo "### Checking for errors ###" | |
316 if [ ! -z "$(grep 'primer3_core: Illegal element in PRIMER_PRODUCT_SIZE_RANGE' pal_finder.log)" ] ; then | |
317 echo ERROR primer3 terminated prematurely due to bad product size ranges | |
318 cat >&2 <<EOF | |
319 ERROR primer3 terminated prematurely due to bad product size ranges | |
320 | |
321 Pal_finder generated bad ranges for the following read IDs: | |
322 EOF | |
323 $(find_bad_primer_ranges Output/pr3in.txt) >&2 | |
324 cat >&2 <<EOF | |
325 | |
326 This error can occur when input data contains short R1 reads and has | |
327 has not been properly trimmed and filtered. | |
328 | |
329 EOF | |
330 fatal pal_finder failed to complete successfully | |
331 EOF | |
334 fi | 332 fi |
335 # | 333 # |
336 # Sort outputs into a consistent order regardless of Perl version | 334 # Sort outputs into a consistent order regardless of Perl version |
337 echo "### Sorting outputs ###" | 335 echo "### Sorting outputs ###" |
338 head -1 Output/PAL_summary.txt > Output/PAL_summary.sorted.txt | 336 head -1 Output/PAL_summary.txt > Output/PAL_summary.sorted.txt |
352 echo WARNING output too long, truncated to last $MAX_LINES lines: | 350 echo WARNING output too long, truncated to last $MAX_LINES lines: |
353 echo ... | 351 echo ... |
354 fi | 352 fi |
355 tail -$MAX_LINES pal_filter.log | 353 tail -$MAX_LINES pal_filter.log |
356 if [ $? -ne 0 ] ; then | 354 if [ $? -ne 0 ] ; then |
357 echo ERROR $PALFINDER_FILTER exited with non-zero status >&2 | 355 fatal $PALFINDER_FILTER exited with non-zero status |
358 exit 1 | |
359 elif [ ! -f PAL_summary.filtered ] ; then | 356 elif [ ! -f PAL_summary.filtered ] ; then |
360 echo ERROR no output from $PALFINDER_FILTER >&2 | 357 fatal no output from $PALFINDER_FILTER |
361 exit 1 | |
362 fi | 358 fi |
363 fi | 359 fi |
364 # | 360 # |
365 # Clean up | 361 # Clean up |
366 echo "### Handling output files ###" | 362 echo "### Handling output files ###" |
376 if [ ! -z "$OUTPUT_ASSEMBLY" ] ; then | 372 if [ ! -z "$OUTPUT_ASSEMBLY" ] ; then |
377 assembly=${fastq_r1%.*}_pal_filter_assembly_output.txt | 373 assembly=${fastq_r1%.*}_pal_filter_assembly_output.txt |
378 if [ -f "$assembly" ] ; then | 374 if [ -f "$assembly" ] ; then |
379 /bin/mv $assembly "$OUTPUT_ASSEMBLY" | 375 /bin/mv $assembly "$OUTPUT_ASSEMBLY" |
380 else | 376 else |
381 echo ERROR no assembly output found >&2 | 377 fatal no assembly output found |
382 exit 1 | |
383 fi | 378 fi |
384 fi | 379 fi |
385 if [ ! -z "$OUTPUT_CONFIG_FILE" ] && [ -f config.txt ] ; then | 380 if [ ! -z "$OUTPUT_CONFIG_FILE" ] && [ -f config.txt ] ; then |
386 /bin/mv config.txt $OUTPUT_CONFIG_FILE | 381 /bin/mv config.txt $OUTPUT_CONFIG_FILE |
387 fi | 382 fi |