2 # BioPerl module for Bio::PopGen::Genotype
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Jason Stajich <jason-at-bioperl.org>
8 # Copyright Jason Stajich
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::PopGen::Genotype - An implementation of GenotypeI which is just an allele container
20 use Bio::PopGen::Genotype;
21 my $genotype = Bio::PopGen::Genotype->new(-marker_name => $name,
22 -individual_id => $indid,
23 -alleles => \@alleles);
27 This object will contain alleles for a given marker for a given
30 The class variable BlankAlleles (accessible through
31 $Bio::PopGen::Genotype::BlankAlleles = 'somepattern') can be set to a
32 regexp pattern for identifying blank alleles which should no be
33 counted (they are effectively missing data). By default it set to
34 match white space, '-', 'N' or 'n', and '?' as blank alleles which are
41 User feedback is an integral part of the evolution of this and other
42 Bioperl modules. Send your comments and suggestions preferably to
43 the Bioperl mailing list. Your participation is much appreciated.
45 bioperl-l@bioperl.org - General discussion
46 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
50 Please direct usage questions or support issues to the mailing list:
52 I<bioperl-l@bioperl.org>
54 rather than to the module maintainer directly. Many experienced and
55 reponsive experts will be able look at the problem and quickly
56 address it. Please include a thorough description of the problem
57 with code and data examples if at all possible.
61 Report bugs to the Bioperl bug tracking system to help us keep track
62 of the bugs and their resolution. Bug reports can be submitted via
65 https://redmine.open-bio.org/projects/bioperl/
67 =head1 AUTHOR - Jason Stajich
69 Email jason-at-bioperl.org
73 Matthew Hahn, matthew.hahn-at-duke.edu
77 The rest of the documentation details each of the object methods.
78 Internal methods are usually preceded with a _
83 # Let the code begin...
86 package Bio
::PopGen
::Genotype
;
87 use vars
qw($BlankAlleles);
90 $BlankAlleles = '[\s\-Nn\?]';
93 # Object preamble - inherits from Bio::Root::Root
97 use base qw(Bio::Root::Root Bio::PopGen::GenotypeI);
102 Usage : my $obj = Bio::PopGen::Genotype->new();
103 Function: Builds a new Bio::PopGen::Genotype object
104 Returns : an instance of Bio::PopGen::Genotype
105 Args : -marker_name => string representing name of the marker
106 -individual_id => string representing individual id (optional)
107 -alleles => arrayref with each item in the array being an allele
112 my($class,@args) = @_;
114 my $self = $class->SUPER::new
(@args);
115 my ($marker_name, $marker_type, $ind_id, $alleles) = $self->_rearrange([qw(MARKER_NAME
119 defined $marker_name && $self->marker_name($marker_name);
120 defined $marker_type && $self->marker_type($marker_type);
121 defined $ind_id && $self->individual_id($ind_id);
122 if( defined $alleles ) {
123 if( ref($alleles) =~ /array/i ) {
124 $self->add_Allele(@
$alleles);
126 $self->warn("Could not initialize with -alleles value, it is not an array ref");
136 Usage : my $name = $genotype->marker_name();
137 Function: Get the marker name for a genotype result
139 Args : [optional] marker name value to store
146 return $self->{'_marker_name'} = shift if @_;
147 return $self->{'_marker_name'};
153 Usage : my $name = $genotype->marker_type();
154 Function: Get the marker type for a genotype result
155 Returns : M (microsatellite, or other multi-allelic
156 locus) or S (biallelic/SNP locus)
157 Args : [optional] marker type value to store
164 return $self->{'_marker_type'} = shift if @_;
165 return $self->{'_marker_type'};
171 Title : individual_id
172 Usage : my $indid = $genotype->individual_id();
173 Function: Gets the individual id associated with a genotype
174 This is effectively a back reference since we will typically
175 associate a genotype with an individual with an
176 individual HAS-A genotype relationship.
177 Returns : unique id string for an individual
185 return $self->{'_individual_id'} = shift if @_;
186 return $self->{'_individual_id'};
192 Usage : my @alleles = $genotype->get_Alleles();
193 Function: Get the alleles for a given marker and individual
194 Returns : array of alleles (strings in this implementation)
195 Args : $showblank - boolean flag to indicate return ALL alleles not
196 skipping the coded EMPTY alleles
198 Note : Uses the class variable $BlankAlleles to test if alleles
199 should be skipped or not.
207 return @
{$self->{'_alleles'} || []};
209 if( defined $self->{'_cached_noblank'} ) {
210 return @
{$self->{'_cached_noblank'}}
212 # one liners - woo hoo.
213 $self->{'_cached_noblank'} = [ grep { ! /^\s*$BlankAlleles\s*$/o }
214 @
{$self->{'_alleles'} || []}];
215 return @
{$self->{'_cached_noblank'}};
222 Usage : $genotype->add_Allele(@alleles);
223 Function: Add alleles to the genotype, at this point there is no
224 verification to insure that haploid individuals only have 1
225 allele or that diploids only have 2 - we assume that is
226 done by the user creating these objects
227 Returns : count of the number of alleles in genotype
228 Args : Array of alleles to store
235 $self->{'_cached_noblank'} = undef;
236 push @
{$self->{'_alleles'}}, @_;
237 return scalar @
{$self->{'_alleles'}};
242 Title : reset_Alleles
243 Usage : $genotype->reset_Alleles;
244 Function: Resets the stored alleles so the list is empty
252 my ($self,@args) = @_;
253 $self->{'_cached_noblank'} = undef;
254 $self->{'_alleles'} = [];