Mercurial > repos > pjbriggs > pal_finder
annotate pal_finder_wrapper.sh @ 1:288a74cd7a8d draft
Explicitly build and use perl 5.16.3 as a tool dependency.
| author | pjbriggs |
|---|---|
| date | Mon, 16 Mar 2015 12:23:20 -0400 |
| parents | 1dac42bb7aab |
| children | 1cea7b4b838f |
| rev | line source |
|---|---|
| 0 | 1 #!/bin/sh |
| 2 # | |
| 3 # pal_finder_wrapper.sh: run pal_finder perl script as a Galaxy tool | |
| 4 # | |
| 5 # Usage: run_palfinder.sh FASTQ_R1 FASTQ_R2 MICROSAT_SUMMARY PAL_SUMMARY FILTERED_MICROSATS [OPTIONS] | |
| 6 # run_palfinder.sh --454 FASTA MICROSAT_SUMMARY PAL_SUMMARY [OPTIONS] | |
| 7 # | |
| 8 # Options: | |
| 9 # | |
| 10 # --primer-prefix PREFIX: prefix added to the beginning of all primer names (prPrefixName) | |
| 11 # --2merMinReps N: miniumum number of 2-mer repeat units to detect (0=ignore units of this size) | |
| 12 # --3merMinReps N | |
| 13 # --4merMinReps N | |
| 14 # --5merMinReps N | |
| 15 # --6merMinReps N | |
| 16 # --primer-mispriming-library FASTA: specify a Fasta file with sequences to avoid amplifying | |
| 17 # --primer-opt-size VALUE: optimum primer length | |
| 18 # --primer-min-size VALUE: minimum acceptable primer length | |
| 19 # --primer-max-size VALUE: maximum acceptable primer length | |
| 20 # --primer-min-gc VALUE: minimum allowable percentage of Gs and Cs in any primer | |
| 21 # --primer-max-gc VALUE: maximum allowable percentage of Gs and Cs | |
| 22 # --primer-gc-clamp VALUE: number of consecutive Gs and Cs at 3' end of both left and right primer | |
| 23 # --primer-max-end-gc VALUE: max number of Gs or Cs in last five 3' bases of left or right primer | |
| 24 # --primer-min-tm VALUE: minimum acceptable melting temperature (Celsius) for a primer oligo | |
| 25 # --primer-max-tm VALUE: maximum acceptable melting temperature (Celsius) | |
| 26 # --primer-opt-tm VALUE: optimum melting temperature (Celsius) | |
| 27 # --primer-pair-max-diff-tm VALUE: max difference between melting temps of left & right primers | |
| 28 # --output_config_file FNAME: write a copy of the config.txt file to FNAME | |
| 29 # --filter_microsats FNAME: run Graeme Fox's Perl script to filter and sort the | |
| 30 # microsatellites from pal_finder and write to FNAME | |
| 31 # | |
| 32 # pal_finder is available from http://sourceforge.net/projects/palfinder/ | |
| 33 # | |
| 34 # primer3 is available from http://primer3.sourceforge.net/releases.php | |
| 35 # (nb needs version 2.0.0-alpha) | |
| 36 # | |
| 37 # Explicitly set the locations of the pal_finder script, data files and the primer3 | |
| 38 # executable by setting the following variables in the environment: | |
| 39 # | |
| 40 # * PALFINDER_SCRIPT_DIR: location of the pal_finder Perl script (defaults to | |
| 41 # /usr/bin) | |
| 42 # * PALFINDER_DATA_DIR: location of the pal_finder data files (specifically | |
| 43 # config.txt and simple.ref; defaults to /usr/share/pal_finder_v0.02.04) | |
| 44 # * PRIMER3_CORE_EXE: name of the primer3_core program, which should include the | |
| 45 # full path if it's not on the Galaxy user's PATH (defaults to primer3_core) | |
| 46 # | |
|
1
288a74cd7a8d
Explicitly build and use perl 5.16.3 as a tool dependency.
pjbriggs
parents:
0
diff
changeset
|
47 echo "### $(basename $0) ###" |
| 0 | 48 echo $* |
| 49 # | |
| 50 # Initialise locations of scripts, data and executables | |
| 51 # | |
| 52 # Set these in the environment to overide at execution time | |
| 53 : ${PALFINDER_SCRIPT_DIR:=/usr/bin} | |
| 54 : ${PALFINDER_DATA_DIR:=/usr/share/pal_finder_v0.02.04} | |
| 55 : ${PRIMER3_CORE_EXE:=primer3_core} | |
| 56 # | |
| 57 # Filter script is in the same directory as this script | |
| 58 PALFINDER_FILTER_PL=$(dirname $0)/pal_finder_filter.pl | |
| 59 if [ ! -f $PALFINDER_FILTER_PL ] ; then | |
| 60 echo No pal_finder_filter.pl script >&2 | |
| 61 exit 1 | |
| 62 fi | |
| 63 # | |
| 64 # Check that we have all the components | |
| 65 function have_program() { | |
| 66 local program=$1 | |
| 67 local got_program=$(which $program 2>&1 | grep "no $(basename $program) in") | |
| 68 if [ -z "$got_program" ] ; then | |
| 69 echo yes | |
| 70 else | |
| 71 echo no | |
| 72 fi | |
| 73 } | |
| 74 if [ "$(have_program $PRIMER3_CORE_EXE)" == "no" ] ; then | |
| 75 echo "ERROR primer3_core missing: ${PRIMER3_CORE_EXE} not found" >&2 | |
| 76 exit 1 | |
| 77 fi | |
| 78 if [ ! -f "${PALFINDER_DATA_DIR}/config.txt" ] ; then | |
| 79 echo "ERROR pal_finder config.txt not found in ${PALFINDER_DATA_DIR}" >&2 | |
| 80 exit 1 | |
| 81 fi | |
| 82 if [ ! -f "${PALFINDER_SCRIPT_DIR}/pal_finder_v0.02.04.pl" ] ; then | |
| 83 echo "ERROR pal_finder_v0.02.04.pl not found in ${PALFINDER_SCRIPT_DIR}" >&2 | |
| 84 exit 1 | |
| 85 fi | |
| 86 # | |
| 87 # Initialise parameters used in the config.txt file | |
| 88 PRIMER_PREFIX="test" | |
| 89 MIN_2_MER_REPS=6 | |
| 90 MIN_3_MER_REPS=0 | |
| 91 MIN_4_MER_REPS=0 | |
| 92 MIN_5_MER_REPS=0 | |
| 93 MIN_6_MER_REPS=0 | |
| 94 PRIMER_MISPRIMING_LIBRARY=$PALFINDER_DATA_DIR/simple.ref | |
| 95 PRIMER_OPT_SIZE= | |
| 96 PRIMER_MAX_SIZE= | |
| 97 PRIMER_MIN_SIZE= | |
| 98 PRIMER_MAX_GC= | |
| 99 PRIMER_MIN_GC= | |
| 100 PRIMER_GC_CLAMP= | |
| 101 PRIMER_MAX_END_GC= | |
| 102 PRIMER_OPT_TM= | |
| 103 PRIMER_MAX_TM= | |
| 104 PRIMER_MIN_TM= | |
| 105 PRIMER_PAIR_MAX_DIFF_TM= | |
| 106 OUTPUT_CONFIG_FILE= | |
| 107 FILTERED_MICROSATS= | |
| 108 # | |
| 109 # Collect command line arguments | |
| 110 if [ $# -lt 2 ] ; then | |
| 111 echo "Usage: $0 FASTQ_R1 FASTQ_R2 MICROSAT_SUMMARY PAL_SUMMARY [OPTIONS]" | |
| 112 echo " $0 --454 FASTA MICROSAT_SUMMARY PAL_SUMMARY [OPTIONS]" | |
| 113 exit | |
| 114 fi | |
| 115 if [ "$1" == "--454" ] ; then | |
| 116 PLATFORM="454" | |
| 117 FNA=$2 | |
| 118 else | |
| 119 PLATFORM="Illumina" | |
| 120 FASTQ_R1=$1 | |
| 121 FASTQ_R2=$2 | |
| 122 fi | |
| 123 MICROSAT_SUMMARY=$3 | |
| 124 PAL_SUMMARY=$4 | |
| 125 shift; shift; shift; shift | |
| 126 # | |
| 127 # Collect command line options | |
| 128 while [ ! -z "$1" ] ; do | |
| 129 case "$1" in | |
| 130 --primer-prefix) | |
| 131 shift | |
|
1
288a74cd7a8d
Explicitly build and use perl 5.16.3 as a tool dependency.
pjbriggs
parents:
0
diff
changeset
|
132 # Convert spaces to underscores in prefix |
|
288a74cd7a8d
Explicitly build and use perl 5.16.3 as a tool dependency.
pjbriggs
parents:
0
diff
changeset
|
133 PRIMER_PREFIX=$(echo $1 | tr " " "_") |
| 0 | 134 ;; |
| 135 --2merMinReps) | |
| 136 shift | |
| 137 MIN_2_MER_REPS=$1 | |
| 138 ;; | |
| 139 --3merMinReps) | |
| 140 shift | |
| 141 MIN_3_MER_REPS=$1 | |
| 142 ;; | |
| 143 --4merMinReps) | |
| 144 shift | |
| 145 MIN_4_MER_REPS=$1 | |
| 146 ;; | |
| 147 --5merMinReps) | |
| 148 shift | |
| 149 MIN_5_MER_REPS=$1 | |
| 150 ;; | |
| 151 --6merMinReps) | |
| 152 shift | |
| 153 MIN_6_MER_REPS=$1 | |
| 154 ;; | |
| 155 --primer-mispriming-library) | |
| 156 shift | |
| 157 PRIMER_MISPRIMING_LIBRARY=$1 | |
| 158 ;; | |
| 159 --primer-opt-size) | |
| 160 shift | |
| 161 PRIMER_OPT_SIZE=$1 | |
| 162 ;; | |
| 163 --primer-max-size) | |
| 164 shift | |
| 165 PRIMER_MAX_SIZE=$1 | |
| 166 ;; | |
| 167 --primer-min-size) | |
| 168 shift | |
| 169 PRIMER_MIN_SIZE=$1 | |
| 170 ;; | |
| 171 --primer-max-gc) | |
| 172 shift | |
| 173 PRIMER_MAX_GC=$1 | |
| 174 ;; | |
| 175 --primer-min-gc) | |
| 176 shift | |
| 177 PRIMER_MIN_GC=$1 | |
| 178 ;; | |
| 179 --primer-gc-clamp) | |
| 180 shift | |
| 181 PRIMER_GC_CLAMP=$1 | |
| 182 ;; | |
| 183 --primer-max-end-gc) | |
| 184 shift | |
| 185 PRIMER_MAX_END_GC=$1 | |
| 186 ;; | |
| 187 --primer-opt-tm) | |
| 188 shift | |
| 189 PRIMER_OPT_TM=$1 | |
| 190 ;; | |
| 191 --primer-max-tm) | |
| 192 shift | |
| 193 PRIMER_MAX_TM=$1 | |
| 194 ;; | |
| 195 --primer-min-tm) | |
| 196 shift | |
| 197 PRIMER_MIN_TM=$1 | |
| 198 ;; | |
| 199 --primer-pair-max-diff-tm) | |
| 200 shift | |
| 201 PRIMER_PAIR_MAX_DIFF_TM=$1 | |
| 202 ;; | |
| 203 --output_config_file) | |
| 204 shift | |
| 205 OUTPUT_CONFIG_FILE=$1 | |
| 206 ;; | |
| 207 --filter_microsats) | |
| 208 shift | |
| 209 FILTERED_MICROSATS=$1 | |
| 210 ;; | |
| 211 *) | |
| 212 echo Unknown option: $1 >&2 | |
| 213 exit 1 | |
| 214 ;; | |
| 215 esac | |
| 216 shift | |
| 217 done | |
| 218 # | |
| 219 # Check that primer3_core is available | |
| 220 got_primer3=`which $PRIMER3_CORE_EXE 2>&1 | grep -v "no primer3_core in"` | |
| 221 if [ -z "$got_primer3" ] ; then | |
| 222 echo ERROR primer3_core not found >&2 | |
| 223 exit 1 | |
| 224 fi | |
| 225 # | |
| 226 # Set up the working dir | |
| 227 if [ "$PLATFORM" == "Illumina" ] ; then | |
| 228 # Paired end Illumina data as input | |
| 229 if [ $FASTQ_R1 == $FASTQ_R2 ] ; then | |
| 230 echo ERROR R1 and R2 fastqs are the same file >&2 | |
| 231 exit 1 | |
| 232 fi | |
| 233 ln -s $FASTQ_R1 | |
| 234 ln -s $FASTQ_R2 | |
| 235 fastq_r1=$(basename $FASTQ_R1) | |
| 236 fastq_r2=$(basename $FASTQ_R2) | |
| 237 else | |
| 238 # 454 data as input | |
| 239 ln -s $FNA | |
| 240 fna=$(basename $FNA) | |
| 241 fi | |
| 242 ln -s $PRIMER_MISPRIMING_LIBRARY | |
| 243 PRIMER_MISPRIMING_LIBRARY=$(basename $PRIMER_MISPRIMING_LIBRARY) | |
| 244 mkdir Output | |
| 245 # | |
| 246 # Copy in the default config.txt file | |
|
1
288a74cd7a8d
Explicitly build and use perl 5.16.3 as a tool dependency.
pjbriggs
parents:
0
diff
changeset
|
247 echo "### Creating config.txt file for pal_finder run ###" |
| 0 | 248 /bin/cp $PALFINDER_DATA_DIR/config.txt . |
| 249 # | |
| 250 # Update the config.txt file with new values | |
| 251 function set_config_value() { | |
| 252 local key=$1 | |
| 253 local value=$2 | |
| 254 local config_txt=$3 | |
| 255 if [ -z "$value" ] ; then | |
| 256 echo "No value for $key, left as default" | |
| 257 else | |
| 258 echo Setting "$key" to "$value" | |
| 259 sed -i 's,^'"$key"' .*,'"$key"' '"$value"',' $config_txt | |
| 260 fi | |
| 261 } | |
| 262 # Input files | |
| 263 set_config_value platform $PLATFORM config.txt | |
| 264 if [ "$PLATFORM" == "Illumina" ] ; then | |
| 265 set_config_value inputFormat fastq config.txt | |
| 266 set_config_value pairedEnd 1 config.txt | |
| 267 set_config_value inputReadFile $fastq_r1 config.txt | |
| 268 set_config_value pairedReadFile $fastq_r2 config.txt | |
| 269 else | |
| 270 set_config_value inputFormat fasta config.txt | |
| 271 set_config_value pairedEnd 0 config.txt | |
| 272 set_config_value input454reads $fna config.txt | |
| 273 fi | |
| 274 # Output files | |
| 275 set_config_value MicrosatSumOut Output/microsat_summary.txt config.txt | |
| 276 set_config_value PALsummaryOut Output/PAL_summary.txt config.txt | |
| 277 # Microsat info | |
| 278 set_config_value 2merMinReps $MIN_2_MER_REPS config.txt | |
| 279 set_config_value 3merMinReps $MIN_3_MER_REPS config.txt | |
| 280 set_config_value 4merMinReps $MIN_4_MER_REPS config.txt | |
| 281 set_config_value 5merMinReps $MIN_5_MER_REPS config.txt | |
| 282 set_config_value 6merMinReps $MIN_6_MER_REPS config.txt | |
| 283 # Primer3 settings | |
| 284 set_config_value primer3input Output/pr3in.txt config.txt | |
| 285 set_config_value primer3output Output/pr3out.txt config.txt | |
| 286 set_config_value primer3executable $PRIMER3_CORE_EXE config.txt | |
| 287 set_config_value prNamePrefix ${PRIMER_PREFIX}_ config.txt | |
| 288 set_config_value PRIMER_MISPRIMING_LIBRARY "$PRIMER_MISPRIMING_LIBRARY" config.txt | |
| 289 set_config_value PRIMER_OPT_SIZE "$PRIMER_OPT_SIZE" config.txt | |
| 290 set_config_value PRIMER_MIN_SIZE "$PRIMER_MIN_SIZE" config.txt | |
| 291 set_config_value PRIMER_MAX_SIZE "$PRIMER_MAX_SIZE" config.txt | |
| 292 set_config_value PRIMER_MIN_GC "$PRIMER_MIN_GC" config.txt | |
| 293 set_config_value PRIMER_MAX_GC "$PRIMER_MAX_GC" config.txt | |
| 294 set_config_value PRIMER_GC_CLAMP "$PRIMER_GC_CLAMP" config.txt | |
| 295 set_config_value PRIMER_MAX_END_GC "$PRIMER_MAX_END_GC" config.txt | |
| 296 set_config_value PRIMER_MIN_TM "$PRIMER_MIN_TM" config.txt | |
| 297 set_config_value PRIMER_MAX_TM "$PRIMER_MAX_TM" config.txt | |
| 298 set_config_value PRIMER_OPT_TM "$PRIMER_OPT_TM" config.txt | |
| 299 set_config_value PRIMER_PAIR_MAX_DIFF_TM "$PRIMER_PAIR_MAX_DIFF_TM" config.txt | |
| 300 # | |
| 301 # Run pal_finder | |
|
1
288a74cd7a8d
Explicitly build and use perl 5.16.3 as a tool dependency.
pjbriggs
parents:
0
diff
changeset
|
302 echo "### Running pal_finder ###" |
| 0 | 303 perl $PALFINDER_SCRIPT_DIR/pal_finder_v0.02.04.pl config.txt 2>&1 | tee pal_finder.log |
|
1
288a74cd7a8d
Explicitly build and use perl 5.16.3 as a tool dependency.
pjbriggs
parents:
0
diff
changeset
|
304 echo "### pal_finder finised ###" |
| 0 | 305 # |
| 306 # Check that log ends with "Done!!" message | |
| 307 if [ -z "$(tail -n 1 pal_finder.log | grep Done!!)" ] ; then | |
| 308 echo ERROR pal_finder failed to complete successfully >&2 | |
| 309 exit 1 | |
| 310 fi | |
| 311 # | |
| 312 # Run the pal_finder_filter.pl script from Graeme Fox | |
| 313 if [ ! -z "$FILTERED_MICROSATS" ] ; then | |
|
1
288a74cd7a8d
Explicitly build and use perl 5.16.3 as a tool dependency.
pjbriggs
parents:
0
diff
changeset
|
314 echo "### Running filtering script ###" |
| 0 | 315 perl $PALFINDER_FILTER_PL Output/PAL_summary.txt 2>&1 |
| 316 if [ $? -ne 0 ] ; then | |
| 317 echo ERROR pal_finder_filter.pl exited with non-zero status >&2 | |
| 318 exit 1 | |
| 319 elif [ ! -f pal_finder_filter_output.txt ] ; then | |
| 320 echo ERROR no output from pal_finder_filter.pl >&2 | |
| 321 exit 1 | |
| 322 fi | |
| 323 fi | |
| 324 # | |
| 325 # Clean up | |
|
1
288a74cd7a8d
Explicitly build and use perl 5.16.3 as a tool dependency.
pjbriggs
parents:
0
diff
changeset
|
326 echo "### Handling output files ###" |
| 0 | 327 if [ -f Output/microsat_summary.txt ] ; then |
| 328 /bin/mv Output/microsat_summary.txt $MICROSAT_SUMMARY | |
| 329 fi | |
| 330 if [ -f Output/PAL_summary.txt ] ; then | |
| 331 /bin/mv Output/PAL_summary.txt $PAL_SUMMARY | |
| 332 fi | |
| 333 if [ ! -z "$FILTERED_MICROSATS" ] && [ -f pal_finder_filter_output.txt ] ; then | |
| 334 /bin/mv pal_finder_filter_output.txt $FILTERED_MICROSATS | |
| 335 fi | |
| 336 if [ ! -z "$OUTPUT_CONFIG_FILE" ] && [ -f config.txt ] ; then | |
| 337 /bin/mv config.txt $OUTPUT_CONFIG_FILE | |
| 338 fi | |
| 339 ## | |
| 340 # |
