File Coverage

lib/Sanger/CGP/Vagrent/Data/Transcript.pm
Criterion Covered Total %
branch 4 44 9.0
subroutine 31 40 77.5
pod 27 30 90.0
total 62 114 54.3


line bran sub pod code
1       package Sanger::CGP::Vagrent::Data::Transcript;
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 Data::Dumper;
28   4   use Sanger::CGP::Vagrent qw($VERSION);
29   4   use Sort::Key qw(nkeysort);
30   4   use Const::Fast qw(const);
31        
32   4   use base qw(Sanger::CGP::Vagrent);
33        
34       const my $PROTEIN_CODING_TYPE => 'ProteinCoding';
35       const my $MIRCO_RNA_TYPE => 'miRNA';
36       const my $LINC_RNA_TYPE => 'lincRNA';
37       const my $SNO_RNA_TYPE => 'snoRNA';
38       const my $SN_RNA_TYPE => 'snRNA';
39       const my $R_RNA_TYPE => 'rRNA';
40        
41       const my @ALL_GENE_TYPES => ($PROTEIN_CODING_TYPE,$MIRCO_RNA_TYPE,$LINC_RNA_TYPE,$SNO_RNA_TYPE,$SN_RNA_TYPE,$R_RNA_TYPE);
42        
43       1;
44        
45       sub new {
46   0 1 my $proto = shift;
47       my $class = ref($proto) || $proto;
48       my $self = {};
49       bless($self, $class);
50       $self->_init(@_);
51       return $self;
52       }
53        
54       sub _init {
55   0   my $self = shift;
56       my %vars = @_;
57       foreach my $k(keys(%vars)){
58 0     if($k eq 'db'){
  0      
  0      
  0      
  0      
  0      
  0      
  0      
  0      
  0      
  0      
  0      
  0      
  0      
  0      
  0      
  0      
59       $self->{_db} = $vars{db};
60       } elsif($k eq 'dbversion'){
61       $self->{_dbversion} = $vars{dbversion};
62       } elsif($k eq 'exons' && ref($vars{exons}) eq 'ARRAY'){
63       $self->{_exons} = $vars{exons};
64       } elsif($k eq 'strand'){
65       $self->{_strand} = $vars{strand};
66       } elsif($k eq 'genomicminpos'){
67       $self->{_genomicminpos} = $vars{genomicminpos};
68       } elsif($k eq 'genomicmaxpos'){
69       $self->{_genomicmaxpos} = $vars{genomicmaxpos};
70       } elsif($k eq 'cdnaseq'){
71       $self->{_cdnaseq} = $vars{cdnaseq};
72       } elsif($k eq 'cdsphase'){
73       $self->{_cdsphase} = $vars{cdsphase};
74       } elsif($k eq 'cdsminpos'){
75       $self->{_cdsminpos} = $vars{cdsminpos};
76       } elsif($k eq 'cdsmaxpos'){
77       $self->{_cdsmaxpos} = $vars{cdsmaxpos};
78       } elsif($k eq 'acc'){
79       $self->{_acc} = $vars{acc};
80       } elsif($k eq 'accversion'){
81       $self->{_accversion} = $vars{accversion};
82       } elsif($k eq 'proteinacc'){
83       $self->{_proteinacc} = $vars{proteinacc};
84       } elsif($k eq 'proteinaccversion'){
85       $self->{_proteinaccversion} = $vars{proteinaccversion};
86       } elsif($k eq 'ccds'){
87       $self->{_ccds} = $vars{ccds};
88       } elsif($k eq 'genename'){
89       $self->{_genename} = $vars{genename};
90       } elsif($k eq 'genetype'){
91       $self->{_genetype} = $vars{genetype};
92       my $good = undef;
93       foreach my $type(@ALL_GENE_TYPES){
94 0     if($vars{genetype} eq $type){
95       $good = $vars{genetype};
96       last;
97       }
98       }
99 0     if(defined($good)){
100       $self->{_genetype} = $good;
101       } else {
102       croak('recieved unknown gene type: '.$vars{genetype});
103       }
104       }
105       }
106       }
107        
108       sub getAllGeneTypes {
109   818 0 return @ALL_GENE_TYPES;
110       }
111        
112       sub getGeneType {
113   5808 1 return shift->{_genetype};
114       }
115        
116       sub getCCDS {
117   1636 1 return shift->{_ccds};
118       }
119        
120       sub getGeneName {
121   1636 1 return shift->{_genename};
122       }
123        
124       sub getAccession {
125   5858 1 return shift->{_acc};
126       }
127        
128       sub getAccessionVersion {
129   2518 1 return shift->{_accversion};
130       }
131        
132       sub getProteinAccession {
133   882 1 return shift->{_proteinacc};
134       }
135        
136       sub getProteinAccessionVersion {
137   882 1 return shift->{_proteinaccversion};
138       }
139        
140       sub getDatabase {
141   3400 1 return shift->{_db};
142       }
143        
144       sub getDatabaseVersion {
145   3400 1 return shift->{_dbversion};
146       }
147        
148       sub getExons {
149   1745 1 my $self = shift;
150   33955   return nkeysort {$_->getRnaMinPos} @{$self->{_exons}};
151       }
152        
153       sub getExonsGenomicOrder {
154   519 0 my $self = shift;
155   10490   return nkeysort {$_->getMinPos} @{$self->{_exons}};
156       }
157        
158       sub getStrand {
159   19488 1 return shift->{_strand};
160       }
161        
162       sub getcDNASeq {
163   1052 1 return shift->{_cdnaseq};
164       }
165        
166       sub getCdsSeq {
167   1344 1 my $self = shift;
168       return substr($self->{_cdnaseq},($self->{_cdsminpos} - 1),(($self->{_cdsmaxpos} - $self->{_cdsminpos}) + 1));
169       }
170        
171       sub getCdsPhase {
172   441 1 return shift->{_cdsphase};
173       }
174        
175       sub getCdsMinPos {
176   3670 1 return shift->{_cdsminpos};
177       }
178        
179       sub getCdsMaxPos {
180   3486 1 return shift->{_cdsmaxpos};
181       }
182        
183       sub getCdsLength {
184   745 1 my $self = shift;
185 100     unless(defined($self->{_cdslength})){
186       $self->{_cdslength} = ($self->getCdsMaxPos - $self->getCdsMinPos) + 1;
187       }
188       return $self->{_cdslength};
189       }
190        
191       sub getmRNALength {
192   0 0 my $self = shift;
193 0     unless(defined $self->{_mrnalength}){
194       my $size = 0;
195       foreach my $e (@{$self->{_exons}}){
196       $size += $e->getLength();
197       }
198       $self->{_mrnalength} = $size;
199       }
200       return $self->{_mrnalength};
201       }
202        
203        
204       sub getGenomicMinPos {
205   0 1 return shift->{_genomicminpos};
206       }
207        
208       sub getGenomicMaxPos {
209   0 1 return shift->{_genomicmaxpos};
210       }
211        
212       sub isProteinCoding {
213 100 4172 1 if(shift->getGeneType eq $PROTEIN_CODING_TYPE){
214       return 1;
215       } else {
216       return 0;
217       }
218       }
219        
220       sub getProteinCodingType {
221   707 1 return $PROTEIN_CODING_TYPE;
222       }
223        
224       sub getMicroRnaType {
225   0 1 return $MIRCO_RNA_TYPE;
226       }
227        
228       sub getLincRnaType {
229   111 1 return $LINC_RNA_TYPE;
230       }
231        
232       sub getSnoRnaType {
233   0 1 return $SNO_RNA_TYPE;
234       }
235        
236       sub getSnRnaType {
237   0 1 return $SN_RNA_TYPE;
238       }
239        
240       sub getRRnaType {
241   0 1 return $R_RNA_TYPE;
242       }
243        
244       __END__
245        
246       =head1 NAME
247        
248       Sanger::CGP::Vagrent::Data::Transcript - Data object representing a transcript
249        
250       =head1 DESCRIPTION
251        
252       This is a data class to hold details about a transcript. This allows the transcript information
253       to be abstracted away from its original source.
254        
255       =head1 METHODS
256        
257       =head2 Constructor
258        
259       =head3 new
260        
261       =over
262        
263       =item Usage :
264        
265       my $trans = Sanger::CGP::Vagrent::Data::Transcript->new(%params);
266        
267       =item Function :
268        
269       Builds a new Sanger::CGP::Vagrent::Data::Transcript object
270        
271       =item Returns :
272        
273       Sanger::CGP::Vagrent::Data::Transcript object initialized with parameter values
274        
275       =item Params :
276        
277       db => source DB the transcript came from
278       dbversion => version of the source DB
279       exons => array ref of Sanger::CGP::Vagrent::Data::Exon objects
280       strand => Genomic strand of the transcript (1 or -1)
281       cdnaseq => cDNA sequence string
282       cdsminpos => CDS minimum coordinate in the cDNA sequence
283       cdsmaxpos => CDS maximum coordinate in the cDNA sequence
284       cdsphase => The phase of translation on the CDS (ie the number of N's to add to the begining of the CDS to make it translate)
285       acc => Transcript accession number (typically the cDNA accession)
286       accversion => Version of the transcript accession number
287       proteinacc => Protein accession number (optional)
288       proteinaccversion => Version of the protein accession number (optional)
289       ccds => CCDS id for the transcript (optional)
290       genename => Gene name
291       genetype => Gene type (defined by type constant)
292        
293        
294       =back
295        
296       =head2 Attributes
297        
298       =head3 getGeneName
299        
300       =over
301        
302       =item Usage :
303        
304       my $name = $trans->getGeneName;
305        
306       =item Function
307        
308       The gene name for the transcript
309        
310       =item Returns
311        
312       String
313        
314       =back
315        
316       =head3 getGeneType
317        
318       =over
319        
320       =item Usage :
321        
322       my $type = $trans->getGeneType;
323        
324       =item Function
325        
326       Returns the gene type, will be equal to one of the type constant values
327        
328       =item Returns
329        
330       String
331        
332       =back
333        
334       =head3 getCCDS
335        
336       =over
337        
338       =item Usage :
339        
340       my $ccds = $trans->getCCDS;
341        
342       =item Function
343        
344       The CCDS identifier for the transcript
345        
346       =item Returns
347        
348       String
349        
350       =back
351        
352       =head3 getAccession
353        
354       =over
355        
356       =item Usage :
357        
358       my $accession = $trans->getAccession;
359        
360       =item Function
361        
362       The accession of the sequence record for the transcript
363        
364       =item Returns
365        
366       String
367        
368       =back
369        
370       =head3 getAccessionVersion
371        
372       =over
373        
374       =item Usage :
375        
376       my $accessionVers = $trans->getAccessionVersion;
377        
378       =item Function
379        
380       The accession verson of the sequence record for the transcript
381        
382       =item Returns
383        
384       String
385        
386       =back
387        
388       =head3 getProteinAccession
389        
390       =over
391        
392       =item Usage :
393        
394       my $protAccession = $trans->getProteinAccession;
395        
396       =item Function
397        
398       The protein accession of the sequence record for the transcript
399        
400       =item Returns
401        
402       String
403        
404       =back
405        
406       =head3 getProteinAccessionVersion
407        
408       =over
409        
410       =item Usage :
411        
412       my $protAccessionVers = $trans->getProteinAccessionVersion;
413        
414       =item Function
415        
416       The protein accession verson of the sequence record for the transcript
417        
418       =item Returns
419        
420       String
421        
422       =back
423        
424       =head3 getDatabase
425        
426       =over
427        
428       =item Usage :
429        
430       my $sourceDB = $trans->getDatabase;
431        
432       =item Function
433        
434       The name of database the transcript originated from
435        
436       =item Returns
437        
438       String
439        
440       =back
441        
442       =head3 getDatabaseVersion
443        
444       =over
445        
446       =item Usage :
447        
448       my $sourceDBversion = $trans->getDatabaseVersion;
449        
450       =item Function
451        
452       The version of database the transcript originated from
453        
454       =item Returns
455        
456       String
457        
458       =back
459        
460       =head3 getGenomicMinPos
461        
462       =over
463        
464       =item Usage :
465        
466       my $genomicMin = $trans->getGenomicMinPos;
467        
468       =item Function
469        
470       The minimum position of the cDNA in the genome
471        
472       =item Returns
473        
474       Integer
475        
476       =back
477        
478       =head3 getGenomicMaxPos
479        
480       =over
481        
482       =item Usage :
483        
484       my $genomicMax = $trans->getGenomicMaxPos;
485        
486       =item Function
487        
488       The maximum position of the cDNA in the genome
489        
490       =item Returns
491        
492       Integer
493        
494       =back
495        
496       =head3 getStrand
497        
498       =over
499        
500       =item Usage :
501        
502       my $strand = $trans->getStrand;
503        
504       =item Function
505        
506       The genomic strand of the transcript
507        
508       =item Returns
509        
510       Integer (either 1 or -1)
511        
512       =back
513        
514       =head3 getCdsMinPos
515        
516       =over
517        
518       =item Usage :
519        
520       my $cdsMin = $trans->getCdsMinPos;
521        
522       =item Function
523        
524       The minimum position of the CDS within the cDNA sequence
525        
526       =item Returns
527        
528       Integer
529        
530       =back
531        
532       =head3 getCdsMaxPos
533        
534       =over
535        
536       =item Usage :
537        
538       my $cdsMax = $trans->getCdsMaxPos;
539        
540       =item Function
541        
542       The maximum position of the CDS within the cDNA sequence
543        
544       =item Returns
545        
546       Integer
547        
548       =back
549        
550       =head3 getcDNASeq
551        
552       =over
553        
554       =item Usage :
555        
556       my $cDNAseq = $trans->getcDNASeq;
557        
558       =item Function
559        
560       The cDNA sequence string
561        
562       =item Returns
563        
564       String - DNA sequence
565        
566       =back
567        
568       =head3 getCdsPhase
569        
570       =over
571        
572       =item Usage :
573        
574       my $phase = $trans->getCdsPhase;
575        
576       =item Function
577        
578       The CDS phase, ie the number of N's needed to append to the start of CDS sequence to create the right translation frame
579        
580       =item Returns
581        
582       Integer
583        
584       =back
585        
586       =head3 getExons
587        
588       =over
589        
590       =item Usage :
591        
592       my @exons = $trans->getExons;
593        
594       =item Function
595        
596       Returns the Sanger::CGP::Vagrent::Data::Exon objects that make up the transcript sorted into transcript order
597        
598       =item Returns
599        
600       Array of Sanger::CGP::Vagrent::Data::Exon objects
601        
602       =back
603        
604       =head2 Functions
605        
606       =head3 isProteinCoding
607        
608       =over
609        
610       =item Usage :
611        
612       my $isCoding = $trans->isProteinCoding;
613        
614       if($trans->isProteinCoding){
615       ......
616       }
617        
618       =item Function
619        
620       Convenience function. Returns true if the gene type is protein coding, equivalent to
621        
622       if($trans->getType eq $trans->getProteinCodingType){
623       ......
624       }
625        
626        
627       =item Returns
628        
629       Integer boolean (either 1 or 0)
630        
631       =back
632        
633       =head3 getCdsSeq
634        
635       =over
636        
637       =item Usage :
638        
639       my $CDSseq = $trans->getCdsSeq;
640        
641       =item Function
642        
643       CDS sequence string, ie the subsequence of the cDNA string defined by the CDS min and max coordinates
644        
645       =item Returns
646        
647       String - DNA sequence
648        
649       =back
650        
651       =head3 getCdsLength
652        
653       =over
654        
655       =item Usage :
656        
657       my $length = $trans->getCdsLength;
658        
659       =item Function
660        
661       The length of the CDS, based on the CDS min and max coordinates on the cDNA
662        
663       =item Returns
664        
665       Integer
666        
667       =back
668        
669       =head2 Constants
670        
671       =head3 getProteinCodingType
672        
673       =over
674        
675       =item Usage :
676        
677       my $type = $trans->getProteinCodingType();
678       my $type = Sanger::CGP::Vagrent::Data::Transcript::getProteinCodingType();
679        
680       =item Function :
681        
682       Constant lookup, returns the protein coding gene type
683        
684       =item Returns :
685        
686       String
687        
688       =back
689        
690       =head3 getMicroRnaType
691        
692       =over
693        
694       =item Usage :
695        
696       my $type = $trans->getMicroRnaType();
697       my $type = Sanger::CGP::Vagrent::Data::Transcript::getMicroRnaType();
698        
699       =item Function :
700        
701       Constant lookup, returns the microRNA gene type
702        
703       =item Returns :
704        
705       String
706        
707       =back
708        
709       =head3 getLincRnaType
710        
711       =over
712        
713       =item Usage :
714        
715       my $type = $trans->getLincRnaType();
716       my $type = Sanger::CGP::Vagrent::Data::Transcript::getLincRnaType();
717        
718       =item Function :
719        
720       Constant lookup, returns the lincRNA gene type
721        
722       =item Returns :
723        
724       String
725        
726       =back
727        
728       =head3 getSnoRnaType
729        
730       =over
731        
732       =item Usage :
733        
734       my $type = $trans->getSnoRnaType();
735       my $type = Sanger::CGP::Vagrent::Data::Transcript::getSnoRnaType();
736        
737       =item Function :
738        
739       Constant lookup, returns the snoRNA gene type
740        
741       =item Returns :
742        
743       String
744        
745       =back
746        
747       =head3 getSnRnaType
748        
749       =over
750        
751       =item Usage :
752        
753       my $type = $trans->getSnRnaType();
754       my $type = Sanger::CGP::Vagrent::Data::Transcript::getSnRnaType();
755        
756       =item Function :
757        
758       Constant lookup, returns the snRNA gene type
759        
760       =item Returns :
761        
762       String
763        
764       =back
765        
766       =head3 getRRnaType
767        
768       =over
769        
770       =item Usage :
771        
772       my $type = $trans->getRRnaType();
773       my $type = Sanger::CGP::Vagrent::Data::Transcript::getRRnaType();
774        
775       =item Function :
776        
777       Constant lookup, returns the rRNA gene type
778        
779       =item Returns :
780        
781       String
782        
783       =back