Translation.pm 21.1 KB
Newer Older
Ewan Birney's avatar
Ewan Birney committed
1
#
2
# Ensembl module for Bio::EnsEMBL::Translation
Ewan Birney's avatar
Ewan Birney committed
3
4
5
6
7
8
9
10
#
#
# You may distribute this module under the same terms as perl itself

# POD documentation - main docs before the code

=head1 NAME

11
12
Bio::EnsEMBL::Translation - A class representing the translation of a
transcript
Ewan Birney's avatar
Ewan Birney committed
13
14
15

=head1 SYNOPSIS

16

Ewan Birney's avatar
Ewan Birney committed
17
18
=head1 DESCRIPTION

19
A Translation object defines the CDS and UTR regions of a Transcript
20
through the use of start_Exon/end_Exon, and start/end attributes.
Ewan Birney's avatar
Ewan Birney committed
21
22
23

=head1 CONTACT

24
Post questions to the EnsEMBL Developer list: ensembl-dev@ebi.ac.uk
Ewan Birney's avatar
Ewan Birney committed
25

26
=head1 METHODS
Ewan Birney's avatar
Ewan Birney committed
27
28
29
30
31
32
33
34

=cut


package Bio::EnsEMBL::Translation;
use vars qw($AUTOLOAD @ISA);
use strict;

35
36
use Bio::EnsEMBL::Utils::Exception qw( deprecate throw warning );
use Bio::EnsEMBL::Utils::Argument qw( rearrange );
Ewan Birney's avatar
Ewan Birney committed
37

38
use Bio::EnsEMBL::Storable;
Ewan Birney's avatar
Ewan Birney committed
39

40
@ISA = qw(Bio::EnsEMBL::Storable);
Ewan Birney's avatar
Ewan Birney committed
41
42


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

=head2 new

  Arg [-START_EXON] : The Exon object in which the translation (CDS) starts
  Arg [-END_EXON]   : The Exon object in which the translation (CDS) ends
  Arg [-SEQ_START]  : The offset in the start_Exon indicating the start
                      position of the CDS.
  Arg [-SEQ_END]    : The offset in the end_Exon indicating the end
                      position of the CDS.
  Arg [-STABLE_ID]  : The stable identifier for this Translation
  Arg [-VERSION]    : The version of the stable identifier
  Arg [-DBID]       : The internal identifier of this Translation
  Arg [-ADAPTOR]    : The TranslationAdaptor for this Translation
  Arg [-SEQ]        : Manually sets the peptide sequence of this translation.
                      May be useful if this translation is not stored in
                      a database.
59
60
  Arg [-CREATED_DATE]: the date the translation was created
  Arg [-MODIFIED_DATE]: the date the translation was modified
61
62
63
64
65
66
67
68
69
  Example    : my $tl = Bio::EnsEMBL::Translation->new
                   (-START_EXON => $ex1,
                    -END_EXON   => $ex2,
                    -SEQ_START  => 98,
                    -SEQ_END    => 39);
  Description: Constructor.  Creates a new Translation object
  Returntype : Bio::EnsEMBL::Translation
  Exceptions : none
  Caller     : general
70
  Status     : Stable
71
72
73

=cut

74
sub new {
Graham McVicker's avatar
Graham McVicker committed
75
  my $caller = shift;
76

Graham McVicker's avatar
Graham McVicker committed
77
  my $class = ref($caller) || $caller;
Ewan Birney's avatar
Ewan Birney committed
78

79
  my ( $start_exon, $end_exon, $seq_start, $seq_end,
80
81
       $stable_id, $version, $dbID, $adaptor, $seq,
       $created_date, $modified_date ) = 
82
    rearrange( [ "START_EXON", "END_EXON", "SEQ_START", "SEQ_END",
83
                 "STABLE_ID", "VERSION", "DBID", "ADAPTOR",
84
                 "SEQ", "CREATED_DATE", "MODIFIED_DATE" ], @_ );
85
86
87

  my $self = bless {
		    'start_exon' => $start_exon,
88
89
90
91
92
93
94
		    'end_exon'   => $end_exon,
		    'adaptor'    => $adaptor,
		    'dbID'       => $dbID,
		    'start'      => $seq_start,
		    'end'        => $seq_end,
		    'stable_id'  => $stable_id,
		    'version'    => $version,
95
96
		    'created_date' => $created_date,
		    'modified_date' => $modified_date,
97
        'seq'        => $seq
98
99
100
		   }, $class;

  return $self;
Ewan Birney's avatar
Ewan Birney committed
101
102
103
104
105
106
107
}


=head2 start

 Title   : start
 Usage   : $obj->start($newval)
Philip Lijnzaad's avatar
docu  
Philip Lijnzaad committed
108
109
 Function: return or assign the value of start, which is a position within
           the exon given by start_exon_id.
Ewan Birney's avatar
Ewan Birney committed
110
111
 Returns : value of start
 Args    : newvalue (optional)
112
 Status  : Stable
Ewan Birney's avatar
Ewan Birney committed
113
114
115
116
117
118
119

=cut

sub start{
   my $obj = shift;
   if( @_ ) {
      my $value = shift;
Laura Clarke's avatar
 
Laura Clarke committed
120
      
Ewan Birney's avatar
Ewan Birney committed
121
122
123
124
125
126
127
      $obj->{'start'} = $value;
    }
    return $obj->{'start'};

}


128
129
130
131
132
133
134
135
=head2 end

 Title   : end
 Usage   : $obj->end($newval)
 Function: return or assign the value of end, which is a position within
           the exon given by end_exon.
 Returns : value of end
 Args    : newvalue (optional)
136
 Status  : Stable
137
138
139
140
141
142
143
144


=cut

sub end {
   my $self = shift;
   if( @_ ) {
      my $value = shift;
Laura Clarke's avatar
 
Laura Clarke committed
145
      
146
147
148
149
150
151
152
      $self->{'end'} = $value;
    }
    return $self->{'end'};

}


Graham McVicker's avatar
Graham McVicker committed
153
=head2 start_Exon
154
155

 Title   : start_exon
Graham McVicker's avatar
Graham McVicker committed
156
 Usage   : $obj->start_Exon($newval)
157
 Function: return or assign the value of start_exon, which denotes the
Philip Lijnzaad's avatar
docu  
Philip Lijnzaad committed
158
159
           exon at which translation starts (and within this exon, at the
           position indicated by start, see above).
160
 Returns : value of start_exon (Exon object)
Ewan Birney's avatar
Ewan Birney committed
161
 Args    : newvalue (optional)
162
 Status  : Stable
Ewan Birney's avatar
Ewan Birney committed
163
164
165
166


=cut

Graham McVicker's avatar
Graham McVicker committed
167
sub start_Exon {
168
   my $self = shift;
169

Ewan Birney's avatar
Ewan Birney committed
170
171
   if( @_ ) {
      my $value = shift;
172
      if( !ref $value || !$value->isa('Bio::EnsEMBL::Exon') ) {
173
         throw("Got to have an Exon object, not a $value");
174
175
      }
      $self->{'start_exon'} = $value;
Ewan Birney's avatar
Ewan Birney committed
176
    }
177
   return $self->{'start_exon'};
Ewan Birney's avatar
Ewan Birney committed
178
179
180
}


181
182


Graham McVicker's avatar
Graham McVicker committed
183
=head2 end_Exon
184
185

 Title   : end_exon
Graham McVicker's avatar
Graham McVicker committed
186
 Usage   : $obj->end_Exon($newval)
187
188
189
190
 Function: return or assign the value of end_exon, which denotes the
           exon at which translation ends (and within this exon, at the
           position indicated by end, see above).
 Returns : value of end_exon (Exon object)
Ewan Birney's avatar
Ewan Birney committed
191
 Args    : newvalue (optional)
192
 Status  : Stable
Ewan Birney's avatar
Ewan Birney committed
193
194
195

=cut

Graham McVicker's avatar
Graham McVicker committed
196
sub end_Exon {
197
   my $self = shift;
Ewan Birney's avatar
Ewan Birney committed
198
199
   if( @_ ) {
      my $value = shift;
200
      if( !ref $value || !$value->isa('Bio::EnsEMBL::Exon') ) {
201
         throw("Got to have an Exon object, not a $value");
202
203
      }
      $self->{'end_exon'} = $value;
204
    } 
Ewan Birney's avatar
Ewan Birney committed
205

206
    return $self->{'end_exon'};
Ewan Birney's avatar
Ewan Birney committed
207
208
209
}


Graham McVicker's avatar
Graham McVicker committed
210

211
=head2 version
212

213
214
215
216
217
218
  Arg [1]    : string $version
  Example    : none
  Description: get/set for attribute version
  Returntype : string
  Exceptions : none
  Caller     : general
219
  Status     : Stable
Ewan Birney's avatar
Ewan Birney committed
220
221
222

=cut

223
sub version {
224
   my $self = shift;
225
226
  $self->{'version'} = shift if( @_ );
  return $self->{'version'};
Ewan Birney's avatar
Ewan Birney committed
227
}
228
229


230
=head2 stable_id
Graham McVicker's avatar
Graham McVicker committed
231

232
233
234
235
236
237
  Arg [1]    : string $stable_id
  Example    : none
  Description: get/set for attribute stable_id
  Returntype : string
  Exceptions : none
  Caller     : general
238
  Status     : Stable
239
240
241

=cut

242
sub stable_id {
243
   my $self = shift;
244
245
  $self->{'stable_id'} = shift if( @_ );
  return $self->{'stable_id'};
246
247
}

248
249
250
251
252
253
254
255
256
257
258
259
=head2 created_date

  Arg [1]    : (optional) string to be used for the created date
  Example    : none
  Description: get/set for attribute created date
  Returntype : string
  Exceptions : none
  Caller     : general
  Status     : Stable

=cut 

260
261
262
263
264
265
266
sub created_date {
  my $self = shift;
  $self->{'created_date'} = shift if ( @_ );
  return $self->{'created_date'};
}


267
268
269
270
271
272
273
274
275
276
277
278
=head2 modified_date

  Arg [1]    : (optional) string to be used for the modified date
  Example    : none
  Description: get/set for attribute modified date
  Returntype : string
  Exceptions : none
  Caller     : general
  Status     : Stable

=cut 

279
280
281
282
283
284
sub modified_date {
  my $self = shift;
  $self->{'modified_date'} = shift if ( @_ );
  return $self->{'modified_date'};
}

285

Graham McVicker's avatar
Graham McVicker committed
286

287
288
=head2 transform

289
290
291
292
293
  Arg  1    : hashref $old_new_exon_map
              a hash that maps old to new exons for a whole gene
  Function  : maps start end end exon according to mapping table
              if an exon is not mapped, just keep the old one
  Returntype: none
294
  Exceptions: none
295
  Caller    : Transcript->transform() 
296
  Status     : Stable
297
298
299
300
301
302
303

=cut

sub transform {
  my $self = shift;
  my $href_exons = shift;

Graham McVicker's avatar
Graham McVicker committed
304
305
  my $start_exon = $self->start_Exon();
  my $end_exon = $self->end_Exon();
306

Arne Stabenau's avatar
Arne Stabenau committed
307
308
  if ( exists $href_exons->{$start_exon} ) {
    $self->start_Exon($href_exons->{$start_exon});
309
310
  } else {
    # do nothing, the start exon wasnt mapped
311
312
  }

Arne Stabenau's avatar
Arne Stabenau committed
313
314
  if ( exists $href_exons->{$end_exon} ) {
    $self->end_Exon($href_exons->{$end_exon});
315
316
  } else { 
    # do nothing, the end exon wasnt mapped
317
318
319
  }
}

320
321
322
323
324
325
326
327
328
329
330
331
332
333

=head2 get_all_DBEntries

  Arg [1]    : none
  Example    : @dbentries = @{$gene->get_all_DBEntries()};
  Description: Retrieves DBEntries (xrefs) for this translation.  

               This method will attempt to lazy-load DBEntries from a
               database if an adaptor is available and no DBEntries are present
               on the translation (i.e. they have not already been added or 
               loaded).
  Returntype : list reference to Bio::EnsEMBL::DBEntry objects
  Exceptions : none
  Caller     : get_all_DBLinks, TranslationAdaptor::store
334
  Status     : Stable
335
336
337
338
339
340
341

=cut

sub get_all_DBEntries {
  my $self = shift;

  #if not cached, retrieve all of the xrefs for this gene
342
343
344
  if(!defined $self->{'dbentries'}) {
    my $adaptor = $self->adaptor();
    my $dbID    = $self->dbID();
Graham McVicker's avatar
Graham McVicker committed
345
346
347
348

    return [] if(!$adaptor || !$dbID);

    $self->{'dbentries'} =
349
350
351
      $self->adaptor->db->get_DBEntryAdaptor->fetch_all_by_Translation($self);
  }

352
353
  $self->{'dbentries'} ||= [];

354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
  return $self->{'dbentries'};
}


=head2 add_DBEntry

  Arg [1]    : Bio::EnsEMBL::DBEntry $dbe
               The dbEntry to be added
  Example    : @dbentries = @{$gene->get_all_DBEntries()};
  Description: Associates a DBEntry with this gene. Note that adding DBEntries
               will prevent future lazy-loading of DBEntries for this gene
               (see get_all_DBEntries).
  Returntype : none
  Exceptions : thrown on incorrect argument type
  Caller     : general
369
  Status     : Stable
370
371
372
373
374
375
376
377

=cut

sub add_DBEntry {
  my $self = shift;
  my $dbe = shift;

  unless($dbe && ref($dbe) && $dbe->isa('Bio::EnsEMBL::DBEntry')) {
378
    throw('Expected DBEntry argument');
379
380
381
382
383
384
385
  }

  $self->{'dbentries'} ||= [];
  push @{$self->{'dbentries'}}, $dbe;
}


Stephen Keenan's avatar
Stephen Keenan committed
386
387
=head2 get_all_DBLinks

388
389
390
391
392
393
394
  Arg [1]    : see get_all_DBEntries
  Example    : see get_all_DBEntries
  Description: This is here for consistancy with the Transcript and Gene 
               classes.  It is a synonym for the get_all_DBEntries method.
  Returntype : see get_all_DBEntries
  Exceptions : none
  Caller     : general
395
  Status     : Stable
Stephen Keenan's avatar
Stephen Keenan committed
396
397
398
399
400

=cut

sub get_all_DBLinks {
  my $self = shift;
401
  return $self->get_all_DBEntries(@_);
Stephen Keenan's avatar
Stephen Keenan committed
402
403
}

404

405
406
407
408
409
410
411
412
413
414
415
416
417
418
419


=head2 get_all_ProteinFeatures

  Arg [1]    : (optional) string $logic_name
               The analysis logic_name of the features to retrieve.  If not
               specified, all features are retrieved instead.
  Example    : $features = $self->get_all_ProteinFeatures('PFam');
  Description: Retrieves all ProteinFeatures associated with this 
               Translation. If a logic_name is specified, only features with 
               that logic_name are returned.  If no logic_name is provided all
               associated protein_features are returned.
  Returntype : Bio::EnsEMBL::ProteinFeature
  Exceptions : none
  Caller     : general
420
  Status     : Stable
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444

=cut

sub get_all_ProteinFeatures {
  my $self = shift;
  my $logic_name = shift;

  if(!$self->{'protein_features'}) {
    my $adaptor = $self->adaptor();
    my $dbID    = $self->dbID();
    if(!$adaptor || !$dbID) {
      warning("Cannot retrieve ProteinFeatures from translation without " .
              "an attached adaptor and a dbID. Returning empty list.");
      return [];
    }

    my %hash;
    $self->{'protein_features'} = \%hash;

    my $pfa = $adaptor->db()->get_ProteinFeatureAdaptor();
    my $name;
    foreach my $f (@{$pfa->fetch_all_by_translation_id($dbID)}) {
      my $analysis = $f->analysis();
      if($analysis) {
445
        $name = lc($f->analysis->logic_name());
James Stalker's avatar
James Stalker committed
446
	#warn "$dbID has analysis $name\n";
447
      } else {
448
449
        warning("ProteinFeature has no attached analysis\n");
        $name = '';
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
      }
      $hash{$name} ||= [];
      push @{$hash{$name}}, $f;
    }
  }

  #a specific type of protein feature was requested
  if(defined($logic_name)) {
    $logic_name = lc($logic_name);
    return $self->{'protein_features'}->{$logic_name} || [];
  }

  my @features;

  #all protein features were requested
  foreach my $type (keys %{$self->{'protein_features'}}) {
    push @features, @{$self->{'protein_features'}->{$type}};
  }

  return \@features;    
}



=head2 get_all_DomainFeatures

  Arg [1]    : none
  Example    : @domain_feats = @{$translation->get_all_DomainFeatures};
  Description: A convenience method which retrieves all protein features
               that are considered to be 'Domain' features.  Features which
               are 'domain' features are those with analysis logic names:
               'pfscan', 'scanprosite', 'superfamily', 'pfam', 'prints'.
  Returntype : listref of Bio::EnsEMBL::ProteinFeatures
  Exceptions : none
  Caller     : webcode (protview)
485
  Status     : Stable
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506

=cut

sub get_all_DomainFeatures{
 my ($self) = @_;

 my @features;

 my @types = ('pfscan',      #profile (prosite or pfam motifs) 
              'scanprosite', #prosite 
              'superfamily', 
              'pfam',
              'prints');

 foreach my $type (@types) {
   push @features, @{$self->get_all_ProteinFeatures($type)};
 }

 return \@features;
}

507
508


509
510
511
512
513
514
515
516
517
518
=head2 display_id

  Arg [1]    : none
  Example    : print $translation->display_id();
  Description: This method returns a string that is considered to be
               the 'display' identifier.  For translations this is the 
               stable id if it is available otherwise it is an empty string.
  Returntype : string
  Exceptions : none
  Caller     : web drawing code
519
  Status     : Stable
520
521
522
523
524
525
526
527
528

=cut

sub display_id {
  my $self = shift;
  return $self->{'stable_id'} || '';
}


529
530
531
532
533
534
535
536
537
=head2 length

  Arg [1]    : none
  Example    : print "Peptide length =", $translation->length();
  Description: Retrieves the length of the peptide sequence (i.e. number of
               amino acids) represented by this Translation object.
  Returntype : int
  Exceptions : none
  Caller     : webcode (protview etc.)
538
  Status     : Stable
539
540
541

=cut

Web Admin's avatar
Web Admin committed
542
sub length {
543
544
  my $self = shift;
  my $seq = $self->seq();
Web Admin's avatar
testing  
Web Admin committed
545

546
  return ($seq) ? CORE::length($seq) : 0;
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
}


=head2 seq

  Arg [1]    : none
  Example    : print $translation->seq();
  Description: Retrieves a string representation of the peptide sequence
               of this Translation.  This retrieves the transcript from the
               database and gets its sequence, or retrieves the sequence which
               was set via the constructor.  If no adaptor is attached to this
               translation.
  Returntype : string
  Exceptions : warning if the sequence is not set and cannot be retrieved from
               the database.
  Caller     : webcode (protview etc.)
563
  Status     : Stable
564
565
566
567
568
569

=cut

sub seq {
  my $self = shift;

570
571
572
573
574
  if(@_) {
    $self->{'seq'} = shift;
    return $self->{'seq'};
  }

575
576
577
578
579
580
581
582
583
  return $self->{'seq'} if($self->{'seq'});

  my $adaptor = $self->{'adaptor'};
  if(!$adaptor) {
    warning("Cannot retrieve sequence from Translation - adaptor is not set.");
  }

  my $dbID = $self->{'dbID'};
  if(!$dbID) {
584
    warning("Cannot retrieve sequence from Translation - dbID is not set.");
585
586
587
588
589
  }
  
  my $tr_adaptor = $self->{'adaptor'}->db()->get_TranscriptAdaptor;

  my $seq = $tr_adaptor->fetch_by_translation_id($dbID)->translate();
590
591
592
593
594
595
596
  if($seq){
    $self->{'seq'} = $seq->seq();
    return $self->{'seq'};
  }
  else{
    return ''; #empty string
  }
597
598
}

599
600
601
602
=head2 get_all_Attributes

  Arg [1]    : optional string $attrib_code
               The code of the attribute type to retrieve values for.
603
  Example    : ($sc_attr) = @{$tl->get_all_Attributes('_selenocysteine')};
604
               @tl_attributes = @{$translation->get_all_Attributes()};
605
606
  Description: Gets a list of Attributes of this translation.
               Optionally just get Attrubutes for given code.
607
               Recognized attribute "_selenocysteine"
608
609
610
611
  Returntype : listref Bio::EnsEMBL::Attribute
  Exceptions : warning if translation does not have attached adaptor and 
               attempts lazy load.
  Caller     : general, modify_translation
612
  Status     : Stable
613
614
615
616
617
618
619
620
621
622
623
624
625

=cut

sub get_all_Attributes {
  my $self = shift;
  my $attrib_code = shift;

  if( ! exists $self->{'attributes' } ) {
    if(!$self->adaptor() ) {
#      warning('Cannot get attributes without an adaptor.');
      return [];
    }

626
627
    my $aa = $self->adaptor->db->get_AttributeAdaptor();
    $self->{'attributes'} = $aa->fetch_all_by_Translation( $self );
628
629
630
  }

  if( defined $attrib_code ) {
631
    my @results = grep { uc($_->code()) eq uc($attrib_code) }
632
633
634
635
636
637
638
639
640
641
642
643
    @{$self->{'attributes'}};
    return \@results;
  } else {
    return $self->{'attributes'};
  }
}


=head2 add_Attributes

  Arg [1...] : Bio::EnsEMBL::Attribute $attribute
               You can have more Attributes as arguments, all will be added.
644
  Example    : $translation->add_Attributes($selenocysteine_attribute);
645
  Description: Adds an Attribute to the Translation. Usefull to 
646
               do _selenocysteine.
647
648
               If you add an attribute before you retrieve any from database, 
               lazy load will be disabled.
649
  Returntype : none
650
  Exceptions : throw on incorrect arguments
651
  Caller     : general
652
  Status     : Stable
653
654
655
656
657
658
659
660
661
662
663
664
665

=cut

sub add_Attributes {
  my $self = shift;
  my @attribs = @_;

  if( ! exists $self->{'attributes'} ) {
    $self->{'attributes'} = [];
  }

  for my $attrib ( @attribs ) {
    if( ! $attrib->isa( "Bio::EnsEMBL::Attribute" )) {
666
      throw( "Argument to add_Attribute must be a Bio::EnsEMBL::Attribute" );
667
668
669
670
671
    }
    push( @{$self->{'attributes'}}, $attrib );
  }
}

672
=head2 get_all_SeqEdits
673

674
675
676
677
678
679
680
  Arg [1]    : none
  Example    : my @seqeds = @{$transcript->get_all_SeqEdits()};
  Description: Retrieves all post transcriptional sequence modifications for
               this transcript.
  Returntype : Bio::EnsEMBL::SeqEdit
  Exceptions : none
  Caller     : spliced_seq()
681
  Status     : Stable
682
683
684

=cut

685
sub get_all_SeqEdits {
686
687
  my $self = shift;

688
  my @seqeds;
689

690
691
692
693
694
695
696
  my $attribs;
  
  my @edits = ('initial_met', '_selenocysteine');
  

  foreach my $edit(@edits){
    $attribs = $self->get_all_Attributes($edit);
697

698
699
700
701
    # convert attributes to SeqEdit objects
    foreach my $a (@$attribs) {
      push @seqeds, Bio::EnsEMBL::SeqEdit->new(-ATTRIB => $a);
    }
702
  }
703
  
704

705
706
  return \@seqeds;
}
707
708
709
710

=head2 modify_translation

  Arg    1   : Bio::Seq $peptide 
711
712
  Example    : my $seq = Bio::Seq->new(-SEQ => $dna)->translate();
               $translation->modify_translation($seq);
713
  Description: Applies sequence edits such as selenocysteines to the Bio::Seq 
714
               peptide thats passed in
715
  Returntype : Bio::Seq
716
  Exceptions :
717
  Caller     : Bio::EnsEMBL::Transcript->translate
718
  Status     : Stable
719
720
721
722
723
724

=cut

sub modify_translation {
  my ($self, $seq) = @_;

725
  my @seqeds = @{$self->get_all_SeqEdits()};
726

727
728
  # sort in reverse order to avoid complication of adjusting downstream edits
  @seqeds = sort {$b <=> $a} @seqeds;
729

730
731
732
733
  # apply all edits
  my $peptide = $seq->seq();
  foreach my $se (@seqeds) {
    $se->apply_edit(\$peptide);
734
  }
735
  $seq->seq($peptide);
736
737
738
739
740

  return $seq;
}


741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
=head2 temporary_id

  Description: DEPRECATED This method should not be needed. Use dbID,
               stable_id or something else.

=cut

sub temporary_id {
   my $self = shift;
   deprecate( "I cant see what a temporary_id is good for, please use " .
               "dbID or stableID or\n try without an id." );
  $self->{'temporary_id'} = shift if( @_ );
  return $self->{'temporary_id'};
}


757
758
759
760
761
762
=head2 get_all_DASFactories

  Arg [1]   : none
  Function  : Retrieves a listref of registered DAS objects
  Returntype: [ DAS_objects ]
  Exceptions:
763
  Caller    : webcode
764
  Example   : $dasref = $prot->get_all_DASFactories
765
  Status     : Stable
766
767
768
769
770
771
772
773
774

=cut

sub get_all_DASFactories {
   my $self = shift;
   return [ $self->adaptor()->db()->_each_DASFeatureFactory ];
}


Web Admin's avatar
testing  
Web Admin committed
775

776
777
778
779
780
781
782
783
784
785
786
787
=head2 get_all_DAS_Features

  Arg [1]    : none
  Example    : $features = $prot->get_all_DAS_Features;
  Description: Retreives a hash reference to a hash of DAS feature
               sets, keyed by the DNS, NOTE the values of this hash
               are an anonymous array containing:
                (1) a pointer to an array of features;
                (2) a pointer to the DAS stylesheet
  Returntype : hashref of Bio::SeqFeatures
  Exceptions : ?
  Caller     : webcode
788
  Status     : Stable
789
790
791
792
793
794
795
796
797
798

=cut

sub get_all_DAS_Features{
  my ($self,@args) = @_;
  $self->{_das_features} ||= {}; # Cache
  my %das_features;

  my $db = $self->adaptor->db;
  my $GeneAdaptor = $db->get_GeneAdaptor;
799
  my $Gene = $GeneAdaptor->fetch_by_translation_stable_id($self->stable_id) || return;
800
801
802
803
  my $slice = $Gene->feature_Slice;

  foreach my $dasfact( @{$self->get_all_DASFactories} ){
    my $dsn = $dasfact->adaptor->dsn;
804
    my $name = $dasfact->adaptor->name;
805
    my $type = $dasfact->adaptor->type;
806
    my $url = $dasfact->adaptor->url;
807

808
809
# Construct a cache key : SOURCE_URL/TYPE
# Need the type to handle sources that serve multiple types of features
810

811
812
    my $key = $url || $dasfact->adaptor->protocol .'://'.$dasfact->adaptor->domain;
    $key .= "/$dsn/$type";
813

814
815
816
    if( $self->{_das_features}->{$key} ){ # Use cached
	$das_features{$name} = $self->{_das_features}->{$key};
	next;
817
    } else{ # Get fresh data
818
819
#	my $featref = ($type eq 'ensembl_location') ?  ($dasfact->fetch_all_by_Slice( $slice ))[0] : $dasfact->fetch_all_by_ID( $self );
	my $featref = ($type =~ /^ensembl_location/) ?  ($dasfact->fetch_all_Features( $slice, $type ))[0] : $dasfact->fetch_all_by_ID( $self );
820
821
822
	$self->{_das_features}->{$key} = $featref;
	$das_features{$name} = $featref;
    }
823
824
825
826
  }
  return \%das_features;
}

827
=head2 get_all_regulatory_features
828
829

  Arg [1]    : none
Glenn Proctor's avatar
Glenn Proctor committed
830
  Example    : @features = $translation->get_all_regulatory_features();
831
832
833
834
835
  Description: Gets all the regulatory features associated with this translation.
               Each feature only appears once.
  Returntype : Listref of Bio::EnsEMBL::RegulatoryFeature
  Exceptions : If arg is not of correct type.
  Caller     : ?
836
837
838
  Status     : At Risk
             : Regulatory features are currently under development and are 
             : likely to change.
839
840
841

=cut

842
sub get_all_regulatory_features {
843
844
845
846
847
848
849
850
851

   my ($self) = @_;

   my $rfa = $self->adaptor->db->get_RegulatoryFeatureAdaptor();

   return $rfa->fetch_all_by_translation($self);

}

852
1;