File Coverage

Bio/PopGen/Genotype.pm
Criterion Covered Total %
statement 46 51 90.2
branch 19 24 79.1
condition 2 3 66.6
subroutine 9 10 90.0
pod 7 7 100.0
total 83 95 87.3


line stmt bran cond sub pod time code
1             #
2             # BioPerl module for Bio::PopGen::Genotype
3             #
4             # Please direct questions and support issues to
5             #
6             # Cared for by Jason Stajich
7             #
8             # Copyright Jason Stajich
9             #
10             # You may distribute this module under the same terms as perl itself
11              
12             # POD documentation - main docs before the code
13              
14             =head1 NAME
15              
16             Bio::PopGen::Genotype - An implementation of GenotypeI which is just an allele container
17              
18             =head1 SYNOPSIS
19              
20             use Bio::PopGen::Genotype;
21             my $genotype = Bio::PopGen::Genotype->new(-marker_name => $name,
22             -individual_id => $indid,
23             -alleles => \@alleles);
24              
25             =head1 DESCRIPTION
26              
27             This object will contain alleles for a given marker for a given
28             individual.
29              
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
35             skipped.
36              
37             =head1 FEEDBACK
38              
39             =head2 Mailing Lists
40              
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.
44              
45             bioperl-l@bioperl.org - General discussion
46             http://bioperl.org/wiki/Mailing_lists - About the mailing lists
47              
48             =head2 Support
49              
50             Please direct usage questions or support issues to the mailing list:
51              
52             I
53              
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.
58              
59             =head2 Reporting Bugs
60              
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
63             the web:
64              
65             https://github.com/bioperl/bioperl-live/issues
66              
67             =head1 AUTHOR - Jason Stajich
68              
69             Email jason-at-bioperl.org
70              
71             =head1 CONTRIBUTORS
72              
73             Matthew Hahn, matthew.hahn-at-duke.edu
74              
75             =head1 APPENDIX
76              
77             The rest of the documentation details each of the object methods.
78             Internal methods are usually preceded with a _
79              
80             =cut
81              
82              
83             # Let the code begin...
84              
85              
86             package Bio::PopGen::Genotype;
87 5     5   1014 use vars qw($BlankAlleles);
  5         4  
  5         184  
88 5     5   21 use strict;
  5         5  
  5         139  
89              
90             $BlankAlleles = '[\s\-Nn\?]';
91              
92              
93             # Object preamble - inherits from Bio::Root::Root
94              
95              
96              
97 5     5   16 use base qw(Bio::Root::Root Bio::PopGen::GenotypeI);
  5         5  
  5         1432  
98              
99             =head2 new
100              
101             Title : new
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
108              
109             =cut
110              
111             sub new {
112 48540     48540 1 60364 my($class,@args) = @_;
113              
114 48540         72361 my $self = $class->SUPER::new(@args);
115 48540         102384 my ($marker_name, $marker_type, $ind_id, $alleles) = $self->_rearrange([qw(MARKER_NAME
116             MARKER_TYPE
117             INDIVIDUAL_ID
118             ALLELES)],@args);
119 48540 50       122470 defined $marker_name && $self->marker_name($marker_name);
120 48540 100       61931 defined $marker_type && $self->marker_type($marker_type);
121 48540 100       78077 defined $ind_id && $self->individual_id($ind_id);
122 48540 50       61282 if( defined $alleles ) {
123 48540 50       112995 if( ref($alleles) =~ /array/i ) {
124 48540         57726 $self->add_Allele(@$alleles);
125             } else {
126 0         0 $self->warn("Could not initialize with -alleles value, it is not an array ref");
127             }
128             }
129 48540         80491 return $self;
130             }
131              
132              
133             =head2 marker_name
134              
135             Title : marker_name
136             Usage : my $name = $genotype->marker_name();
137             Function: Get the marker name for a genotype result
138             Returns : string
139             Args : [optional] marker name value to store
140              
141              
142             =cut
143              
144             sub marker_name{
145 102021     102021 1 74549 my ($self) = shift;
146 102021 100       146141 return $self->{'_marker_name'} = shift if @_;
147 53481         62338 return $self->{'_marker_name'};
148             }
149              
150             =head2 marker_type
151              
152             Title : marker_type
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
158              
159              
160             =cut
161              
162             sub marker_type{
163 3114     3114 1 2213 my ($self) = shift;
164 3114 100       5416 return $self->{'_marker_type'} = shift if @_;
165 39         68 return $self->{'_marker_type'};
166             }
167              
168              
169             =head2 individual_id
170              
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
178             Args : none
179              
180              
181             =cut
182              
183             sub individual_id {
184 96410     96410 1 66382 my ($self) = shift;
185 96410 100       153439 return $self->{'_individual_id'} = shift if @_;
186 1         4 return $self->{'_individual_id'};
187             }
188              
189             =head2 get_Alleles
190              
191             Title : get_Alleles
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
197              
198             Note : Uses the class variable $BlankAlleles to test if alleles
199             should be skipped or not.
200              
201             =cut
202              
203             sub get_Alleles{
204 95124     95124 1 65569 my ($self) = shift;
205            
206 95124 100 66     143447 if( @_ && $_[0] ) {
207 49 50       30 return @{$self->{'_alleles'} || []};
  49         147  
208             } else {
209 95075 100       128448 if( defined $self->{'_cached_noblank'} ) {
210 84099         50037 return @{$self->{'_cached_noblank'}}
  84099         163618  
211             }
212             # one liners - woo hoo.
213 20997         38388 $self->{'_cached_noblank'} = [ grep { ! /^\s*$BlankAlleles\s*$/o }
214 10976 50       6654 @{$self->{'_alleles'} || []}];
  10976         19377  
215 10976         7388 return @{$self->{'_cached_noblank'}};
  10976         19684  
216             }
217             }
218              
219             =head2 add_Allele
220              
221             Title : add_Allele
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
229              
230              
231             =cut
232              
233             sub add_Allele {
234 48540     48540 1 34780 my ($self) = shift;
235 48540         40557 $self->{'_cached_noblank'} = undef;
236 48540         28638 push @{$self->{'_alleles'}}, @_;
  48540         73236  
237 48540         32769 return scalar @{$self->{'_alleles'}};
  48540         48070  
238             }
239              
240             =head2 reset_Alleles
241              
242             Title : reset_Alleles
243             Usage : $genotype->reset_Alleles;
244             Function: Resets the stored alleles so the list is empty
245             Returns : None
246             Args : None
247              
248              
249             =cut
250              
251             sub reset_Alleles{
252 0     0 1   my ($self,@args) = @_;
253 0           $self->{'_cached_noblank'} = undef;
254 0           $self->{'_alleles'} = [];
255 0           return 0;
256             }
257              
258              
259             1;