Mercurial > repos > pjbriggs > pal_finder
comparison pal_finder_wrapper_utils.sh @ 8:4e625d3672ba draft
Pal_finder tool version 0.02.04.7: add detection/reporting of bad ranges; enable subset of reads to be used; check n-mers.
author | pjbriggs |
---|---|
date | Wed, 16 May 2018 07:39:16 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7:5e133b7b79a6 | 8:4e625d3672ba |
---|---|
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 outfile=$2 | |
42 local pattern="^(SEQUENCE_ID|PRIMER_PRODUCT_SIZE_RANGE)" | |
43 for line in $(grep -E "$pattern" $pr3in | sed 's/ /^/' | sed 'N;s/\n/*/') | |
44 do | |
45 # Loop over pairs of SEQUENCE_ID and PRIMER_PRODUCT_SIZE_RANGE | |
46 # keywords in the primer3 input | |
47 if [ ! -z "$(echo $line | grep ^SEQUENCE_ID)" ] ; then | |
48 # Lines look like: | |
49 # SEQUENCE_ID=(AT_1_16)(AT_1_16)M00879:99:000000000-AH9KG:1:2107:10006:2535*PRIMER_PRODUCT_SIZE_RANGE=194-329^59-194 | |
50 local size_range=$(echo $line | cut -d'*' -f2 | cut -d'=' -f2 | tr '^' ' ') | |
51 local seq_id=$(echo $line | cut -d'*' -f1 | cut -d'=' -f2) | |
52 elif [ ! -z "$(echo $line | grep ^PRIMER_PRODUCT_SIZE_RANGE)" ] ; then | |
53 # Lines look like: | |
54 # PRIMER_PRODUCT_SIZE_RANGE=194-329^59-194*SEQUENCE_ID=(AT_1_16)(AT_1_16)M00879:99:000000000-AH9KG:1:2107:10006:2535 | |
55 local size_range=$(echo $line | cut -d'*' -f1 | cut -d'=' -f2 | tr '^' ' ') | |
56 local seq_id=$(echo $line | cut -d'*' -f2 | cut -d'=' -f2) | |
57 fi | |
58 seq_id=$(echo $seq_id | cut -d')' -f3) | |
59 # Check the upper and lower limits in each range | |
60 # to see if it's okay | |
61 local bad_range= | |
62 for range in $(echo $size_range) ; do | |
63 local lower=$(echo $range | cut -d'-' -f1) | |
64 local upper=$(echo $range | cut -d'-' -f2) | |
65 if [ "$lower" -gt "$upper" ] ; then | |
66 bad_range=yes | |
67 break | |
68 fi | |
69 done | |
70 # Report if the range is wrong | |
71 if [ ! -z "$bad_range" ] ; then | |
72 echo "${seq_id}"$'\t'"(${size_range})" >>$outfile | |
73 fi | |
74 done | |
75 } |