3 # BioPerl module for Bio::PopGen::Individual
5 # Cared for by Jason Stajich <jason-at-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::Individual - An implementation of an Individual who has
16 Genotype or Sequence Results
20 use Bio::PopGen::Individual;
22 my $ind = Bio::PopGen::Individual->new(-unique_id => $id,
23 -genotypes => \@genotypes);
27 This object is a container for genotypes.
33 User feedback is an integral part of the evolution of this and other
34 Bioperl modules. Send your comments and suggestions preferably to
35 the Bioperl mailing list. Your participation is much appreciated.
37 bioperl-l@bioperl.org - General discussion
38 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
42 Report bugs to the Bioperl bug tracking system to help us keep track
43 of the bugs and their resolution. Bug reports can be submitted via
46 http://bugzilla.open-bio.org/
48 =head1 AUTHOR - Jason Stajich
50 Email jason-at-bioperl.org
54 Matthew Hahn, matthew.hahn-at-duke.edu
58 The rest of the documentation details each of the object methods.
59 Internal methods are usually preceded with a _
64 # Let the code begin...
67 package Bio
::PopGen
::Individual
;
68 use vars
qw($UIDCOUNTER);
70 BEGIN { $UIDCOUNTER = 1 }
72 # Object preamble - inherits from Bio::Root::Root
75 use base qw(Bio::Root::Root Bio::PopGen::IndividualI);
80 Usage : my $obj = Bio::PopGen::Individual->new();
81 Function: Builds a new Bio::PopGen::Individual object
82 Returns : an instance of Bio::PopGen::Individual
83 Args : -unique_id => $id,
84 -genotypes => \@genotypes
90 my($class,@args) = @_;
92 my $self = $class->SUPER::new
(@args);
93 $self->{'_genotypes'} = {};
94 my ($uid,$genotypes) = $self->_rearrange([qw(UNIQUE_ID
96 unless( defined $uid ) {
99 $self->unique_id($uid);
100 if( defined $genotypes ) {
101 if( ref($genotypes) =~ /array/i ) {
102 $self->add_Genotype(@
$genotypes);
104 $self->warn("Must provide a valid array reference to set the genotypes value in the contructor");
113 Usage : my $id = $individual->unique_id
114 Function: Unique Identifier
115 Returns : string representing unique identifier
123 return $self->{'_unique_id'} = shift if @_;
124 return $self->{'_unique_id'};
127 =head2 num_of_results
129 Title : num_of_results
130 Usage : my $count = $person->num_results;
131 Function: returns the count of the number of Results for a person
138 return scalar keys %{shift->{'_genotypes'}};
145 Usage : $individual->add_Genotype
146 Function: add a genotype value
147 Returns : count of the number of genotypes associated with this individual
148 Args : @genotypes - L<Bio::PopGen::GenotypeI> object(s) containing
149 alleles plus a marker name
154 my ($self,@genotypes) = @_;
156 foreach my $g ( @genotypes ) {
157 if( !ref($g) || ! $g->isa('Bio::PopGen::GenotypeI') ) {
158 $self->warn("cannot add $g as a genotype skipping");
161 my $mname = $g->marker_name;
162 if( ! defined $mname || ! length($mname) ) {
163 # can't just say ! name b/c '0' wouldn't be valid
164 $self->warn("cannot add genotype because marker name is not defined or is an empty string");
167 if( $self->verbose > 0 &&
168 defined $self->{'_genotypes'}->{$mname} ) {
169 # a warning when we have verbosity cranked up
170 $self->debug("Overwriting the previous value for $mname for this individual");
172 # this will force Genotype individual_id to be set to
173 # the Individual it has been added for
174 $g->individual_id($self->unique_id);
175 $self->{'_genotypes'}->{$mname} = $g;
177 return scalar keys %{$self->{'_genotypes'}};
180 =head2 reset_Genotypes
182 Title : reset_Genotypes
183 Usage : $individual->reset_Genotypes;
184 Function: Reset the genotypes stored for this individual
192 shift->{'_genotypes'} = {};
195 =head2 remove_Genotype
197 Title : remove_Genotype
198 Usage : $individual->remove_Genotype(@names)
199 Function: Removes the genotypes for the requested markers
201 Args : Names of markers
207 my ($self,@mkrs) = @_;
208 foreach my $m ( @mkrs ) {
209 delete($self->{'_genotypes'}->{$m});
215 Title : get_Genotypes
216 Usage : my @genotypes = $ind->get_Genotypes(-marker => $markername);
217 Function: Get the genotypes for an individual, based on a criteria
218 Returns : Array of genotypes
219 Args : either none (return all genotypes) or
220 -marker => name of marker to return (exact match, case matters)
226 my ($self,@args) = @_;
228 unshift @args, '-marker' if( @args == 1 ); # deal with single args
230 my ($name) = $self->_rearrange([qw(MARKER)], @args);
232 $self->warn("Only know how to process the -marker field currently");
235 my $v = $self->{'_genotypes'}->{$name};
238 return values %{$self->{'_genotypes'} || {}};
244 Usage : if( $ind->has_Marker($name) ) {}
245 Function: Boolean test to see if an Individual has a genotype
246 for a specific marker
247 Returns : Boolean (true or false)
248 Args : String representing a marker name
254 my ($self,$name) = @_;
255 return 0 if ! defined $name;
257 $name = $name->name if ref($name) && $name->isa('Bio::PopGen::MarkerI');
259 $self->warn("Passed in a ".ref($name). " to has_Marker, expecting either a string or a Bio::PopGen::MarkerI");
262 return defined $self->{'_genotypes'}->{$name};
265 =head2 get_marker_names
267 Title : get_marker_names
268 Usage : my @names = $individual->get_marker_names;
269 Function: Returns the list of known marker names
270 Returns : List of strings
276 sub get_marker_names
{
278 return keys %{$self->{'_genotypes'}};