tag fourth (and hopefully last) alpha
[bioperl-live.git] / branch-1-6 / Bio / Tools / Gel.pm
blob438c02d19de95cc91b73cadbc9ce54a38869e193
1 # $Id$
2 #
3 # BioPerl module for Bio::Tools::Gel
4 # Copyright Allen Day <allenday@ucla.edu>
5 # You may distribute this module under the same terms as perl itself
7 # POD documentation - main docs before the code
9 =head1 NAME
11 Bio::Tools::Gel - Calculates relative electrophoretic migration distances
13 =head1 SYNOPSIS
15 use Bio::PrimarySeq;
16 use Bio::Restriction::Analysis;
17 use Bio::Tools::Gel;
19 # get a sequence
20 my $d = 'AAAAAAAAAGAATTCTTTTTTTTTTTTTTGAATTCGGGGGGGGGGGGGGGGGGGG';
21 my $seq1 = Bio::Seq->new(-id=>'groundhog day',-seq=>$d);
23 # cut it with an enzyme
24 my $ra=Bio::Restriction::Analysis->new(-seq=>$seq1);
25 @cuts = $ra->fragments('EcoRI'), 3;
27 # analyse the fragments in a gel
28 my $gel = Bio::Tools::Gel->new(-seq=>\@cuts,-dilate=>10);
29 my %bands = $gel->bands;
30 foreach my $band (sort {$b <=> $a} keys %bands){
31 print $band,"\t", sprintf("%.1f", $bands{$band}),"\n";
34 #prints:
35 #20 27.0
36 #25 26.0
37 #10 30.0
40 =head1 DESCRIPTION
42 This takes a set of sequences or Bio::Seq objects, and calculates their
43 respective migration distances using:
44 distance = dilation * (4 - log10(length(dna));
46 Source: Molecular Cloning, a Laboratory Manual. Sambrook, Fritsch, Maniatis.
47 CSHL Press, 1989.
49 Bio::Tools::Gel currently calculates migration distances based solely on
50 the length of the nucleotide sequence. Secondary or tertiary structure,
51 curvature, and other biophysical attributes of a sequence are currently
52 not considered. Polypeptide migration is currently not supported.
54 =head1 FEEDBACK
56 =head2 Mailing Lists
58 User feedback is an integral part of the evolution of this and other
59 Bioperl modules. Send your comments and suggestions preferably to
60 the Bioperl mailing list. Your participation is much appreciated.
62 bioperl-l@bioperl.org - General discussion
63 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
65 =head2 Support
67 Please direct usage questions or support issues to the mailing list:
69 I<bioperl-l@bioperl.org>
71 rather than to the module maintainer directly. Many experienced and
72 reponsive experts will be able look at the problem and quickly
73 address it. Please include a thorough description of the problem
74 with code and data examples if at all possible.
76 =head2 Reporting Bugs
78 Report bugs to the Bioperl bug tracking system to help us keep track
79 of the bugs and their resolution. Bug reports can be submitted via the
80 web:
82 http://bugzilla.open-bio.org/
84 =head1 AUTHOR - Allen Day
86 Email allenday@ucla.edu
88 =head1 APPENDIX
90 The rest of the documentation details each of the object methods.
91 Internal methods are usually preceded with a _
93 =cut
96 # Let the code begin...
99 package Bio::Tools::Gel;
100 use strict;
102 use Bio::PrimarySeq;
104 use base qw(Bio::Root::Root);
106 =head2 new
108 Title : new
109 Usage : my $gel = Bio::Tools::Gel->new(-seq => $sequence,-dilate => 3);
110 Function: Initializes a new Gel
111 Returns : Bio::Tools::Gel
112 Args : -seq => Bio::Seq(s), scalar(s) or list of either/both
113 (default: none)
114 -dilate => Expand band migration distances (default: 1)
116 =cut
118 sub new {
119 my($class,@args) = @_;
121 my $self = $class->SUPER::new(@args);
122 my ($seqs,$dilate) = $self->_rearrange([qw(SEQ DILATE)],
123 @args);
124 if( ! ref($seqs) ) {
125 $self->add_band([$seqs]);
126 } elsif( ref($seqs) =~ /array/i ||
127 $seqs->isa('Bio::PrimarySeqI') ) {
128 $self->add_band($seqs);
130 $self->dilate($dilate || 1);
132 return $self;
136 =head2 add_band
138 Title : add_band
139 Usage : $gel->add_band($seq);
140 Function: Calls _add_band with a (possibly created) Bio::Seq object.
141 Returns :
142 Args : Bio::Seq, scalar sequence, or list of either/both.
144 =cut
146 sub add_band {
147 my($self,$args) = @_;
149 foreach my $arg (@$args){
150 my $seq;
151 if( ! ref($arg) ) {
152 if( $arg =~ /^\d+/ ) {
153 $seq= Bio::PrimarySeq->new(-seq=>"N"x$arg, -id => $arg);
154 } else {
155 $seq= Bio::PrimarySeq->new(-seq=>$arg,-id=>length($arg));
157 } elsif( $arg->isa('Bio::PrimarySeqI') ) {
158 $seq = $arg;
161 $seq->validate_seq or $seq->throw("invalid symbol in sequence".$seq->seq()."\n");
162 $self->_add_band($seq);
166 =head2 _add_band
168 Title : _add_band
169 Usage : $gel->_add_band($seq);
170 Function: Adds a new band to the gel.
171 Returns :
172 Args : Bio::Seq object
174 =cut
176 sub _add_band {
177 my($self,$arg) = @_;
178 if( defined $arg) {
179 push (@{$self->{'bands'}},$arg);
183 =head2 dilate
185 Title : dilate
186 Usage : $gel->dilate(1);
187 Function: Sets/retrieves the dilation factor.
188 Returns : dilation factor
189 Args : Float or none
191 =cut
193 sub dilate {
194 my($self,$arg) = @_;
195 return $self->{dilate} unless $arg;
196 $self->throw("-dilate should be numeric") if defined $arg and $arg =~ /[^e\d\.]/;
197 $self->{dilate} = $arg;
198 return $self->{dilate};
201 sub migrate {
202 my ($self,$arg) = @_;
203 $arg = $self unless $arg;
204 if ( $arg ) {
205 return 4 - log10($arg);
206 } else { return 0; }
209 =head2 bands
211 Title : bands
212 Usage : $gel->bands;
213 Function: Calculates migration distances of sequences.
214 Returns : hash of (seq_id => distance)
215 Args :
217 =cut
219 sub bands {
220 my $self = shift;
221 $self->throw("bands() is read-only") if @_;
223 my %bands = ();
225 foreach my $band (@{$self->{bands}}){
226 my $distance = $self->dilate * migrate($band->length);
227 $bands{$band->id} = $distance;
230 return %bands;
233 =head2 log10
235 Title : log10
236 Usage : log10($n);
237 Function: returns base 10 log of $n.
238 Returns : float
239 Args : float
241 =cut
243 #from programming perl
244 sub log10 {
245 my $n = shift;
246 return log($n)/log(10);