File Coverage

Bio/PopGen/Marker.pm
Criterion Covered Total %
statement 46 63 73.0
branch 11 26 42.3
condition 0 3 0.0
subroutine 10 14 71.4
pod 11 11 100.0
total 78 117 66.6


line stmt bran cond sub pod time code
1             #
2             # BioPerl module for Bio::PopGen::Marker
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::Marker - A genetic marker which one uses to generate genotypes
17              
18             =head1 SYNOPSIS
19              
20             my $name = $marker->name(); # marker name
21             my $description = $marker->description(); # description
22             my $type = $marker->type(); # coded type of the marker
23             my $unique_id = $marker->unique_id; # optional unique ID
24             my @alleles = $marker->get_Alleles(); # the known alleles
25             my %allele_freqs = $marker->get_Allele_Frequencies(); # keys are marker names
26             # vals are frequencies
27             # may change to handle multiple populations
28              
29             =head1 DESCRIPTION
30              
31             This object will not contain genotype information pertaining to an
32             individual, but rather population level statistics and descriptive
33             information about a marker.
34              
35             =head1 FEEDBACK
36              
37             =head2 Mailing Lists
38              
39             User feedback is an integral part of the evolution of this and other
40             Bioperl modules. Send your comments and suggestions preferably to
41             the Bioperl mailing list. Your participation is much appreciated.
42              
43             bioperl-l@bioperl.org - General discussion
44             http://bioperl.org/wiki/Mailing_lists - About the mailing lists
45              
46             =head2 Support
47              
48             Please direct usage questions or support issues to the mailing list:
49              
50             I
51              
52             rather than to the module maintainer directly. Many experienced and
53             reponsive experts will be able look at the problem and quickly
54             address it. Please include a thorough description of the problem
55             with code and data examples if at all possible.
56              
57             =head2 Reporting Bugs
58              
59             Report bugs to the Bioperl bug tracking system to help us keep track
60             of the bugs and their resolution. Bug reports can be submitted via
61             the web:
62              
63             https://github.com/bioperl/bioperl-live/issues
64              
65             =head1 AUTHOR - Jason Stajich
66              
67             Email jason-at-bioperl.org
68              
69             =head1 CONTRIBUTORS
70              
71             Matthew Hahn, matthew.hahn-at-duke.edu
72              
73             =head1 APPENDIX
74              
75             The rest of the documentation details each of the object methods.
76             Internal methods are usually preceded with a _
77              
78             =cut
79              
80              
81             # Let the code begin...
82              
83              
84             package Bio::PopGen::Marker;
85 3     3   8 use strict;
  3         4  
  3         70  
86              
87             # Object preamble - inherits from Bio::Root::Root
88              
89              
90 3     3   8 use vars qw($UniqueCounter);
  3         3  
  3         106  
91              
92             $UniqueCounter = 0;
93              
94 3     3   9 use base qw(Bio::Root::Root Bio::PopGen::MarkerI);
  3         3  
  3         826  
95              
96             =head2 new
97              
98             Title : new
99             Usage : my $obj = Bio::PopGen::Marker->new();
100             Function: Builds a new Bio::PopGen::Marker object
101             Returns : an instance of Bio::PopGen::Marker
102             Args : -name => [string] marker name
103             -description => [string] marker description
104             -type => [string] marker type
105             -unique_id => [string/int] unique id
106             -allele_freq => [hash ref] allele frequencies
107              
108             =cut
109              
110             sub new {
111 493     493 1 767 my($class,@args) = @_;
112              
113 493         1546 my $self = $class->SUPER::new(@args);
114 493         1467 my ($name,$desc,$type,$uid,$af) = $self->_rearrange([qw(NAME
115             DESCRIPTION
116             TYPE
117             UNIQUE_ID
118             ALLELE_FREQ)],@args);
119 493         1546 $self->{'_allele_freqs'} = {};
120 493 50       1012 if( ! defined $uid ) {
121 493         591 $uid = $UniqueCounter++;
122             }
123 493 50       750 if( defined $name) {
124 493         860 $self->name($name);
125             } else {
126 0         0 $self->throw("Must provide a name when initializing a Marker");
127             }
128 493 50       753 defined $desc && $self->description($desc);
129 493 50       736 defined $type && $self->type($type);
130 493         916 $self->unique_id($uid);
131 493 100       874 if( defined $af) {
132 2 50       6 if( ref($af) !~ /HASH/i ) {
133 0         0 $self->warn("Must provide valid Hash reference for allele_freq method");
134             } else {
135 2         5 foreach my $allele ( keys %$af ) {
136 5         9 $self->add_Allele_Frequency($allele, $af->{$allele});
137             }
138             }
139             }
140 493         982 return $self;
141             }
142              
143             =head2 name
144              
145             Title : name
146             Usage : my $name = $marker->name();
147             Function: Get the name of the marker
148             Returns : string representing the name of the marker
149             Args : [optional] name
150              
151              
152             =cut
153              
154             sub name{
155 50035     50035 1 30144 my $self = shift;
156              
157 50035 100       53169 return $self->{'_name'} = shift if @_;
158 49542         59119 return $self->{'_name'};
159             }
160              
161              
162             =head2 description
163              
164             Title : description
165             Usage : my $desc = $marker->description
166             Function: Get the marker description free text
167             Returns : string
168             Args : [optional] string
169              
170              
171             =cut
172              
173             sub description{
174 0     0 1 0 my $self = shift;
175              
176 0 0       0 return $self->{'_description'} = shift if @_;
177 0         0 return $self->{'_description'};
178             }
179              
180             =head2 type
181              
182             Title : type
183             Usage : my $type = $marker->type;
184             Function: Get coded string for marker type
185             Returns : string
186             Args : [optional] string
187              
188              
189             =cut
190              
191             sub type{
192 0     0 1 0 my $self = shift;
193              
194 0 0       0 return $self->{'_type'} = shift if @_;
195 0         0 return $self->{'_type'};
196             }
197              
198              
199             =head2 unique_id
200              
201             Title : unique_id
202             Usage : my $id = $marker->unique_id;
203             Function: Get the unique marker ID
204             Returns : unique ID string
205             Args : [optional ] string
206              
207              
208             =cut
209              
210             sub unique_id{
211 493     493 1 466 my $self = shift;
212              
213 493 50       988 return $self->{'_uniqueid'} = shift if @_;
214 0         0 return $self->{'_uniqueid'};
215             }
216              
217              
218             =head2 annotation
219              
220             Title : annotation
221             Usage : my $annotation_collection = $marker->annotation;
222             Function: Get/set a Bio::AnnotationCollectionI for this marker
223             Returns : Bio::AnnotationCollectionI object
224             Args : [optional set] Bio::AnnotationCollectionI object
225              
226             =cut
227              
228             sub annotation{
229 0     0 1 0 my ($self, $arg) = @_;
230 0 0       0 return $self->{_annotation} unless $arg;
231 0 0 0     0 $self->throw("Bio::AnnotationCollectionI required for argument") unless
232             ref($arg) && $arg->isa('Bio::AnnotationCollectionI');
233 0         0 return $self->{_annotation} = $arg;
234             }
235              
236             =head2 get_Alleles
237              
238             Title : get_Alleles
239             Usage : my @alleles = $marker->get_Alleles();
240             Function: Get the available marker alleles
241             Returns : Array of strings
242             Args : none
243              
244             =cut
245              
246             sub get_Alleles{
247 164     164 1 113 my $self = shift;
248 164         100 my (@numeric,@alpha);
249              
250 164         108 for ( keys %{$self->{'_allele_freqs'}} ) {
  164         351  
251 311 50       464 if( /[^\d\.\-e]/ ) { push @alpha, $_ }
  311         296  
252 0         0 else { push @numeric, $_ }
253             }
254 164         145 @numeric = sort { $b <=> $a } @numeric;
  0         0  
255 164         182 @alpha = sort { $b cmp $a } @alpha;
  148         141  
256 164         271 return @numeric,@alpha;
257             }
258              
259              
260             =head2 get_Allele_Frequencies
261              
262             Title : get_Allele_Frequencies
263             Usage : my %allele_freqs = $marker->get_Allele_Frequencies;
264             Function: Get the alleles and their frequency (set relative to
265             a given population - you may want to create different
266             markers with the same name for different populations
267             with this current implementation
268             Returns : Associative array where keys are the names of the alleles
269             Args : none
270              
271              
272             =cut
273              
274             sub get_Allele_Frequencies{
275 409     409 1 719 return %{$_[0]->{'_allele_freqs'}};
  409         1049  
276             }
277              
278             =head2 add_Allele_Frequency
279              
280             Title : add_Allele_Frequency
281             Usage : $marker->add_Allele_Frequency($allele,$freq)
282             Function: Adds an allele frequency
283             Returns : None
284             Args : $allele - allele name
285             $freq - frequency value
286              
287              
288             =cut
289              
290             sub add_Allele_Frequency{
291 941     941 1 952 my ($self,$allele,$freq) = @_;
292 941         1757 $self->{'_allele_freqs'}->{$allele} = $freq;
293             }
294              
295             =head2 reset_alleles
296              
297             Title : reset_alleles
298             Usage : $marker->reset_alleles();
299             Function: Reset the alleles for a marker
300             Returns : None
301             Args : None
302              
303              
304             =cut
305              
306             sub reset_alleles{
307 0     0 1 0 my ($self) = @_;
308 0         0 $self->{'_allele_freqs'} = {};
309             }
310              
311             =head2 marker_coverage
312              
313             Title : marker_coverage
314             Usage : $marker->marker_coverage();
315             Function: Get marker coverage, that is, the number of
316             individuals where the marker is present
317             excluding missing or ambiguous alleles
318             Returns : integer, representing marker coverage
319             Args :
320              
321              
322             =cut
323              
324             sub marker_coverage{
325 2     2 1 301 my ($self) = @_;
326            
327 2         6 return $self->{_marker_coverage};
328             }
329              
330             1;