Fetching contributors…
Cannot retrieve contributors at this time
222 lines (156 sloc) 5.65 KB
# $Id: 15549 2009-02-21 00:48:48Z maj $
# BioPerl module for Bio::Tools::Primer3Redux
# Copyright (c) Chris Fields
# You may distribute this module under the same terms as perl itself
# POD documentation - main docs before the code
=head1 NAME
Bio::Tools::Primer3Redux - Create input for and work with the output from
the program primer3.
# parse primer3 output to get some data
# this is also called from Bio::Tools::Run::Primer3
use Bio::Tools::Primer3;
# read a primer3 output file
my $p3 = Bio::Tools::Primer3::Redux->new(-file=>"data/primer3_output.txt");
# iterate through each result in the file
Bio::Tools::Primer3 creates the input files needed to design primers using
primer3 and provides mechanisms to access data in the primer3 output files.
This module provides a bioperl interface to the program primer3. See
for details and to download the software.
This module is based on one written by Chad Matsalla
I have ripped some of his code, and added a lot of my own. I hope he
is not mad at me!
This is probably best run in one of the two following ways:
i. To parse the output from Bio::Tools::Run::Primer3.
You will most likely just use next_primer to get the results from
ii. To parse the output of primer3 handed to it as a file name.
=head2 Mailing Lists
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to one
of the Bioperl mailing lists. Your participation is much appreciated. - General discussion - About the mailing lists
=head2 Support
Please direct usage questions or support issues to the mailing list:
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
=head2 Reporting Bugs
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via the web:
=head1 AUTHOR -
Chris Fields
Rob Edwards
Based heavily on work of
Chad Matsalla
Brian Osborne bosborne at
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
# Let the code begin...
package Bio::Tools::Primer3Redux;
use strict;
use warnings;
use Bio::Tools::Primer3Redux::Result;
use base qw(Bio::Root::IO Bio::AnalysisParserI);
=head2 new
Title : new()
Usage : my $primer3 = Bio::Tools::Primer3->new(-file=>$file)
to read a primer3 output file.
Function: Parse primer3 output
Returns : Does not return anything. If called with a filename will
allow you to retrieve the results
Args : -file (optional) file of primer3 results to parse -verbose
(optional) set verbose output
Notes :
my $SF_TAGS =
sub next_result {
my $self = shift;
while (my $line = $self->_readline) {
last if index($line, '=') == 0;
chomp $line;
my ($tag, $data) = split('=', $line, 2 );
if ($tag =~ /^PRIMER_(LEFT|RIGHT|INTERNAL_OLIGO|INTERNAL|PAIR|PRODUCT)(?:(?:_(\d+))?_(.*))?/xmso) {
my ($type, $rank, $primer_tag) = ($1, $2, $3);
if (!defined $rank && defined $primer_tag && $primer_tag =~ /(?:(\w+)_)?(\d+)$/) {
($primer_tag, $rank) = ($1, $2);
$rank ||= 0;
$type = 'INTERNAL' if $type eq 'INTERNAL_OLIGO';
# indicates location information
$primer_tag ||= 'LOCATION';
if ($primer_tag eq 'EXPLAIN' || $primer_tag eq 'NUM_RETURNED') {
$self->{persistent}->{$type}->{lc $primer_tag} = $data;
# v1 -> v2 change
if ($type eq 'PRODUCT') {
$type = 'PAIR';
$primer_tag = 'PRODUCT_SIZE';
$self->{features}->{$rank}->{$type}->{lc $primer_tag} = $data;
} elsif ($tag =~ /^(?:PRIMER_)?SEQUENCE(?:_(?:ID|TEMPLATE))?$/ ) {
$self->{sequence}->{$tag} = $data;
} else{ # anything else
$self->{run_parameters}->{$tag} = $data;
my $doc = $self->end_document;
return $doc;
=head2 start_document
Title : start_document
Usage : $obj->start_document
Function :
Returns :
Args :
sub start_document {
my $self = shift;
for my $data (qw(sequence features persistent run_parameters)) {
$self->{$data} = undef;
=head2 end_document
Title : end_document
Usage : $obj->end_document
Function :
Returns :
Args :
sub end_document {
my $self = shift;
my $result;
if (defined $self->{sequence} || defined $self->{features}) {
$result = Bio::Tools::Primer3Redux::Result->new();
# data is created on the fly within the result
$result->_initialize(-seq => $self->{sequence},
-features => $self->{features},
-persistent => $self->{persistent},
-parameters => $self->{run_parameters});
return $result;