comparison pal_finder_wrapper_utils.sh @ 10:e95e2b7b3c84 draft

Fix previous upload (was missing pal_finder_wrapper_utils.sh file)
author pjbriggs
date Fri, 16 Jun 2017 09:30:37 -0400
parents
children a3af1ff4cad1
comparison
equal deleted inserted replaced
9:b3ca3ece8a8b 10:e95e2b7b3c84
1 #!/bin/bash
2 #
3 # Helper functions for the pal_finder_wrapper.sh script
4 #
5 # Utility function for terminating on fatal error
6 function fatal() {
7 echo "FATAL $@" >&2
8 exit 1
9 }
10 #
11 # Check that specified program is available
12 function have_program() {
13 local program=$1
14 local got_program=$(which $program 2>&1 | grep "no $(basename $program) in")
15 if [ -z "$got_program" ] ; then
16 echo yes
17 else
18 echo no
19 fi
20 }
21 #
22 # Set the value for a parameter in the pal_finder config file
23 function set_config_value() {
24 local key=$1
25 local value=$2
26 local config_txt=$3
27 if [ -z "$value" ] ; then
28 echo "No value for $key, left as default"
29 else
30 echo Setting "$key" to "$value"
31 sed -i 's,^'"$key"' .*,'"$key"' '"$value"',' $config_txt
32 fi
33 }
34 #
35 # Identify 'bad' PRIMER_PRODUCT_SIZE_RANGE from pr3in.txt file
36 function find_bad_primer_ranges() {
37 # Parses a pr3in.txt file from pal_finder and reports
38 # sequence ids where the PRIMER_PRODUCT_SIZE_RANGE has
39 # upper limit which is smaller than lower limit
40 local pr3in=$1
41 local pattern="^(SEQUENCE_ID|PRIMER_PRODUCT_SIZE_RANGE)"
42 for line in $(grep -E "$pattern" $pr3in | sed 's/ /^/' | sed 'N;s/\n/*/')
43 do
44 # Loop over pairs of SEQUENCE_ID and PRIMER_PRODUCT_SIZE_RANGE
45 # keywords in the primer3 input
46 if [ ! -z "$(echo $line | grep ^SEQUENCE_ID)" ] ; then
47 # Extract the values
48 local size_range=$(echo $line | cut -d'*' -f2 | cut -d'=' -f2 | tr '^' ' ')
49 local seq_id=$(echo $line | cut -d'*' -f1 | cut -d'=' -f2)
50 else
51 local size_range=$(echo $line | cut -d'*' -f1 | cut -d'=' -f2)
52 local seq_id=$(echo $line | cut -d'*' -f2 | cut -d'=' -f2)
53 fi
54 seq_id=$(echo $seq_id | cut -d')' -f3)
55 # Check the upper and lower limits in each range
56 # to see if it's okay
57 local bad_range=
58 for range in $(echo $size_range) ; do
59 local lower=$(echo $range | cut -d'-' -f1)
60 local upper=$(echo $range | cut -d'-' -f2)
61 if [ $lower -gt $upper ] ; then
62 bad_range=yes
63 break
64 fi
65 done
66 # Report if the range is wrong
67 if [ ! -z "$bad_range" ] ; then
68 echo "$seq_id ($size_range)"
69 fi
70 done
71 }