EnsEMBL/PredictionTranscript.pm untested

filter: Statementstmt 0.0% 0 / 134 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 18 Subroutinesub 0.0% 0 / 31 Podpod 0.0% 0 / 23 totaltotal 0.0% 0 / 240 CC 18 SCAR 26.4
CC
18
Cov
0%
translate
56.0
translation
20.0
transform
20.0
CRAP 14.0
1 =head1 LICENSE
2  
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5  
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9  
10 http://www.apache.org/licenses/LICENSE-2.0
11  
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17  
18 =cut
19  
20  
21 =head1 CONTACT
22  
23 Please email comments or questions to the public Ensembl
24 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25  
26 Questions may also be sent to the Ensembl help desk at
27 <http://www.ensembl.org/Help/Contact>.
28  
29 =cut
30  
31 =head1 NAME
32  
33 PredictionTranscript
34  
35 =head1 SYNOPSIS
36  
37 =head1 DESCRIPTION
38  
39 Container for single transcript ab initio gene prediction such as
40 GenScan or SNAP. Is directly storable/retrievable in Ensembl using
41 PredictionTranscriptAdaptor.
42  
43 Creation:
44  
45 my $tran = new Bio::EnsEMBL::PredictionTranscript();
46 $tran->add_Exon($pred_exon);
47  
48 my $tran =
49 new Bio::EnsEMBL::PredictionTranscript( -EXONS => @pred_exons );
50  
51 Manipulation:
52  
53 # Returns an array of PredictionExon objects
54 my @pred_exons = @{ $tran->get_all_Exons };
55  
56 # Returns the peptide translation as string
57 my $pep = $tran->translate()->seq();
58  
59 # Get the exon cdna sequence.
60 my $cdna = $trans->spliced_seq();
61  
62 =head1 METHODS
63  
64 =cut
65  
66 package Bio::EnsEMBL::PredictionTranscript;
67 $Bio::EnsEMBL::PredictionTranscript::VERSION = '114.0.0_50'; # TRIAL
68 $Bio::EnsEMBL::PredictionTranscript::VERSION = '114.0.050';
69 use vars qw(@ISA);
70 use strict;
71  
72 use Bio::Seq;
73 use Bio::EnsEMBL::Feature;
74 use Bio::EnsEMBL::Transcript;
75 use Bio::EnsEMBL::Translation;
76  
77 use Bio::EnsEMBL::Utils::Exception qw( throw warning );
78 use Bio::EnsEMBL::Utils::Argument qw( rearrange );
79  
80 @ISA = qw(Bio::EnsEMBL::Transcript);
81  
82  
83 =head2 new
84  
85 Arg [-DISPLAY_LABEL]
86 string - a displayable identifier for this prediction
87 Arg [...] : See Bio::EnsEMBL::Transcript superclass constructor
88 Example : $pt = Bio::EnsEMBL::PredictionTranscript->new
89 ( '-start' => $seq_region_start,
90 '-end' => $seq_region_end,
91 '-strand' => $seq_region_strand,
92 '-adaptor' => $self,
93 '-slice' => $slice,
94 '-analysis' => $analysis,
95 '-dbID' => $prediction_transcript_id,
96 '-display_label' => $display_label);
97 Description: Constructor. Creates a new Bio::EnsEMBL::PredictionTranscript
98 object
99 Returntype : Bio::EnsEMBL::PredictionTranscript
100 Exceptions : none
101 Caller : general
102 Status : Stable
103  
104 =cut
105  
106 sub new {
107 my $class = shift;
108  
109 my $self = $class->SUPER::new(@_);
110  
111 my ($display_label) = rearrange(['DISPLAY_LABEL'], @_);
112  
113 $self->{'display_label'} = $display_label;
114  
115 return $self;
116 }
117  
118  
119 =head2 coding_region_start
120  
121 Arg [1] : none
122 Example : $coding_region_start = $pt->coding_region_start
123 Description: Retrieves the start of the coding region of this transcript in
124 slice coordinates. For prediction transcripts this
125 is always the start of the transcript (i.e. there is no UTR).
126 By convention, the coding_region_start is always lower than
127 the value returned by the coding_end method.
128 The value returned by this function is NOT the biological
129 coding start since on the reverse strand the biological coding
130 start would be the higher genomic value.
131 Returntype : int
132 Exceptions : none
133 Caller : general
134 Status : Stable
135  
136 =cut
137  
138 sub coding_region_start {
139 my $self = shift;
140 return $self->start();
141 }
142  
143  
144 =head2 coding_region_end
145  
146 Arg [1] : none
147 Example : $coding_region_end = $transcript->coding_region_end
148 Description: Retrieves the start of the coding region of this prediction
149 transcript. For prediction transcripts this is always the same
150 as the end since no UTRs are stored.
151 By convention, the coding_region_end is always higher than the
152 value returned by the coding_region_start method.
153 The value returned by this function is NOT the biological
154 coding start since on the reverse strand the biological coding
155 end would be the lower genomic value.
156 Returntype : int
157 Exceptions : none
158 Caller : general
159 Status : Stable
160  
161 =cut
162  
163 sub coding_region_end {
164 my $self = shift;
165 return $self->end();
166 }
167  
168  
169  
170 =head2 get_all_translateable_Exons
171  
172 Arg [1] : none
173 Example : $exons = $self->get_all_translateable_Exons
174 Description: Retrieves the translateable portion of all exons in this
175 transcript. For prediction transcripts this means all exons
176 since no UTRs are stored for them.
177 Returntype : listref of Bio::EnsEMBL::PredictionExons
178 Exceptions : none
179 Caller : general
180 Status : Stable
181  
182 =cut
183  
184 sub get_all_translateable_Exons {
185 my $self = shift;
186 return $self->get_all_Exons();
187 }
188  
189  
190 =head2 display_label
191  
192 Arg [1] : string $newval (optional)
193 The new value to set the display_label attribute to
194 Example : $display_label = $pt->display_label()
195 Description: Getter/Setter for a displayable identifier for this
196 prediction transcript.
197 Returntype : string
198 Exceptions : none
199 Caller : general
200 Status : Stable
201  
202 =cut
203  
204 sub display_label{
205 my $self = shift;
206 return $self->{'display_label'} = shift if(@_);
207 return $self->{'display_label'};
208 }
209  
210  
211 =head2 summary_as_hash
212  
213 Example : my $hash = $misc_feature->summary_as_hash();
214 Description: Retrieves a textual summary of this prediction.
215 Not inherited from Features.
216 Returntype : Hashref of arrays of descriptive strings
217 Exceptions : none
218 Caller : general
219 Status : Stable
220  
221 =cut
222  
223 sub summary_as_hash {
224 my $self = shift;
225 my %summary;
226 $summary{'id'} = $self->dbID;
227 $summary{'Name'} = $self->display_id;
228 $summary{'version'} = $self->version() if $self->version();
229 $summary{'start'} = $self->seq_region_start;
230 $summary{'end'} = $self->seq_region_end;
231 $summary{'strand'} = $self->strand;
232 $summary{'seq_region_name'} = $self->seq_region_name;
233 $summary{'source'} = $self->analysis->gff_source() || 'ensembl';
234 return \%summary;
235 }
236  
237  
238  
239 =head2 stable_id
240  
241 Arg [1] : none
242 Example : print $pt->stable_id();
243 Description: Gets a 'stable' identifier for this prediction transcript. Note
244 that prediction transcripts do not have true *stable*
245 identifiers (i.e. identifiers maintained between releases).
246 This method chains to the display_label method and is intended
247 to provide polymorphism with the Transcript class.
248 Returntype : string
249 Exceptions : none
250 Caller : general
251 Status : Stable
252  
253 =cut
254  
255 sub stable_id { return display_label(@_); }
256  
257 sub get_all_DBEntries { return []; }
258  
259 sub get_all_DBLinks { return []; }
260  
261 sub add_DBEntry {}
262  
263 sub external_db { return undef; }
264  
265 sub external_status { return undef; }
266  
267 sub external_name { return undef; }
268  
269 sub is_known { return 0;}
270  
271  
272 =head2 translation
273  
274 Arg [1] : none
275 Example : $translation = $pt->translation();
276 Description: Retrieves a Bio::EnsEMBL::Translation object for this prediction
277 transcript. Note that this translation is generated on the fly
278 and is not stored in the database. The translation always
279 spans the entire transcript (no UTRs; all CDS) and does not
280 have an associated dbID, stable_id or adaptor.
281 Returntype : int
282 Exceptions : none
283 Caller : general
284 Status : Stable
285  
286 =cut
287  
288 sub translation {
289 my $self = shift;
290  
291 #calculate translation on the fly
292 my $strand = $self->strand();
293  
294 my $start_exon;
295 my $end_exon;
296  
297 my @exons = @{$self->get_all_Exons()};
298  
299 return undef if(!@exons);
300  
301 $start_exon = $exons[0];
302 $end_exon = $exons[-1];
303  
304 my $pta;
305  
306 if($self->adaptor()) {
307 $pta = $self->adaptor()->db()->get_TranslationAdaptor();
308 } else {
309 #warning("PredictionTranscript has no adaptor, may not be able to obtain " .
310 # "translation");
311 }
312  
313 my $Xseq = $self->spliced_seq();
314 my $start_phase = $start_exon->phase;
315 if( $start_phase > 0 ) {
316 $Xseq = "N"x$start_phase . $Xseq;
317 }
318  
319 my $tmpSeq = new Bio::Seq( -id => $self->display_id,
320 -seq => $Xseq,
321 -moltype => 'dna',
322 -alphabet => 'dna' );
323  
324 return Bio::EnsEMBL::Translation->new
325 (-ADAPTOR => $pta,
326 -START_EXON => $start_exon,
327 -END_EXON => $end_exon,
328 -SEQ_START => 1,
329 -SEQ_END => $end_exon->length(),
330 -SEQ => $tmpSeq->translate()->seq());
331 }
332  
333  
334  
335 =head2 translate
336  
337 Arg [1] : Boolean, emulate the behavior of old bioperl versions where
338 an incomplete final codon of 2 characters is padded and guessed
339 Function : Give a peptide translation of all exons currently in
340 the PT. Gives empty string when none is in.
341 Returntype: a Bio::Seq as in transcript->translate()
342 Exceptions: none
343 Caller : general
344 Status : Stable
345  
346 =cut
347  
348  
349 sub translate {
350 my ($self, $complete_codon) = @_;
351  
352 my $dna = $self->translateable_seq();
353  
354 my $codon_table_id;
355 if ( defined( $self->slice() ) ) {
356 my $attrib;
357
358 ($attrib) = @{ $self->slice()->get_all_Attributes('codon_table') };
359 if ( defined($attrib) ) {
360 $codon_table_id = $attrib->value();
361 }
362 }
363 $codon_table_id ||= 1; #default will be vertebrates
364  
365 # Remove the final stop codon from the mrna
366 # sequence produced if it is present, this is so any peptide produced
367 # won't have a terminal stop codon
368 # if you want to have a terminal stop codon either comment this line out
369 # or call translatable seq directly and produce a translation from it
370 if( CORE::length( $dna ) % 3 == 0 ) {
371 # $dna =~ s/TAG$|TGA$|TAA$//i;
372 my $codon_table = Bio::Tools::CodonTable->new( -id => $codon_table_id );
373
374 if ( $codon_table->is_ter_codon( substr( $dna, -3, 3 ) ) ) {
375 substr( $dna, -3, 3, '' );
376 }
377 } elsif ( CORE::length($dna) % 3 == 2 ) {
378 # If we have a partial codon of 2 bp we need to decide if we
379 # trim it or not to fix some bad behaviour in older bioperl
380 # versions
381 if ( $complete_codon ) {
382 # If we want to do the bad behavior of bioperl 1.6.1 and older
383 # where we guess the last codon if inomplete, pad an N
384 # to the mrna sequence
385 $dna .= 'N';
386 } else {
387 # Otherwise trim those last two bp off so the behavior is
388 # consistent across bioperl versions
389 substr( $dna, -2, 2, '' );
390 }
391 }
392  
393 my $bioseq = new Bio::Seq( -id => $self->display_id,
394 -seq => $dna,
395 -moltype => 'dna',
396 -alphabet => 'dna' );
397  
398 my $translation = $bioseq->translate(undef,undef,undef,$codon_table_id);
399  
400 return $translation;
401 }
402  
403  
404 =head2 cdna_coding_start
405  
406 Arg [1] : none
407 Example : $relative_coding_start = $transcript->cdna_coding_start();
408 Description: Retrieves the position of the coding start of this transcript
409 in cdna coordinates (relative to the start of the 5prime end of
410 the transcript, excluding introns, including utrs). This is
411 always 1 for prediction transcripts because they have no UTRs.
412 Returntype : int
413 Exceptions : none
414 Caller : five_prime_utr, get_all_snps, general
415 Status : Stable
416  
417 =cut
418  
419 sub cdna_coding_start { return 1 }
420  
421  
422  
423 =head2 cdna_coding_end
424  
425 Arg [1] : none
426 Example : $relative_coding_start = $transcript->cdna_coding_end();
427 Description: Retrieves the position of the coding end of this transcript
428 in cdna coordinates (relative to the start of the 5prime end of
429 the transcript, excluding introns, including utrs). This is
430 always te length of the cdna for prediction transcripts because
431 they have no UTRs.
432 Returntype : int
433 Exceptions : none
434 Caller : five_prime_utr, get_all_snps, general
435 Status : Stable
436  
437 =cut
438  
439 sub cdna_coding_end {
440 my ($self) = @_;
441 return length( $self->spliced_seq() );
442 }
443  
444  
445 =head2 transform
446  
447 Arg 1 : String $coordinate_system_name
448 Arg [2] : String $coordinate_system_version
449 Example : $ptrans = $ptrans->transform('chromosome', 'NCBI33');
450 $ptrans = $ptrans->transform('clone');
451 Description: Moves this PredictionTranscript to the given coordinate system.
452 If this Transcript has Exons attached, they move as well.
453 A new Transcript is returned or undefined if this PT is not
454 defined in the new coordinate system.
455 Returntype : Bio::EnsEMBL::PredictionTranscript
456 Exceptions : wrong parameters
457 Caller : general
458 Status : Stable
459  
460 =cut
461  
462 sub transform {
463 my $self = shift;
464  
465 # catch for old style transform calls
466 if( ref $_[0] && ($_[0]->isa( "Bio::EnsEMBL::Slice" ) or $_[0]->isa( "Bio::EnsEMBL::LRGSlice" ))) {
467 throw("transform needs coordinate systems details now," .
468 "please use transfer");
469 }
470  
471 my $new_transcript = Bio::EnsEMBL::Feature::transform($self, @_ );
472 return undef unless $new_transcript;
473  
474 #go through the _trans_exon_array so as not to prompt lazy-loading
475 if(exists($self->{'_trans_exon_array'})) {
476 my @new_exons;
477 foreach my $old_exon ( @{$self->{'_trans_exon_array'}} ) {
478 my $new_exon = $old_exon->transform(@_);
479 push(@new_exons, $new_exon);
480 }
481 $new_transcript->{'_trans_exon_array'} = \@new_exons;
482 }
483  
484 return $new_transcript;
485 }
486  
487  
488  
489 =head2 transfer
490  
491 Arg 1 : Bio::EnsEMBL::Slice $destination_slice
492 Example : $ptrans = $ptrans->transfer($slice);
493 Description: Moves this PredictionTranscript to the given slice.
494 If this Transcripts has Exons attached, they move as well.
495 If this transcript cannot be moved then undef is returned
496 instead.
497 Returntype : Bio::EnsEMBL::PredictionTranscript
498 Exceptions : none
499 Caller : general
500 Status : Stable
501  
502 =cut
503  
504 sub transfer {
505 my $self = shift;
506  
507 my $new_transcript = $self->SUPER::transfer( @_ );
508 return undef unless $new_transcript;
509  
510 if( exists $self->{'_trans_exon_array'} ) {
511 my @new_exons;
512 for my $old_exon ( @{$self->{'_trans_exon_array'}} ) {
513 my $new_exon = $old_exon->transfer( @_ );
514 push( @new_exons, $new_exon );
515 }
516  
517 $new_transcript->{'_trans_exon_array'} = \@new_exons;
518 }
519  
520 return $new_transcript;
521 }
522  
523 =head2 get_all_Exons
524  
525 Arg [1] : none
526 Example : my @exons = @{$transcript->get_all_Exons()};
527 Description: Returns an listref of the exons in this transcipr in order.
528 i.e. the first exon in the listref is the 5prime most exon in
529 the transcript.
530 Returntype : a list reference to Bio::EnsEMBL::Exon objects
531 Exceptions : none
532 Caller : general
533 Status : Stable
534  
535 =cut
536  
537 sub get_all_Exons {
538 my ($self) = @_;
539 if( ! defined $self->{'_trans_exon_array'} && defined $self->adaptor() ) {
540 $self->{'_trans_exon_array'} = $self->adaptor()->db()->
541 get_PredictionExonAdaptor()->fetch_all_by_PredictionTranscript( $self );
542 }
543 return $self->{'_trans_exon_array'};
544 }
545  
546 =head2 display_id
547  
548 Arg [1] : none
549 Example : print $rf->display_id();
550 Description: This method returns a string that is considered to be
551 the 'display' identifier. For prediction transcripts this is
552 (depending on availability and in this order) the stable Id, the
553 dbID or an empty string.
554 Returntype : string
555 Exceptions : none
556 Caller : web drawing code
557 Status : Stable
558  
559 =cut
560  
561 sub display_id {
562 my $self = shift;
563 return $self->stable_id || $self->dbID || '';
564 }
565  
566 =head2 get_all_Attributes
567  
568 Arg [1] : none
569 Example :
570 Description: DOES NOTHING, Returns empty listref. Provided here to prevent
571 Transcript attributes being returned for PredictionTranscripts.
572 Returntype : EMPTY listref Bio::EnsEMBL::Attribute
573 Exceptions : none
574 Caller : general
575 Status : At risk
576  
577 =cut
578  
579 sub get_all_Attributes {
580 my $self = shift;
581  
582 return [];
583 }
584  
585  
586 1;