my ( $self, $sequence ) = @_;
if ( defined($sequence) ) {
$self->{'seq'} = $sequence;
} elsif ( !defined( $self->{'seq'} ) ) {
my $transcript = $self->transcript();
my $canonical_translation = $transcript->translation();
my $is_alternative;
if(!$canonical_translation) {
throw "Transcript does not have a canonical translation";
}
if ( defined( $canonical_translation->stable_id() )
&& defined( $self->stable_id() ) )
{
# Try stable ID.
$is_alternative =
( $canonical_translation->stable_id() ne $self->stable_id() );
} elsif ( defined( $canonical_translation->dbID() )
&& defined( $self->dbID() ) )
{
# Try dbID.
$is_alternative =
( $canonical_translation->dbID() != $self->dbID() );
} else {
# Resort to using geomic start/end coordinates.
$is_alternative = ( ($canonical_translation->genomic_start() !=
$self->genomic_start() )
|| ( $canonical_translation->genomic_end() !=
$self->genomic_end() ) );
}
if ($is_alternative) {
# To deal with non-canonical (alternative) translations, subsitute
# the canonical translation in the transcript with $self for a
# while.
$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
}
return $self->{'seq'};