blib/lib/Bio/Tools/Run/Primer3.pm

filter: Statementstmt 29.0% 52 / 179 Branchbran 12.2% 12 / 98 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 64.7% 11 / 17 Podpod 100% 7 / 7 totaltotal 26.1% 82 / 314 CC 58 SCAR 54.4
CC
58
Cov
22%
add_targets
600.0
run
182.0
version
30.0
CRAP 231.5
« blib/lib/Bio/Tools/Run/Phylo/Phylip/ProtDist.pm ↑ Summary blib/lib/Bio/Tools/Run/Alignment/TCoffee.pm »
1 # $Id$
2 #
3 # This is the original copyright statement. I have relied on Chad's module
4 # extensively for this module.
5 #
6 # Copyright (c) 1997-2001 bioperl, Chad Matsalla. All Rights Reserved.
7 # This module is free software; you can redistribute it and/or
8 # modify it under the same terms as Perl itself.
9 #
10 # Copyright Chad Matsalla
11 #
12 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
14 #
15 # But I have modified lots of it, so I guess I should add:
16 #
17 # Copyright (c) 2003 bioperl, Rob Edwards. All Rights Reserved.
18 # This module is free software; you can redistribute it and/or
19 # modify it under the same terms as Perl itself.
20 #
21 # Copyright Rob Edwards
22 #
23 # You may distribute this module under the same terms as perl itself
24 # POD documentation - main docs before the code
25  
26 =head1 NAME
27  
28 Bio::Tools::Run::Primer3 - Create input for and work with the output
29 from the program primer3
30  
31 =head1 SYNOPSIS
32  
33 Bio::Tools::Primer3 creates the input files needed to design primers
34 using primer3 and provides mechanisms to access data in the primer3
35 output files.
36  
37 This module provides a bioperl interface to the program primer3. See
38 http://frodo.wi.mit.edu/primer3/primer3_code.html for
39 details and to download the software. This module only works for
40 primer3 release 1 but is not guaranteed to work with earlier versions.
41  
42 # design some primers.
43 # the output will be put into temp.out
44 use Bio::Tools::Run::Primer3;
45 use Bio::SeqIO;
46  
47 my $seqio = Bio::SeqIO->new(-file=>'data/dna1.fa');
48 my $seq = $seqio->next_seq;
49 my $primer3 = Bio::Tools::Run::Primer3->new(-seq => $seq,
50 -outfile => "temp.out",
51 -path => "/usr/bin/primer3_core");
52  
53 # or after the fact you can change the program_name
54 $primer3->program_name('my_suprefast_primer3');
55  
56 unless ($primer3->executable) {
57 print STDERR "primer3 can not be found. Is it installed?\n";
58 exit(-1)
59 }
60  
61 # what are the arguments, and what do they mean?
62 my $args = $primer3->arguments;
63  
64 print "ARGUMENT\tMEANING\n";
65 foreach my $key (keys %{$args}) {print "$key\t", $$args{$key}, "\n"}
66  
67 # set the maximum and minimum Tm of the primer
68 $primer3->add_targets('PRIMER_MIN_TM'=>56, 'PRIMER_MAX_TM'=>90);
69  
70 # design the primers. This runs primer3 and returns a
71 # Bio::Tools::Run::Primer3 object with the results
72 $results = $primer3->run;
73  
74 # see the Bio::Tools::Run::Primer3 pod for
75 # things that you can get from this. For example:
76  
77 print "There were ", $results->number_of_results, " primers\n";
78  
79 Bio::Tools::Run::Primer3 creates the input files needed to design primers
80 using primer3 and provides mechanisms to access data in the primer3
81 output files.
82  
83 This module provides a bioperl interface to the program primer3. See
84 http://www-genome.wi.mit.edu/genome_software/other/primer3.html for
85 details and to download the software.
86  
87 This module is based on one written by Chad Matsalla
88 (bioinformatics1@dieselwurks.com). I have ripped some of his code, and
89 added a lot of my own. I hope he is not mad at me!
90  
91 =head1 FEEDBACK
92  
93 =head2 Mailing Lists
94  
95 User feedback is an integral part of the evolution of this and other
96 Bioperl modules. Send your comments and suggestions preferably to one
97 of the Bioperl mailing lists. Your participation is much appreciated.
98  
99 bioperl-l@bioperl.org - General discussion
100 http://www.bioperl.org/MailList.html - About the mailing lists
101  
102 =head2 Support
103  
104 Please direct usage questions or support issues to the mailing list:
105  
106 I<bioperl-l@bioperl.org>
107  
108 rather than to the module maintainer directly. Many experienced and
109 reponsive experts will be able look at the problem and quickly
110 address it. Please include a thorough description of the problem
111 with code and data examples if at all possible.
112  
113 =head2 Reporting Bugs
114  
115 Report bugs to the Bioperl bug tracking system to help us keep track
116 the bugs and their resolution. Bug reports can be submitted via the
117 web:
118  
119 http://redmine.open-bio.org/projects/bioperl/
120  
121 =head1 AUTHOR
122  
123 Rob Edwards
124  
125 redwards@utmem.edu
126  
127 Based heavily on work of Chad Matsalla
128  
129 bioinformatics1@dieselwurks.com
130  
131 =head1 CONTRIBUTORS
132  
133 Shawn Hoon shawnh-at-stanford.edu
134 Jason Stajich jason-at-bioperl.org
135 Brian Osborne osborne1-at-optonline.net
136  
137 =head1 SEE ALSO
138  
139 L<Bio::Tools::Primer3>
140  
141 =head1 APPENDIX
142  
143 The rest of the documentation details each of the object methods.
144 Internal methods are usually preceded with a _
145  
146 =cut
147  
148 # Let the code begin...
149  
150  
151 package Bio::Tools::Run::Primer3;
152  
153 1 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
154 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
155 1 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
156 1 ▶use Bio::Tools::Primer3;
Subroutine BEGIN: called CC=1 SCAR=0.0
157 1 ▶use Bio::Tools::Run::WrapperBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
158 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
159  
160 1 ▶use vars qw($AUTOLOAD @ISA @PRIMER3_PARAMS $PROGRAMNAME %OK_FIELD);
Subroutine BEGIN: called CC=1 SCAR=0.0
161  
162 1 @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
163  
164  
165 BEGIN {
166 1 ▶ $PROGRAMNAME = 'primer3';
Subroutine BEGIN: called CC=2 SCAR=6.9
167 1 @PRIMER3_PARAMS=qw( PROGRAM EXCLUDED_REGION INCLUDED_REGION
168 PRIMER_COMMENT PRIMER_DNA_CONC PRIMER_EXPLAIN_FLAG PRIMER_FILE_FLAG
169 PRIMER_FIRST_BASE_INDEX PRIMER_GC_CLAMP
170 PRIMER_INTERNAL_OLIGO_DNA_CONC PRIMER_INTERNAL_OLIGO_EXCLUDED_REGION
171 PRIMER_INTERNAL_OLIGO_INPUT PRIMER_INTERNAL_OLIGO_MAX_GC
172 PRIMER_INTERNAL_OLIGO_MAX_MISHYB PRIMER_INTERNAL_OLIGO_MAX_POLY_X
173 PRIMER_INTERNAL_OLIGO_MAX_SIZE PRIMER_INTERNAL_OLIGO_MAX_TM
174 PRIMER_INTERNAL_OLIGO_MIN_GC PRIMER_INTERNAL_OLIGO_MIN_QUALITY
175 PRIMER_INTERNAL_OLIGO_MIN_SIZE PRIMER_INTERNAL_OLIGO_MIN_TM
176 PRIMER_INTERNAL_OLIGO_MISHYB_LIBRARY
177 PRIMER_INTERNAL_OLIGO_OPT_GC_PERCENT PRIMER_INTERNAL_OLIGO_OPT_SIZE
178 PRIMER_INTERNAL_OLIGO_OPT_TM PRIMER_INTERNAL_OLIGO_SALT_CONC
179 PRIMER_INTERNAL_OLIGO_SELF_ANY PRIMER_INTERNAL_OLIGO_SELF_END
180 PRIMER_IO_WT_COMPL_ANY PRIMER_IO_WT_COMPL_END PRIMER_IO_WT_END_QUAL
181 PRIMER_IO_WT_GC_PERCENT_GT PRIMER_IO_WT_GC_PERCENT_LT
182 PRIMER_IO_WT_NUM_NS PRIMER_IO_WT_REP_SIM PRIMER_IO_WT_SEQ_QUAL
183 PRIMER_IO_WT_SIZE_GT PRIMER_IO_WT_SIZE_LT PRIMER_IO_WT_TM_GT
184 PRIMER_IO_WT_TM_LT PRIMER_LEFT_INPUT PRIMER_LIBERAL_BASE
185 PRIMER_MAX_DIFF_TM PRIMER_MAX_END_STABILITY PRIMER_MAX_GC
186 PRIMER_MAX_MISPRIMING PRIMER_MAX_POLY_X PRIMER_MAX_SIZE PRIMER_MAX_TM
187 PRIMER_MIN_END_QUALITY PRIMER_MIN_GC PRIMER_MIN_QUALITY
188 PRIMER_MIN_SIZE PRIMER_MIN_TM PRIMER_MISPRIMING_LIBRARY
189 PRIMER_NUM_NS_ACCEPTED PRIMER_NUM_RETURN PRIMER_OPT_GC_PERCENT
190 PRIMER_OPT_SIZE PRIMER_OPT_TM PRIMER_PAIR_MAX_MISPRIMING
191 PRIMER_PAIR_WT_COMPL_ANY PRIMER_PAIR_WT_COMPL_END
192 PRIMER_PAIR_WT_DIFF_TM PRIMER_PAIR_WT_IO_PENALTY
193 PRIMER_PAIR_WT_PRODUCT_SIZE_GT PRIMER_PAIR_WT_PRODUCT_SIZE_LT
194 PRIMER_PAIR_WT_PRODUCT_TM_GT PRIMER_PAIR_WT_PRODUCT_TM_LT
195 PRIMER_PAIR_WT_PR_PENALTY PRIMER_PAIR_WT_REP_SIM PRIMER_PICK_ANYWAY
196 PRIMER_PICK_INTERNAL_OLIGO PRIMER_PRODUCT_MAX_TM
197 PRIMER_PRODUCT_MIN_TM PRIMER_PRODUCT_OPT_SIZE PRIMER_PRODUCT_OPT_TM
198 PRIMER_PRODUCT_SIZE_RANGE PRIMER_QUALITY_RANGE_MAX
199 PRIMER_QUALITY_RANGE_MIN PRIMER_RIGHT_INPUT PRIMER_SALT_CONC
200 PRIMER_SELF_ANY PRIMER_SELF_END PRIMER_SEQUENCE_ID
201 PRIMER_SEQUENCE_QUALITY PRIMER_START_CODON_POSITION PRIMER_TASK
202 PRIMER_WT_COMPL_ANY PRIMER_WT_COMPL_END PRIMER_WT_END_QUAL
203 PRIMER_WT_END_STABILITY PRIMER_WT_GC_PERCENT_GT
204 PRIMER_WT_GC_PERCENT_LT PRIMER_WT_NUM_NS PRIMER_WT_POS_PENALTY
205 PRIMER_WT_REP_SIM PRIMER_WT_SEQ_QUAL PRIMER_WT_SIZE_GT
206 PRIMER_WT_SIZE_LT PRIMER_WT_TM_GT PRIMER_WT_TM_LT SEQUENCE TARGET
207 PRIMER_DEFAULT_PRODUCT
208 PRIMER_DEFAULT_SIZE
209 PRIMER_INSIDE_PENALTY
210 PRIMER_INTERNAL_OLIGO_MAX_TEMPLATE_MISHYB
211 PRIMER_OUTSIDE_PENALTY
212 PRIMER_LIB_AMBIGUITY_CODES_CONSENSUS
213 PRIMER_MAX_TEMPLATE_MISPRIMING
214 PRIMER_PAIR_MAX_TEMPLATE_MISPRIMING
215 PRIMER_PAIR_WT_TEMPLATE_MISPRIMING
216 PRIMER_WT_TEMPLATE_MISPRIMING
217 );
218  
219 1 foreach my $attr (@PRIMER3_PARAMS) {$OK_FIELD{$attr}++}
220 }
221  
222 sub AUTOLOAD {
223 0 ▶ my $self = shift;
Subroutine AUTOLOAD: not called CC=3 SCAR=24.8
224 0 my $attr = $AUTOLOAD;
225 0 $attr =~ s/.*:://;
226 0 $attr = uc $attr;
227 0 ▶ $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless $Bio::Tools::Run::Primer3::OK_FIELD{$attr} 0 0 0
228 0 ▶ $self->{$attr} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
229 0 return $self->{$attr};
230 }
231  
232  
233 =head2 new()
234  
235 Title : new()
236 Usage : my $primer3 = Bio::Tools::Run::Primer3->new(-file=>$file) to read
237 a primer3 output file.
238 my $primer3 = Bio::Tools::Run::Primer3->new(-seq=>sequence object)
239 design primers against sequence
240 Function: Start primer3 working and adds a sequence. At the moment it
241 will not clear out the old sequence, but I suppose it should.
242 Returns : Does not return anything. If called with a filename will allow
243 you to retrieve the results
244 Args : -seq (optional) Bio::Seq object of sequence. This is required
245 to run primer3 but can be added later with add_targets()
246 -outfile file name to output results to (can also be added
247 with $primer3->outfile_name
248 -path path to primer3 executable, including program name, e.g.
249 "/usr/bin/primer3_core". This can also be set with program_name
250 and program_dir
251 -verbose (optional) set verbose output
252 Notes :
253  
254 =cut
255  
256  
257 sub new {
258 1 ▶ my($class,%args) = @_;
Subroutine new: called CC=7 SCAR=24.9
Pod documented
259 1 my $self = $class->SUPER::new(%args);
260 1 $self->io->_initialize_io();
261  
262 1 ▶ $self->program_name($args{-program}) if defined $args{'-program'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"-program"} 0 1 1
263  
264 1 ▶ if ($args{'-verbose'}) {$self->{'verbose'}=1}
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"-verbose"}) 0 1 1
265 1 ▶ if ($args{'-seq'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"-seq"}) 1 0 1
266 1 $self->{'seqobject'}=$args{'-seq'};
267 1 my @input;
268 push (@input, ("PRIMER_SEQUENCE_ID=".$self->{'seqobject'}->id),
269 1 ("SEQUENCE=".$self->{'seqobject'}->seq));
270 1 $self->{'primer3_input'}=\@input;
271 }
272 1 ▶ if ($args{'-outfile'}) {$self->{_outfilename}=$args{'-outfile'}}
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"-outfile"}) 0 1 1
273 1 ▶ if ($args{'-path'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"-path"}) 0 1 1
274
275 0 my (undef,$path,$prog) = File::Spec->splitpath($args{'-path'});
276
277 # For Windows system, $path better (Letter disk not truncated)
278 0 ▶ if ( $^O =~ m{mswin}i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /mswin/i) 0 0 0
279 0 require File::Basename;
280 0 $path = File::Basename::dirname( $args{'-path'} );
281 0 $prog = File::Basename::basename( $args{'-path'} );
282 }
283
284 0 $self->program_dir($path);
285 0 $self->program_name($prog);
286 }
287 1 return $self;
288 }
289  
290 =head2 program_name
291  
292 Title : program_name
293 Usage : $primer3->program_name()
294 Function: holds the program name
295 Returns: string
296 Args : None
297  
298 =cut
299  
300 sub program_name {
301 6 ▶ my $self = shift;
Subroutine program_name: called CC=5 SCAR=18.1
Pod documented
302 6 ▶ return $self->{'program_name'} = shift @_ if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 6 6
303 6 ▶ return $self->{'program_name'} if $self->{'program_name'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"program_name"} 0 6 6
304 6 for (qw(primer3 primer3_core)) {
305 12 ▶ if ($self->io->exists_exe($_)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->io->exists_exe($_)) 0 12 12
306 0 $PROGRAMNAME = $_;
307 0 last;
308 }
309 }
310 # don't set permanently, use global
311 6 return $PROGRAMNAME;
312 }
313  
314 =head2 program_dir
315  
316 Title : program_dir
317 Usage : $primer3->program_dir($dir)
318 Function: returns the program directory, which may also be obtained from ENV variable.
319 Returns : string
320 Args :
321  
322 =cut
323  
324 sub program_dir {
325 5 ▶ my ($self, $dir) = @_;
Subroutine program_dir: called CC=4 SCAR=14.8
Pod documented
326 5 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) 0 5 5
327 0 $self->{'program_dir'}=$dir;
328 }
329
330 # we need to stop here if we know what the answer is, otherwise we can
331 # never set it and then call it later
332 5 ▶ return $self->{'program_dir'} if $self->{'program_dir'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"program_dir"} 4 1 5
333
334 1 ▶ if ($ENV{PRIMER3}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'PRIMER3'}) { } 0 1 1
335 0 $self->{'program_dir'} = Bio::Root::IO->catfile($ENV{PRIMER3});
336 } else {
337 1 $self->{'program_dir'} = Bio::Root::IO->catfile('usr','local','bin');
338 }
339
340 1 return $self->{'program_dir'}
341 }
342  
343  
344 =head2 add_targets()
345  
346 Title : add_targets()
347 Usage : $primer3->add_targets(key=>value)
348 Function: Add any legal value to the input command line.
349 Returns : Returns the number of arguments added.
350 Args : Use $primer3->arguments to find a list of all the values
351 that are allowed, or see the primer3 docs.
352 Notes : This will only do limited error checking at the moment,
353 but it should work.
354  
355 =cut
356  
357  
358 sub add_targets {
359 0 ▶ my ($self, %args)=@_;
Subroutine add_targets: not called CC=24 SCAR=64.0
Pod documented
360 0 my $added_args; # a count of what we have added.
361 0 my $inputarray = $self->{'primer3_input'};
362 0 foreach my $key (keys %args) {
363 # we will allow them to add a sequence before checking for arguments
364 0 ▶ if ((uc($key) eq "-SEQ") || (uc($key) eq "-SEQUENCE")) {
Branch: 1 branch
BranchTrueFalseTotal
if (uc $key eq "-SEQ" or uc $key eq "-SEQUENCE") 0 0 0
Condition0%0/3
uc $key eq "-SEQ" or uc $key eq "-SEQUENCE"
l!l&&r!l&&!r
000
MC/DC0%0/2
uc $key eq "-SEQ" or uc $key eq "-SEQUENCE"
uc $key eq "-SEQ" uc $key eq "-SEQUENCE"
Truth table0%0/3
A or B
A= uc $key eq "-SEQ"B= uc $key eq "-SEQUENCE"
ABresult
1X1
011
000
365 # adding a new sequence. We need to separate them with an =
366 0 $self->{'seqobject'}=$args{$key};
367 0 ▶ if (defined $$inputarray[0]) {push (@$inputarray, "=")}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $inputarray->[0]) 0 0 0
368 push (@$inputarray, ("PRIMER_SEQUENCE_ID=".
369 0 $self->{'seqobject'}->id),("SEQUENCE=".$self->{'seqobject'}->seq));
370 0 next;
371 }
372  
373 0 ▶ unless ($self->{'no_param_checks'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"no_param_checks"}) 0 0 0
374 0 ▶ unless ($OK_FIELD{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Bio::Tools::Run::Primer3::OK_FIELD{$key}) 0 0 0
375 0 $self->warn("Parameter $key is not a valid Primer3 parameter");
376 0 next}
377 }
378  
379 0 ▶ if (uc($key) eq "INCLUDED_REGION") {
Branch: 4 branches
BranchTrueFalseTotal
if (uc $key eq 'INCLUDED_REGION') { } 0 0 0
elsif (uc $key eq 'PRIMER_MIN_SIZE') { } 0 0 0
elsif ($key eq 'PRIMER_MAX_SIZE') { } 0 0 0
elsif (uc $key eq 'SEQUENCE') { } 0 0 0
380 # this must be a comma separated start, length.
381 0 my $sequencelength;
382 # we don't have a length, hence we need to add the length of the
383 # sequence less the start.
384 0 foreach my $input (@$inputarray) {
385 0 ▶ if ($input =~ /SEQUENCE=(.*)/) {$sequencelength=length($1)}
Branch: 1 branch
BranchTrueFalseTotal
if ($input =~ /SEQUENCE=(.*)/) 0 0 0
386 }
387
388 0 ▶ if (!$args{$key}) {$args{$key}="0," . $sequencelength}
Branch: 2 branches
BranchTrueFalseTotal
if (not $args{$key}) { } 0 0 0
elsif (not $args{$key} =~ /\,/) { } 0 0 0
389 elsif ($args{$key} !~ /\,/) {
390 0 my $length_of_included = $sequencelength-$args{$key};
391 0 $args{$key} .= ",".$length_of_included;
392 }
393 }
394 elsif (uc($key) eq "PRIMER_MIN_SIZE") {
395 # minimum size must be less than MAX size and greater than zero
396 0 ▶ if (exists $args{"PRIMER_MAX_SIZE"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"PRIMER_MAX_SIZE"}) 0 0 0
397 0 ▶ unless ($args{"PRIMER_MAX_SIZE"} > $args{"PRIMER_MIN_SIZE"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"PRIMER_MAX_SIZE"} > $args{"PRIMER_MIN_SIZE"}) 0 0 0
398 0 $self->warn('Maximum primer size (PRIMER_MAX_SIZE) must be greater than minimum primer size (PRIMER_MIN_SIZE)');
399 }
400 }
401 0 ▶ if ($args{$key} < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{$key} < 0) 0 0 0
402 0 $self->warn('Minimum primer size (PRIMER_MIN_SIZE) must be greater than 0');
403 }
404 }
405 elsif ($key eq "PRIMER_MAX_SIZE") {
406 0 ▶ if ($args{$key}>35) {$self->warn('Maximum primer size (PRIMER_MAX_SIZE) must be less than 35')}
Branch: 1 branch
BranchTrueFalseTotal
if ($args{$key} > 35) 0 0 0
407 }
408 elsif (uc($key) eq "SEQUENCE") {
409 # Add seqobject if not present, since it is checked for by Bio::Tools::Primer3->next_primer()
410 0 ▶ $self->{'seqobject'}=Bio::Seq->new(-seq=>$args{$key}) if not defined($self->{'seqobject'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"seqobject"} 0 0 0
411 }
412  
413 # need a check to see whether this is already in the array
414 # and finally add the argument to the list.
415  
416 0 my $toadd=uc($key)."=".$args{$key};
417 0 my $replaced; # don't add it if it is replacing something!
418 my @new_array;
419 0 foreach my $input (@$inputarray) {
420 0 my ($array_key, $array_value) = split '=', $input;
421 0 ▶ if (uc($array_key) eq uc($key)) {push @new_array, $toadd; $replaced=1}
Branch: 1 branch
BranchTrueFalseTotal
if (uc $array_key eq uc $key) { } 0 0 0
422 0 else {push @new_array, $input}
423 }
424 0 ▶ unless ($replaced) {push @new_array, $toadd}
Branch: 1 branch
BranchTrueFalseTotal
unless ($replaced) 0 0 0
425 0 @$inputarray=@new_array;
426  
427 0 ▶ if ($self->{'verbose'}) {print STDERR "Updated ",
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 0 0
428 uc($key), " to $args{$key}\n"}
429 0 $added_args++;
430 }
431  
432 0 $self->{'primer3_input'}=$inputarray;
433 0 return $added_args;
434 }
435  
436 =head2 run()
437  
438 Title : run()
439 Usage : $primer3->run();
440 Function: Run the primer3 program with the arguments that you have supplied.
441 Returns : A Bio::Tools::Primer3 object containing the results.
442 Args : None.
443 Note : See the Bio::Tools::Primer3 documentation for those functions.
444  
445 =cut
446  
447 sub run {
448 0 ▶ my($self) = @_;
Subroutine run: not called CC=13 SCAR=52.0
Pod documented
449 0 my $executable = $self->executable;
450 0 my $input = $self->{'primer3_input'};
451 0 ▶ unless ($executable && -e $executable) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($executable and -e $executable) 0 0 0
Condition0%0/3
$executable and -e $executable
!ll&&!rl&&r
000
MC/DC0%0/2
$executable and -e $executable
$executable -e $executable
Truth table0%0/3
A and B
A= $executableB= -e $executable
ABresult
0X0
100
111
452 0 ▶ $self->throw("Executable was not found. Do not know where primer3 is!") if !$executable;
Branch: 1 branch
BranchTrueFalseTotal
unless $executable 0 0 0
453 0 $self->throw("$executable was not found. Do not know where primer3 is!");
454 0 exit(-1);
455 }
456  
457 # note that I write this to a temp file because we need both read
458 # and write access to primer3, therefore,
459 # we can't use a simple pipe.
460  
461 0 ▶ if ($self->{'verbose'}) {print STDERR "TRYING\n",
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 0 0
462 0 join "\n", @{$self->{'primer3_input'}}, "=\n"}
463  
464 # make a temporary file and print the instructions to it.
465 0 my ($temphandle, $tempfile) = $self->io->tempfile;
466 0 print $temphandle join "\n", @{$self->{'primer3_input'}}, "=\n";
467 0 close($temphandle);
468  
469 0 my $executable_command = $executable;
470 0 ▶ if ( $executable =~ m{^[^\'\"]+(.+)[^\'\"]+$} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($executable =~ /^[^\'\"]+(.+)[^\'\"]+$/) 0 0 0
471 0 $executable_command = "\"$executable\" < \"$tempfile\"|";
472 }
473  
474 0 ▶ open (RESULTS, $executable_command) || $self->throw("Can't open RESULTS");
Branch: 1 branch
BranchTrueFalseTotal
open RESULTS, $executable_command or $self->throw("Can't open RESULTS") 0 0 0
475 0 ▶ if ($self->{'_outfilename'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_outfilename"}) 0 0 0
476 # I can't figure out how to use either of these to write the results out.
477 # neither work, what am I doing wrong or missing in the docs?
478 # $self->{output}=$self->_initialize_io(-file=>$self->{'outfile'});
479 # $self->{output}=$self->io;
480 # OK, for now, I will just do it myself, because I need this to
481 # check the parser :)
482 open (OUT, ">".$self->{'_outfilename'}) ||
483 0 ▶ $self->throw("Can't open ".$self->{'_outfilename'}." for writing");
Branch: 1 branch
BranchTrueFalseTotal
open OUT, '>' . $self->{"_outfilename"} or $self->throw(q[Can't open ] . $self->{"_outfilename"} . ' for writing') 0 0 0
484 }
485  
486 0 my @results;
487 0 ▶ while (<RESULTS>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline RESULTS)) 0 0 0
488 0 ▶ if ($self->{'_outfilename'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_outfilename"}) 0 0 0
489 # this should work, but isn't
490 #$self->{output}->_print($_);
491 0 print OUT $_;
492 }
493 0 chomp;
494 0 ▶ next if( $_ eq '='); # skip over bolderio record terminator
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "=" 0 0 0
495 0 my ($return, $value) = split('=',$_);
496 0 $self->{'results'}->{$return} = $value;
497 }
498 0 close RESULTS;
499  
500 # close the output file
501 0 ▶ if ($self->{'_outfilename'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_outfilename"}) 0 0 0
502 0 close OUT;
503 }
504  
505 0 $self->cleanup;
506 # convert the results to individual results
507 0 $self->{results_obj} = Bio::Tools::Primer3->new;
508 0 $self->{results_obj}->_set_variable('results', $self->{results});
509 0 $self->{results_obj}->_set_variable('seqobject', $self->{seqobject});
510  
511 # Bio::Tools::Primer3::_separate needs a hash of the primer3 arguments,
512 # with the arg as the key and the value as the value (surprise!).
513 0 my %input_hash = map {split '='} @{$self->{'primer3_input'}};
514 0 $self->{results_obj}->_set_variable('input_options', \%input_hash);
515 0 $self->{results_separated}= $self->{results_obj}->_separate();
516 0 return $self->{results_obj};
517 }
518  
519 =head2 arguments()
520  
521 Title : arguments()
522 Usage : $hashref = $primer3->arguments();
523 Function: Describes the options that you can set through Bio::Tools::Run::Primer3,
524 with a brief (one line) description of what they are and their
525 default values
526 Returns : A string (if an argument is supplied) or a reference to a hash.
527 Args : If supplied with an argument will return a string of its
528 description.
529 If no arguments are supplied, will return all the arguments as a
530 reference to a hash
531 Notes : Much of this is taken from the primer3 README file, and you should
532 read that file for a more detailed description.
533  
534 =cut
535  
536 sub arguments {
537 0 ▶ my ($self, $required) = @_;
Subroutine arguments: not called CC=3 SCAR=24.8
Pod documented
538 0 ▶ unless ($self->{'input_options'}) {$self->_input_args}
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"input_options"}) 0 0 0
539 0 ▶ if ($required) {return ${$self->{'input_options'}}{'$required'}}
Branch: 1 branch
BranchTrueFalseTotal
if ($required) { } 0 0 0
540 0 else {return $self->{'input_options'}}
541 }
542  
543 =head2 version
544  
545 Title : version
546 Usage : $v = $prog->version();
547 Function: Determine the version number of the program
548 Example :
549 Returns : float or undef
550 Args : none
551  
552 =cut
553  
554 sub version {
555 0 ▶ my ($self) = @_;
Subroutine version: not called CC=5 SCAR=34.0
Pod documented
556 0 ▶ return unless my $exe = $self->executable;
Branch: 1 branch
BranchTrueFalseTotal
unless my $exe = $self->executable 0 0 0
557 0 ▶ if (!defined $self->{'_progversion'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_progversion"}) 0 0 0
558 0 my $string = `$exe -about 2>&1`;
559 0 my $v;
560 0 ▶ if ($string =~ m{primer3\s+release\s+([\d\.]+)}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /primer3\s+release\s+([\d\.]+)/) 0 0 0
561 0 $self->{'_progversion'} = $1;
562 }
563 }
564 0 ▶ return $self->{'_progversion'} || undef;
Condition0%0/2
$self->{'_progversion'} || undef
l!l
00
MC/DC0%0/1
$self->{'_progversion'} || undef
$self->{'_progversion'}
Truth table0%0/2
A
A= $self->{'_progversion'}
Aresult
11
00
565 }
566  
567 =head2 _input_args()
568  
569 Title : _input_args()
570 Usage : an internal method to set the input arguments for Primer3
571 Function: Define a hash with keys for each of the input arguments and values
572 as a short one line description
573 Returns : A reference to a hash.
574 Args : None.
575 Notes : Much of this is taken from the primer3 README file, and you should
576 read that file for a more detailed description.
577  
578 =cut
579  
580 sub _input_args {
581 0 ▶ my($self) = shift;
Subroutine _input_args: not called CC=1 SCAR=6.9
582 # just return functions that we can set and what they are
583 0 my %hash=(
584 'PRIMER_SEQUENCE_ID'=>'(string, optional) an id. Optional. Note must be present if PRIMER_FILE_FLAG is set',
585 'SEQUENCE'=>'(nucleotide sequence, REQUIRED) The sequence itself. Cannot contain newlines',
586 'INCLUDED_REGION'=>'(interval, optional) Where to pick primers from. In form <start>,<length>. Based on zero indexing!',
587 'TARGET'=>'(interval list, default empty) Regions that must be included in the product. The value should be a space-separated list of <start>,<length>',
588 'EXCLUDED_REGION'=>'(interval list, default empty) Regions that must NOT be included in the product. The value should be a space-separated list of <start>,<length>',
589 'PRIMER_COMMENT'=>'(string) This is ignored, so we will just save, and return it',
590 'PRIMER_SEQUENCE_QUALITY'=>'(quality list, default empty) A list of space separated integers with one per base. Could adapt a Phred object to this.',
591 'PRIMER_LEFT_INPUT'=>'(nucleotide sequence, default empty) If you know the left primer sequence, put it here',
592 'PRIMER_RIGHT_INPUT'=>'(nucleotide sequence, default empty) If you know the right primer sequence, put it here',
593 'PRIMER_START_CODON_POSITION'=>'(int, default -1000000) Location of known start codons for designing in frame primers.',
594 'PRIMER_PICK_ANYWAY'=>'boolean, default 0) Pick a primer, even if we have violated some constraints.',
595 'PRIMER_MISPRIMING_LIBRARY'=>'(string, optional) A file containing sequences to avoid amplifying. Should be fasta format, but see primer3 docs for constraints.',
596 'PRIMER_MAX_MISPRIMING'=>'(decimal,9999.99, default 12.00) Weighting for PRIMER_MISPRIMING_LIBRARY',
597 'PRIMER_PAIR_MAX_MISPRIMING'=>'(decimal,9999.99, default 24.00 Weighting for PRIMER_MISPRIMING_LIBRARY',
598 'PRIMER_PRODUCT_MAX_TM'=>'(float, default 1000000.0) The maximum allowed Tm of the product.',
599 'PRIMER_PRODUCT_MIN_TM'=>'(float, default -1000000.0) The minimum allowed Tm of the product',
600 'PRIMER_EXPLAIN_FLAG'=>'(boolean, default 0) If set it will print a bunch of information out.',
601 'PRIMER_PRODUCT_SIZE_RANGE'=>'(size range list, default 100-300) space separated list of product sizes eg <a>-<b> <x>-<y>',
602
603 'PRIMER_DEFAULT_PRODUCT' => '(size range list, default 100-300)',
604 'PRIMER_PICK_INTERNAL_OLIGO'=>'(boolean, default 0) if set, a hybridization probe will be selected',
605 'PRIMER_GC_CLAMP'=>'(int, default 0) Number of Gs and Cs at the 3 prime end.',
606 'PRIMER_OPT_SIZE'=>'(int, default 20) Optimal primer size. Primers will be close to this value in length',
607 'PRIMER_DEFAULT_SIZE' => '(int, default 20)',
608 'PRIMER_MIN_SIZE'=>'(int, default 18) Minimum size. Must be 0 < PRIMER_MIN_SIZE < PRIMER_MAX_SIZE ',
609 'PRIMER_MAX_SIZE'=>'(int, default 27) Maximum size. Must be < 35.',
610 'PRIMER_OPT_TM'=>'(float, default 60.0C) Optimum Tm of a primer.',
611 'PRIMER_MIN_TM'=>'(float, default 57.0C) Minimum Tm of a primer',
612 'PRIMER_MAX_TM'=>'(float, default 63.0C) Maximum Tm of a primer',
613 'PRIMER_MAX_DIFF_TM'=>'(float, default 100.0C) acceptable difference in Tms',
614 'PRIMER_MIN_GC'=>'(float, default 20.0%) Minimum allowable GCs',
615 'PRIMER_OPT_GC_PERCENT'=>'(float, default 50.0%) Optimal GCs',
616 'PRIMER_MAX_GC'=>'(float, default 80.0%) Maximum allowable GCs',
617 'PRIMER_SALT_CONC'=>'(float, default 50.0 mM) Salt concentration required for Tm calcs.',
618 'PRIMER_DNA_CONC'=>'(float, default 50.0 nM) DNA concentration required for Tm calcs. ',
619 'PRIMER_NUM_NS_ACCEPTED'=>'(int, default 0) Maximum number of unknown bases (N) allowable in any primer.',
620 'PRIMER_SELF_ANY'=>'(decimal,9999.99, default 8.00) Maximum aligment score for within and between primers when checking for hairpin loops',
621 'PRIMER_SELF_END'=>'(decimal 9999.99, default 3.00) Maximum aligment score for within and between primers when checking for primer dimers',
622 'PRIMER_FILE_FLAG'=>'(boolean, default 0) Output <sequence_id>.for and <sequence_id>.rev with all acceptable forward and reverse primers',
623 'PRIMER_MAX_POLY_X'=>'(int, default 5) The maximum allowable length of a mononucleotide repeat.',
624 'PRIMER_LIBERAL_BASE'=>'(boolean, default 0) Use IUPAC codes (well, just change them to N). Note must also set PRIMER_NUM_NS_ACCEPTED',
625 'PRIMER_NUM_RETURN'=>'(int, default 5) Number of primers to return',
626 'PRIMER_FIRST_BASE_INDEX'=>'(int, default 0) Index of the first base. Do not change this or allow it to be changed, as we will have to mess with subseqs and whatnot.',
627 'PRIMER_MIN_QUALITY'=>'(int, default 0) Minimum sequence quality calculated from PRIMER_SEQUENCE_QUALITY',
628 'PRIMER_MIN_END_QUALITY'=>'(int, default 0) Minimum sequence quality calculated from PRIMER_SEQUENCE_QUALITY at 5 prime 5 bases',
629 'PRIMER_QUALITY_RANGE_MIN'=>'(int, default 0) Minimum sequence quality calculated from PRIMER_SEQUENCE_QUALITY',
630 'PRIMER_QUALITY_RANGE_MAX'=>'(int, default 100) Maximum sequence quality calculated from PRIMER_SEQUENCE_QUALITY',
631 'PRIMER_MAX_END_STABILITY'=>'(float 999.9999, default 100.0) Maximum stability for the five 3 prime bases of a primer. Bigger numbers mean more stable 3 prime ends.',
632 'PRIMER_PRODUCT_OPT_TM'=>'(float, default 0.0) Optimum melting temperature for the PCR product. 0 means no optimum.',
633 'PRIMER_PRODUCT_OPT_SIZE'=>'(int, default 0) Optimum size for the PCR product. 0 means no optimum.',
634 'PRIMER_TASK'=>'(string, default pick_pcr_primers) Choose from pick_pcr_primers, pick_pcr_primers_and_hyb_probe, pick_left_only, pick_right_only, pick_hyb_probe_only',
635 'PRIMER_WT_TM_GT'=>'(float, default 1.0) Penalty weight for primers with Tm over PRIMER_OPT_TM.',
636 'PRIMER_WT_TM_LT'=>'(float, default 1.0) Penalty weight for primers with Tm under PRIMER_OPT_TM.',
637 'PRIMER_WT_SIZE_LT'=>'(float, default 1.0) Penalty weight for primers shorter than PRIMER_OPT_SIZE.',
638 'PRIMER_WT_SIZE_GT'=>'(float, default 1.0) Penalty weight for primers longer than PRIMER_OPT_SIZE.',
639 'PRIMER_WT_GC_PERCENT_LT'=>'(float, default 1.0) Penalty weight for primers with GC percent greater than PRIMER_OPT_GC_PERCENT.',
640 'PRIMER_WT_GC_PERCENT_GT'=>'(float, default 1.0) Penalty weight for primers with GC percent greater than PRIMER_OPT_GC_PERCENT.',
641 'PRIMER_WT_COMPL_ANY'=>'(float, default 0.0)',
642 'PRIMER_WT_COMPL_END'=>'(float, default 0.0)',
643 'PRIMER_WT_NUM_NS'=>'(float, default 0.0)',
644 'PRIMER_WT_REP_SIM'=>'(float, default 0.0)',
645 'PRIMER_WT_SEQ_QUAL'=>'(float, default 0.0)',
646 'PRIMER_WT_END_QUAL'=>'(float, default 0.0)',
647 'PRIMER_WT_POS_PENALTY'=>'(float, default 0.0)',
648 'PRIMER_WT_END_STABILITY'=>'(float, default 0.0)',
649 'PRIMER_PAIR_WT_PR_PENALTY'=>'(float, default 1.0)',
650 'PRIMER_PAIR_WT_IO_PENALTY'=>'(float, default 0.0)',
651 'PRIMER_PAIR_WT_DIFF_TM'=>'(float, default 0.0)',
652 'PRIMER_PAIR_WT_COMPL_ANY'=>'(float, default 0.0)',
653 'PRIMER_PAIR_WT_COMPL_END'=>'(float, default 0.0)',
654 'PRIMER_PAIR_WT_PRODUCT_TM_LT'=>'(float, default 0.0)',
655 'PRIMER_PAIR_WT_PRODUCT_TM_GT'=>'(float, default 0.0)',
656 'PRIMER_PAIR_WT_PRODUCT_SIZE_GT'=>'(float, default 0.0)',
657 'PRIMER_PAIR_WT_PRODUCT_SIZE_LT'=>'(float, default 0.0)',
658 'PRIMER_PAIR_WT_REP_SIM'=>'(float, default 0.0)',
659 'PRIMER_INTERNAL_OLIGO_EXCLUDED_REGION'=>'(interval list, default empty) Internal oligos must ignore these regions',
660 'PRIMER_INTERNAL_OLIGO_INPUT'=>'(nucleotide sequence, default empty) Known sequence of an internal oligo',
661 'PRIMER_INTERNAL_OLIGO_OPT_SIZE'=>'(int, default 20)',
662 'PRIMER_INTERNAL_OLIGO_MIN_SIZE'=>'(int, default 18)',
663 'PRIMER_INTERNAL_OLIGO_MAX_SIZE'=>'(int, default 27)',
664 'PRIMER_INTERNAL_OLIGO_OPT_TM'=>'(float, default 60.0 degrees C)',
665 'PRIMER_INTERNAL_OLIGO_OPT_GC_PERCENT'=>'(float, default 50.0%)',
666 'PRIMER_INTERNAL_OLIGO_MIN_TM'=>'(float, default 57.0 degrees C)',
667 'PRIMER_INTERNAL_OLIGO_MAX_TM'=>'(float, default 63.0 degrees C)',
668 'PRIMER_INTERNAL_OLIGO_MIN_GC'=>'(float, default 20.0%)',
669 'PRIMER_INTERNAL_OLIGO_MAX_GC'=>'(float, default 80.0%)',
670 'PRIMER_INTERNAL_OLIGO_SALT_CONC'=>'(float, default 50.0 mM)',
671 'PRIMER_INTERNAL_OLIGO_DNA_CONC'=>'(float, default 50.0 nM)',
672 'PRIMER_INTERNAL_OLIGO_SELF_ANY'=>'(decimal 9999.99, default 12.00)',
673 'PRIMER_INTERNAL_OLIGO_MAX_POLY_X'=>'(int, default 5)',
674 'PRIMER_INTERNAL_OLIGO_SELF_END'=>'(decimal 9999.99, default 12.00)',
675 'PRIMER_INTERNAL_OLIGO_MISHYB_LIBRARY'=>'(string, optional)',
676 'PRIMER_INTERNAL_OLIGO_MAX_MISHYB'=>'(decimal,9999.99, default 12.00)',
677 'PRIMER_INTERNAL_OLIGO_MIN_QUALITY'=>'(int, default 0)',
678 'PRIMER_IO_WT_TM_GT'=>'(float, default 1.0)',
679 'PRIMER_IO_WT_TM_LT'=>'(float, default 1.0)',
680 'PRIMER_IO_WT_GC_PERCENT_GT'=>'(float, default 1.0)',
681 'PRIMER_IO_WT_GC_PERCENT_LT'=>'(float, default 1.0)',
682 'PRIMER_IO_WT_SIZE_LT'=>'(float, default 1.0)',
683 'PRIMER_IO_WT_SIZE_GT'=>'(float, default 1.0)',
684 'PRIMER_IO_WT_COMPL_ANY'=>'(float, default 0.0)',
685 'PRIMER_IO_WT_COMPL_END'=>'(float, default 0.0)',
686 'PRIMER_IO_WT_NUM_NS'=>'(float, default 0.0)',
687 'PRIMER_IO_WT_REP_SIM'=>'(float, default 0.0)',
688 'PRIMER_IO_WT_SEQ_QUAL'=>'(float, default 0.0)',
689 'PRIMER_IO_WT_END_QUAL'=>'(float, default 0.0)',
690 'PRIMER_INSIDE_PENALTY' => '(float, default -1.0)',
691 'PRIMER_INTERNAL_OLIGO_MAX_TEMPLATE_MISHYB' => '(decimal 9999.99, default 12.00)',
692 'PRIMER_OUTSIDE_PENALTY' => '(float, default 0.0)',
693 'PRIMER_LIB_AMBIGUITY_CODES_CONSENSUS' => '(boolean, default 1)',
694 'PRIMER_MAX_TEMPLATE_MISPRIMING' => '(decimal,9999.99, default -1.00)',
695 'PRIMER_PAIR_MAX_TEMPLATE_MISPRIMING' => '(decimal,9999.99, default -1.00)',
696 'PRIMER_PAIR_WT_TEMPLATE_MISPRIMING' => '(float, default 0.0)',
697 'PRIMER_WT_TEMPLATE_MISPRIMING' => '(float, default 0.0)'
698 );
699 0 $self->{'input_options'}=\%hash;
700 0 return \%hash;
701 }
702  
703 1 1;
« blib/lib/Bio/Tools/Run/Phylo/Phylip/ProtDist.pm ↑ Summary blib/lib/Bio/Tools/Run/Alignment/TCoffee.pm »