Bio::DB::TFBS namespace has been moved to its own distribution named after itself
[bioperl-live.git] / Bio / SeqFeature / Amplicon.pm
blob06d2906f02ce525aba2a11a6556011aa50fcdb15
2 # BioPerl module for Bio::SeqFeature::Amplicon
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Copyright Florent Angly
8 # You may distribute this module under the same terms as perl itself
11 =head1 NAME
13 Bio::SeqFeature::Amplicon - Amplicon feature
15 =head1 SYNOPSIS
17 # Amplicon with explicit sequence
18 use Bio::SeqFeature::Amplicon;
19 my $amplicon = Bio::SeqFeature::Amplicon->new(
20 -seq => $seq_object,
21 -fwd_primer => $primer_object_1,
22 -rev_primer => $primer_object_2,
25 # Amplicon with implicit sequence
26 use Bio::Seq;
27 my $template = Bio::Seq->new( -seq => 'AAAAACCCCCGGGGGTTTTT' );
28 $amplicon = Bio::SeqFeature::Amplicon->new(
29 -start => 6,
30 -end => 15,
32 $template->add_SeqFeature($amplicon);
33 print "Amplicon start : ".$amplicon->start."\n";
34 print "Amplicon end : ".$amplicon->end."\n";
35 print "Amplicon sequence: ".$amplicon->seq->seq."\n";
36 # Amplicon sequence should be 'CCCCCGGGGG'
38 =head1 DESCRIPTION
40 Bio::SeqFeature::Amplicon extends L<Bio::SeqFeature::Subseq> to represent an
41 amplicon sequence and optional primer sequences.
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 one
49 of the Bioperl mailing lists. 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 I<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 the bugs and their resolution. Bug reports can be submitted via
69 the web:
71 https://github.com/bioperl/bioperl-live/issues
73 =head1 AUTHOR
75 Florent Angly <florent.angly@gmail.com>
77 =head1 APPENDIX
79 The rest of the documentation details each of the object
80 methods. Internal methods are usually preceded with a _
82 =cut
85 package Bio::SeqFeature::Amplicon;
87 use strict;
89 use base qw(Bio::SeqFeature::SubSeq);
91 =head2 new
93 Title : new()
94 Usage : my $amplicon = Bio::SeqFeature::Amplicon( -seq => $seq_object );
95 Function: Instantiate a new Bio::SeqFeature::Amplicon object
96 Args : -seq , the sequence object or sequence string of the amplicon (optional)
97 -fwd_primer , a Bio::SeqFeature primer object with specified location on amplicon (optional)
98 -rev_primer , a Bio::SeqFeature primer object with specified location on amplicon (optional)
99 Returns : A Bio::SeqFeature::Amplicon object
101 =cut
103 sub new {
104 my ($class, @args) = @_;
105 my $self = $class->SUPER::new(@args);
106 my ($fwd_primer, $rev_primer) =
107 $self->_rearrange([qw(FWD_PRIMER REV_PRIMER)], @args);
108 $fwd_primer && $self->fwd_primer($fwd_primer);
109 $rev_primer && $self->rev_primer($rev_primer);
110 return $self;
114 sub _primer {
115 # Get or set a primer. Type is either 'fwd' or 'rev'.
116 my ($self, $type, $primer) = @_;
117 if (defined $primer) {
118 if ( not(ref $primer) || not $primer->isa('Bio::SeqFeature::Primer') ) {
119 $self->throw("Expected a primer object but got a '".ref($primer)."'\n");
121 if ( not defined $self->location ) {
122 $self->throw("Location of $type primer on amplicon is not known. ".
123 "Use start(), end() or location() to set it.");
125 $primer->primary_tag($type.'_primer');
126 $self->add_SeqFeature($primer);
128 return (grep { $_->primary_tag eq $type.'_primer' } $self->get_SeqFeatures)[0];
132 =head2 fwd_primer
134 Title : fwd_primer
135 Usage : my $primer = $feat->fwd_primer();
136 Function: Get or set the forward primer. When setting it, the primary tag
137 'fwd_primer' is added to the primer and its start, stop and strand
138 attributes are set if needed, assuming that the forward primer is
139 at the beginning of the amplicon and the reverse primer at the end.
140 Args : A Bio::SeqFeature::Primer object (optional)
141 Returns : A Bio::SeqFeature::Primer object
143 =cut
145 sub fwd_primer {
146 my ($self, $primer) = @_;
147 return $self->_primer('fwd', $primer);
151 =head2 rev_primer
153 Title : rev_primer
154 Usage : my $primer = $feat->rev_primer();
155 Function: Get or set the reverse primer. When setting it, the primary tag
156 'rev_primer' is added to the primer.
157 Args : A Bio::SeqFeature::Primer object (optional)
158 Returns : A Bio::SeqFeature::Primer object
160 =cut
162 sub rev_primer {
163 my ($self, $primer) = @_;
164 return $self->_primer('rev', $primer);