Add tests for memory leaks and weaken for Issue #81
[bioperl-live.git] / examples / tools / run_primer3.pl
blob5b4d9171c3ca5c475110c868b3d825e221fb7fa4
1 #!/usr/bin/perl
3 =head1 NAME
5 run_primer3.pl - run primer3 and parse its output
7 =head1 SYNOPSIS
9 ./run_primer3.pl -i test.fa
11 #or
13 ./run_primer3.pl --input=test.fa
15 =head1 DESCRIPTION
17 Example of how to run primer3 and parse its output, essentially taken from an
18 email written by Paul Wiersma to bioperl-l.
20 =head1 FEEDBACK
22 User feedback is an integral part of the evolution of this and other
23 Bioperl scripts. Send your comments and suggestions to the Bioperl
24 mailing list. Your participation is much appreciated.
26 bioperl-l@bioperl.org - General discussion
27 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
29 =head2 Reporting Bugs
31 Report bugs to the Bioperl bug tracking system to help us keep track
32 of the bugs and their resolution. Bug reports can be submitted via the
33 web:
35 https://github.com/bioperl/bioperl-live/issues
37 =head1 AUTHOR
39 Brian Osborne, bosborne at alum.mit.edu
41 =cut
43 use strict;
44 use Getopt::Long;
45 use Bio::Tools::Run::Primer3;
46 use Bio::SeqIO;
48 my $in_file;
50 GetOptions("i|input:s" => \$in_file );
52 usage() unless $in_file;
54 my $seqio = Bio::SeqIO->new(-file => $in_file);
56 while (my $seq = $seqio->next_seq) {
57 my $primer3 = Bio::Tools::Run::Primer3->new(-seq => $seq);
58 $primer3->program_name('primer3_core') unless $primer3->executable;
60 $primer3->add_targets('PRIMER_MIN_TM' => 56, 'PRIMER_MAX_TM' => 90);
62 my $results = $primer3->run;
64 unless ($results->number_of_results) {
65 print "No results for ",$seq->display_id;
66 next;
69 my @out_keys_part = qw(START
70 LENGTH
72 GC_PERCENT
73 SELF_ANY
74 SELF_END
75 SEQUENCE );
77 print "\n", $seq->display_id, "\n";
79 for (my $i = 0 ; $i < $results->number_of_results ; $i++){
80 my $result = $results->primer_results($i);
82 print "\n", $i + 1;
83 for my $key qw(PRIMER_LEFT PRIMER_RIGHT){
84 my ($start, $length) = split /,/, $result->{$key};
85 $result->{$key . "_START"} = $start;
86 $result->{$key . "_LENGTH"} = $length;
87 foreach my $partkey (@out_keys_part) {
88 print "\t", $result->{$key . "_" . $partkey};
90 print "\n";
92 print "\tPRODUCT SIZE: ", $result->{'PRIMER_PRODUCT_SIZE'}, ", PAIR ANY COMPL: ",
93 $result->{'PRIMER_PAIR_COMPL_ANY'};
94 print ", PAIR 3\' COMPL: ", $result->{'PRIMER_PAIR_COMPL_END'}, "\n";
98 sub usage {
99 exec('perldoc',$0);
100 exit(0);
103 __END__