sync w/ main trunk
[bioperl-live.git] / Bio / Tools / Primer / Feature.pm
blob9d6930aadb1cde465a62b4e88b344973994bec3d
1 # $Id$
3 # BioPerl module for Bio::Tools::Primer::Feature
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Ewan Birney <birney@ebi.ac.uk>
9 # Copyright Ewan Birney
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
15 =head1 NAME
17 Bio::Tools::Primer::Feature - position of a single primer
19 =head1 SYNOPSIS
21 use Bio::Tools::Primer::Feature;
23 my $pf = Bio::Tools::Primer::Feature->new( -start => $start, -end => $end, -strand => $strand);
24 $pf->attach_seq($seq);
26 # is a SeqFeatureI
28 print "primer starts at ",$pf->start," with sequence ",$pf->seq->seq(),"\n";
30 # helper functions
32 print "GC percentage ",$pf->gc(),"\n";
33 print "has inversion of size 4 at ",$pf->inversion(4),"\n";
37 =head1 DESCRIPTION
39 Primer Features represents one primer in a primer pair. This object is
40 mainly for designing primers, and probably principly used in the
41 primer design system
43 =head1 FEEDBACK
45 =head2 Mailing Lists
47 User feedback is an integral part of the evolution of this and other
48 Bioperl modules. Send your comments and suggestions preferably to
49 the Bioperl mailing list. Your participation is much appreciated.
51 bioperl-l@bioperl.org - General discussion
52 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
54 =head2 Support
56 Please direct usage questions or support issues to the mailing list:
58 L<bioperl-l@bioperl.org>
60 rather than to the module maintainer directly. Many experienced and
61 reponsive experts will be able look at the problem and quickly
62 address it. Please include a thorough description of the problem
63 with code and data examples if at all possible.
65 =head2 Reporting Bugs
67 Report bugs to the Bioperl bug tracking system to help us keep track
68 of the bugs and their resolution. Bug reports can be submitted via the
69 web:
71 http://bugzilla.open-bio.org/
73 =head1 AUTHOR - Ewan Birney
75 Email birney-at-ebi.ac.uk
77 =head1 APPENDIX
79 The rest of the documentation details each of the object methods.
80 Internal methods are usually preceded with a _
82 =cut
85 # Let the code begin...
89 package Bio::Tools::Primer::Feature;
91 use base qw(Bio::SeqFeature::Generic);
95 sub new {
96 my ( $caller, @args) = @_;
97 my ($self) = $caller->SUPER::new(@args);
99 # done - we hope
100 return $self;
103 sub gc_percent {
104 my $self = shift;
106 my $seq = $self->seq();
108 if( !defined $seq ) {
109 $self->throw("Primer feature has no attached sequence, can't calculate GC");
112 my $str = $seq->seq();
114 my $count = $str =~ tr/GCgc/GCgc/;
116 return $count*100.0 / $seq->length;
119 sub inversion {
120 my $self = shift;
121 my $size = shift;
123 if( !defined $size ) {
124 $self->throw("Must have size paramter in inversion");
127 my $seq = $self->seq();
129 if( !defined $seq ) {
130 $self->throw("Primer feature has no attached sequence, can't calculate inversion");
133 my $len = $seq->length - $size;
135 my $str = $seq->seq();
137 foreach my $i ( 0 .. $len ) {
138 my $revstr = substr($str,$i,$size);
139 my $orig = $revstr;
140 $revstr = reverse $revstr;
141 $revstr = s/[^ATGCNatgcn]/N/g;
143 $revstr =~ tr/ATGCNatgcn/TACGNtacgn/;
145 if( $str =~ /$revstr/ ) {
146 return $orig;
150 return;