Commit ed2c1c89 authored by Andreas Kusalananda Kähäri's avatar Andreas Kusalananda Kähäri
Browse files

* Make each Translation keep track of their Transcript.

* Add a transcript() method to the Translation object to retrieve its
  Transcript.

* Modify seq() in Translation so that it temporarily swaps out the
  canonical translation of the transcript if needed.
parent 147909cc
......@@ -179,17 +179,17 @@ sub fetch_all_by_Transcript {
push( @{$translations},
Bio::EnsEMBL::Translation->new_fast( {
'dbID' => $translation_id,
'adaptor' => $self,
'start' => $seq_start,
'end' => $seq_end,
'start_exon' => $start_exon,
'end_exon' => $end_exon,
'stable_id' => $stable_id,
'version' => $version,
'created_date' => $created_date || undef,
'modified_date' => $modified_date || undef
} ) );
'dbID' => $translation_id,
'adaptor' => $self,
'start' => $seq_start,
'end' => $seq_end,
'start_exon' => $start_exon,
'end_exon' => $end_exon,
'stable_id' => $stable_id,
'version' => $version,
'created_date' => $created_date || undef,
'modified_date' => $modified_date || undef,
'transcript' => $transcript } ) );
} ## end while ( $sth->fetch() )
return $translations;
......@@ -267,18 +267,19 @@ sub fetch_by_Transcript {
$transcript->dbID() ) );
}
my $translation = Bio::EnsEMBL::Translation->new_fast( {
'dbID' => $translation_id,
'adaptor' => $self,
'start' => $seq_start,
'end' => $seq_end,
'start_exon' => $start_exon,
'end_exon' => $end_exon,
'stable_id' => $stable_id,
'version' => $version,
'created_date' => $created_date || undef,
'modified_date' => $modified_date || undef
} );
my $translation =
Bio::EnsEMBL::Translation->new_fast( {
'dbID' => $translation_id,
'adaptor' => $self,
'start' => $seq_start,
'end' => $seq_end,
'start_exon' => $start_exon,
'end_exon' => $end_exon,
'stable_id' => $stable_id,
'version' => $version,
'created_date' => $created_date || undef,
'modified_date' => $modified_date || undef,
'transcript' => $transcript } );
return $translation;
} ## end sub fetch_by_Transcript
......
......@@ -592,9 +592,18 @@ sub translation {
}
$self->{'translation'} = $value;
$value->transcript($self);
} elsif ( !exists( $self->{'translation'} )
&& defined( $self->adaptor() ) )
$self->{'cdna_coding_start'} = undef;
$self->{'cdna_coding_end'} = undef;
$self->{'coding_region_start'} = undef;
$self->{'coding_region_end'} = undef;
$self->{'transcript_mapper'} = undef;
} elsif ( !exists( $self->{'translation'} )
&& defined( $self->adaptor() ) )
{
$self->{'translation'} =
$self->adaptor()->db()->get_TranslationAdaptor()
......@@ -602,7 +611,7 @@ sub translation {
}
return $self->{'translation'};
}
} ## end sub translation
=head2 get_all_alternative_translations
......@@ -744,16 +753,16 @@ sub spliced_seq {
sub translateable_seq {
my ( $self ) = @_;
if(!$self->translation()) {
if ( !$self->translation() ) {
return '';
}
my $mrna = $self->spliced_seq();
my $start = $self->cdna_coding_start();
my $end = $self->cdna_coding_end();
my $end = $self->cdna_coding_end();
$mrna = substr( $mrna, $start-1, $end-$start+1 );
$mrna = substr( $mrna, $start - 1, $end - $start + 1 );
my $start_phase = $self->translation->start_Exon->phase();
if( $start_phase > 0 ) {
......
......@@ -137,6 +137,32 @@ sub new_fast {
return bless $hashref, $class;
}
sub transcript {
my ( $self, $transcript ) = @_;
if ( defined($transcript) ) {
$self->{'transcript'} = $transcript;
} elsif ( !defined( $self->{'transcript'} ) ) {
my $adaptor = $self->{'adaptor'};
if ( !defined($adaptor) ) {
throw("Adaptor is not set.");
}
my $dbID = $self->{'dbID'};
if ( !defined($dbID) ) {
throw("dbID is not set.");
}
$self->{'transcript'} =
$adaptor->db()->get_TranscriptAdaptor()
->fetch_by_translation_id($dbID);
}
return $self->{'transcript'};
}
=head2 start
......@@ -807,26 +833,32 @@ sub seq {
} elsif ( !defined( $self->{'seq'} ) ) {
my $adaptor = $self->{'adaptor'};
if ( !defined($adaptor) ) {
warning( "Cannot retrieve sequence from Translation "
. "- adaptor is not set." );
}
my $transcript = $self->transcript();
my $dbID = $self->{'dbID'};
if ( !defined($dbID) ) {
warning( "Cannot retrieve sequence from Translation "
. "- dbID is not set." );
}
my $canonical_translation = $transcript->translation();
my $is_alternative =
( $canonical_translation->stable_id() ne $self->stable_id() );
my $tr_adaptor = $adaptor->db()->get_TranscriptAdaptor();
if ($is_alternative) {
# To deal with non-canonical (alternative) translations, subsitute
# the canonical translation in the transcript with $self for a
# while.
my $seq = $tr_adaptor->fetch_by_translation_id($dbID)->translate();
$transcript->translation($self);
}
my $seq = $transcript->translate();
if ( defined($seq) ) {
$self->{'seq'} = $seq->seq();
}
}
if ($is_alternative) {
# Reinstate the real canonical translation.
$transcript->translation($canonical_translation);
}
} ## end elsif ( !defined( $self->...))
if ( !defined( $self->{'seq'} ) ) {
return ''; # Empty string
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment