| 1 | #!/usr/bin/env perl | ||
| 2 | package Bio::AssemblyImprovement::Bin::Abacas; | ||
| 3 | # ABSTRACT: Algorithm Based Automatic Contiguation of Assembled Sequences | ||
| 4 | # PODNAME: abacas.pl | ||
| 5 | |||
| 6 | |||
| 7 | # Copyright (C) 2008-11 Genome Research Limited. All Rights Reserved. | ||
| 8 | # | ||
| 9 | # This program is free software; you can redistribute it and/or | ||
| 10 | # modify it under the terms of the GNU General Public License | ||
| 11 | # as published by the Free Software Foundation; either version 2 | ||
| 12 | # of the License, or (at your option) any later version. | ||
| 13 | #This program is distributed in the hope that it will be useful, | ||
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | # GNU General Public License for more details. | ||
| 17 | # | ||
| 18 | # You should have received a copy of the GNU General Public License | ||
| 19 | # along with this program; if not, write to the Free Software | ||
| 20 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 21 | |||
| 22 | #ABACAS.1.3.2 | ||
| 23 | #-------------------------------- | ||
| 24 | #Please report bugs to: | ||
| 25 | #sa4@sanger.ac.uk & tdo@sanger.ac.uk | ||
| 26 | |||
| 27 | |||
| 28 | use strict; | ||
| 29 | use warnings; | ||
| 30 | use POSIX qw(ceil floor); | ||
| 31 | use Getopt::Std; | ||
| 32 | our $version="1.3.2"; | ||
| 33 | #------------------------------------------------------------------------------- | ||
| 34 | |||
| 35 | if (@ARGV < 1) { usage();} | ||
| 36 | |||
| 37 | my ($help, $reference, $query_file, $choice, $sen, $seed, $mlfas, $fasta_bin, $avoid_Ns, | ||
| 38 | $tbx, $min_id, $min_cov, $diff_cov, $min_len,$add_bin_2ps, $pick_primer, | ||
| 39 | $flank, $chk_uniq,$redoMummer, $is_circular,$escapeToPrimers, $debug, $gaps_2file, $prefix,$optionsLog,$numNs) | ||
| 40 | =checkUserInput( @ARGV ); | ||
| 41 | |||
| 42 | my $ref_inline; | ||
| 43 | if ($escapeToPrimers ==1) | ||
| 44 | { | ||
| 45 | pickPrimers ($reference, $query_file, $flank, $chk_uniq); | ||
| 46 | exit; | ||
| 47 | } | ||
| 48 | #BEGIN | ||
| 49 | #------------------------------------------------------------------------------- | ||
| 50 | print_header(); | ||
| 51 | print $optionsLog; | ||
| 52 | |||
| 53 | $ref_inline = Ref_Inline($reference); | ||
| 54 | #Get length of the reference sequence | ||
| 55 | my $ref_len = length($ref_inline); | ||
| 56 | |||
| 57 | |||
| 58 | ################### | ||
| 59 | # Running MUMmer # | ||
| 60 | ################### | ||
| 61 | my ($path_dir, $run_mum, $path_toPass); | ||
| 62 | if ($debug) | ||
| 63 | { | ||
| 64 | print "the seed is $seed \n"; | ||
| 65 | print "RedoMummer= ",$redoMummer."\n"; | ||
| 66 | } | ||
| 67 | my @do_mum_return; | ||
| 68 | my $mummer_tiling; | ||
| 69 | if ($redoMummer==0) | ||
| 70 | { | ||
| 71 | print "#\tPREPARING DATA FOR $choice \n"; | ||
| 72 | @do_mum_return = doMummer($reference, $query_file, $choice,$sen,$seed,$min_id, $min_cov, $diff_cov,$min_len, $debug, $is_circular) or die "Couldn't run MUMmer\n"; | ||
| 73 | $mummer_tiling = $do_mum_return[0]; | ||
| 74 | $path_dir = $do_mum_return[2]; | ||
| 75 | $path_toPass = $do_mum_return[1]; | ||
| 76 | |||
| 77 | } | ||
| 78 | elsif ($redoMummer ==1) | ||
| 79 | { print "not doing mummer\n"; | ||
| 80 | my @check = checkProg ($choice); | ||
| 81 | $mummer_tiling = '$choice.tiling'; | ||
| 82 | $path_dir = $check[2]; | ||
| 83 | $path_toPass = $check[1]; | ||
| 84 | } | ||
| 85 | else | ||
| 86 | { | ||
| 87 | print "Unknown option for -R\n"; | ||
| 88 | exit; | ||
| 89 | } | ||
| 90 | |||
| 91 | #################################### | ||
| 92 | # Processing tiling output # | ||
| 93 | #################################### | ||
| 94 | if ($debug) { | ||
| 95 | print "Do tiling...\n"; | ||
| 96 | } | ||
| 97 | |||
| 98 | #-------------------------------- | ||
| 99 | |||
| 100 | ################## | ||
| 101 | #Do Tiling | ||
| 102 | #------------------------------------------- | ||
| 103 | doTiling ($mummer_tiling, $path_toPass, $path_dir,$reference, $query_file, $choice, $prefix,$mlfas, $fasta_bin, $avoid_Ns, $ref_len, $gaps_2file, $ref_inline, $add_bin_2ps, $pick_primer, $flank, $chk_uniq, $tbx,$numNs); | ||
| 104 | |||
| 105 | |||
| 106 | |||
| 107 | |||
| 108 | |||
| 109 | ############################################## SUB ROUTINES for CONTIG ORDERING and PRIMER DESIGN ########################################################## | ||
| 110 | # Put in one file for ease of downloading. They could be placed in separate packages. | ||
| 111 | #---------------------------------------------------------------------------------------------------------- | ||
| 112 | #################################Contig ordering ########################################################## | ||
| 113 | ######## | ||
| 114 | |||
| 115 | sub help | ||
| 116 | { | ||
| 117 | |||
| 118 | die <<EOF | ||
| 119 | |||
| 120 | *********************************************************************************** | ||
| 121 | * ABACAS: Algorithm Based Automatic Contiguation of Assembled Sequences * | ||
| 122 | * * | ||
| 123 | * * | ||
| 124 | * Copyright (C) 2008-11 The Wellcome Trust Sanger Institute, Cambridge, UK. * | ||
| 125 | * All Rights Reserved. * | ||
| 126 | * * | ||
| 127 | *********************************************************************************** | ||
| 128 | |||
| 129 | USAGE | ||
| 130 | abacas.pl -r <reference file: single fasta> -q <query sequence file: fasta> -p <nucmer/promer> [OPTIONS] | ||
| 131 | |||
| 132 | -r reference sequence in a single fasta file | ||
| 133 | -q contigs in multi-fasta format | ||
| 134 | -p MUMmer program to use: 'nucmer' or 'promer' | ||
| 135 | OR | ||
| 136 | abacas.pl -r <reference file: single fasta> -q <pseudomolecule/ordered sequence file: fasta> -e | ||
| 137 | OPTIONS | ||
| 138 | -h print usage | ||
| 139 | -d use default nucmer/promer parameters | ||
| 140 | -s int minimum length of exact matching word (nucmer default = 12, promer default = 4) | ||
| 141 | -m print ordered contigs to file in multifasta format | ||
| 142 | -b print contigs in bin to file | ||
| 143 | -N print a pseudomolecule without "N"s | ||
| 144 | -i int mimimum percent identity [default 40] | ||
| 145 | -v int mimimum contig coverage [default 40] | ||
| 146 | -V int minimum contig coverage difference [default 1] | ||
| 147 | -l int minimum contig length [default 1] | ||
| 148 | -t run tblastx on contigs that are not mapped | ||
| 149 | -g string (file name) print uncovered regions (gaps) on reference to file name | ||
| 150 | -n int insert n Ns between overlapping contigs [default 100] | ||
| 151 | -a append contigs in bin to the pseudomolecule | ||
| 152 | -o prefix output files will have this prefix | ||
| 153 | -P pick primer sets to close gaps | ||
| 154 | -f int number of flanking bases on either side of a gap for primer design (default 350) | ||
| 155 | -R int Run mummer [default 1, use -R 0 to avoid running mummer] | ||
| 156 | -e Escape contig ordering i.e. go to primer design | ||
| 157 | -c Reference sequence is circular | ||
| 158 | |||
| 159 | EOF | ||
| 160 | } | ||
| 161 | ######## | ||
| 162 | sub usage | ||
| 163 | { | ||
| 164 | |||
| 165 | die <<EOF | ||
| 166 | --------------------------------------------------------------------------------------------------- | ||
| 167 | |||
| 168 | ABACAS.$version | ||
| 169 | visit www.abacas.sourceforge.net for more information. | ||
| 170 | -------------------------------- | ||
| 171 | Please report bugs to:sa4 (at)sanger.ac.uk and tdo (at) sanger.ac.uk | ||
| 172 | ---------------------------------------------------------------------------------------------------- | ||
| 173 | |||
| 174 | USAGE | ||
| 175 | abacas.pl -r <reference file: single fasta> -q <query sequence file: fasta> -p <nucmer/promer> [OPTIONS] | ||
| 176 | -r reference sequence in a single fasta file | ||
| 177 | -q contigs in multi-fasta format | ||
| 178 | -p MUMmer program to use: 'nucmer' or 'promer' | ||
| 179 | for contig ordering and primer design | ||
| 180 | |||
| 181 | OR | ||
| 182 | abacas.pl -r <reference file: single fasta> -q <pseudomolecule/ordered sequence file: fasta> -e | ||
| 183 | to escape contig ordering and go directly to primer design | ||
| 184 | |||
| 185 | OR | ||
| 186 | abacas.pl -h for help | ||
| 187 | |||
| 188 | EOF | ||
| 189 | } | ||
| 190 | ######## | ||
| 191 | ################## | ||
| 192 | sub print_header | ||
| 193 | { | ||
| 194 | print " | ||
| 195 | *********************************************************************************** | ||
| 196 | * ABACAS: Algorithm Based Automatic Contiguation of Assembled Sequences * | ||
| 197 | * * | ||
| 198 | * * | ||
| 199 | * Copyright (C) 2008-11 The Wellcome Trust Sanger Institute, Cambridge, UK. * | ||
| 200 | * All Rights Reserved. * | ||
| 201 | * * | ||
| 202 | *********************************************************************************** | ||
| 203 | \n"; | ||
| 204 | } | ||
| 205 | ######################################### | ||
| 206 | sub checkUserInput{ | ||
| 207 | my %options; | ||
| 208 | getopts('hr:q:p:ds:mbNi:v:V:l:n:tg:ao:Pf:Ru:ecD', \%options); | ||
| 209 | my $optionsLog="# Checking user options:"; | ||
| 210 | my ($help, $reference, $query_file, $choice, $sen, $seed, $mlfas, $fasta_bin, $avoid_Ns, | ||
| 211 | $tbx, $min_id, $min_cov, $diff_cov, $min_len,$add_bin_2ps, $pick_primer, | ||
| 212 | $flank, $chk_uniq,$redoMummer, $is_circular,$escapeToPrimers, $debug, $gaps_2file, $prefix); | ||
| 213 | |||
| 214 | if($options{h}) { | ||
| 215 | $help = $options{h}; | ||
| 216 | help(); | ||
| 217 | } | ||
| 218 | if ($options{r} && $options{q} ){ | ||
| 219 | ($reference, $query_file) = ($options{r},$options{q}); | ||
| 220 | $optionsLog.="\n#\t-r Reference=$reference\n#\t-q Query=$query_file\n"; | ||
| 221 | }else{ | ||
| 222 | usage() unless $options{e}; | ||
| 223 | } | ||
| 224 | |||
| 225 | if ($options{p}){ | ||
| 226 | $choice = $options{p}; | ||
| 227 | $optionsLog.="#\t-p $choice\n"; | ||
| 228 | unless ($choice eq "nucmer" || $choice eq "promer"){ | ||
| 229 | print "Unknown MuMmer function\n Please use nucmer or promer\n"; | ||
| 230 | exit; | ||
| 231 | } | ||
| 232 | }else{ | ||
| 233 | usage() unless $options{e}; | ||
| 234 | } | ||
| 235 | if ($options{e}){ #$escapeToPrimers) | ||
| 236 | print_header(); | ||
| 237 | print "Primer design selected,... escaping contig ordering\n"; | ||
| 238 | $escapeToPrimers = 1; | ||
| 239 | $chk_uniq = "nucmer"; | ||
| 240 | $choice = ""; | ||
| 241 | $optionsLog.="#\t-e Primer design selected,... escaping contig ordering\n"; | ||
| 242 | }else{ | ||
| 243 | $escapeToPrimers = 0; | ||
| 244 | } | ||
| 245 | if ($options{d}) { | ||
| 246 | $sen =1; | ||
| 247 | $optionsLog.="#\t-d use default setting i.e. --mumreference in $choice\n"; | ||
| 248 | } else { | ||
| 249 | $sen =0; | ||
| 250 | $optionsLog.="#\t-d 0 use sensitive mapping in $choice i.e. --maxmatch\n"; | ||
| 251 | } #print $sen , " ---sen\n"; | ||
| 252 | #print $options{t}, "\n"; exit; | ||
| 253 | if($options{t}) {$tbx = 1;} else {$tbx = 0;} #print $tbx, " ---tbx\n"; # | ||
| 254 | if ($options{s}){ | ||
| 255 | $seed = $options{s}; | ||
| 256 | $optionsLog.="#\t-s seed=$seed\n"; | ||
| 257 | } | ||
| 258 | else{ | ||
| 259 | if ($choice eq "nucmer"){ | ||
| 260 | $seed = 12; | ||
| 261 | } | ||
| 262 | else{ | ||
| 263 | $seed =4; | ||
| 264 | } | ||
| 265 | |||
| 266 | } | ||
| 267 | if ($options{m}){ | ||
| 268 | $mlfas =1; | ||
| 269 | $optionsLog.="#\t-m print multifasta file of ordered contigs\n" | ||
| 270 | } else { $mlfas =0; } #print $mlfas , " ---mlfasta\n"; | ||
| 271 | if ($options{b}) { | ||
| 272 | $fasta_bin =1; | ||
| 273 | $optionsLog.="#\t-b print multifasta file of contigs in bin to file\n" | ||
| 274 | } else {$fasta_bin =0;} | ||
| 275 | if ($options {N}){ | ||
| 276 | $avoid_Ns =1; | ||
| 277 | $optionsLog.="#\t-N don't print Ns in pseudo-molecule\n" | ||
| 278 | } else {$avoid_Ns=0;} | ||
| 279 | |||
| 280 | if($options{i}){ | ||
| 281 | $min_id=$options{i}; | ||
| 282 | $optionsLog.="#\t-i $min_id is the minimum identity cutoff\n"; | ||
| 283 | } | ||
| 284 | else{$min_id =40; | ||
| 285 | # $optionsLog.="#\t-i not defined: $min_id is the default minimum identity cutoff\n"; | ||
| 286 | } | ||
| 287 | if ($options{v}){ | ||
| 288 | $min_cov = $options{v}; | ||
| 289 | $optionsLog.="#\t-v $min_cov is the minimum contig-coverage cutoff\n"; | ||
| 290 | } | ||
| 291 | else{ | ||
| 292 | $min_cov =40; | ||
| 293 | #$optionsLog.="#\t-v not defined $min_id is the default contig-coverage cutoff\n"; | ||
| 294 | } | ||
| 295 | if($options{V}){ | ||
| 296 | $diff_cov = $options{V}; | ||
| 297 | $optionsLog.="#\t-V $diff_cov\n"; | ||
| 298 | } | ||
| 299 | else {$diff_cov =1; | ||
| 300 | # $optionsLog.="#\t-V $diff_cov using the default value\n"; | ||
| 301 | } | ||
| 302 | if ($options {l}){ | ||
| 303 | $min_len = $options {l}; | ||
| 304 | $optionsLog.="#\t-l $min_len is the minimum length of contigs to be ordered\n"; | ||
| 305 | } | ||
| 306 | else{$min_len = 1; | ||
| 307 | # $optionsLog.="#\t-l not defined: using 1 as the default minimum length of contigs to be ordered\n"; | ||
| 308 | } | ||
| 309 | if ($options{a}) {$add_bin_2ps = 1; }else {$add_bin_2ps =0;} | ||
| 310 | if ($options{P}) {$pick_primer=1;} else {$pick_primer =0;} | ||
| 311 | if ($options{f}) {$flank = $options{f};} else {$flank = 1000;} | ||
| 312 | if ($options{u}) {$chk_uniq = $options{u}; } else {$chk_uniq = "nucmer";} | ||
| 313 | |||
| 314 | #unless ($options{R}) {$re} | ||
| 315 | if($options{R}) {$redoMummer = 1; } else {$redoMummer = 0;} | ||
| 316 | |||
| 317 | if($options{c}) {$is_circular = 1;}else {$is_circular =0;} | ||
| 318 | if ($options{g}) {$gaps_2file = $options{g};} else {$gaps_2file ="";} | ||
| 319 | if($options{o}) {$prefix = $options{o};} else {$prefix = "";} | ||
| 320 | if ($options {n}) {$numNs =$options{o};} else{$numNs=100;} | ||
| 321 | if($options{D}){ | ||
| 322 | $debug=1; | ||
| 323 | $optionsLog.="#\t-D debug\n"; | ||
| 324 | } | ||
| 325 | else {$debug =0}; | ||
| 326 | if ($tbx ==1 && $fasta_bin !=1) | ||
| 327 | { | ||
| 328 | print "ERROR: Please use -t -b if you want to run tblastx on contigs in bin\n"; | ||
| 329 | exit; | ||
| 330 | } | ||
| 331 | # print $redoMummer , "\n"; exit; | ||
| 332 | |||
| 333 | $optionsLog.="#\tInput checking done!!\n"; | ||
| 334 | #print $optionsLog; | ||
| 335 | return ($help, $reference, $query_file, $choice, $sen, $seed, $mlfas, $fasta_bin, $avoid_Ns, | ||
| 336 | $tbx, $min_id, $min_cov, $diff_cov, $min_len,$add_bin_2ps, $pick_primer, | ||
| 337 | $flank, $chk_uniq,$redoMummer, $is_circular,$escapeToPrimers, $debug, $gaps_2file, $prefix,$optionsLog,$numNs); | ||
| 338 | |||
| 339 | } ## end of checkUserInput | ||
| 340 | ############# | ||
| 341 | ## get the reference sequence in one line | ||
| 342 | #-------------------------------------------------- | ||
| 343 | sub Ref_Inline | ||
| 344 | { | ||
| 345 | my $ref = shift; | ||
| 346 | open (refFH, $ref) or die "Could not open file $ref\n"; | ||
| 347 | my $seq =""; | ||
| 348 | my @r = <refFH>; | ||
| 349 | my $num_chr =0; | ||
| 350 | foreach(@r){ | ||
| 351 | if ($_ =~ /\>/){ | ||
| 352 | $num_chr +=1; | ||
| 353 | } | ||
| 354 | } | ||
| 355 | if ($num_chr > 1){ | ||
| 356 | print "\nERROR: Please use a single fasta reference file. You can simply merge chromosomes in to a union fasta file.\n\n"; | ||
| 357 | exit; | ||
| 358 | } | ||
| 359 | shift @r; | ||
| 360 | foreach(@r){ | ||
| 361 | chomp; | ||
| 362 | $seq = $seq.$_; | ||
| 363 | } | ||
| 364 | return $seq; | ||
| 365 | } | ||
| 366 | ################ | ||
| 367 | # Run mummer | ||
| 368 | #-------------------------------------------- | ||
| 369 | sub doMummer | ||
| 370 | { | ||
| 371 | my ($reference, $query_file, $choice, $sen,$seed,$min_id, $min_cov, $diff_cov,$min_len, $debug, $is_circular ) = @_; | ||
| 372 | |||
| 373 | my $df = 'delta-filter'; | ||
| 374 | my $st = 'show-tiling'; | ||
| 375 | my $ask = 'which'; | ||
| 376 | my ($path_toPass, $run_mum); # params to return... | ||
| 377 | my ($command, $Path, $dir) = checkProg($choice); | ||
| 378 | my ($run_df, $df_path, $df_dir) = checkProg($df); | ||
| 379 | my ($run_st, $st_path, $st_dir) = checkProg($st); | ||
| 380 | my (@running, @deltaRes, @coordsRes); | ||
| 381 | if ($choice eq "nucmer") | ||
| 382 | { | ||
| 383 | if ($sen ==0) | ||
| 384 | { | ||
| 385 | @running = `$command --maxmatch -l $seed -p $choice $reference $query_file &> /dev/null`; | ||
| 386 | @deltaRes = `$run_df -q $choice.delta >$choice.filtered.delta`; | ||
| 387 | if ($is_circular == 1) | ||
| 388 | { | ||
| 389 | @coordsRes = `$run_st -c -i $min_id -v $min_cov -V $diff_cov -l $min_len -R -u unused_contigs.out $choice.filtered.delta > $choice.tiling`; | ||
| 390 | } | ||
| 391 | else | ||
| 392 | { | ||
| 393 | @coordsRes = `$run_st -i $min_id -v $min_cov -V $diff_cov -l $min_len -R -u unused_contigs.out $choice.filtered.delta > $choice.tiling`; | ||
| 394 | |||
| 395 | } | ||
| 396 | } | ||
| 397 | else | ||
| 398 | { | ||
| 399 | @running = `$command -p $choice $reference $query_file &> /dev/null`; | ||
| 400 | @deltaRes = `$run_df -q $choice.delta >$choice.filtered.delta`; | ||
| 401 | if ($is_circular ==1) {@coordsRes = `$run_st -c -i $min_id -v $min_cov -V $diff_cov -l $min_len -R -u unused_contigs.out $choice.filtered.delta > $choice.tiling`;} | ||
| 402 | else { @coordsRes = `$run_st -i $min_id -v $min_cov -V $diff_cov -l $min_len -R -u unused_contigs.out $choice.filtered.delta > $choice.tiling`;} | ||
| 403 | } | ||
| 404 | |||
| 405 | } | ||
| 406 | else | ||
| 407 | { | ||
| 408 | if ($sen ==0) | ||
| 409 | { | ||
| 410 | @running = `$command --maxmatch -l $seed -x 1 -p $choice $reference $query_file &> /dev/null`; | ||
| 411 | @deltaRes = `$run_df -q $choice.delta >$choice.filtered.delta`; | ||
| 412 | if ($is_circular == 1) | ||
| 413 | { | ||
| 414 | @coordsRes= `$run_st -c -i $min_id -v $min_cov -V $diff_cov -l $min_len -R -u unused_contigs.out $choice.filtered.delta > $choice.tiling`; | ||
| 415 | } | ||
| 416 | else | ||
| 417 | { | ||
| 418 | @coordsRes= `$run_st -i $min_id -v $min_cov -V $diff_cov -l $min_len -R -u unused_contigs.out $choice.filtered.delta > $choice.tiling`; | ||
| 419 | } | ||
| 420 | } | ||
| 421 | else | ||
| 422 | { | ||
| 423 | @running = `$command -l $seed -p $choice $reference $query_file &> /dev/null`; | ||
| 424 | @deltaRes = `$run_df -q $choice.delta >$choice.filtered.delta`; | ||
| 425 | if ($is_circular == 1) { | ||
| 426 | @coordsRes= `$run_st -c -i $min_id -v $min_cov -V $diff_cov -l $min_len -R -u unused_contigs.out $choice.filtered.delta > $choice.tiling`; | ||
| 427 | } | ||
| 428 | else | ||
| 429 | { | ||
| 430 | @coordsRes= `$run_st -i $min_id -v $min_cov -V $diff_cov -l $min_len -R -u unused_contigs.out $choice.filtered.delta > $choice.tiling`; | ||
| 431 | } | ||
| 432 | } | ||
| 433 | } | ||
| 434 | my $Coordsfull= "$choice.tiling"; | ||
| 435 | return ($Coordsfull,$Path, $dir); | ||
| 436 | } | ||
| 437 | |||
| 438 | ## ############################################################################# | ||
| 439 | sub checkProg{ #checks if a given excutable is in the path... | ||
| 440 | my $prog = shift; | ||
| 441 | my $ask = 'which'; | ||
| 442 | my @check_prog = `$ask $prog`; | ||
| 443 | my $path_toPass; | ||
| 444 | my $path_dir; | ||
| 445 | my $command; | ||
| 446 | if (defined $check_prog[0] && $check_prog[0] =~ /$prog$/) | ||
| 447 | { | ||
| 448 | $path_toPass = $prog; | ||
| 449 | $command = $prog; | ||
| 450 | } | ||
| 451 | else | ||
| 452 | { | ||
| 453 | print "\nENTER the directory for your ", $prog, " executables [default ./]: "; | ||
| 454 | my $path=<STDIN>; | ||
| 455 | chomp $path; | ||
| 456 | $path_dir = $path; | ||
| 457 | if ($path_dir =~/\/$/) | ||
| 458 | { | ||
| 459 | $path_dir = $path_dir; | ||
| 460 | } | ||
| 461 | else | ||
| 462 | { | ||
| 463 | $path_dir = $path_dir."/"; | ||
| 464 | } | ||
| 465 | my @final_check = `$ask $command`; | ||
| 466 | if (exists $final_check[0] && $final_check[0] =~ /$prog$/) | ||
| 467 | { | ||
| 468 | $command = $path_dir.$prog; | ||
| 469 | $path_toPass = $command; | ||
| 470 | } | ||
| 471 | else | ||
| 472 | { | ||
| 473 | print "ERROR: Could not run ", $prog, ", please check if it is installed in your path\n or provide the directory \n"; | ||
| 474 | exit; | ||
| 475 | } | ||
| 476 | } | ||
| 477 | |||
| 478 | return ($command, $path_toPass, $path_dir); | ||
| 479 | } | ||
| 480 | |||
| 481 | ############################## | ||
| 482 | # converts a fasta file to an ordered single line | ||
| 483 | #-------------------------------------------------- | ||
| 484 | sub Fasta2ordered | ||
| 485 | { | ||
| 486 | if( @_ != 1 ) | ||
| 487 | { | ||
| 488 | print "Usage: Fasta2ordered <fasta_file>\n"; | ||
| 489 | exit; | ||
| 490 | } | ||
| 491 | my $fast = shift; #print $fast; exit; | ||
| 492 | my @fasta = split (/\n/, $fast); | ||
| 493 | if ($fasta[0] =~ /\>/ ) #remove chromosome name if exists in the onput sequence. | ||
| 494 | { | ||
| 495 | my $ch_name = $fasta[0]; | ||
| 496 | shift @fasta; | ||
| 497 | } | ||
| 498 | #print $fasta[0]; exit; | ||
| 499 | foreach(@fasta){chomp;} | ||
| 500 | my $num_lines = scalar(@fasta); | ||
| 501 | my $dna = ''; | ||
| 502 | for(my $i=0; $i< $num_lines; $i+=1) | ||
| 503 | { | ||
| 504 | $dna = $dna.$fasta[$i]; | ||
| 505 | } | ||
| 506 | my $ordered_dna = $dna; | ||
| 507 | return $ordered_dna; | ||
| 508 | } | ||
| 509 | ############################################################## | ||
| 510 | # Hash input contigs | ||
| 511 | #------------------------------------------------ | ||
| 512 | |||
| 513 | sub hash_contigs { | ||
| 514 | if( @_ != 1 ) | ||
| 515 | { | ||
| 516 | print "Usage: hash_contigs contigs_file"; | ||
| 517 | exit; | ||
| 518 | } | ||
| 519 | my $contigs_file = shift; | ||
| 520 | if( $contigs_file =~ /\.gz$/ ) | ||
| 521 | { | ||
| 522 | open(CONTIGS, $contigs_file, "gunzip -c $contigs_file |" ) or die "Cant open contigs file: $!\n"; | ||
| 523 | } | ||
| 524 | else | ||
| 525 | { | ||
| 526 | open( CONTIGS, $contigs_file) or die "Cant open contigs file: $!\n"; | ||
| 527 | } | ||
| 528 | |||
| 529 | my %contigs_hash; # hash to store contig names and sequences | ||
| 530 | my $contigName; | ||
| 531 | |||
| 532 | |||
| 533 | while (<CONTIGS>) ##add error checking... | ||
| 534 | { | ||
| 535 | if (/^>(\S+)/) { | ||
| 536 | $contigName=$1; | ||
| 537 | } | ||
| 538 | else { | ||
| 539 | chomp; | ||
| 540 | $contigs_hash{$contigName} .= $_; | ||
| 541 | } | ||
| 542 | } | ||
| 543 | close(CONTIGS); | ||
| 544 | #tdo | ||
| 545 | ## check if qual exists | ||
| 546 | my %contigs_qual_hash; | ||
| 547 | |||
| 548 | |||
| 549 | if (-r "$contigs_file.qual" or -r "$contigs_file.qual.gz") { | ||
| 550 | if( -r "$contigs_file.qual.gz" ) | ||
| 551 | { | ||
| 552 | open(CONTIGS, "$contigs_file.qual.gz", "gunzip -c $contigs_file.qual.gz |" ) or die "Cant open contigs file: $!\n"; | ||
| 553 | } | ||
| 554 | else | ||
| 555 | { | ||
| 556 | open( CONTIGS, "$contigs_file.qual" ) or die "Cant open contigs file: $!\n"; | ||
| 557 | } | ||
| 558 | |||
| 559 | |||
| 560 | while (<CONTIGS>) { | ||
| 561 | if (/^>(\S+)/) { | ||
| 562 | $contigName=$1; | ||
| 563 | } | ||
| 564 | else { | ||
| 565 | chomp; | ||
| 566 | $contigs_qual_hash{$contigName} .= $_; | ||
| 567 | } | ||
| 568 | } | ||
| 569 | |||
| 570 | } # end tdo # end if exist | ||
| 571 | |||
| 572 | |||
| 573 | return (\%contigs_hash,\%contigs_qual_hash); | ||
| 574 | } | ||
| 575 | ####################### | ||
| 576 | ############################## | ||
| 577 | ### it gets a delta name | ||
| 578 | sub getMummerComparison{ | ||
| 579 | my $deltaName = shift; | ||
| 580 | |||
| 581 | |||
| 582 | ### transform the delta file to coords | ||
| 583 | my $call ="show-coords -H -T -q $deltaName > $deltaName.coords "; | ||
| 584 | !system(" $call") or die "Problems doing the show-coords comparison: $call $!\n"; | ||
| 585 | |||
| 586 | |||
| 587 | ### willh old results | ||
| 588 | my %h; | ||
| 589 | |||
| 590 | ### has as index the postion with the max hits | ||
| 591 | my %h_max; | ||
| 592 | my $tmp=0; | ||
| 593 | my $tmp_index; | ||
| 594 | my $key=''; | ||
| 595 | my $is_promer =0; | ||
| 596 | if ($deltaName =~/^promer/) | ||
| 597 | { | ||
| 598 | $is_promer =1; | ||
| 599 | } | ||
| 600 | |||
| 601 | open (F,"$deltaName.coords") or die "Problem in getComparisonFile to open file $deltaName.coords\n"; | ||
| 602 | my @File=<F>; | ||
| 603 | my @a; | ||
| 604 | @a=split(/\s+/,$File[0]); | ||
| 605 | $tmp=$a[5]; | ||
| 606 | $tmp_index=$a[0]; | ||
| 607 | if ($is_promer ==1) | ||
| 608 | { | ||
| 609 | $key=$a[12]; ## nucmer: $key = $a[8] | ||
| 610 | } | ||
| 611 | else | ||
| 612 | { | ||
| 613 | $key = $a[8]; | ||
| 614 | } | ||
| 615 | |||
| 616 | foreach (@File) { | ||
| 617 | @a=split(/\s+/); | ||
| 618 | |||
| 619 | if ($is_promer ==1) | ||
| 620 | { | ||
| 621 | push @{ $h{$a[12]}}, "$a[12]\t$a[11]\t$a[7]\t$a[5]\t0\t0\t$a[2]\t$a[3]\t$a[0]\t$a[1]\t1\t$a[5]\n"; | ||
| 622 | if ($key eq $a[12] and $a[5]>$tmp) | ||
| 623 | { | ||
| 624 | $tmp=$a[5]; # length | ||
| 625 | $tmp_index=$a[0]; # position reference | ||
| 626 | } | ||
| 627 | elsif ($key ne $a[12]) { | ||
| 628 | ### here possible bugg... | ||
| 629 | $h_max{$tmp_index}=$key; | ||
| 630 | $key=$a[12]; | ||
| 631 | $tmp=$a[5]; # length | ||
| 632 | $tmp_index=$a[0]; # position reference | ||
| 633 | |||
| 634 | } | ||
| 635 | } #end if | ||
| 636 | #else i.e. if nucmer | ||
| 637 | else | ||
| 638 | { | ||
| 639 | push @{ $h{$a[8]}}, "$a[8]\t$a[6]\t$a[6]\t$a[5]\t0\t0\t$a[2]\t$a[3]\t$a[0]\t$a[1]\t1\t$a[5]\n"; | ||
| 640 | if ($key eq $a[8] and $a[5]>$tmp) | ||
| 641 | { | ||
| 642 | $tmp=$a[5]; # length | ||
| 643 | $tmp_index=$a[0]; # position reference | ||
| 644 | } | ||
| 645 | elsif ($key ne $a[8]) { | ||
| 646 | ### here possible bugg... | ||
| 647 | $h_max{$tmp_index}=$key; | ||
| 648 | $key=$a[8]; | ||
| 649 | $tmp=$a[5]; # length | ||
| 650 | $tmp_index=$a[0]; # position reference | ||
| 651 | |||
| 652 | } | ||
| 653 | } | ||
| 654 | |||
| 655 | } | ||
| 656 | $h_max{$tmp_index}=$key; | ||
| 657 | # print Dumper %h_max; | ||
| 658 | |||
| 659 | return (\%h,\%h_max); | ||
| 660 | } | ||
| 661 | ################################## | ||
| 662 | ########################### | ||
| 663 | sub writeBinContigs2Ref{ | ||
| 664 | my $nameBin = shift; | ||
| 665 | my $name = shift; | ||
| 666 | |||
| 667 | open (F, "$nameBin") or die "Couldn't find file $nameBin: $!\n"; | ||
| 668 | |||
| 669 | my @ar; | ||
| 670 | |||
| 671 | my $count=0; | ||
| 672 | |||
| 673 | while (<F>) { | ||
| 674 | push @ar, $_; | ||
| 675 | $count++; | ||
| 676 | } | ||
| 677 | #### sa4: added error checking:- if file is empty | ||
| 678 | if (scalar(@ar) < 1) | ||
| 679 | { | ||
| 680 | print "No contigs in unusedcontigs file\n"; | ||
| 681 | $count = 0; | ||
| 682 | |||
| 683 | } | ||
| 684 | else | ||
| 685 | { | ||
| 686 | open (F, "> $name.notMapped.contigs.tab") or die "Couldn't write file $name.tab: $!\n"; | ||
| 687 | print F doArt(\@ar); | ||
| 688 | close(F); | ||
| 689 | } | ||
| 690 | return $count; | ||
| 691 | |||
| 692 | } | ||
| 693 | |||
| 694 | |||
| 695 | ############################## | ||
| 696 | sub doArt{ | ||
| 697 | my ($ref) = @_; | ||
| 698 | |||
| 699 | |||
| 700 | ## hash of array with all positions of the contig | ||
| 701 | my %Pos; | ||
| 702 | |||
| 703 | ## Hash with note of result line of nucmer | ||
| 704 | my %lines; | ||
| 705 | |||
| 706 | foreach (@$ref) { | ||
| 707 | chomp; | ||
| 708 | my @ar=split(/\t/); | ||
| 709 | push @{ $Pos{$ar[12]}}, "$ar[0]..$ar[1]"; | ||
| 710 | $lines{$ar[12]} .= "FT $_\n"; | ||
| 711 | } | ||
| 712 | |||
| 713 | my $res; | ||
| 714 | |||
| 715 | foreach my $contig (keys %lines) { | ||
| 716 | |||
| 717 | if (scalar(@{ $Pos{$contig} } >1)) { | ||
| 718 | my $tmp; | ||
| 719 | |||
| 720 | foreach (@{ $Pos{$contig} }) { | ||
| 721 | $tmp.="$_,"; | ||
| 722 | } | ||
| 723 | $tmp =~ s/,$//g; # get away last comma | ||
| 724 | $res .= "FT contig join($tmp)\n"; | ||
| 725 | } | ||
| 726 | else { | ||
| 727 | $res .= "FT contig $Pos{$contig}[0]\n"; | ||
| 728 | } | ||
| 729 | $res .= "FT /systematic_id=\"$contig\"\n"; | ||
| 730 | $res .= "FT /note=\"Contig $contig couldn't map perfectly.\n"; | ||
| 731 | $res .= $lines{$contig}; | ||
| 732 | $res .= "FT \"\n"; | ||
| 733 | |||
| 734 | } | ||
| 735 | |||
| 736 | return $res; | ||
| 737 | } | ||
| 738 | |||
| 739 | ########################################################################## | ||
| 740 | #--------------------------- | ||
| 741 | sub makeN #creates a string of Ns | ||
| 742 | { | ||
| 743 | my $n = shift; | ||
| 744 | my $Ns= "N"; | ||
| 745 | for (my $i =1; $i < $n; $i+=1) | ||
| 746 | { | ||
| 747 | $Ns = $Ns."N"; | ||
| 748 | } | ||
| 749 | return $Ns; | ||
| 750 | } | ||
| 751 | |||
| 752 | ########################################################################### | ||
| 753 | ## reverse complement a sequence | ||
| 754 | #--------------------------------------------- | ||
| 755 | sub revComp { | ||
| 756 | my $dna = shift; | ||
| 757 | my $revcomp = reverse($dna); | ||
| 758 | |||
| 759 | $revcomp =~ tr/ACGTacgt/TGCAtgca/; | ||
| 760 | |||
| 761 | return $revcomp; | ||
| 762 | } | ||
| 763 | #### | ||
| 764 | #### basic stats | ||
| 765 | sub getAM{ | ||
| 766 | my @array = @_; | ||
| 767 | return undef unless(scalar(@array)); | ||
| 768 | my $sum =0; | ||
| 769 | my $siz = scalar(@array); | ||
| 770 | foreach (@array){ | ||
| 771 | $sum = $sum + $_; | ||
| 772 | } | ||
| 773 | my $Amean = sprintf("%.2f",($sum/$siz)); | ||
| 774 | return $Amean; | ||
| 775 | } | ||
| 776 | |||
| 777 | sub getMedian{ | ||
| 778 | my @arr = @_; | ||
| 779 | return undef unless(scalar(@arr)); | ||
| 780 | my $median; | ||
| 781 | my @array = sort {$a<=> $b} @arr; | ||
| 782 | my $siz = scalar(@array); | ||
| 783 | if ($siz%2==1){# $number is odd | ||
| 784 | $median = $array[($#array / 2)]; | ||
| 785 | } | ||
| 786 | else{ # $number is even | ||
| 787 | |||
| 788 | $median = $array[int($#array / 2)] + (($array[int($#array / 2) + 1] - $array[int($#array / 2)]) / 2); | ||
| 789 | } | ||
| 790 | return $median; | ||
| 791 | } | ||
| 792 | |||
| 793 | sub get_SD | ||
| 794 | { | ||
| 795 | my(@numbers) = @_; | ||
| 796 | return undef unless(scalar(@numbers)); | ||
| 797 | # Step 1, find the mean of the numbers | ||
| 798 | my $total1 = 0; | ||
| 799 | foreach my $num (@numbers) { | ||
| 800 | $total1 += $num; | ||
| 801 | } | ||
| 802 | my $mean1 = $total1 / (scalar @numbers); | ||
| 803 | |||
| 804 | # Step 2, find the mean of the squares of the differences | ||
| 805 | # between each number and the mean | ||
| 806 | my $total2 = 0; | ||
| 807 | foreach my $num (@numbers) { | ||
| 808 | $total2 += ($mean1-$num)**2; | ||
| 809 | } | ||
| 810 | my $mean2 = $total2 / (scalar @numbers); | ||
| 811 | |||
| 812 | # Step 3, standard deviation is the square root of the | ||
| 813 | # above mean | ||
| 814 | my $std_dev = sprintf("%.2f",(sqrt($mean2))); | ||
| 815 | return $std_dev; | ||
| 816 | } | ||
| 817 | sub getMin { | ||
| 818 | my @array = @_; | ||
| 819 | return undef unless(scalar(@array)); | ||
| 820 | my @sorted = sort {$a<=> $b} @array; | ||
| 821 | my $min = $sorted[0]; | ||
| 822 | return $min; | ||
| 823 | } | ||
| 824 | sub getMax { | ||
| 825 | my @array = @_; | ||
| 826 | return undef unless(scalar(@array)); | ||
| 827 | my @sorted = sort {$a<=> $b} @array; | ||
| 828 | my $siz = scalar(@sorted); | ||
| 829 | my $max = $sorted[$siz -1]; | ||
| 830 | return $max; | ||
| 831 | } | ||
| 832 | |||
| 833 | sub getN50 { | ||
| 834 | my @array = @_; | ||
| 835 | my $totLen=0; | ||
| 836 | foreach (@array){ | ||
| 837 | chomp; | ||
| 838 | $totLen+=$_; | ||
| 839 | } | ||
| 840 | my @sort = sort {$b <=> $a} @array; | ||
| 841 | my $n50; | ||
| 842 | foreach my $val(@sort){ | ||
| 843 | $n50+=$val; | ||
| 844 | if($n50 >= $totLen/2){ | ||
| 845 | return ($totLen, $val); | ||
| 846 | last; | ||
| 847 | } | ||
| 848 | } | ||
| 849 | } | ||
| 850 | |||
| 851 | ################################################################################ | ||
| 852 | ### function to visualize rep. regions in Reference genome. | ||
| 853 | sub findRepeats | ||
| 854 | { | ||
| 855 | my $reference = shift; | ||
| 856 | my $name = shift; | ||
| 857 | my $path_prog = shift; | ||
| 858 | |||
| 859 | # get path | ||
| 860 | my ($path_coords) = $path_prog; | ||
| 861 | |||
| 862 | $path_coords =~ s/nucmer/show-coords/; | ||
| 863 | |||
| 864 | my $call = "$path_prog --maxmatch -c 100 -b 40 -p $name.repeats -l 25 $reference $reference &> /dev/null "; | ||
| 865 | !system("$call") or die "Problems doing the nucmer comparison: $call $!\n"; | ||
| 866 | $call ="$path_coords -r -c -l $name.repeats.delta > $name.repeats.coords "; | ||
| 867 | !system(" $call") or die "Problems doing the show-coords comparison: $call $!\n"; | ||
| 868 | |||
| 869 | my @Res; | ||
| 870 | open (F, "$name.repeats.coords" ) or die "Problems to open file $reference.repeats.coords: Is MUMmer installed correctly and inserted in the PATH environment variable? ($!)\n"; | ||
| 871 | $_=<F>; $_=<F>; $_=<F>; $_=<F>;$_=<F>; | ||
| 872 | while (<F>) { | ||
| 873 | my @ar = split(/\s+/); | ||
| 874 | if (!($ar[1] == $ar[4] or $ar[2] == $ar[5] or $ar[7] > 100000)) { # to exclude self alignment | ||
| 875 | |||
| 876 | foreach ($ar[1]..$ar[2]) { | ||
| 877 | $Res[($_-1)]++; | ||
| 878 | } | ||
| 879 | } | ||
| 880 | } | ||
| 881 | |||
| 882 | ### write the result to the plot file | ||
| 883 | |||
| 884 | my $res; | ||
| 885 | foreach (@Res){ | ||
| 886 | if (defined($_)) { | ||
| 887 | $res .= "$_\n"; | ||
| 888 | } | ||
| 889 | else { | ||
| 890 | $res .= "0\n"; | ||
| 891 | } | ||
| 892 | } | ||
| 893 | |||
| 894 | open (F, "> $name.Repeats.plot") or die "Couldn't open file $name.plot to write: $! \n"; | ||
| 895 | print F $res; | ||
| 896 | close(F); | ||
| 897 | |||
| 898 | ### delete files | ||
| 899 | unlink("$name.repeats.delta"); | ||
| 900 | unlink("$name.repeats.coords"); | ||
| 901 | unlink("$name.repeats.cluster"); | ||
| 902 | } | ||
| 903 | |||
| 904 | ################################################################################ | ||
| 905 | # reverse a list of qualities | ||
| 906 | #------------------------------ | ||
| 907 | sub reverseQual{ | ||
| 908 | my $str = shift; | ||
| 909 | |||
| 910 | $str =~ s/\s+$//g; | ||
| 911 | |||
| 912 | my @ar = split(/\s/,$str); | ||
| 913 | my $res; | ||
| 914 | |||
| 915 | for (my $i=(scalar(@ar)-1);$i>=0;$i--) { | ||
| 916 | $res.="$ar[$i] "; | ||
| 917 | } | ||
| 918 | return $res; | ||
| 919 | } | ||
| 920 | |||
| 921 | ############################################################################## | ||
| 922 | # ---------------- | ||
| 923 | sub getPosCoords{ | ||
| 924 | my $ref_ar = shift; | ||
| 925 | my $contig = shift; | ||
| 926 | |||
| 927 | my $offset = shift; | ||
| 928 | my $res; | ||
| 929 | # print Dumper $$ref_ar{$contig}; | ||
| 930 | foreach (@{$$ref_ar{$contig}}) { | ||
| 931 | print "in getPos Coords: $_\n";; | ||
| 932 | |||
| 933 | my @ar=split(/\t/); | ||
| 934 | $ar[6]+=$offset; | ||
| 935 | $ar[7]+=$offset; | ||
| 936 | $res .= join("\t",@ar);; | ||
| 937 | } | ||
| 938 | |||
| 939 | return $res; | ||
| 940 | |||
| 941 | } | ||
| 942 | ############################################################################# | ||
| 943 | # ----------------------------- | ||
| 944 | sub getPosCoordsTurn{ | ||
| 945 | my $ref_ar = shift; | ||
| 946 | my $contig = shift; | ||
| 947 | |||
| 948 | my $offset = shift; | ||
| 949 | |||
| 950 | |||
| 951 | my $res; | ||
| 952 | |||
| 953 | # print Dumper $$ref_ar{$contig}; | ||
| 954 | foreach (@{$$ref_ar{$contig}}) { | ||
| 955 | my @ar=split(/\t/); | ||
| 956 | my $tmp_8=$ar[8]; | ||
| 957 | my $tmp_9=$ar[9]; | ||
| 958 | |||
| 959 | $ar[8]=$ar[6]+$offset; | ||
| 960 | $ar[9]=$ar[7]+$offset; | ||
| 961 | $ar[6]=$tmp_8; | ||
| 962 | $ar[7]=$tmp_9; | ||
| 963 | |||
| 964 | ## change query subject | ||
| 965 | |||
| 966 | $res .= join("\t",@ar);; | ||
| 967 | } | ||
| 968 | |||
| 969 | return $res; | ||
| 970 | |||
| 971 | } | ||
| 972 | |||
| 973 | ############################################################################ | ||
| 974 | #------------------------ | ||
| 975 | sub printStats{ | ||
| 976 | |||
| 977 | my ($num_fortillingcontigs,$num_notsetTilling,$num_mapped, $num_contigs, $num_inComparisoncontigs, $ref_len, $total_bases_mpd) = @_; | ||
| 978 | $num_fortillingcontigs=$num_notsetTilling+$num_mapped; | ||
| 979 | my $res; | ||
| 980 | $res.= "Short statistics of run.\n"; | ||
| 981 | $res.= "$num_contigs\t\tcontigs entered to be mapped against the reference.\n"; | ||
| 982 | $res.= sprintf("$num_inComparisoncontigs\t%0.2f \%\tmade a hit against the reference to the given parameter (-s -d etc)\n",($num_inComparisoncontigs*100/$num_contigs)); | ||
| 983 | $res.= sprintf("$num_fortillingcontigs\t%0.2f \%\twere considered for the tilling graph (-s -d etc)\n",($num_fortillingcontigs*100/$num_contigs)); | ||
| 984 | $res.= sprintf("$num_mapped\t%0.2f \%\tare mapped in the tilling graph (-s -d etc)\n",($num_mapped*100/$num_contigs)); | ||
| 985 | $res.= sprintf("\nCoverage: The reference is $ref_len long. Up to $total_bases_mpd bp (%0.2f \%) are covered by the contigs (This doesn't mean that these regions are really similar...)\n",($total_bases_mpd*100/$ref_len)); | ||
| 986 | |||
| 987 | print $res; | ||
| 988 | |||
| 989 | } | ||
| 990 | ################################################## | ||
| 991 | #### Do Tiling | ||
| 992 | #---------------------------------------------------- | ||
| 993 | sub doTiling { | ||
| 994 | |||
| 995 | my ($mummer_tiling, $path_toPass, $path_dir,$reference, $query_file, $choice, $prefix, | ||
| 996 | $mlfas, $fasta_bin, $avoid_Ns, $ref_len, $gaps_2file, $ref_inline, $add_bin_2ps, | ||
| 997 | $pick_primer, $flank, $chk_uniq, $run_blast, $numNs) = @_; | ||
| 998 | |||
| 999 | ### these are also defined in the main script.... to be changed!! | ||
| 1000 | my ($num_contigs , $num_inbincontigs, $avg_cont_size,$num_overlaps , $num_gaps, | ||
| 1001 | $num_mapped,$total_bases_mpd,$p_ref_covered,$num_ambigus,$num_inComparisoncontigs, | ||
| 1002 | $num_fortillingcontigs,$num_notsetTilling)= (0,0,0,0,0,0,0,0,0,0,0,0); | ||
| 1003 | |||
| 1004 | my ($href, $ref_contigs_qual) = hash_contigs($query_file); | ||
| 1005 | my $qualAvailable=0; | ||
| 1006 | my %contigs_hash = %{$href}; | ||
| 1007 | my @c_keys = keys %contigs_hash; | ||
| 1008 | $num_contigs = scalar(@c_keys); | ||
| 1009 | my @cont_lens; | ||
| 1010 | my (@ids ,$id, $id_len); | ||
| 1011 | my (@Rs, @Re, @G, @Len, @cov, @pid, @orient, @Cid); | ||
| 1012 | my (@Ps, @Pe); | ||
| 1013 | my ($total); | ||
| 1014 | my $g; #define gap size between contigs | ||
| 1015 | my $tiling_gap; #gap size from tiling graph | ||
| 1016 | open (TIL, $mummer_tiling) or die "Could not open $mummer_tiling: $!"; | ||
| 1017 | while (<TIL>) | ||
| 1018 | { | ||
| 1019 | chomp; | ||
| 1020 | if ($_ =~/^>/) | ||
| 1021 | { | ||
| 1022 | my $line = substr $_, 1; | ||
| 1023 | my @splits = split /\s+/, $line; | ||
| 1024 | $id = $splits[0]; | ||
| 1025 | push @ids, $id; | ||
| 1026 | $id_len= $splits[1]; | ||
| 1027 | } | ||
| 1028 | else | ||
| 1029 | { | ||
| 1030 | my @splits = split /\s+/, $_; | ||
| 1031 | push @Rs, $splits[0]; | ||
| 1032 | push @Re, $splits[1]; | ||
| 1033 | push @G, $splits[2]; | ||
| 1034 | push @Len, $splits[3]; | ||
| 1035 | push @cov, $splits[4]; | ||
| 1036 | push @pid, $splits[5]; | ||
| 1037 | push @orient, $splits[6]; | ||
| 1038 | push @Cid, $splits[7]; | ||
| 1039 | } | ||
| 1040 | |||
| 1041 | } | ||
| 1042 | close (TIL); | ||
| 1043 | if (scalar(@Rs) != scalar(@Re)) | ||
| 1044 | { | ||
| 1045 | print "ERROR: unequal array size\n"; | ||
| 1046 | exit; | ||
| 1047 | } | ||
| 1048 | else | ||
| 1049 | { | ||
| 1050 | $total = scalar(@Rs); | ||
| 1051 | $num_mapped = scalar(@Rs); | ||
| 1052 | } | ||
| 1053 | my $ref_loc = $reference; # get locations of reference and query files | ||
| 1054 | my $qry_loc = $query_file; | ||
| 1055 | my $dif_dir =0; #assume query and reference are in the working directory | ||
| 1056 | my @splits_reference = split (/\//, $reference); | ||
| 1057 | my $new_reference_file = $splits_reference[(scalar(@splits_reference)-1)]; | ||
| 1058 | my @splits_query = split (/\//, $query_file); | ||
| 1059 | my $new_query_file = $splits_query[(scalar(@splits_query)-1)]; | ||
| 1060 | if ($prefix eq "") | ||
| 1061 | { | ||
| 1062 | $prefix = $new_query_file."_".$new_reference_file; | ||
| 1063 | } | ||
| 1064 | #------------------------------------------------------------------- | ||
| 1065 | #define file handles for output files and open files to write output | ||
| 1066 | #------------------------------------------------------------------- | ||
| 1067 | my ($seqFH,$tabFH,$binFH,$crunchFH, $gapFH, $gapFHT,$gapFHS,@gap_sizes,$mlFH, $dbinFH, $avoidNFH,$ref_gapsFH); | ||
| 1068 | open ($seqFH, '>', $prefix . '.fasta') or die "Could not open file $prefix.fasta for write: $!\n"; | ||
| 1069 | open ($tabFH, '>', $prefix . '.tab') or die "Could not open file $prefix.tab for write: $!\n"; | ||
| 1070 | open ($binFH, '>', $prefix . '.bin') or die "Could not open file $prefix.bin for write: $!\n"; | ||
| 1071 | open ($crunchFH, '>', $prefix . '.crunch') or die "Could not open file $prefix.crunch for write: $!\n"; | ||
| 1072 | open ($gapFH, '>', $prefix . '.gaps') or die "Could not open file $prefix.gaps for write: $!\n"; | ||
| 1073 | open ($gapFHT, '>', $prefix . '.gaps.tab') or die "Could not open file $prefix.gaps.tab for write: $!\n"; | ||
| 1074 | open ($gapFHS, '>', $prefix . '.gaps.stats') or die "Could not open file $prefix.gaps.stats for write: $!\n"; | ||
| 1075 | my $num_ov=0; | ||
| 1076 | if ($mlfas ==1) | ||
| 1077 | { | ||
| 1078 | open ($mlFH, '>', $prefix . '.MULTIFASTA.fa') or die "Could not open file $prefix.contigs.fas for write: $!\n"; | ||
| 1079 | } | ||
| 1080 | if ($fasta_bin ==1) | ||
| 1081 | { | ||
| 1082 | open ($dbinFH, '>', $prefix . '.contigsInbin.fas') or die "Could not open file $prefix.contigsInbin.fas for write: $!\n"; | ||
| 1083 | } | ||
| 1084 | if ($avoid_Ns ==1) | ||
| 1085 | { | ||
| 1086 | open ($avoidNFH, '>', $prefix .'.NoNs.fasta') or die "Could not open file $prefix.NoNs.fasta for write: $!\n"; | ||
| 1087 | } | ||
| 1088 | if ($gaps_2file ne "") | ||
| 1089 | { | ||
| 1090 | open ($ref_gapsFH, '>', $gaps_2file.'.Gaps_onRef') or die "Could not open file $gaps_2file.Gaps_onRef for write: $!\n"; | ||
| 1091 | } | ||
| 1092 | #------------------------------------------------------------------------- | ||
| 1093 | # Writing tiling graph and generating a pseudomolecule | ||
| 1094 | # Note use use ps for pseudomolecule | ||
| 1095 | #@Ps = start of ps, and @Pe = end of ps | ||
| 1096 | my $ps_start =1; | ||
| 1097 | $Ps[0] = 1; | ||
| 1098 | $Pe[0] = $Ps[0] + $Len[0] -1; | ||
| 1099 | my $tmp_qual; | ||
| 1100 | my $tmp_nqual; | ||
| 1101 | my $tmp_seq =""; | ||
| 1102 | my $tmp_nseq =""; | ||
| 1103 | print "#\tOrdered contigs = $total \n"; | ||
| 1104 | |||
| 1105 | #------------------------------------------------------------ | ||
| 1106 | # The 'for loop' loops over each contig in the Tiling output | ||
| 1107 | #Writing to file is done for each contig to speed up the process | ||
| 1108 | #This part could potentially be a separate subroutine | ||
| 1109 | |||
| 1110 | print $tabFH "ID ",$id, "\n"; | ||
| 1111 | print $seqFH ">", "ordered_", $id, "\n"; | ||
| 1112 | print $gapFHT "ID ",$id, "\n"; | ||
| 1113 | |||
| 1114 | for (my $i=1; $i <= $total; $i+=1) | ||
| 1115 | { | ||
| 1116 | my $covv =sprintf("%.0f",$cov[$i -1]); #ROUNDING | ||
| 1117 | my $pidd = sprintf("%.0f", $pid[$i -1]); | ||
| 1118 | my ($contig_coord, $color, $contig_seq); | ||
| 1119 | my $contig_qual=''; | ||
| 1120 | $tiling_gap = $G[$i -1]; | ||
| 1121 | if ($tiling_gap <= 1){ #insert 100Ns for overlaps and gaps of size less than or equal to one base | ||
| 1122 | $g = $numNs; # default gap size to | ||
| 1123 | } | ||
| 1124 | else{ | ||
| 1125 | $g = $tiling_gap; | ||
| 1126 | } | ||
| 1127 | if (defined($Len[$i])) | ||
| 1128 | { | ||
| 1129 | $Ps[$i] = $Pe[$i-1] +$g +1; | ||
| 1130 | $Pe[$i] = $Ps[$i] + $Len[$i] -1; | ||
| 1131 | $total_bases_mpd+=$Len[$i]; | ||
| 1132 | } | ||
| 1133 | |||
| 1134 | if ($Rs[$i -1] <0) #check if a reference starting position is less than 0 | ||
| 1135 | { | ||
| 1136 | $Rs[$i -1] =1; | ||
| 1137 | } | ||
| 1138 | |||
| 1139 | if($orient[$i-1] eq "+") | ||
| 1140 | { | ||
| 1141 | $contig_coord = $Ps[$i -1]."..".$Pe[$i-1]; | ||
| 1142 | $color = 4; | ||
| 1143 | $contig_seq = $contigs_hash{$Cid[$i-1]}; | ||
| 1144 | } | ||
| 1145 | else | ||
| 1146 | { | ||
| 1147 | $contig_coord = "complement(".$Ps[$i -1]."..".$Pe[$i-1].")"; | ||
| 1148 | $color =3; | ||
| 1149 | $contig_seq = revComp($contigs_hash{$Cid[$i-1]}); #REVERSE COMPLEMENT A SEQUENCE | ||
| 1150 | |||
| 1151 | } | ||
| 1152 | push (@cont_lens, length($contig_seq)); | ||
| 1153 | |||
| 1154 | # tdo | ||
| 1155 | if (defined($$ref_contigs_qual{$Cid[$i-1]})) { | ||
| 1156 | ## flag to know, that the qual exists | ||
| 1157 | $qualAvailable=1; | ||
| 1158 | $contig_qual = $$ref_contigs_qual{$Cid[$i-1]}; | ||
| 1159 | } | ||
| 1160 | $tmp_qual .= $contig_qual; | ||
| 1161 | $tmp_seq .= $contig_seq; | ||
| 1162 | if ($avoid_Ns ==1) | ||
| 1163 | { | ||
| 1164 | $tmp_nseq.= $contig_seq; | ||
| 1165 | #tdo | ||
| 1166 | $tmp_nqual .= $contig_qual; | ||
| 1167 | } | ||
| 1168 | if ($mlfas ==1) | ||
| 1169 | { | ||
| 1170 | my $multifasta_seq = write_Fasta ($contig_seq); | ||
| 1171 | print $mlFH ">", $Cid[$i-1], "\n", $multifasta_seq; | ||
| 1172 | } | ||
| 1173 | if ($Re[$i -1] > $ref_len) | ||
| 1174 | { | ||
| 1175 | $Re[$i -1] = $ref_len -1; | ||
| 1176 | } | ||
| 1177 | if ($Pe[$i -1] > length($tmp_seq)) | ||
| 1178 | { | ||
| 1179 | $Pe[$i -1] = length($tmp_seq); | ||
| 1180 | } | ||
| 1181 | |||
| 1182 | #----------------------------------------- | ||
| 1183 | print $crunchFH $covv, " ", $pidd, " ", $Ps[$i -1], " ", $Pe[$i -1], " ", $Cid[$i -1], " ", $Rs[$i -1], " ", $Re[$i-1], " ", "unknown NONE\n"; | ||
| 1184 | |||
| 1185 | #WRITE FEATURE FILE | ||
| 1186 | print $tabFH "FT contig ",$contig_coord, "\n"; | ||
| 1187 | print $tabFH "FT ", "/systematic_id=\"", $Cid[$i-1],"\"","\n"; | ||
| 1188 | print $tabFH "FT ", "/method=\"", "mummer\"", "\n"; | ||
| 1189 | print $tabFH "FT ", "/Contig_coverage=\"",$cov[$i -1], "\"", "\n"; | ||
| 1190 | print $tabFH "FT ", "/Percent_identity=\"",$pid[$i -1], "\"", "\n"; | ||
| 1191 | my ($gap_coord, $gapCol,$gap_start,$gap_end,$ref_start, $ref_end) ; | ||
| 1192 | |||
| 1193 | |||
| 1194 | $gap_start = $Pe[$i -1] +1; | ||
| 1195 | if (defined $Ps[$i]) | ||
| 1196 | { | ||
| 1197 | $gap_end = $Ps[$i] -1; | ||
| 1198 | } | ||
| 1199 | else | ||
| 1200 | { | ||
| 1201 | $gap_end = $gap_start + ($g) -1 ; ############ ...... check..... | ||
| 1202 | } | ||
| 1203 | $ref_start = $Re[$i -1] +1; | ||
| 1204 | |||
| 1205 | if (defined $Rs[$i]) | ||
| 1206 | { | ||
| 1207 | $ref_end =$Rs[$i]-1; | ||
| 1208 | } | ||
| 1209 | else | ||
| 1210 | { | ||
| 1211 | $ref_end = "END"; | ||
| 1212 | } | ||
| 1213 | $gap_coord = $gap_start."..".$gap_end; | ||
| 1214 | my $ov =""; | ||
| 1215 | |||
| 1216 | if ($tiling_gap > 1) #WRITE GAP LOCATIONS AND SIZE TO FILE | ||
| 1217 | { | ||
| 1218 | print $gapFH "Gap\t",$tiling_gap, "\t", $gap_start, "\t", $gap_end, "\t", $ref_start, "\t", $ref_end,"\tNON-Overlapping\n"; | ||
| 1219 | $ov = "NO"; | ||
| 1220 | $gapCol = 8; | ||
| 1221 | push @gap_sizes, $g; | ||
| 1222 | if ($gaps_2file ne "" && $ref_start < $ref_len) | ||
| 1223 | { | ||
| 1224 | my $gapOnref = substr ($ref_inline, $ref_start, $g); | ||
| 1225 | print $ref_gapsFH ">StartOnRef_",$ref_start, " [Gap=",$g,"]\n"; | ||
| 1226 | my $file_toPrint = write_Fasta ($gapOnref); | ||
| 1227 | print $ref_gapsFH $file_toPrint; | ||
| 1228 | } | ||
| 1229 | } | ||
| 1230 | else | ||
| 1231 | { | ||
| 1232 | $color = 5; | ||
| 1233 | $gapCol =9; | ||
| 1234 | $ov ="YES"; | ||
| 1235 | $num_ov+=1; | ||
| 1236 | print $gapFH "Gap\t",$g, "\t", $gap_start, "\t", $gap_end, "\t", $ref_start, "\t", $ref_end,"\tOverlapping\n"; | ||
| 1237 | print $tabFH "FT ", "/Overlapping=\"", "YES\"", "\n"; | ||
| 1238 | } | ||
| 1239 | |||
| 1240 | print $gapFHT "FT GAP ",$gap_coord, "\n"; | ||
| 1241 | print $gapFHT "FT ", "/SIZE=\"", $g,"\"","\n"; | ||
| 1242 | print $gapFHT "FT ", "/Overlapping=\"", $ov, "\"","\n"; | ||
| 1243 | print $gapFHT "FT ", "/colour=\"",$gapCol, "\"", "\n"; | ||
| 1244 | print $tabFH "FT ", "/colour=\"",$color, "\"", "\n"; | ||
| 1245 | |||
| 1246 | my $ns = makeN($g); | ||
| 1247 | $tmp_seq = $tmp_seq.$ns; | ||
| 1248 | #tdo | ||
| 1249 | for (1..length($ns)) | ||
| 1250 | { | ||
| 1251 | $tmp_qual .= "0 "; | ||
| 1252 | } | ||
| 1253 | |||
| 1254 | } | ||
| 1255 | ## get gap stats... | ||
| 1256 | my $realGaps = scalar(@gap_sizes); | ||
| 1257 | print $gapFHS "$num_ov Gaps introduced because of overlaps\n"; | ||
| 1258 | print $gapFHS "$realGaps Real_gaps found\n#### Stats on real gaps\n"; | ||
| 1259 | |||
| 1260 | if ($realGaps >0) | ||
| 1261 | { | ||
| 1262 | my $minG = getMin(@gap_sizes); | ||
| 1263 | my $maxG = getMax(@gap_sizes); | ||
| 1264 | my $medG = getMedian(@gap_sizes); | ||
| 1265 | my ($sum, $n50) = getN50(@gap_sizes); | ||
| 1266 | print $gapFHS "Min. gap size is $minG\nMax. gap size is $maxG\nMedian gap size is $medG\nSum of gaps is $sum\nN50 gap size is $n50\n"; | ||
| 1267 | } | ||
| 1268 | #------------------------------------------------------------------ | ||
| 1269 | #tdo | ||
| 1270 | my @Quality_Array; | ||
| 1271 | if ($qualAvailable) { | ||
| 1272 | @Quality_Array = split(/\s/,$tmp_qual); | ||
| 1273 | my $res; | ||
| 1274 | foreach (@Quality_Array) { | ||
| 1275 | $res .= "$_\n"; | ||
| 1276 | } | ||
| 1277 | ## get name | ||
| 1278 | my @splits_query = split (/\//, $query_file); | ||
| 1279 | $new_query_file = $splits_query[(scalar(@splits_query)-1)]; | ||
| 1280 | open (F,"> $new_query_file.qual.plot") or die "problems\n"; | ||
| 1281 | print F $res; | ||
| 1282 | close(F); | ||
| 1283 | } | ||
| 1284 | ##WRITE PSEUDOMOLECULE WITHOUT 'N's | ||
| 1285 | #-------------------------------------- | ||
| 1286 | if ($avoid_Ns ==1) | ||
| 1287 | { | ||
| 1288 | print $avoidNFH ">", "ordered_", $id, "without 'N's","\n"; | ||
| 1289 | my $toWrite = write_Fasta ($tmp_nseq); | ||
| 1290 | print $avoidNFH $toWrite; | ||
| 1291 | } | ||
| 1292 | #################################### | ||
| 1293 | #WRITE CONTIGS WITH NO HIT TO FILE # | ||
| 1294 | ################################# | ||
| 1295 | my %Cids; | ||
| 1296 | |||
| 1297 | foreach(@Cid) | ||
| 1298 | { | ||
| 1299 | chomp; | ||
| 1300 | $Cids{$_} = 1; | ||
| 1301 | } | ||
| 1302 | my @contigs_2bin = (); | ||
| 1303 | my %h_contigs_2bin; | ||
| 1304 | |||
| 1305 | foreach (@c_keys) | ||
| 1306 | { | ||
| 1307 | push(@contigs_2bin, $_) unless exists $Cids{$_}; | ||
| 1308 | |||
| 1309 | } | ||
| 1310 | foreach(@contigs_2bin) | ||
| 1311 | { | ||
| 1312 | $h_contigs_2bin{$_}=1; | ||
| 1313 | |||
| 1314 | print $binFH "$_ \n"; | ||
| 1315 | |||
| 1316 | } | ||
| 1317 | $num_inbincontigs= scalar(@contigs_2bin); | ||
| 1318 | print "#\tBin contigs = $num_inbincontigs\n"; | ||
| 1319 | ######## | ||
| 1320 | # WRITE PSEUDOMOLECULE TO FILE | ||
| 1321 | #---------------------------------- | ||
| 1322 | my $new_seq = $tmp_seq; | ||
| 1323 | my $prev_len = length($tmp_seq); | ||
| 1324 | my $total_len = $prev_len; | ||
| 1325 | foreach (@contigs_2bin) | ||
| 1326 | { | ||
| 1327 | chomp; | ||
| 1328 | #my $binseq = $contigs_hash{$contigs_2bin[$i]}; | ||
| 1329 | my $l = length ($contigs_hash{$_}); | ||
| 1330 | $total_len +=$l; | ||
| 1331 | } | ||
| 1332 | if ($add_bin_2ps ==1) #appending unmapped contigs to pseudomolecule | ||
| 1333 | { | ||
| 1334 | |||
| 1335 | for (my $i =0; $i < scalar(@contigs_2bin); $i+=1) | ||
| 1336 | { | ||
| 1337 | my $binseq = $contigs_hash{$contigs_2bin[$i]}; | ||
| 1338 | $new_seq .=$contigs_hash{$contigs_2bin[$i]}; | ||
| 1339 | my $len_current_contig = length($binseq); | ||
| 1340 | my $start = $prev_len +1; | ||
| 1341 | my $end = $start + $len_current_contig -1; | ||
| 1342 | my $col = 7; | ||
| 1343 | if ($start > $total_len) | ||
| 1344 | { | ||
| 1345 | $start = $total_len; | ||
| 1346 | } | ||
| 1347 | if ($end >$total_len) | ||
| 1348 | { | ||
| 1349 | $end = $total_len; | ||
| 1350 | } | ||
| 1351 | my $co_cord = $start."..".$end; | ||
| 1352 | my $note = "NO_HIT"; | ||
| 1353 | print $tabFH "FT contig ",$co_cord, "\n"; | ||
| 1354 | print $tabFH "FT ", "/systematic_id=\"", $contigs_2bin[$i],"\"","\n"; | ||
| 1355 | print $tabFH "FT ", "/method=\"", "mummer\"", "\n"; | ||
| 1356 | print $tabFH "FT ", "/colour=\"",$col, "\"", "\n"; | ||
| 1357 | print $tabFH "FT ", "/", $note, "\n"; | ||
| 1358 | $prev_len= $end; | ||
| 1359 | } | ||
| 1360 | } | ||
| 1361 | my $to_write = write_Fasta ($new_seq); | ||
| 1362 | print $seqFH $to_write; | ||
| 1363 | ######## | ||
| 1364 | #WRITE CONTIGS IN BIN TO FILE # | ||
| 1365 | #------------------------------------------------------ | ||
| 1366 | if ($fasta_bin ==1) | ||
| 1367 | { | ||
| 1368 | foreach(@contigs_2bin) | ||
| 1369 | { | ||
| 1370 | print $dbinFH ">", $_, "\n"; | ||
| 1371 | my $to_write = write_Fasta($contigs_hash{$_}); | ||
| 1372 | print $dbinFH $to_write; | ||
| 1373 | } | ||
| 1374 | } | ||
| 1375 | unlink ("$choice.delta"); | ||
| 1376 | unlink ("$choice.filtered.delta"); | ||
| 1377 | unlink ("$choice.cluster"); | ||
| 1378 | unlink ("$choice.tiling"); | ||
| 1379 | #PRINT FINAL MESSAGE | ||
| 1380 | print "#\tFINISHED CONTIG ORDERING\n"; | ||
| 1381 | print "#\n#\tTo view your results in ACT\n#\t\t Sequence file 1: $new_reference_file\n#\t\t Comparison file 1: $prefix.crunch\n#\t\t Sequence file 2: $prefix.fasta\n#\n#\t\tACT feature file is: $prefix.tab\n#\t\tContigs bin file is: $prefix.bin\n#\t\tGaps in pseudomolecule are in: $prefix.gaps\n#-------------------------------------------------\n"; | ||
| 1382 | |||
| 1383 | #Run tblastx.... | ||
| 1384 | if ($run_blast ==1) | ||
| 1385 | { | ||
| 1386 | print "Running tblastx on contigs in bin...\nThis may take several minutes ...\n"; | ||
| 1387 | my $formatdb = 'formatdb -p F -i' ; | ||
| 1388 | # my @formating = ` | ||
| 1389 | !system("$formatdb $new_reference_file") or die "ERROR: Could not find 'formatdb' for blast\n"; | ||
| 1390 | my $blast_opt = 'blastall -m 9 -p tblastx -d '; | ||
| 1391 | my $contigs_inBin = $prefix.'.contigsInbin.fas'; | ||
| 1392 | # my @bigger_b = ` | ||
| 1393 | !system("$blast_opt $new_reference_file -i $contigs_inBin -o blast.out") or die "ERROR: Could not find 'blastall' , please install blast in your working path (other dir==0)\n$blast_opt $new_reference_file -i $contigs_inBin -o blast.out\n \n"; | ||
| 1394 | } | ||
| 1395 | |||
| 1396 | |||
| 1397 | if ($pick_primer == 1) | ||
| 1398 | { | ||
| 1399 | print " DESIGNING PRIMERS FOR GAP CLOSURE...\n"; | ||
| 1400 | my $qq = "$prefix.fasta"; | ||
| 1401 | pickPrimers($qq, $reference, $flank, $path_toPass, $chk_uniq,$qualAvailable,@Quality_Array); | ||
| 1402 | } | ||
| 1403 | } | ||
| 1404 | |||
| 1405 | |||
| 1406 | #------------------------------ | ||
| 1407 | sub write_Fasta { | ||
| 1408 | my $sequence = shift; | ||
| 1409 | my $fasta_seq =""; | ||
| 1410 | my $length = length($sequence); | ||
| 1411 | if ($length <= 60) | ||
| 1412 | { | ||
| 1413 | $fasta_seq = $sequence."\n"; | ||
| 1414 | } | ||
| 1415 | elsif ($length> 60 ) | ||
| 1416 | { | ||
| 1417 | for (my $i =0; $i < $length; $i+=60) | ||
| 1418 | { | ||
| 1419 | my $tmp_s = substr $sequence, $i, 60; | ||
| 1420 | $fasta_seq .= $tmp_s."\n"; | ||
| 1421 | } | ||
| 1422 | } | ||
| 1423 | |||
| 1424 | return $fasta_seq; | ||
| 1425 | } | ||
| 1426 | #---------------------------------------------- END OF CONTIG ORDERING SUBROUTINES---------------------------------------------------- | ||
| 1427 | |||
| 1428 | #----------------------------------------------- PRIMER DESIGN --------------------------------------------------- | ||
| 1429 | sub pickPrimers | ||
| 1430 | { | ||
| 1431 | #$ps = pseudo molecule,$rf = reference, $flan = flanking region size | ||
| 1432 | my ($ps,$rf, $flan, $passed_path, $chk_uniq,$qualAvailable, @Quality_Array); | ||
| 1433 | if (@_==4){ | ||
| 1434 | ($rf,$ps, $flan, $chk_uniq) = @_; | ||
| 1435 | print "Primers without ordering..\n"; | ||
| 1436 | print $rf; | ||
| 1437 | $passed_path = "nucmer"; | ||
| 1438 | $qualAvailable =0; | ||
| 1439 | @Quality_Array = []; | ||
| 1440 | } | ||
| 1441 | else #(@_ == 7) | ||
| 1442 | { | ||
| 1443 | ($ps,$rf, $flan, $passed_path, $chk_uniq, $qualAvailable, @Quality_Array) = @_; | ||
| 1444 | } | ||
| 1445 | |||
| 1446 | my $dna=''; | ||
| 1447 | my @gappedSeq; | ||
| 1448 | my $records=''; | ||
| 1449 | my @sequence; | ||
| 1450 | my $input=''; | ||
| 1451 | #tdo | ||
| 1452 | my @gappedQual; | ||
| 1453 | #my $quality=''; | ||
| 1454 | my $path_toPass = $passed_path; | ||
| 1455 | my @fasta; | ||
| 1456 | my $query=''; | ||
| 1457 | my @exc_regions; | ||
| 1458 | my $ch_name; | ||
| 1459 | #my $flank = $flan; | ||
| 1460 | open (FH, $rf) or die "Could not open reference file\n"; | ||
| 1461 | open (FH2, $ps) or die "Could not open query/pseudomolecule file\n"; | ||
| 1462 | my $ref; #print ".... ", $rf; exit; | ||
| 1463 | my @r = <FH>; | ||
| 1464 | my @qry = <FH2>; | ||
| 1465 | my $dn = join ("", @qry); | ||
| 1466 | $ref = join ("", @r); | ||
| 1467 | $dna = Fasta2ordered ($dn); | ||
| 1468 | #check if primer3 is installed | ||
| 1469 | my $pr3 = "primer3_core"; | ||
| 1470 | my ($pr3_path, $pr3_Path, $pr3_path_dir) = checkProg ($pr3); | ||
| 1471 | #my @check_prog = `which primer3_core`; | ||
| 1472 | open (PRI, '>primer3.summary.out') or die "Could not open file for write\n"; | ||
| 1473 | |||
| 1474 | # | ||
| 1475 | |||
| 1476 | #print $ref; exit; | ||
| 1477 | #PARSING FOR PRIMER3 INPUT | ||
| 1478 | my ($opt,$min,$max,$optTemp,$minTemp,$maxTemp,$flank,$lowRange,$maxRange,$gcMin,$gcOpt,$gcMax,$gclamp,$exclude,$quality) = getPoptions($qualAvailable); | ||
| 1479 | my ($gap_position,@positions, %seq_hash); | ||
| 1480 | |||
| 1481 | my $exc1 = $flank -$exclude; #start of left exclude | ||
| 1482 | print "Please wait... extracting target regions ...\n"; | ||
| 1483 | #regular expression extracts dna sequence before and after gaps in sequence (defined by N) | ||
| 1484 | while($dna=~ /([atgc]{$flank,$flank}N+[atgc]{$flank,$flank})/gi) | ||
| 1485 | { | ||
| 1486 | $records= $1; | ||
| 1487 | push (@gappedSeq, $records); | ||
| 1488 | $gap_position = index($dna, $records); | ||
| 1489 | push @positions, $gap_position; | ||
| 1490 | $seq_hash{$gap_position}=$records; | ||
| 1491 | #dna | ||
| 1492 | if ($qualAvailable) { | ||
| 1493 | my $res; | ||
| 1494 | for (my $nn=($gap_position-1); $nn <= ($gap_position-1+length($records)-1); $nn++) { | ||
| 1495 | $res.="$Quality_Array[$nn] "; | ||
| 1496 | } | ||
| 1497 | push @gappedQual, $res; | ||
| 1498 | } | ||
| 1499 | } | ||
| 1500 | #loop prints out primer targets into a file format accepted by primer3 | ||
| 1501 | my $count=1; | ||
| 1502 | my $identify=''; | ||
| 1503 | my $seq_num = scalar @gappedSeq; | ||
| 1504 | my $name= " "; | ||
| 1505 | |||
| 1506 | my ($totalp, @left_name, @right_name, @left_seq, @right_seq); | ||
| 1507 | |||
| 1508 | my ($leftP_names, $rightP_names, $leftP_seqs, $rightP_seqs, $leftP_start, $leftP_lens, $rightP_ends, $rightP_lens,$left_Exclude,$right_Exclude, $primers_toExc, $prod_size)= | ||
| 1509 | ("","","","","","","","","","", "", ""); | ||
| 1510 | |||
| 1511 | print $seq_num, " gaps found in target sequence\n"; | ||
| 1512 | print "Please wait...\nLooking for primers...\n"; | ||
| 1513 | print "Running Primer3 and checking uniquness of primers...\nCounting left and right primer hits from a nucmer mapping (-c 15 -l 15)\n"; | ||
| 1514 | |||
| 1515 | for (my $i=0; $i<$seq_num; $i+=1) | ||
| 1516 | { | ||
| 1517 | $identify = $count++; | ||
| 1518 | if (defined $ch_name) | ||
| 1519 | { | ||
| 1520 | $name = $ch_name; | ||
| 1521 | } | ||
| 1522 | my $len = length($gappedSeq[$i]); | ||
| 1523 | my $exc2 = $len - $flank; | ||
| 1524 | open(FILE, '>data') or die "Could not open file\n"; | ||
| 1525 | #tdo | ||
| 1526 | my $qual=''; | ||
| 1527 | if ($qualAvailable) { | ||
| 1528 | $qual="PRIMER_SEQUENCE_QUALITY=$gappedQual[$i]\nPRIMER_MIN_QUALITY=$quality\n"; | ||
| 1529 | } | ||
| 1530 | |||
| 1531 | #WARNING: indenting the following lines may cause problems in primer3 | ||
| 1532 | print FILE "PRIMER_SEQUENCE_ID=Starting_Pos $positions[$i] | ||
| 1533 | SEQUENCE=$gappedSeq[$i] | ||
| 1534 | PRIMER_OPT_SIZE=$opt | ||
| 1535 | PRIMER_MIN_SIZE=$min | ||
| 1536 | PRIMER_MAX_SIZE=$max | ||
| 1537 | PRIMER_OPT_TM=$optTemp | ||
| 1538 | PRIMER_MIN_TM=$minTemp | ||
| 1539 | PRIMER_MAX_TM=$maxTemp | ||
| 1540 | PRIMER_NUM_NS_ACCEPTED=1 | ||
| 1541 | PRIMER_PRODUCT_SIZE_RANGE=$lowRange-$maxRange | ||
| 1542 | PRIMER_MIN_GC=$gcMin | ||
| 1543 | PRIMER_GC_CLAMP =$gclamp | ||
| 1544 | PRIMER_OPT_GC_PERCENT=$gcOpt | ||
| 1545 | PRIMER_MAX_GC=$gcMax | ||
| 1546 | PRIMER_INTERNAL_OLIGO_EXCLUDED_REGION=$exc1,$exclude $exc2,$exclude | ||
| 1547 | ".$qual."Number To Return=1 | ||
| 1548 | =\n"; | ||
| 1549 | close FILE; | ||
| 1550 | |||
| 1551 | #runs primer3 from commandline | ||
| 1552 | |||
| 1553 | ################# NOTE: PRIMER3 SHOULD BE IN YOUR WORKING PATH ######### | ||
| 1554 | |||
| 1555 | my @Pr3_output = `$pr3_path -format_output <data`; | ||
| 1556 | #print $positions[$i], "\t", $i, " ", $path_toPass, " ", $rf, $exc1, " ",$exc2, "\n"; | ||
| 1557 | my $fil = join (":%:", @Pr3_output); | ||
| 1558 | my ($uniq_primer, $string,$left_nm,$right_nm,$left_sq, $right_sq,$left_strt,$left_ln, $right_End,$right_ln,$primers_toExclude, $product_size) | ||
| 1559 | = check_Primers ($fil, $positions[$i], $i,$path_toPass, $rf, $exc1, $exc2); | ||
| 1560 | |||
| 1561 | print PRI $string; | ||
| 1562 | if ($uniq_primer ==1) | ||
| 1563 | { | ||
| 1564 | $leftP_names.=$left_nm."\n"; | ||
| 1565 | $rightP_names.=$right_nm."\n"; | ||
| 1566 | $leftP_seqs.=$left_sq."\n"; | ||
| 1567 | $rightP_seqs.=$right_sq."\n"; | ||
| 1568 | $leftP_start.=$left_strt."\n"; | ||
| 1569 | $leftP_lens.=$left_ln."\n"; | ||
| 1570 | $rightP_ends.=$right_End."\n"; | ||
| 1571 | $rightP_lens.=$right_ln."\n"; | ||
| 1572 | $left_Exclude.=$exc1."\n"; | ||
| 1573 | $right_Exclude.=$exc2."\n"; | ||
| 1574 | $prod_size.=$product_size."\n"; | ||
| 1575 | } | ||
| 1576 | if ($primers_toExclude ne "") | ||
| 1577 | { | ||
| 1578 | $primers_toExc.= $primers_toExclude; #."\n"; | ||
| 1579 | } | ||
| 1580 | |||
| 1581 | } | ||
| 1582 | write_Primers ($leftP_names, $rightP_names, $leftP_seqs, $rightP_seqs, $leftP_start, $leftP_lens, $rightP_ends, $rightP_lens,$primers_toExc,$left_Exclude,$right_Exclude, $prod_size); | ||
| 1583 | #write_Primers (@left_name, @right_name, @left_seq, @right_seq,@left_start, @left_len, @right_end, @right_len, @left_exclude, @right_exclude, $primers_toExclude); | ||
| 1584 | |||
| 1585 | } | ||
| 1586 | |||
| 1587 | #checks the uniqueness of primers | ||
| 1588 | #input an array with promer3 output for each gap | ||
| 1589 | sub check_Primers | ||
| 1590 | { | ||
| 1591 | |||
| 1592 | my ($fil, $position, $index,$path_toPass, $rf, $exc1, $exc2) = @_; | ||
| 1593 | my @Pr3_output = split /:%:/, $fil; | ||
| 1594 | my ($left_name, $right_name, $left_seq, $right_seq, $left_start,$left_len,$right_end,$right_len,$left_exclude,$right_exclude) = ("", "", "", "", "", "", "", "", "", ""); | ||
| 1595 | my $primers_toExclude =""; | ||
| 1596 | my $product_size =""; | ||
| 1597 | my $string =""; | ||
| 1598 | my $uniq_primer = 0; | ||
| 1599 | $string.="=========================================================================================\n"; | ||
| 1600 | $string.="Primer set for region starting at ".$position."\n"; | ||
| 1601 | |||
| 1602 | if (defined $Pr3_output[5] && defined $Pr3_output[6]) | ||
| 1603 | { | ||
| 1604 | if ($Pr3_output[5]=~ /LEFT PRIMER/) | ||
| 1605 | { | ||
| 1606 | # print $Pr3_output[5]; | ||
| 1607 | #check uniquness of primer against the genome | ||
| 1608 | my @splits_1 = split (/\s+/, $Pr3_output[5]); | ||
| 1609 | my $left_primer = $splits_1[8]; | ||
| 1610 | my $left_st = $splits_1[2]; | ||
| 1611 | my $left_length = $splits_1[3]; | ||
| 1612 | |||
| 1613 | my @splits_2 = split (/\s+/, $Pr3_output[6]); | ||
| 1614 | my $right_primer = $splits_2[8]; | ||
| 1615 | my $right_st = $splits_2[2]; | ||
| 1616 | my $right_length = $splits_2[3]; | ||
| 1617 | |||
| 1618 | open (QRY_1, '>./left_query'); # open a file for left primers | ||
| 1619 | print QRY_1 ">left_01\n"; # | ||
| 1620 | print QRY_1 $left_primer,"\n"; | ||
| 1621 | open (QRY_2, '>./right_query'); | ||
| 1622 | print QRY_2 ">right_01\n"; | ||
| 1623 | print QRY_2 $right_primer,"\n"; | ||
| 1624 | |||
| 1625 | my ($left_count, $right_count); | ||
| 1626 | #if ($chk_uniq eq "nucmer") | ||
| 1627 | #{ | ||
| 1628 | my $options = "-c 15 --coords -l 15 "; | ||
| 1629 | my $rq = "right_query"; | ||
| 1630 | my $lq = "left_query"; | ||
| 1631 | my (@right_ps, @left_ps); | ||
| 1632 | # print $path_toPass, "\t", $options, "\n"; | ||
| 1633 | |||
| 1634 | |||
| 1635 | my @Rrun = `$path_toPass $options -p R $rf $rq &> /dev/null`; | ||
| 1636 | print "."; | ||
| 1637 | my $f1 = "R.coords"; | ||
| 1638 | open (RP, $f1) or die "Could not open file $f1 while checking uniqueness of right primer\n"; | ||
| 1639 | while (<RP>) | ||
| 1640 | { | ||
| 1641 | chomp; | ||
| 1642 | if ($_ =~ /right_01$/) | ||
| 1643 | { | ||
| 1644 | push @right_ps, $_; | ||
| 1645 | } | ||
| 1646 | } | ||
| 1647 | close (RP); | ||
| 1648 | my @Lrun = `$path_toPass $options -p L $rf $lq &> /dev/null`; | ||
| 1649 | print "."; | ||
| 1650 | my $f2 = "L.coords"; | ||
| 1651 | open (LQ, $f2) or die "Could not open file $f2\n"; | ||
| 1652 | while (<LQ>) | ||
| 1653 | { | ||
| 1654 | chomp; | ||
| 1655 | if ($_ =~ /left_01$/) | ||
| 1656 | { | ||
| 1657 | push @left_ps, $_; | ||
| 1658 | } | ||
| 1659 | } | ||
| 1660 | close (LQ); | ||
| 1661 | $right_count = scalar (@right_ps); | ||
| 1662 | $left_count = scalar(@left_ps); | ||
| 1663 | #check if a primer is not in the excluded region:: | ||
| 1664 | my $primer_NearEnd =0; | ||
| 1665 | if ($left_st > $exc1 || $right_st < $exc2) | ||
| 1666 | { | ||
| 1667 | $primer_NearEnd = 1; | ||
| 1668 | } | ||
| 1669 | |||
| 1670 | if ($left_count < 2 && $right_count<2 && $primer_NearEnd ==0) | ||
| 1671 | { | ||
| 1672 | $string.=$left_count."\t".$Pr3_output[5]."\n"; | ||
| 1673 | $string.=$right_count."\t".$Pr3_output[6]."\n"; | ||
| 1674 | $string.="***************************** PRIMER3 OUTPUT **************************\n"; | ||
| 1675 | foreach (@Pr3_output) {$string.=$_;} | ||
| 1676 | |||
| 1677 | my @prod_size_split = split /\s+/, $Pr3_output[10]; | ||
| 1678 | |||
| 1679 | $product_size = substr($prod_size_split[2], 0, -1); | ||
| 1680 | $left_name = $position; | ||
| 1681 | $right_name = $position; | ||
| 1682 | my $lp_uc = uc ($left_primer); | ||
| 1683 | my $rp_uc = uc($right_primer); | ||
| 1684 | #print $left_count, "..", $right_count, "\t"; | ||
| 1685 | $left_seq = $lp_uc; | ||
| 1686 | $right_seq= $rp_uc; | ||
| 1687 | |||
| 1688 | $left_start= $left_st; | ||
| 1689 | $left_len = $left_length; | ||
| 1690 | |||
| 1691 | $right_end = $right_st; | ||
| 1692 | $right_len = $right_length; | ||
| 1693 | |||
| 1694 | $left_exclude = $exc1; | ||
| 1695 | $right_exclude =$exc2; | ||
| 1696 | $uniq_primer =1; | ||
| 1697 | } | ||
| 1698 | else | ||
| 1699 | { | ||
| 1700 | if ($primer_NearEnd ==1) | ||
| 1701 | { | ||
| 1702 | $string.="One of the oligos is near the end of a contig\n"; | ||
| 1703 | } | ||
| 1704 | else | ||
| 1705 | { | ||
| 1706 | $string.="Primer set not unique\n"; | ||
| 1707 | } | ||
| 1708 | $primers_toExclude.=">L.".$position."\n".$left_primer."\n"; | ||
| 1709 | $primers_toExclude.=">R.".$position."\n".$right_primer."\n"; | ||
| 1710 | } | ||
| 1711 | |||
| 1712 | } | ||
| 1713 | else | ||
| 1714 | { | ||
| 1715 | $string.="No Primers found\n"; | ||
| 1716 | } | ||
| 1717 | } | ||
| 1718 | |||
| 1719 | return ($uniq_primer, $string,$left_name,$right_name,$left_seq, $right_seq,$left_start,$left_len, $right_end,$right_len,$primers_toExclude, $product_size); | ||
| 1720 | |||
| 1721 | |||
| 1722 | } | ||
| 1723 | |||
| 1724 | ###------------------------------------ | ||
| 1725 | # Writes primers and their regions to file | ||
| 1726 | sub write_Primers { | ||
| 1727 | my ($leftP_names, $rightP_names, $leftP_seqs, $rightP_seqs, $leftP_start, $leftP_lens, $rightP_ends, $rightP_lens,$primers_toExclude,$left_Exclude,$right_Exclude, $product_sizes) = @_; | ||
| 1728 | my (@left_name, @right_name, @left_seq, @right_seq, @left_start, @left_len, @right_end, @right_len, @left_exclude, @right_exclude, @product_size); | ||
| 1729 | |||
| 1730 | #open files to read | ||
| 1731 | @left_name = split /\n/, $leftP_names; | ||
| 1732 | @right_name= split /\n/, $rightP_names; | ||
| 1733 | @left_seq = split /\n/, $leftP_seqs; | ||
| 1734 | @right_seq = split /\n/, $rightP_seqs; | ||
| 1735 | |||
| 1736 | @left_start = split /\n/, $leftP_start; | ||
| 1737 | @left_len = split /\n/, $leftP_lens; | ||
| 1738 | @right_end = split/\n/, $rightP_ends; | ||
| 1739 | @right_len = split /\n/, $rightP_lens; | ||
| 1740 | @left_exclude = split /\n/, $left_Exclude; | ||
| 1741 | @right_exclude = split /\n/,$right_Exclude; | ||
| 1742 | @product_size = split /\n/, $product_sizes; | ||
| 1743 | |||
| 1744 | my $primers_withSize =""; | ||
| 1745 | open (SEN, '>sense_primers.out') or die "Could not open file for write\n"; | ||
| 1746 | open (ASEN, '>antiSense_primers.out') or die "Could not open file for write\n"; | ||
| 1747 | open (REG_1, '>sense_regions.out') or die "Could not open file for write\n"; | ||
| 1748 | open (REG_2, '>antiSense_regions.out') or die "Could not open file for write\n"; | ||
| 1749 | |||
| 1750 | if ($primers_toExclude ne "") | ||
| 1751 | { | ||
| 1752 | open (PEX, '>primers_toExclude.out') or die "Could not open file for write\n"; | ||
| 1753 | print PEX $primers_toExclude; | ||
| 1754 | } | ||
| 1755 | |||
| 1756 | |||
| 1757 | my $totalp = scalar (@left_name); | ||
| 1758 | |||
| 1759 | #print $totalp, "\n"; exit; | ||
| 1760 | |||
| 1761 | my $well_pos; | ||
| 1762 | my $max_plates = ceil($totalp/96); | ||
| 1763 | #print "MAX Ps ", $max_plates, "\n"; | ||
| 1764 | my $plate=1; | ||
| 1765 | my $sen =""; | ||
| 1766 | my $asen =""; | ||
| 1767 | my $plate_counter =0; | ||
| 1768 | my $wells = 96; | ||
| 1769 | for (my $index =0; $index < $totalp; $index += $wells) | ||
| 1770 | { | ||
| 1771 | my $do = $index; | ||
| 1772 | my $upper_bound= $index + $wells; | ||
| 1773 | if ($upper_bound > $totalp) | ||
| 1774 | { | ||
| 1775 | $upper_bound = $totalp; | ||
| 1776 | } | ||
| 1777 | |||
| 1778 | for (my $j=$index; $j <= ($upper_bound-1); $j+=1) | ||
| 1779 | { | ||
| 1780 | my $i = $j; | ||
| 1781 | if ($j < 96) | ||
| 1782 | { | ||
| 1783 | $well_pos = get_WellPosition ($j); | ||
| 1784 | } | ||
| 1785 | else | ||
| 1786 | { | ||
| 1787 | $well_pos = get_WellPosition ($j - $wells) | ||
| 1788 | } | ||
| 1789 | |||
| 1790 | #$primers_withSize.=$product_size[$i]."\t"."Plate_".$plate. "\t\tS.".$i."\tS.".$left_name[$i]."\t". | ||
| 1791 | print SEN "Plate_".$plate, "\t\t","S.", $i, "\tS.", $left_name[$i], "\t", $left_seq[$i], "\t\t+", "\t", $well_pos, "\n"; | ||
| 1792 | print ASEN "Plate_".$plate, "\t\t","AS.", $i, "\tAS.", $right_name[$i], "\t", $right_seq[$i], "\t\t-","\t", $well_pos,"\n"; | ||
| 1793 | print REG_1 "Plate_".$plate, "\t\t","S.", $i, "\t", $left_start[$i], "\t", $left_len[$i], "\n"; | ||
| 1794 | print REG_2 "Plate_".$plate, "\t\t","AS.", $i, "\t", $right_end[$i], "\t",$right_len[$i], "\n"; | ||
| 1795 | |||
| 1796 | } | ||
| 1797 | $plate +=1; | ||
| 1798 | } | ||
| 1799 | |||
| 1800 | #delete tmp. files | ||
| 1801 | #my $rm = "rm -f"; | ||
| 1802 | system ("rm -f data left_query right_query R.delta R.cluster R.coords L.delta L.cluster L.coords"); | ||
| 1803 | print "\nPRIMER DESIGN DONE\n\n"; | ||
| 1804 | # end of primer design program | ||
| 1805 | }#// | ||
| 1806 | ##### | ||
| 1807 | # returns a well position for oligos | ||
| 1808 | sub get_WellPosition{ | ||
| 1809 | |||
| 1810 | my $j = shift; | ||
| 1811 | my $well_pos; | ||
| 1812 | if ($j < 12) | ||
| 1813 | { | ||
| 1814 | $well_pos = "a".($j+1); | ||
| 1815 | } | ||
| 1816 | elsif ($j>11 && $j<24) { | ||
| 1817 | $well_pos = "b". (($j+1) -12); | ||
| 1818 | } | ||
| 1819 | elsif ($j>23 && $j<36) { | ||
| 1820 | $well_pos = "c". (($j+1) -24); | ||
| 1821 | } | ||
| 1822 | elsif ($j>35 && $j<48) { | ||
| 1823 | $well_pos = "d". (($j+1) - 36); | ||
| 1824 | } | ||
| 1825 | elsif($j>47 && $j<60) { | ||
| 1826 | $well_pos = "e". (($j+1) -48); | ||
| 1827 | } | ||
| 1828 | elsif ($j>59 && $j<72) | ||
| 1829 | { | ||
| 1830 | $well_pos = "f". (($j+1) - 60); | ||
| 1831 | } | ||
| 1832 | elsif ($j>71 && $j< 84) | ||
| 1833 | { | ||
| 1834 | $well_pos = "g". (($j+1) - 72); | ||
| 1835 | } | ||
| 1836 | elsif ($j>83 && $j<96) | ||
| 1837 | { | ||
| 1838 | $well_pos = "h". (($j+1) - 84); | ||
| 1839 | } | ||
| 1840 | return $well_pos; | ||
| 1841 | } | ||
| 1842 | |||
| 1843 | |||
| 1844 | #################################################################### | ||
| 1845 | #get options for primer design | ||
| 1846 | #---------------------- | ||
| 1847 | sub getPoptions{ | ||
| 1848 | |||
| 1849 | my $qualAvailable = shift; | ||
| 1850 | #### USER INPUTS ########## | ||
| 1851 | #ask for optimum primer size | ||
| 1852 | print "\nEnter Optimum Primer size (default 20 bases):"; | ||
| 1853 | my $opt=<STDIN>; | ||
| 1854 | chomp $opt; | ||
| 1855 | if($opt eq '') | ||
| 1856 | { | ||
| 1857 | $opt = 20; | ||
| 1858 | } | ||
| 1859 | #ask for minimum primer size | ||
| 1860 | print "\nEnter Minimum Primer size (default 18 bases):"; | ||
| 1861 | my $min=<STDIN>; | ||
| 1862 | chomp $min; | ||
| 1863 | if($min eq '') | ||
| 1864 | { | ||
| 1865 | $min = 18; | ||
| 1866 | } | ||
| 1867 | #ask for maximum primer size | ||
| 1868 | print "\nEnter Maximum Primer size (default 27 bases):"; | ||
| 1869 | my $max= <STDIN>; | ||
| 1870 | chomp $max; | ||
| 1871 | if($max eq '') | ||
| 1872 | { | ||
| 1873 | $max= 27; | ||
| 1874 | } | ||
| 1875 | #ask for optimum primer temperature | ||
| 1876 | print "\nEnter Optimum melting temperature (Celcius) for a primer oligo (default 60.0C):"; | ||
| 1877 | my $optTemp=<STDIN>; | ||
| 1878 | chomp $optTemp; | ||
| 1879 | if($optTemp eq '') | ||
| 1880 | { | ||
| 1881 | $optTemp = 60.0; | ||
| 1882 | } | ||
| 1883 | #ask for minimum primer temperature | ||
| 1884 | print "\nEnter Minimum melting temperature (Celcius) for a primer oligo (default 57.0C):"; | ||
| 1885 | my $minTemp=<STDIN>; | ||
| 1886 | chomp $minTemp; | ||
| 1887 | if($minTemp eq '') | ||
| 1888 | { | ||
| 1889 | $minTemp = 57.0; | ||
| 1890 | } | ||
| 1891 | #ask for maximum primer temperature | ||
| 1892 | print "\nEnter Maximum melting temperature (Celcius) for a primer oligo (default 63.0C):"; | ||
| 1893 | my $maxTemp=<STDIN>; | ||
| 1894 | chomp $maxTemp; | ||
| 1895 | if($maxTemp eq '') | ||
| 1896 | { | ||
| 1897 | $maxTemp = 63.0; | ||
| 1898 | } | ||
| 1899 | print "\nEnter flanking region size (default 1000 bases): "; | ||
| 1900 | my $flank=<STDIN>; | ||
| 1901 | chomp $flank; | ||
| 1902 | if ($flank eq '') | ||
| 1903 | { | ||
| 1904 | $flank = 1000; | ||
| 1905 | } | ||
| 1906 | #ask for primer product range | ||
| 1907 | print "\nEnter minimum product size produced by primers (default =flanking size):"; | ||
| 1908 | my $lowRange=<STDIN>; | ||
| 1909 | chomp $lowRange; | ||
| 1910 | if($lowRange eq '') | ||
| 1911 | { | ||
| 1912 | $lowRange = $flank; | ||
| 1913 | } | ||
| 1914 | print "\nEnter maxmimum product size produced by primers (default 7000):"; | ||
| 1915 | my $maxRange=<STDIN>; | ||
| 1916 | chomp $maxRange; | ||
| 1917 | if($maxRange eq '') | ||
| 1918 | { | ||
| 1919 | $maxRange = 7000; | ||
| 1920 | } | ||
| 1921 | #ask for minimum GC content in primers | ||
| 1922 | print "\nEnter minimum GC content in primers (default 20%):"; | ||
| 1923 | my $gcMin=<STDIN>; | ||
| 1924 | chomp $gcMin; | ||
| 1925 | if($gcMin eq '') | ||
| 1926 | { | ||
| 1927 | $gcMin = 20.0; | ||
| 1928 | } | ||
| 1929 | #ask for optimum GC content in primers | ||
| 1930 | print "\nEnter optimum GC content in primers (default 50%):"; | ||
| 1931 | my $gcOpt=<STDIN>; | ||
| 1932 | chomp $gcOpt; | ||
| 1933 | if($gcOpt eq '') | ||
| 1934 | { | ||
| 1935 | $gcOpt = 50.0; | ||
| 1936 | } | ||
| 1937 | #ask for maximum GC content in primers | ||
| 1938 | print "\nEnter maximum GC content in primers (default 80%):"; | ||
| 1939 | my $gcMax=<STDIN>; | ||
| 1940 | chomp $gcMax; | ||
| 1941 | if($gcMax eq '') | ||
| 1942 | { | ||
| 1943 | $gcMax = 80.0; | ||
| 1944 | } | ||
| 1945 | print "\nEnter GC clamp (default 1):"; | ||
| 1946 | my $gclamp=<STDIN>; | ||
| 1947 | chomp $gclamp; | ||
| 1948 | if($gclamp eq '') | ||
| 1949 | { | ||
| 1950 | $gclamp = 1; | ||
| 1951 | } | ||
| 1952 | print "\nEnter size of region to exclude at the end of contigs (default 100 bases):"; | ||
| 1953 | my $exclude=<STDIN>; | ||
| 1954 | chomp $exclude; | ||
| 1955 | if ($exclude eq '') | ||
| 1956 | { | ||
| 1957 | $exclude = 100; | ||
| 1958 | } | ||
| 1959 | |||
| 1960 | |||
| 1961 | #tdo | ||
| 1962 | my $quality=''; | ||
| 1963 | if ($qualAvailable) | ||
| 1964 | { | ||
| 1965 | |||
| 1966 | print "\nEnter minimum quality for primer pick (default 40):"; | ||
| 1967 | $quality=<STDIN>; | ||
| 1968 | chomp $quality; | ||
| 1969 | if($quality eq '') | ||
| 1970 | { | ||
| 1971 | $quality = 40; | ||
| 1972 | } | ||
| 1973 | } | ||
| 1974 | |||
| 1975 | |||
| 1976 | return ($opt,$min,$max,$optTemp,$minTemp,$maxTemp,$flank,$lowRange,$maxRange,$gcMin,$gcOpt,$gcMax,$gclamp,$exclude, $quality); | ||
| 1977 | |||
| 1978 | } | ||
| 1979 | ############### | ||
| 1980 | #-----------------------------------------------------END of PRIMER DESIGN ---------------------------------------------------------------- | ||
| 1981 | #-----------------------------------------------------END OF ABACAS ----------------------------------------------------------------------- | ||
| 1982 | |||
| 1983 | __END__ |