3 # BioPerl module for Bio::PopGen::Individual
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Jason Stajich <jason-at-bioperl.org>
9 # Copyright Jason Stajich
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
17 Bio::PopGen::Individual - An implementation of an Individual who has
18 Genotype or Sequence Results
22 use Bio::PopGen::Individual;
24 my $ind = Bio::PopGen::Individual->new(-unique_id => $id,
25 -genotypes => \@genotypes);
29 This object is a container for genotypes.
35 User feedback is an integral part of the evolution of this and other
36 Bioperl modules. Send your comments and suggestions preferably to
37 the Bioperl mailing list. Your participation is much appreciated.
39 bioperl-l@bioperl.org - General discussion
40 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
44 Please direct usage questions or support issues to the mailing list:
46 L<bioperl-l@bioperl.org>
48 rather than to the module maintainer directly. Many experienced and
49 reponsive experts will be able look at the problem and quickly
50 address it. Please include a thorough description of the problem
51 with code and data examples if at all possible.
55 Report bugs to the Bioperl bug tracking system to help us keep track
56 of the bugs and their resolution. Bug reports can be submitted via
59 http://bugzilla.open-bio.org/
61 =head1 AUTHOR - Jason Stajich
63 Email jason-at-bioperl.org
67 Matthew Hahn, matthew.hahn-at-duke.edu
71 The rest of the documentation details each of the object methods.
72 Internal methods are usually preceded with a _
77 # Let the code begin...
80 package Bio
::PopGen
::Individual
;
81 use vars
qw($UIDCOUNTER);
83 BEGIN { $UIDCOUNTER = 1 }
85 # Object preamble - inherits from Bio::Root::Root
88 use base qw(Bio::Root::Root Bio::PopGen::IndividualI);
93 Usage : my $obj = Bio::PopGen::Individual->new();
94 Function: Builds a new Bio::PopGen::Individual object
95 Returns : an instance of Bio::PopGen::Individual
96 Args : -unique_id => $id,
97 -genotypes => \@genotypes
103 my($class,@args) = @_;
105 my $self = $class->SUPER::new
(@args);
106 $self->{'_genotypes'} = {};
107 my ($uid,$genotypes) = $self->_rearrange([qw(UNIQUE_ID
109 unless( defined $uid ) {
110 $uid = $UIDCOUNTER++;
112 $self->unique_id($uid);
113 if( defined $genotypes ) {
114 if( ref($genotypes) =~ /array/i ) {
115 $self->add_Genotype(@
$genotypes);
117 $self->warn("Must provide a valid array reference to set the genotypes value in the contructor");
126 Usage : my $id = $individual->unique_id
127 Function: Unique Identifier
128 Returns : string representing unique identifier
136 return $self->{'_unique_id'} = shift if @_;
137 return $self->{'_unique_id'};
140 =head2 num_of_results
142 Title : num_of_results
143 Usage : my $count = $person->num_results;
144 Function: returns the count of the number of Results for a person
151 return scalar keys %{shift->{'_genotypes'}};
158 Usage : $individual->add_Genotype
159 Function: add a genotype value
160 Returns : count of the number of genotypes associated with this individual
161 Args : @genotypes - L<Bio::PopGen::GenotypeI> object(s) containing
162 alleles plus a marker name
167 my ($self,@genotypes) = @_;
169 foreach my $g ( @genotypes ) {
170 if( !ref($g) || ! $g->isa('Bio::PopGen::GenotypeI') ) {
171 $self->warn("cannot add $g as a genotype skipping");
174 my $mname = $g->marker_name;
175 if( ! defined $mname || ! length($mname) ) {
176 # can't just say ! name b/c '0' wouldn't be valid
177 $self->warn("cannot add genotype because marker name is not defined or is an empty string");
180 if( $self->verbose > 0 &&
181 defined $self->{'_genotypes'}->{$mname} ) {
182 # a warning when we have verbosity cranked up
183 $self->debug("Overwriting the previous value for $mname for this individual");
185 # this will force Genotype individual_id to be set to
186 # the Individual it has been added for
187 $g->individual_id($self->unique_id);
188 $self->{'_genotypes'}->{$mname} = $g;
190 return scalar keys %{$self->{'_genotypes'}};
193 =head2 reset_Genotypes
195 Title : reset_Genotypes
196 Usage : $individual->reset_Genotypes;
197 Function: Reset the genotypes stored for this individual
205 shift->{'_genotypes'} = {};
208 =head2 remove_Genotype
210 Title : remove_Genotype
211 Usage : $individual->remove_Genotype(@names)
212 Function: Removes the genotypes for the requested markers
214 Args : Names of markers
220 my ($self,@mkrs) = @_;
221 foreach my $m ( @mkrs ) {
222 delete($self->{'_genotypes'}->{$m});
228 Title : get_Genotypes
229 Usage : my @genotypes = $ind->get_Genotypes(-marker => $markername);
230 Function: Get the genotypes for an individual, based on a criteria
231 Returns : Array of genotypes
232 Args : either none (return all genotypes) or
233 -marker => name of marker to return (exact match, case matters)
239 my ($self,@args) = @_;
241 unshift @args, '-marker' if( @args == 1 ); # deal with single args
243 my ($name) = $self->_rearrange([qw(MARKER)], @args);
245 $self->warn("Only know how to process the -marker field currently");
248 my $v = $self->{'_genotypes'}->{$name};
251 return values %{$self->{'_genotypes'} || {}};
257 Usage : if( $ind->has_Marker($name) ) {}
258 Function: Boolean test to see if an Individual has a genotype
259 for a specific marker
260 Returns : Boolean (true or false)
261 Args : String representing a marker name
267 my ($self,$name) = @_;
268 return 0 if ! defined $name;
270 $name = $name->name if ref($name) && $name->isa('Bio::PopGen::MarkerI');
272 $self->warn("Passed in a ".ref($name). " to has_Marker, expecting either a string or a Bio::PopGen::MarkerI");
275 return defined $self->{'_genotypes'}->{$name};
278 =head2 get_marker_names
280 Title : get_marker_names
281 Usage : my @names = $individual->get_marker_names;
282 Function: Returns the list of known marker names
283 Returns : List of strings
289 sub get_marker_names
{
291 return keys %{$self->{'_genotypes'}};