3 # BioPerl module for Bio::PopGen::Marker
5 # Cared for by Jason Stajich <jason@bioperl.org>
7 # Copyright Jason Stajich
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
15 Bio::PopGen::Marker - A genetic marker which one uses to generate genotypes
19 my $name = $marker->name(); # marker name
20 my $description = $marker->description(); # description
21 my $type = $marker->type(); # coded type of the marker
22 my $unique_id = $marker->unique_id; # optional unique ID
23 my @alleles = $marker->get_Alleles(); # the known alleles
24 my %allele_freqs = $marker->get_Allele_Frequencies(); # keys are marker names
25 # vals are frequencies
26 # may change to handle multiple populations
30 This object will not contain genotype information pertaining to an
31 individual, but rather population level statistics and descriptive
32 information about a marker.
38 User feedback is an integral part of the evolution of this and other
39 Bioperl modules. Send your comments and suggestions preferably to
40 the Bioperl mailing list. Your participation is much appreciated.
42 bioperl-l@bioperl.org - General discussion
43 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
47 Report bugs to the Bioperl bug tracking system to help us keep track
48 of the bugs and their resolution. Bug reports can be submitted via
51 http://bugzilla.open-bio.org/
53 =head1 AUTHOR - Jason Stajich
55 Email jason-at-bioperl.org
59 Matthew Hahn, matthew.hahn-at-duke.edu
63 The rest of the documentation details each of the object methods.
64 Internal methods are usually preceded with a _
69 # Let the code begin...
72 package Bio
::PopGen
::Marker
;
75 # Object preamble - inherits from Bio::Root::Root
78 use vars
qw($UniqueCounter);
82 use base qw(Bio::Root::Root Bio::PopGen::MarkerI);
87 Usage : my $obj = Bio::PopGen::Marker->new();
88 Function: Builds a new Bio::PopGen::Marker object
89 Returns : an instance of Bio::PopGen::Marker
90 Args : -name => [string] marker name
91 -description => [string] marker description
92 -type => [string] marker type
93 -unique_id => [string/int] unique id
94 -allele_freq => [hash ref] allele frequencies
99 my($class,@args) = @_;
101 my $self = $class->SUPER::new
(@args);
102 my ($name,$desc,$type,$uid,$af) = $self->_rearrange([qw(NAME
106 ALLELE_FREQ)],@args);
107 $self->{'_allele_freqs'} = {};
108 if( ! defined $uid ) {
109 $uid = $UniqueCounter++;
114 $self->throw("Must provide a name when initializing a Marker");
116 defined $desc && $self->description($desc);
117 defined $type && $self->type($type);
118 $self->unique_id($uid);
120 if( ref($af) !~ /HASH/i ) {
121 $self->warn("Must provide valid Hash reference for allele_freq method");
123 foreach my $allele ( keys %$af ) {
124 $self->add_Allele_Frequency($allele, $af->{$allele});
134 Usage : my $name = $marker->name();
135 Function: Get the name of the marker
136 Returns : string representing the name of the marker
137 Args : [optional] name
145 return $self->{'_name'} = shift if @_;
146 return $self->{'_name'};
153 Usage : my $desc = $marker->description
154 Function: Get the marker description free text
156 Args : [optional] string
164 return $self->{'_description'} = shift if @_;
165 return $self->{'_description'};
171 Usage : my $type = $marker->type;
172 Function: Get coded string for marker type
174 Args : [optional] string
182 return $self->{'_type'} = shift if @_;
183 return $self->{'_type'};
190 Usage : my $id = $marker->unique_id;
191 Function: Get the unique marker ID
192 Returns : unique ID string
193 Args : [optional ] string
201 return $self->{'_uniqueid'} = shift if @_;
202 return $self->{'_uniqueid'};
208 Usage : my @alleles = $marker->get_Alleles();
209 Function: Get the available marker alleles
210 Returns : Array of strings
217 my (@numeric,@alpha);
219 for ( keys %{$self->{'_allele_freqs'}} ) {
220 if( /[^\d\.\-e]/ ) { push @alpha, $_ }
221 else { push @numeric, $_ }
223 @numeric = sort { $b <=> $a } @numeric;
224 @alpha = sort { $b cmp $a } @alpha;
225 return @numeric,@alpha;
229 =head2 get_Allele_Frequencies
231 Title : get_Allele_Frequencies
232 Usage : my %allele_freqs = $marker->get_Allele_Frequencies;
233 Function: Get the alleles and their frequency (set relative to
234 a given population - you may want to create different
235 markers with the same name for different populations
236 with this current implementation
237 Returns : Associative array where keys are the names of the alleles
243 sub get_Allele_Frequencies
{
244 return %{$_[0]->{'_allele_freqs'}};
247 =head2 add_Allele_Frequency
249 Title : add_Allele_Frequency
250 Usage : $marker->add_Allele_Frequency($allele,$freq)
251 Function: Adds an allele frequency
253 Args : $allele - allele name
254 $freq - frequency value
259 sub add_Allele_Frequency
{
260 my ($self,$allele,$freq) = @_;
261 $self->{'_allele_freqs'}->{$allele} = $freq;
266 Title : reset_alleles
267 Usage : $marker->reset_alleles();
268 Function: Reset the alleles for a marker
277 $self->{'_allele_freqs'} = {};