File Coverage

lib/Sanger/CGP/Vagrent/Data/AbstractGenomicPosition.pm
Criterion Covered Total %
branch 16 26 61.5
subroutine 13 17 76.4
pod 9 10 90.0
total 38 53 71.7


line bran sub pod code
1       package Sanger::CGP::Vagrent::Data::AbstractGenomicPosition;
2        
3       ##########LICENCE##########
4       # Copyright (c) 2014 Genome Research Ltd.
5       #
6       # Author: Cancer Genome Project cgpit@sanger.ac.uk
7       #
8       # This file is part of VAGrENT.
9       #
10       # VAGrENT is free software: you can redistribute it and/or modify it under
11       # the terms of the GNU Affero General Public License as published by the Free
12       # Software Foundation; either version 3 of the License, or (at your option) any
13       # later version.
14       #
15       # This program is distributed in the hope that it will be useful, but WITHOUT
16       # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17       # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18       # details.
19       #
20       # You should have received a copy of the GNU Affero General Public License
21       # along with this program. If not, see <http://www.gnu.org/licenses/>.
22       ##########LICENCE##########
23        
24        
25   4   use strict;
26   4   use Carp;
27   4   use Attribute::Abstract;
28        
29   4   use Sanger::CGP::Vagrent qw($VERSION);
30   4   use base qw(Sanger::CGP::Vagrent);
31        
32       1;
33        
34       sub new {
35   876 1 my $proto = shift;
36       my $class = ref($proto) || $proto;
37       my $self = {};
38       bless($self, $class);
39       $self->_localInit(@_);
40       $self->_init(@_);
41       return $self;
42       }
43        
44       sub _localInit {
45   876   my $self = shift;
46       my %vars = @_;
47       foreach my $k(keys(%vars)){
48 100     if($k eq 'species'){
  100      
  100      
  100      
  100      
  50      
49       $self->{_species} = $vars{species};
50       } elsif($k eq 'genomeVersion'){
51       $self->{_genomeVersion} = $vars{genomeVersion};
52       } elsif($k eq 'chr'){
53       $self->{_chr} = $vars{'chr'};
54       } elsif($k eq 'minpos'){
55       $self->{_minpos} = $vars{minpos};
56       } elsif($k eq 'maxpos'){
57       $self->{_maxpos} = $vars{maxpos};
58       } elsif($k eq 'id'){
59       $self->{_id} = $vars{id};
60       }
61       }
62 50     croak('must specify a species') unless(exists($self->{_species}) && defined($self->{_species}));
63 50     croak('must specify a genomeVersion') unless(exists($self->{_genomeVersion}) && defined($self->{_genomeVersion}));
64 50     croak('must specify a chr') unless(exists($self->{_chr}) && defined($self->{_chr}));
65 50     croak('must specify a minpos') unless(exists($self->{_minpos}) && defined($self->{_minpos}));
66 50     croak('must specify a maxpos') unless(exists($self->{_maxpos}) && defined($self->{_maxpos}));
67       }
68        
69   4   sub _init: Abstract;
70        
71       sub getSpecies {
72   14 1 return shift->{_species};
73       }
74        
75       sub getGenomeVersion {
76   14 1 return shift->{_genomeVersion};
77       }
78        
79       sub getChr {
80   34290 1 return shift->{_chr};
81       }
82        
83       sub getMinPos {
84   1952950 1 return shift->{_minpos};
85       }
86        
87       sub setMinPos {
88   0 1 my ($self,$pos) = @_;
89 0     if(defined $pos){
90       $self->{_minpos} = $pos;
91       }
92       }
93        
94       sub getMaxPos {
95   19334215 1 return shift->{_maxpos};
96       }
97        
98       sub setMaxPos {
99   0 1 my ($self,$pos) = @_;
100 0     if(defined $pos){
101       $self->{_maxpos} = $pos;
102       }
103       }
104        
105       sub getId {
106   0 1 return shift->{_id};
107       }
108        
109       sub getLength {
110   0 0 my $self = shift;
111       return (($self->{_maxpos} - $self->{_minpos}) + 1);
112       }
113        
114       __END__
115        
116       =head1 NAME
117        
118       Sanger::CGP::Vagrent::Data::AbstractGenomicPosition - Abstract Data object representing
119       Genomic position
120        
121       =head1 DESCRIPTION
122        
123       This is an abstract data class designed to be extended, it provides basic functionality for holding
124       genomic position. Child classes must implement an _init method to handle parameter values handed to
125       the object when the constructor is called.
126        
127       =head1 METHODS
128        
129       =head2 Constructor
130        
131       =head3 new
132        
133       =over
134        
135       =item Usage :
136        
137       my $gp = Sanger::CGP::Vagrent::Data::AbstractGenomicPositionSubClass->new(%params);
138        
139       =item Function :
140        
141       Builds a new Sanger::CGP::Vagrent::Data::AbstractGenomicPosition inheriting object
142        
143       =item Returns :
144        
145       L<Sanger::CGP::Vagrent::Data::AbstractGenomicPosition|Sanger::CGP::Vagrent::Data::AbstractGenomicPosition> sub class object initialized with parameter values
146        
147       =item Params :
148        
149       species => Species string (eg Human)
150       genomeVersion => Genome version String (eg GRCh37)
151       chr => Chromosome/contig name
152       minpos => Lowest coordinate of the feature
153       maxpos => Highest coordinate of the feature
154       id => Identifier (Optional)
155        
156       =back
157        
158       =head3 _init
159        
160       =over
161        
162       =item Usage :
163        
164       Abstract internal initialisation method, must be implemented in subclasses. All parameters are passed through from the constructor.
165        
166       =back
167        
168       =head2 Attributes
169        
170       =head3 getId
171        
172       =over
173        
174       =item Usage :
175        
176       my $id = $gp->getId;
177        
178       =item Function :
179        
180       Returns the value of Id
181        
182       =item Returns :
183        
184       String
185        
186       =back
187        
188       =head3 getSpecies
189        
190       =over
191        
192       =item Usage :
193        
194       my $species = $gp->getSpecies;
195        
196       =item Function :
197        
198       Returns the species name
199        
200       =item Returns :
201        
202       String
203        
204       =back
205        
206       =head3 getGenomeVersion
207        
208       =over
209        
210       =item Usage :
211        
212       my $gVers = $gp->getGenomeVersion;
213        
214       =item Function :
215        
216       Returns the genome version string
217        
218       =item Returns :
219        
220       String
221        
222       =back
223        
224       =head3 getChr
225        
226       =over
227        
228       =item Usage :
229        
230       my $chr = $gp->getChr;
231        
232       =item Function :
233        
234       Returns the chromosome/contig name
235        
236       =item Returns :
237        
238       String
239        
240       =back
241        
242       =head3 getMinPos
243        
244       =over
245        
246       =item Usage :
247        
248       my $min = $gp->getMinPos;
249        
250       =item Function :
251        
252       Returns the lowest coordinate of the feature on the sequence
253        
254       =item Returns :
255        
256       Integer
257        
258       =back
259        
260       =head3 setMinPos
261        
262       =over
263        
264       =item Usage :
265        
266       $gp->setMinPos($newPos);
267        
268       =item Function :
269        
270       Sets the lowest coordinate of the feature on the sequence
271        
272       =item Params
273        
274       Integer, new position
275        
276       =item Returns :
277        
278       None
279        
280       =back
281        
282       =head3 getMaxPos
283        
284       =over
285        
286       =item Usage :
287        
288       my $max = $gp->getMaxPos;
289        
290       =item Function :
291        
292       Returns the highest coordinate of the feature on the sequence
293        
294       =item Returns :
295        
296       Integer
297        
298       =back
299        
300       =head3 setMaxPos
301        
302       =over
303        
304       =item Usage :
305        
306       $gp->setMaxPos($newPos);
307        
308       =item Function :
309        
310       Sets the highest coordinate of the feature on the sequence
311        
312       =item Params
313        
314       Integer, new position
315        
316       =item Returns :
317        
318       None
319        
320       =back