File Coverage

lib/Sanger/CGP/Vagrent/Data/Annotation.pm
Criterion Covered Total %
branch 47 54 87.0
subroutine 40 41 97.5
pod 31 31 100.0
total 118 126 93.6


line bran sub pod code
1       package Sanger::CGP::Vagrent::Data::Annotation;
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 Data::Dumper;
27   4   use List::Util qw(first);
28   4   use Carp;
29   4   use Const::Fast qw(const);
30        
31   4   use Sanger::CGP::Vagrent qw($VERSION);
32   4   use base qw(Sanger::CGP::Vagrent);
33        
34       # sequence context constant values
35        
36       const my $CDS_ANNOTATION_CONTEXT => 'CDS';
37       const my $MRNA_ANNOTATION_CONTEXT => 'mRNA';
38       const my $PROTEIN_ANNOTATION_CONTEXT => 'Protein';
39        
40       const my @ALL_ANNOTATION_CONTEXT => ($CDS_ANNOTATION_CONTEXT,$MRNA_ANNOTATION_CONTEXT,$PROTEIN_ANNOTATION_CONTEXT);
41        
42       # variation type constant values
43        
44       const my $SUBSTITUTION_ANNOTATION_TYPE => 'Substitution';
45       const my $DELETION_ANNOTATION_TYPE => 'Deletion';
46       const my $INSERTION_ANNOTATION_TYPE => 'Insertion';
47       const my $COMPLEX_ANNOTATION_TYPE => 'Complex';
48       const my $FRAMESHIFT_ANNOTATION_TYPE => 'FrameShift';
49       const my $UNKNOWN_ANNOTATION_TYPE => 'Unknown';
50        
51       const my @ALL_ANNOTATION_TYPES => ($COMPLEX_ANNOTATION_TYPE,$FRAMESHIFT_ANNOTATION_TYPE,$INSERTION_ANNOTATION_TYPE,$DELETION_ANNOTATION_TYPE,$SUBSTITUTION_ANNOTATION_TYPE,$UNKNOWN_ANNOTATION_TYPE);
52        
53       # variation subtype constant values for location data description
54        
55       const my $POSITION_KNOWN_SUBTYPE => 'POS-KNOWN';
56       const my $POSITION_OFFSET_SUBTYPE => 'POS-OFFSET';
57       const my $POSITION_OFF_SEQUENCE_SUBTYPE => 'POS-OFFSEQ';
58        
59       const my @ALL_ANNOTATION_SUBTYPES => ($POSITION_OFF_SEQUENCE_SUBTYPE,$POSITION_OFFSET_SUBTYPE,$POSITION_KNOWN_SUBTYPE);
60        
61       1;
62        
63       sub new {
64   1700 1 my $proto = shift;
65       my $class = ref($proto) || $proto;
66       my $self = {};
67       bless($self, $class);
68       $self->_init(@_);
69       return $self;
70       }
71        
72       sub _init {
73   1700   my $self = shift;
74       my %vars = @_;
75       foreach my $k(keys(%vars)){
76 100     if($k eq 'minpos'){
  100      
  100      
  100      
  100      
  100      
  100      
  100      
  100      
  100      
  100      
  100      
  100      
  100      
  50      
77       $self->{_minpos} = $vars{minpos};
78       } elsif($k eq 'minOffset'){
79       $self->{_minOffset} = $vars{minOffset};
80       } elsif($k eq 'maxpos'){
81       $self->{_maxpos} = $vars{maxpos};
82       } elsif($k eq 'maxOffset'){
83       $self->{_maxOffset} = $vars{maxOffset};
84       } elsif($k eq 'wt'){
85       $self->{_wt} = $vars{wt};
86       } elsif($k eq 'mt'){
87       $self->{_mt} = $vars{mt};
88       } elsif($k eq 'acc'){
89       $self->{_acc} = $vars{acc};
90       } elsif($k eq 'accversion'){
91       $self->{_accversion} = $vars{accversion};
92       } elsif($k eq 'seqlength'){
93       $self->{_seqlength} = $vars{seqlength};
94       } elsif($k eq 'db'){
95       $self->{_db} = $vars{db};
96       } elsif($k eq 'dbversion'){
97       $self->{_dbversion} = $vars{dbversion};
98       } elsif($k eq 'description'){
99       $self->{_description} = $vars{description};
100       } elsif($k eq 'context'){
101       my $good = undef;
102       foreach my $context(@ALL_ANNOTATION_CONTEXT){
103 100     if($vars{context} eq $context){
104       $good = $vars{context};
105       last;
106       }
107       }
108 50     if(defined($good)){
109       $self->{_context} = $good;
110       } else {
111       croak('recieved unknown annotation context: '.$vars{context});
112       }
113       } elsif($k eq 'type'){
114       my $good = undef;
115       foreach my $type(@ALL_ANNOTATION_TYPES){
116 100     if($vars{type} eq $type){
117       $good = $vars{type};
118       last;
119       }
120       }
121 50     if(defined($good)){
122       $self->{_type} = $good;
123       } else {
124       croak('recieved unknown annotation type: '.$vars{type});
125       }
126       } elsif($k eq 'subtype'){
127       my $good = undef;
128       foreach my $subtype(@ALL_ANNOTATION_SUBTYPES){
129 100     if($vars{subtype} eq $subtype){
130       $good = $vars{subtype};
131       last;
132       }
133       }
134 50     if(defined($good)){
135       $self->{_subtype} = $good;
136       } else {
137       croak('recieved unknown annotation type: '.$vars{subtype});
138       }
139       }
140        
141       }
142       }
143        
144       sub getCDSAnnotationContext {
145   3324 1 return $CDS_ANNOTATION_CONTEXT;
146       }
147        
148       sub getmRNAAnnotationContext {
149   4455 1 return $MRNA_ANNOTATION_CONTEXT;
150       }
151        
152       sub getProteinAnnotationContext {
153   2141 1 return $PROTEIN_ANNOTATION_CONTEXT;
154       }
155        
156       sub getSubstitutionAnnotationType {
157   308 1 return $SUBSTITUTION_ANNOTATION_TYPE;
158       }
159        
160       sub getDeletionAnnotationType {
161   546 1 return $DELETION_ANNOTATION_TYPE;
162       }
163        
164       sub getComplexAnnotationType {
165   458 1 return $COMPLEX_ANNOTATION_TYPE;
166       }
167        
168       sub getInsertionAnnotationType {
169   374 1 return $INSERTION_ANNOTATION_TYPE;
170       }
171        
172       sub getFrameShiftAnnotationType {
173   40 1 return $FRAMESHIFT_ANNOTATION_TYPE;
174       }
175        
176       sub getUnknownAnnotationType {
177   1674 1 return $UNKNOWN_ANNOTATION_TYPE;
178       }
179        
180       sub getPositionKnownSubtype {
181   478 1 return $POSITION_KNOWN_SUBTYPE;
182       }
183        
184       sub getPositionOffsetSubtype {
185   965 1 return $POSITION_OFFSET_SUBTYPE;
186       }
187        
188       sub getPositionOffSequenceSubtype {
189   1674 1 return $POSITION_OFF_SEQUENCE_SUBTYPE;
190       }
191        
192       sub getMinPos {
193   3910 1 return shift->{_minpos};
194       }
195        
196       sub getMaxPos {
197   4191 1 return shift->{_maxpos};
198       }
199        
200       sub getMinOffset {
201   2062 1 return shift->{_minOffset};
202       }
203        
204       sub getMaxOffset {
205   2034 1 return shift->{_maxOffset};
206       }
207        
208       sub getWt {
209   1824 1 return shift->{_wt};
210       }
211        
212       sub getMt {
213   1970 1 return shift->{_mt};
214       }
215        
216       sub getDescription {
217   1741 1 return shift->{_description};
218       }
219        
220       sub getContext {
221   13512 1 return shift->{_context};
222       }
223        
224       sub getType {
225   1700 1 return shift->{_type};
226       }
227        
228       sub getSubtype {
229   1989 1 return shift->{_subtype};
230       }
231        
232       sub getAccession {
233   1700 1 return shift->{_acc};
234       }
235        
236       sub getSequenceVersion {
237   1700 1 return shift->{_accversion};
238       }
239        
240       sub getDatabase {
241   1700 1 return shift->{_db};
242       }
243        
244       sub getDatabaseVersion {
245   1700 1 return shift->{_dbversion};
246       }
247        
248       sub getSequenceLength {
249   0 1 return shift->{_seqlength};
250       }
251        
252       sub addClassification {
253   2840 1 my ($self,@classes) = @_;
254       foreach my $c (@classes){
255 50     if(defined($c)){
256 100     if(defined($self->getClassifications)){
257 50 1518   push(@{$self->{_class}},$c) unless(first {$_ eq $c} $self->getClassifications);
258       } else {
259       push(@{$self->{_class}},$c);
260       }
261       }
262       }
263       }
264        
265       sub getClassifications {
266   9741 1 my ($self,$class) = @_;
267 100     return @{$self->{_class}} if(exists $self->{_class} && defined $self->{_class});
268       return undef;
269       }
270        
271       sub hasClassification {
272   7843 1 my ($self,$class) = @_;
273 50     if(defined($self->{_class})){
274 100 16135   if(first {$_ eq $class} @{$self->{_class}}){
275       return 1;
276       } else {
277       return 0;
278       }
279       }
280       return 0;
281       }
282        
283        
284       __END__
285        
286       =head1 NAME
287        
288       Sanger::CGP::Vagrent::Data::Annotation - Data object containing the description of an variation
289       within a sequence
290        
291       =head1 DESCRIPTION
292        
293       This holds annotation for a variation against a defined piece of sequence
294        
295       =head1 METHODS
296        
297       =head2 Constructor
298        
299       =head3 new
300        
301       =over
302        
303       =item Usage :
304        
305       my $annot = Sanger::CGP::Vagrent::Data::Annotation->new(%params);
306        
307       =item Function :
308        
309       Builds a new Sanger::CGP::Vagrent::Data::Annotation object
310        
311       =item Returns :
312        
313       L<Sanger::CGP::Vagrent::Data::Annotation|Sanger::CGP::Vagrent::Data::Annotation> object initialized with parameter values
314        
315       =item Params :
316        
317       acc => Accession for the sequence record being annotated against
318       accversion => version of the sequence record
319       db => source DB the sequence record came from
320       dbversion => version of the source DB
321       seqlength => length of sequence in the sequence record
322       context => sequence context of the annotation (defined by context constants)
323       type => variation type the annotation describes (defined by type constants)
324       subtype => variation type the annotation describes (defined by subtype constants)
325       minpos => minimum coordinate in the sequence
326       maxpos => maximum coordinate in the sequence
327       minOffset => offset distance away from the minpos (typically used for splice site mutations)
328       maxOffset => offset distance away from the maxpos (typically used for splice site mutations)
329       wt => wild type sequence of variant
330       mt => mutant sequence of variant
331       description => HGVS style description string
332        
333       =back
334        
335       =head2 Attributes
336        
337       =head3 getMinPos
338        
339       =over
340        
341       =item Usage :
342        
343       my $min = $a->getMinPos;
344        
345       =item Function :
346        
347       Returns the lowest coordinate of the annotation on the sequence
348        
349       =item Returns :
350        
351       Integer
352        
353       =back
354        
355       =head3 getMinOffset
356        
357       =over
358        
359       =item Usage :
360        
361       my $minOff = $a->getMinOffset;
362        
363       =item Function :
364        
365       Returns the offset value from the minimim coordinate
366        
367       =item Returns :
368        
369       Signed integer
370        
371       =back
372        
373       =head3 getMaxPos
374        
375       =over
376        
377       =item Usage :
378        
379       my $min = $a->getMaxPos;
380        
381       =item Function :
382        
383       Returns the highest coordinate of the annotation on the sequence
384        
385       =item Returns :
386        
387       Integer
388        
389       =back
390        
391       =head3 getMaxOffset
392        
393       =over
394        
395       =item Usage :
396        
397       my $maxOff = $a->getMaxOffset;
398        
399       =item Function :
400        
401       Returns the offset value from the maximum coordinate
402        
403       =item Returns :
404        
405       Signed integer
406        
407       =back
408        
409       =head3 getWt
410        
411       =over
412        
413       =item Usage :
414        
415       my $wtSeq = $a->getWt;
416        
417       =item Function :
418        
419       Returns the wildtype sequence string
420        
421       =item Returns :
422        
423       String
424        
425       =back
426        
427       =head3 getMt
428        
429       =over
430        
431       =item Usage :
432        
433       my $mtSeq = $a->getMt;
434        
435       =item Function :
436        
437       Returns the mutant sequence string
438        
439       =item Returns :
440        
441       String
442        
443       =back
444        
445       =head3 getDescription
446        
447       =over
448        
449       =item Usage :
450        
451       my $desc = $a->getDescription;
452        
453       =item Function
454        
455       An HGVS style description string of the annotation
456        
457       =item Returns
458        
459       String
460        
461       =back
462        
463       =head3 getContext
464        
465       =over
466        
467       =item Usage :
468        
469       my $ctx = $a->getContext;
470        
471       =item Function
472        
473       The context of the annotation, as defined by a context constant value
474        
475       =item Returns
476        
477       String
478        
479       =back
480        
481       =head3 getType
482        
483       =over
484        
485       =item Usage :
486        
487       my $type = $a->getType;
488        
489       =item Function
490        
491       The type of the annotation, as defined by a type constant value
492        
493       =item Returns
494        
495       String
496        
497       =back
498        
499       =head3 getSubtype
500        
501       =over
502        
503       =item Usage :
504        
505       my $subtype = $a->getSubtype;
506        
507       =item Function
508        
509       The subtype of the annotation, as defined by a subtype constant value
510        
511       =item Returns
512        
513       String
514        
515       =back
516        
517       =head3 getAccession
518        
519       =over
520        
521       =item Usage :
522        
523       my $accession = $a->getAccession;
524        
525       =item Function
526        
527       The accession of the sequence record the annotation is built against
528        
529       =item Returns
530        
531       String
532        
533       =back
534        
535       =head3 getSequenceVersion
536        
537       =over
538        
539       =item Usage :
540        
541       my $vers = $a->getSequenceVersion;
542        
543       =item Function
544        
545       The version of the sequence record the annotation is built against
546        
547       =item Returns
548        
549       String
550        
551       =back
552        
553       =head3 getDatabase
554        
555       =over
556        
557       =item Usage :
558        
559       my $db = $a->getDatabase;
560        
561       =item Function
562        
563       The database the sequence record originated from
564        
565       =item Returns
566        
567       String
568        
569       =back
570        
571       =head3 getDatabaseVersion
572        
573       =over
574        
575       =item Usage :
576        
577       my $dbVersion = $a->getDatabaseVersion;
578        
579       =item Function
580        
581       The version of the database the sequence record originated from
582        
583       =item Returns
584        
585       String
586        
587       =back
588        
589       =head3 getSequenceLength
590        
591       =over
592        
593       =item Usage :
594        
595       my $seqLength = $a->getSequenceLength;
596        
597       =item Function
598        
599       The full length of the sequence in the sequence record
600        
601       =item Returns
602        
603       Integer
604        
605       =back
606        
607       =head3 addClassification
608        
609       =over
610        
611       =item Usage :
612        
613       $a->addClassification($class1,$class2);
614        
615       =item Function
616        
617       Appends one or more classification terms to the annotation
618        
619       =item Params
620        
621       An array of classification terms (Strings)
622        
623       =item Returns
624        
625       None
626        
627       =back
628        
629       =head3 getClassifications
630        
631       =over
632        
633       =item Usage :
634        
635       my @classes = $a->getClassifications;
636        
637       =item Function
638        
639       Returns the stored classification terms
640        
641       =item Returns
642        
643       Array of Strings, or undef if none
644        
645       =back
646        
647       =head2 Functions
648        
649       =head3 hasClassification
650        
651       =over
652        
653       =item Usage :
654        
655       if($a->hasClassification($checkClass)){
656       .....
657       }
658        
659       =item Function
660        
661       Checks an annotation to see if it already contains the specified class
662        
663       =item Returns
664        
665       Boolean, 1 or 0
666        
667       =back
668        
669       =head2 Constants
670        
671       =head3 getmRNAAnnotationContext
672        
673       =over
674        
675       =item Usage :
676        
677       my $ctx = $anno->getmRNAAnnotationContext();
678       my $ctx = Sanger::CGP::Vagrent::Data::Annotation::getmRNAAnnotationContext();
679        
680       =item Function :
681        
682       Constant lookup, returns the mRNA Annotation Context value
683        
684       =item Returns :
685        
686       String
687        
688       =back
689        
690       =head3 getCDSAnnotationContext
691        
692       =over
693        
694       =item Usage :
695        
696       my $ctx = $anno->getCDSAnnotationContext();
697       my $ctx = Sanger::CGP::Vagrent::Data::Annotation::getCDSAnnotationContext();
698        
699       =item Function :
700        
701       Constant lookup, returns the CDS Annotation Context value
702        
703       =item Returns :
704        
705       String
706        
707       =back
708        
709       =head3 getProteinAnnotationContext
710        
711       =over
712        
713       =item Usage :
714        
715       my $ctx = $anno->getProteinAnnotationContext();
716       my $ctx = Sanger::CGP::Vagrent::Data::Annotation::getProteinAnnotationContext();
717        
718       =item Function :
719        
720       Constant lookup, returns the Protein Annotation Context value
721        
722       =item Returns :
723        
724       String
725        
726       =back
727        
728       =head3 getSubstitutionAnnotationType
729        
730       =over
731        
732       =item Usage :
733        
734       my $type = $anno->getSubstitutionAnnotationType();
735       my $type = Sanger::CGP::Vagrent::Data::Annotation::getSubstitutionAnnotationType();
736        
737       =item Function :
738        
739       Constant lookup, returns the Substitution Annotation Type value
740        
741       =item Returns :
742        
743       String
744        
745       =back
746        
747       =head3 getDeletionAnnotationType
748        
749       =over
750        
751       =item Usage :
752        
753       my $type = $anno->getDeletionAnnotationType();
754       my $type = Sanger::CGP::Vagrent::Data::Annotation::getDeletionAnnotationType();
755        
756       =item Function :
757        
758       Constant lookup, returns the Deletion Annotation Type value
759        
760       =item Returns :
761        
762       String
763        
764       =back
765        
766       =head3 getInsertionAnnotationType
767        
768       =over
769        
770       =item Usage :
771        
772       my $type = $anno->getInsertionAnnotationType();
773       my $type = Sanger::CGP::Vagrent::Data::Annotation::getInsertionAnnotationType();
774        
775       =item Function :
776        
777       Constant lookup, returns the Insertion Annotation Type value
778        
779       =item Returns :
780        
781       String
782        
783       =back
784        
785       =head3 getComplexAnnotationType
786        
787       =over
788        
789       =item Usage :
790        
791       my $type = $anno->getComplexAnnotationType();
792       my $type = Sanger::CGP::Vagrent::Data::Annotation::getComplexAnnotationType();
793        
794       =item Function :
795        
796       Constant lookup, returns the Complex Annotation Type value
797        
798       =item Returns :
799        
800       String
801        
802       =back
803        
804       =head3 getFrameShiftAnnotationType
805        
806       =over
807        
808       =item Usage :
809        
810       my $type = $anno->getFrameShiftAnnotationType();
811       my $type = Sanger::CGP::Vagrent::Data::Annotation::getFrameShiftAnnotationType();
812        
813       =item Function :
814        
815       Constant lookup, returns the Frameshift Annotation Type value
816        
817       =item Returns :
818        
819       String
820        
821       =back
822        
823       =head3 getUnknownAnnotationType
824        
825       =over
826        
827       =item Usage :
828        
829       my $type = $anno->getUnknownAnnotationType();
830       my $type = Sanger::CGP::Vagrent::Data::Annotation::getUnknownAnnotationType();
831        
832       =item Function :
833        
834       Constant lookup, returns the Unknown Annotation Type value
835        
836       =item Returns :
837        
838       String
839        
840       =back
841        
842       =head3 getPositionKnownSubtype
843        
844       =over
845        
846       =item Usage :
847        
848       my $subtype = $anno->getPositionKnownSubtype();
849       my $subtype = Sanger::CGP::Vagrent::Data::Annotation::getPositionKnownSubtype();
850        
851       =item Function :
852        
853       Constant lookup, returns the Position Known Subtype value
854        
855       =item Returns :
856        
857       String
858        
859       =back
860        
861       =head3 getPositionOffsetSubtype
862        
863       =over
864        
865       =item Usage :
866        
867       my $subtype = $anno->getPositionOffsetSubtype();
868       my $subtype = Sanger::CGP::Vagrent::Data::Annotation::getPositionOffsetSubtype();
869        
870       =item Function :
871        
872       Constant lookup, returns the Position Offset Subtype value
873        
874       =item Returns :
875        
876       String
877        
878       =back
879        
880       =head3 getPositionOffSequenceSubtype
881        
882       =over
883        
884       =item Usage :
885        
886       my $subtype = $anno->getPositionOffSequenceSubtype();
887       my $subtype = Sanger::CGP::Vagrent::Data::Annotation::getPositionOffSequenceSubtype();
888        
889       =item Function :
890        
891       Constant lookup, returns the Position Off-Sequence Subtype value
892        
893       =item Returns :
894        
895       String
896        
897       =back
898        
899