| 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 | Bio::EnsEMBL::Translation - A class representing the translation of a | ||
| 34 | transcript | ||
| 35 | |||
| 36 | =head1 SYNOPSIS | ||
| 37 | |||
| 38 | my $translation = Bio::EnsEMBL::Translation->new( | ||
| 39 | -START_EXON => $exon1, | ||
| 40 | -END_EXON => $exon2, | ||
| 41 | -SEQ_START => 98, | ||
| 42 | -SEQ_END => 39 | ||
| 43 | ); | ||
| 44 | |||
| 45 | # stable ID setter | ||
| 46 | $translation->stable_id('ENSP00053458'); | ||
| 47 | |||
| 48 | # get start and end position in start/end exons | ||
| 49 | my $start = $translation->start; | ||
| 50 | my $end = $translation->end; | ||
| 51 | |||
| 52 | =head1 DESCRIPTION | ||
| 53 | |||
| 54 | A Translation object defines the CDS and UTR regions of a Transcript | ||
| 55 | through the use of start_Exon/end_Exon, and start/end attributes. | ||
| 56 | |||
| 57 | =cut | ||
| 58 | |||
| 59 | |||
| 60 | package Bio::EnsEMBL::Translation; | ||
| 61 | $Bio::EnsEMBL::Translation::VERSION = '114.0.0_50'; # TRIAL | ||
| 62 | $Bio::EnsEMBL::Translation::VERSION = '114.0.050'; | ||
| 63 | use vars qw($AUTOLOAD @ISA); | ||
| 64 | use strict; | ||
| 65 | |||
| 66 | use Bio::EnsEMBL::Utils::Exception qw(throw warning ); | ||
| 67 | use Bio::EnsEMBL::Utils::Argument qw( rearrange ); | ||
| 68 | use Bio::EnsEMBL::Utils::Scalar qw( assert_ref wrap_array ); | ||
| 69 | use Scalar::Util qw(weaken); | ||
| 70 | |||
| 71 | use Bio::EnsEMBL::Storable; | ||
| 72 | |||
| 73 | @ISA = qw(Bio::EnsEMBL::Storable); | ||
| 74 | |||
| 75 | |||
| 76 | =head2 new | ||
| 77 | |||
| 78 | Arg [-START_EXON] : The Exon object in which the translation (CDS) starts | ||
| 79 | Arg [-END_EXON] : The Exon object in which the translation (CDS) ends | ||
| 80 | Arg [-SEQ_START] : The offset in the start_Exon indicating the start | ||
| 81 | position of the CDS. | ||
| 82 | Arg [-SEQ_END] : The offset in the end_Exon indicating the end | ||
| 83 | position of the CDS. | ||
| 84 | Arg [-STABLE_ID] : The stable identifier for this Translation | ||
| 85 | Arg [-VERSION] : The version of the stable identifier | ||
| 86 | Arg [-DBID] : The internal identifier of this Translation | ||
| 87 | Arg [-ADAPTOR] : The TranslationAdaptor for this Translation | ||
| 88 | Arg [-SEQ] : Manually sets the peptide sequence of this translation. | ||
| 89 | May be useful if this translation is not stored in | ||
| 90 | a database. | ||
| 91 | Arg [-CREATED_DATE]: the date the translation was created | ||
| 92 | Arg [-MODIFIED_DATE]: the date the translation was modified | ||
| 93 | Example : my $tl = Bio::EnsEMBL::Translation->new | ||
| 94 | (-START_EXON => $ex1, | ||
| 95 | -END_EXON => $ex2, | ||
| 96 | -SEQ_START => 98, | ||
| 97 | -SEQ_END => 39); | ||
| 98 | Description: Constructor. Creates a new Translation object | ||
| 99 | Returntype : Bio::EnsEMBL::Translation | ||
| 100 | Exceptions : none | ||
| 101 | Caller : general | ||
| 102 | Status : Stable | ||
| 103 | |||
| 104 | =cut | ||
| 105 | |||
| 106 | sub new { | ||
| 107 | my $caller = shift; | ||
| 108 | |||
| 109 | my $class = ref($caller) || $caller; | ||
| 110 | |||
| 111 | my ( $start_exon, $end_exon, $seq_start, $seq_end, | ||
| 112 | $stable_id, $version, $dbID, $adaptor, $seq, | ||
| 113 | $created_date, $modified_date ) = | ||
| 114 | rearrange( [ "START_EXON", "END_EXON", "SEQ_START", "SEQ_END", | ||
| 115 | "STABLE_ID", "VERSION", "DBID", "ADAPTOR", | ||
| 116 | "SEQ", "CREATED_DATE", "MODIFIED_DATE" ], @_ ); | ||
| 117 | |||
| 118 | # Default version | ||
| 119 | if ( !defined($version) ) { $version = 1 } | ||
| 120 | |||
| 121 | my $self = bless { | ||
| 122 | 'start_exon' => $start_exon, | ||
| 123 | 'end_exon' => $end_exon, | ||
| 124 | 'dbID' => $dbID, | ||
| 125 | 'start' => $seq_start, | ||
| 126 | 'end' => $seq_end, | ||
| 127 | 'stable_id' => $stable_id, | ||
| 128 | 'version' => $version, | ||
| 129 | 'created_date' => $created_date, | ||
| 130 | 'modified_date' => $modified_date, | ||
| 131 | 'seq' => $seq | ||
| 132 | }, $class; | ||
| 133 | |||
| 134 | $self->adaptor($adaptor); | ||
| 135 | |||
| 136 | return $self; | ||
| 137 | } | ||
| 138 | |||
| 139 | |||
| 140 | |||
| 141 | =head2 transcript | ||
| 142 | |||
| 143 | Arg [1] : Transcript object (optional) | ||
| 144 | Description : Sets or retrieves the transcript object associated | ||
| 145 | with this translation object. | ||
| 146 | Exceptions : Throws if there is no adaptor or no dbID defined for | ||
| 147 | the translation object. | ||
| 148 | Returntype : Bio::EnsEMBL::Transcript | ||
| 149 | =cut | ||
| 150 | |||
| 151 | sub transcript { | ||
| 152 | my ( $self, $transcript ) = @_; | ||
| 153 | |||
| 154 | if ( defined($transcript) ) { | ||
| 155 | assert_ref( $transcript, 'Bio::EnsEMBL::Transcript' ); | ||
| 156 | |||
| 157 | $self->{'transcript'} = $transcript; | ||
| 158 | |||
| 159 | weaken( $self->{'transcript'} ); # Avoid circular references. | ||
| 160 | |||
| 161 | } elsif ( @_ > 1 ) { | ||
| 162 | # Break connection to transcript. | ||
| 163 | delete( $self->{'transcript'} ); | ||
| 164 | } elsif ( !defined( $self->{'transcript'} ) ) { | ||
| 165 | my $adaptor = $self->adaptor; | ||
| 166 | if ( !defined($adaptor) ) { | ||
| 167 | throw( "Adaptor is not set for translation, " | ||
| 168 | . "can not fetch its transcript." ); | ||
| 169 | } | ||
| 170 | |||
| 171 | my $dbID = $self->{'dbID'}; | ||
| 172 | if ( !defined($dbID) ) { | ||
| 173 | throw( "dbID is not set for translation, " | ||
| 174 | . " can not fetch its transcript." ); | ||
| 175 | } | ||
| 176 | |||
| 177 | $self->{'transcript'} = | ||
| 178 | $adaptor->db()->get_TranscriptAdaptor() | ||
| 179 | ->fetch_by_translation_id($dbID); | ||
| 180 | |||
| 181 | # Do not weaken the reference if we had to get the transcript from the | ||
| 182 | # database. The user is probably working on translations directly, | ||
| 183 | # not going through transcripts. | ||
| 184 | #weaken( $self->{'transcript'} ); # Avoid circular references. | ||
| 185 | } | ||
| 186 | |||
| 187 | return $self->{'transcript'}; | ||
| 188 | } ## end sub transcript | ||
| 189 | |||
| 190 | |||
| 191 | =head2 start | ||
| 192 | |||
| 193 | Arg [1] : (optional) int $start - start position to set | ||
| 194 | Example : $translation->start(17); | ||
| 195 | Description: Getter/setter for the value of start, which is a position within | ||
| 196 | the exon given by start_Exon. | ||
| 197 | |||
| 198 | If you need genomic coordinates, use the genomic_start() | ||
| 199 | method. | ||
| 200 | Returntype : int | ||
| 201 | Exceptions : none | ||
| 202 | Caller : general | ||
| 203 | Status : Stable | ||
| 204 | |||
| 205 | =cut | ||
| 206 | |||
| 207 | sub start{ | ||
| 208 | my $obj = shift; | ||
| 209 | if( @_ ) { | ||
| 210 | my $value = shift; | ||
| 211 | |||
| 212 | $obj->{'start'} = $value; | ||
| 213 | } | ||
| 214 | return $obj->{'start'}; | ||
| 215 | |||
| 216 | } | ||
| 217 | |||
| 218 | |||
| 219 | =head2 end | ||
| 220 | |||
| 221 | Arg [1] : (optional) int $end - end position to set | ||
| 222 | Example : $translation->end(8); | ||
| 223 | Description: Getter/setter for the value of end, which is a position within | ||
| 224 | the exon given by end_Exon. | ||
| 225 | |||
| 226 | If you need genomic coordinates, use the genomic_end() | ||
| 227 | method. | ||
| 228 | Returntype : int | ||
| 229 | Exceptions : none | ||
| 230 | Caller : general | ||
| 231 | Status : Stable | ||
| 232 | |||
| 233 | =cut | ||
| 234 | |||
| 235 | sub end { | ||
| 236 | my $self = shift; | ||
| 237 | if( @_ ) { | ||
| 238 | my $value = shift; | ||
| 239 | |||
| 240 | $self->{'end'} = $value; | ||
| 241 | } | ||
| 242 | return $self->{'end'}; | ||
| 243 | |||
| 244 | } | ||
| 245 | |||
| 246 | |||
| 247 | =head2 start_Exon | ||
| 248 | |||
| 249 | Arg [1] : (optional) Bio::EnsEMBL::Exon - start exon to assign | ||
| 250 | Example : $translation->start_Exon($exon1); | ||
| 251 | Description: Getter/setter for the value of start_Exon, which denotes the | ||
| 252 | exon at which translation starts (and within this exon, at the | ||
| 253 | position indicated by start, see above). | ||
| 254 | Returntype : Bio::EnsEMBL::Exon | ||
| 255 | Exceptions : thrown on wrong argument type | ||
| 256 | Caller : general | ||
| 257 | Status : Stable | ||
| 258 | |||
| 259 | =cut | ||
| 260 | |||
| 261 | sub start_Exon { | ||
| 262 | my $self = shift; | ||
| 263 | |||
| 264 | if( @_ ) { | ||
| 265 | my $value = shift; | ||
| 266 | if( !ref $value || !$value->isa('Bio::EnsEMBL::Exon') ) { | ||
| 267 | throw("Got to have an Exon object, not a $value"); | ||
| 268 | } | ||
| 269 | $self->{'start_exon'} = $value; | ||
| 270 | } | ||
| 271 | return $self->{'start_exon'}; | ||
| 272 | } | ||
| 273 | |||
| 274 | |||
| 275 | =head2 end_Exon | ||
| 276 | |||
| 277 | Arg [1] : (optional) Bio::EnsEMBL::Exon - start exon to assign | ||
| 278 | Example : $translation->start_Exon($exon1); | ||
| 279 | Description: Getter/setter for the value of end_Exon, which denotes the | ||
| 280 | exon at which translation ends (and within this exon, at the | ||
| 281 | position indicated by end, see above). | ||
| 282 | Returntype : Bio::EnsEMBL::Exon | ||
| 283 | Exceptions : thrown on wrong argument type | ||
| 284 | Caller : general | ||
| 285 | Status : Stable | ||
| 286 | |||
| 287 | =cut | ||
| 288 | |||
| 289 | sub end_Exon { | ||
| 290 | my $self = shift; | ||
| 291 | if( @_ ) { | ||
| 292 | my $value = shift; | ||
| 293 | if( !ref $value || !$value->isa('Bio::EnsEMBL::Exon') ) { | ||
| 294 | throw("Got to have an Exon object, not a $value"); | ||
| 295 | } | ||
| 296 | $self->{'end_exon'} = $value; | ||
| 297 | } | ||
| 298 | |||
| 299 | return $self->{'end_exon'}; | ||
| 300 | } | ||
| 301 | |||
| 302 | =head2 cdna_start | ||
| 303 | |||
| 304 | Arg [1] : (optional) Bio::EnsEMBL::Transcript $transcript | ||
| 305 | The transcript which this is a translation of. | ||
| 306 | Example : $translation_cdna_start = $translation->cdna_start(); | ||
| 307 | Description : Returns the start position of the translation in cDNA | ||
| 308 | coordinates. | ||
| 309 | If no transcript is given, the method will use | ||
| 310 | TranscriptAdaptor->fetch_by_translation_id() to locate | ||
| 311 | the correct transcript. | ||
| 312 | Return type : Integer | ||
| 313 | Exceptions : Throws if the given (optional) argument is not a | ||
| 314 | transcript. | ||
| 315 | Caller : General | ||
| 316 | Status : At Risk (Under Development) | ||
| 317 | |||
| 318 | =cut | ||
| 319 | |||
| 320 | sub cdna_start { | ||
| 321 | my ( $self, $transcript ) = @_; | ||
| 322 | |||
| 323 | if ( defined($transcript) | ||
| 324 | && ( !ref($transcript) | ||
| 325 | || !$transcript->isa('Bio::EnsEMBL::Transcript') ) ) | ||
| 326 | { | ||
| 327 | throw("Argument is not a transcript"); | ||
| 328 | } | ||
| 329 | |||
| 330 | if ( !exists( $self->{'cdna_start'} ) ) { | ||
| 331 | if ( !defined($transcript) ) { | ||
| 332 | # We were not given a transcript, get the transcript out of | ||
| 333 | # the database. | ||
| 334 | $transcript = $self->transcript(); | ||
| 335 | } | ||
| 336 | |||
| 337 | $self->{'cdna_start'} = | ||
| 338 | $self->start_Exon()->cdna_coding_start($transcript); | ||
| 339 | } | ||
| 340 | |||
| 341 | return $self->{'cdna_start'}; | ||
| 342 | } | ||
| 343 | |||
| 344 | =head2 cdna_end | ||
| 345 | |||
| 346 | Arg [1] : (optional) Bio::EnsEMBL::Transcript $transcript | ||
| 347 | The transcript which this is a translation of. | ||
| 348 | Example : $translation_cdna_end = $translation->cdna_end(); | ||
| 349 | Description : Returns the end position of the translation in cDNA | ||
| 350 | coordinates. | ||
| 351 | If no transcript is given, the method will use | ||
| 352 | TranscriptAdaptor->fetch_by_translation_id() to locate | ||
| 353 | the correct transcript. | ||
| 354 | Return type : Integer | ||
| 355 | Exceptions : Throws if the given (optional) argument is not a | ||
| 356 | transcript. | ||
| 357 | Caller : General | ||
| 358 | Status : At Risk (Under Development) | ||
| 359 | |||
| 360 | =cut | ||
| 361 | |||
| 362 | sub cdna_end { | ||
| 363 | my ( $self, $transcript ) = @_; | ||
| 364 | |||
| 365 | if ( defined($transcript) | ||
| 366 | && ( !ref($transcript) | ||
| 367 | || !$transcript->isa('Bio::EnsEMBL::Transcript') ) ) | ||
| 368 | { | ||
| 369 | throw("Argument is not a transcript"); | ||
| 370 | } | ||
| 371 | |||
| 372 | if ( !exists( $self->{'cdna_end'} ) ) { | ||
| 373 | if ( !defined($transcript) ) { | ||
| 374 | # We were not given a transcript, get the transcript out of | ||
| 375 | # the database. | ||
| 376 | $transcript = $self->transcript(); | ||
| 377 | } | ||
| 378 | |||
| 379 | $self->{'cdna_end'} = | ||
| 380 | $self->end_Exon()->cdna_coding_end($transcript); | ||
| 381 | } | ||
| 382 | |||
| 383 | return $self->{'cdna_end'}; | ||
| 384 | } | ||
| 385 | |||
| 386 | =head2 genomic_start | ||
| 387 | |||
| 388 | Args : None | ||
| 389 | Example : $translation_genomic_start = | ||
| 390 | $translation->genomic_start(); | ||
| 391 | Description : Returns the start position of the translation in | ||
| 392 | genomic coordinates on the forward strand. | ||
| 393 | Return type : Integer | ||
| 394 | Exceptions : None | ||
| 395 | Caller : General | ||
| 396 | Status : At Risk (Under Development) | ||
| 397 | |||
| 398 | =cut | ||
| 399 | |||
| 400 | sub genomic_start { | ||
| 401 | my $self = shift; | ||
| 402 | |||
| 403 | if ( !exists $self->{'genomic_start'} ) { | ||
| 404 | if ( $self->start_Exon()->strand() >= 0 ) { | ||
| 405 | $self->{'genomic_start'} = | ||
| 406 | $self->start_Exon()->start() + ( $self->start() - 1 ); | ||
| 407 | } else { | ||
| 408 | $self->{'genomic_start'} = | ||
| 409 | $self->end_Exon()->end() - ( $self->end() - 1 ); | ||
| 410 | } | ||
| 411 | } | ||
| 412 | |||
| 413 | return $self->{'genomic_start'}; | ||
| 414 | } | ||
| 415 | |||
| 416 | =head2 genomic_end | ||
| 417 | |||
| 418 | Args : None | ||
| 419 | Example : $translation_genomic_end = $translation->genomic_end(); | ||
| 420 | Description : Returns the end position of the translation in genomic | ||
| 421 | coordinates on the forward strand. | ||
| 422 | Return type : Integer | ||
| 423 | Exceptions : None | ||
| 424 | Caller : General | ||
| 425 | Status : At Risk (Under Development) | ||
| 426 | |||
| 427 | =cut | ||
| 428 | |||
| 429 | sub genomic_end { | ||
| 430 | my $self = shift; | ||
| 431 | |||
| 432 | if ( !exists $self->{'genomic_end'} ) { | ||
| 433 | if ( $self->end_Exon()->strand() >= 0 ) { | ||
| 434 | $self->{'genomic_end'} = | ||
| 435 | $self->end_Exon()->start() + ( $self->end() - 1 ); | ||
| 436 | } else { | ||
| 437 | $self->{'genomic_end'} = | ||
| 438 | $self->start_Exon()->end() - ( $self->start() - 1 ); | ||
| 439 | } | ||
| 440 | } | ||
| 441 | |||
| 442 | return $self->{'genomic_end'}; | ||
| 443 | } | ||
| 444 | |||
| 445 | =head2 version | ||
| 446 | |||
| 447 | Arg [1] : (optional) string $version - version to set | ||
| 448 | Example : $translation->version(2); | ||
| 449 | Description: Getter/setter for attribute version | ||
| 450 | Returntype : string | ||
| 451 | Exceptions : none | ||
| 452 | Caller : general | ||
| 453 | Status : Stable | ||
| 454 | |||
| 455 | =cut | ||
| 456 | |||
| 457 | sub version { | ||
| 458 | my $self = shift; | ||
| 459 | $self->{'version'} = shift if( @_ ); | ||
| 460 | return $self->{'version'}; | ||
| 461 | } | ||
| 462 | |||
| 463 | |||
| 464 | =head2 stable_id | ||
| 465 | |||
| 466 | Arg [1] : (optional) string $stable_id - stable ID to set | ||
| 467 | Example : $translation->stable_id('ENSP0059890'); | ||
| 468 | Description: Getter/setter for attribute stable_id | ||
| 469 | Returntype : string | ||
| 470 | Exceptions : none | ||
| 471 | Caller : general | ||
| 472 | Status : Stable | ||
| 473 | |||
| 474 | =cut | ||
| 475 | |||
| 476 | sub stable_id { | ||
| 477 | my $self = shift; | ||
| 478 | $self->{'stable_id'} = shift if( @_ ); | ||
| 479 | return $self->{'stable_id'}; | ||
| 480 | } | ||
| 481 | |||
| 482 | =head2 stable_id_version | ||
| 483 | |||
| 484 | Arg [1] : (optional) String - the stable ID with version to set | ||
| 485 | Example : $translation->stable_id("ENSP0059890.3"); | ||
| 486 | Description: Getter/setter for stable id with version for this translation. | ||
| 487 | Returntype : String | ||
| 488 | Exceptions : none | ||
| 489 | Caller : general | ||
| 490 | Status : Stable | ||
| 491 | |||
| 492 | =cut | ||
| 493 | |||
| 494 | sub stable_id_version { | ||
| 495 | my $self = shift; | ||
| 496 | if(my $stable_id = shift) { | ||
| 497 | # See if there's an embedded period, assume that's a | ||
| 498 | # version, might not work for some species but you | ||
| 499 | # should use ->stable_id() and version() if you're worried | ||
| 500 | # about ambiguity | ||
| 501 | my $vindex = rindex($stable_id, '.'); | ||
| 502 | # Set the stable_id and version pair depending on if | ||
| 503 | # we found a version delimiter in the stable_id | ||
| 504 | ($self->{stable_id}, $self->{version}) = ($vindex > 0 ? | ||
| 505 | (substr($stable_id,0,$vindex), substr($stable_id,$vindex+1)) : | ||
| 506 | $stable_id, undef); | ||
| 507 | } | ||
| 508 | return $self->{stable_id} . ($self->{version} ? ".$self->{version}" : ''); | ||
| 509 | } | ||
| 510 | |||
| 511 | =head2 created_date | ||
| 512 | |||
| 513 | Arg [1] : (optional) string $created_date - created date to set | ||
| 514 | Example : $translation->created_date('2007-01-10 20:52:00'); | ||
| 515 | Description: Getter/setter for attribute created date | ||
| 516 | Returntype : string | ||
| 517 | Exceptions : none | ||
| 518 | Caller : general | ||
| 519 | Status : Stable | ||
| 520 | |||
| 521 | =cut | ||
| 522 | |||
| 523 | sub created_date { | ||
| 524 | my $self = shift; | ||
| 525 | $self->{'created_date'} = shift if ( @_ ); | ||
| 526 | return $self->{'created_date'}; | ||
| 527 | } | ||
| 528 | |||
| 529 | |||
| 530 | =head2 modified_date | ||
| 531 | |||
| 532 | Arg [1] : (optional) string $modified_date - modification date to set | ||
| 533 | Example : $translation->modified_date('2007-01-10 20:52:00'); | ||
| 534 | Description: Getter/setter for attribute modified date | ||
| 535 | Returntype : string | ||
| 536 | Exceptions : none | ||
| 537 | Caller : general | ||
| 538 | Status : Stable | ||
| 539 | |||
| 540 | =cut | ||
| 541 | |||
| 542 | sub modified_date { | ||
| 543 | my $self = shift; | ||
| 544 | $self->{'modified_date'} = shift if ( @_ ); | ||
| 545 | return $self->{'modified_date'}; | ||
| 546 | } | ||
| 547 | |||
| 548 | |||
| 549 | |||
| 550 | =head2 transform | ||
| 551 | |||
| 552 | Arg [1] : hashref $old_new_exon_map | ||
| 553 | a hash that maps old to new exons for a whole gene | ||
| 554 | Description: maps start end end exon according to mapping table. | ||
| 555 | If an exon is not mapped, just keep the old one. | ||
| 556 | Returntype : none | ||
| 557 | Exceptions : none | ||
| 558 | Caller : Transcript->transform() | ||
| 559 | Status : Stable | ||
| 560 | |||
| 561 | =cut | ||
| 562 | |||
| 563 | sub transform { | ||
| 564 | my $self = shift; | ||
| 565 | my $href_exons = shift; | ||
| 566 | |||
| 567 | my $start_exon = $self->start_Exon(); | ||
| 568 | my $end_exon = $self->end_Exon(); | ||
| 569 | |||
| 570 | if ( exists $href_exons->{$start_exon} ) { | ||
| 571 | $self->start_Exon($href_exons->{$start_exon}); | ||
| 572 | } else { | ||
| 573 | # do nothing, the start exon wasnt mapped | ||
| 574 | } | ||
| 575 | |||
| 576 | if ( exists $href_exons->{$end_exon} ) { | ||
| 577 | $self->end_Exon($href_exons->{$end_exon}); | ||
| 578 | } else { | ||
| 579 | # do nothing, the end exon wasnt mapped | ||
| 580 | } | ||
| 581 | } | ||
| 582 | |||
| 583 | |||
| 584 | =head2 get_all_DBEntries | ||
| 585 | |||
| 586 | Arg [1] : (optional) String, external database name, | ||
| 587 | SQL wildcard characters (_ and %) can be used to | ||
| 588 | specify patterns. | ||
| 589 | |||
| 590 | Arg [2] : (optional) String, external_db type, | ||
| 591 | ('ARRAY','ALT_TRANS','ALT_GENE','MISC','LIT','PRIMARY_DB_SYNONYM','ENSEMBL'), | ||
| 592 | SQL wildcard characters (_ and %) can be used to | ||
| 593 | specify patterns. | ||
| 594 | |||
| 595 | Example : my @dbentries = @{ $translation->get_all_DBEntries() }; | ||
| 596 | @dbentries = @{ $translation->get_all_DBEntries('Uniprot%') }; | ||
| 597 | @dbentries = @{ $translation->get_all_DBEntries('%', 'ENSEMBL') }; | ||
| 598 | |||
| 599 | Description: Retrieves DBEntries (xrefs) for this translation. | ||
| 600 | |||
| 601 | This method will attempt to lazy-load DBEntries | ||
| 602 | from a database if an adaptor is available and no | ||
| 603 | DBEntries are present on the translation (i.e. they | ||
| 604 | have not already been added or loaded). | ||
| 605 | |||
| 606 | Returntype : Listref to Bio::EnsEMBL::DBEntry objects | ||
| 607 | Exceptions : none | ||
| 608 | Caller : TranslationAdaptor::store | ||
| 609 | Status : Stable | ||
| 610 | |||
| 611 | =cut | ||
| 612 | |||
| 613 | sub get_all_DBEntries { | ||
| 614 | my ( $self, $ex_db_exp, $ex_db_type ) = @_; | ||
| 615 | |||
| 616 | my $cache_name = 'dbentries'; | ||
| 617 | |||
| 618 | if ( defined($ex_db_exp) ) { | ||
| 619 | $cache_name .= $ex_db_exp; | ||
| 620 | } | ||
| 621 | |||
| 622 | if ( defined($ex_db_type) ) { | ||
| 623 | $cache_name .= $ex_db_type; | ||
| 624 | } | ||
| 625 | |||
| 626 | # if not cached, retrieve all of the xrefs for this translation | ||
| 627 | if ( !defined( $self->{$cache_name} ) && defined( $self->adaptor() ) ) | ||
| 628 | { | ||
| 629 | $self->{$cache_name} = | ||
| 630 | $self->adaptor()->db()->get_DBEntryAdaptor() | ||
| 631 | ->fetch_all_by_Translation( $self, $ex_db_exp, $ex_db_type ); | ||
| 632 | } | ||
| 633 | |||
| 634 | $self->{$cache_name} ||= []; | ||
| 635 | |||
| 636 | return $self->{$cache_name}; | ||
| 637 | } ## end sub get_all_DBEntries | ||
| 638 | |||
| 639 | =head2 get_all_object_xrefs | ||
| 640 | |||
| 641 | Arg [1] : (optional) String, external database name | ||
| 642 | |||
| 643 | Arg [2] : (optional) String, external_db type | ||
| 644 | |||
| 645 | Example : @oxrefs = @{ $translation->get_all_object_xrefs() }; | ||
| 646 | |||
| 647 | Description: Retrieves xrefs for this translation. | ||
| 648 | |||
| 649 | This method will attempt to lazy-load xrefs from a | ||
| 650 | database if an adaptor is available and no xrefs | ||
| 651 | are present on the translation (i.e. they have not | ||
| 652 | already been added or loaded). | ||
| 653 | |||
| 654 | NB: This method is an alias for the | ||
| 655 | get_all_DBentries() method. | ||
| 656 | |||
| 657 | Return type: Listref of Bio::EnsEMBL::DBEntry objects | ||
| 658 | |||
| 659 | Status : Stable | ||
| 660 | |||
| 661 | =cut | ||
| 662 | |||
| 663 | sub get_all_object_xrefs { | ||
| 664 | my $self = shift; | ||
| 665 | return $self->get_all_DBEntries(@_); | ||
| 666 | } | ||
| 667 | |||
| 668 | =head2 add_DBEntry | ||
| 669 | |||
| 670 | Arg [1] : Bio::EnsEMBL::DBEntry $dbe | ||
| 671 | The dbEntry to be added | ||
| 672 | Example : $translation->add_DBEntry($xref); | ||
| 673 | Description: Associates a DBEntry with this translation. Note that adding | ||
| 674 | DBEntries will prevent future lazy-loading of DBEntries for this | ||
| 675 | translation (see get_all_DBEntries). | ||
| 676 | Returntype : none | ||
| 677 | Exceptions : thrown on incorrect argument type | ||
| 678 | Caller : general | ||
| 679 | Status : Stable | ||
| 680 | |||
| 681 | =cut | ||
| 682 | |||
| 683 | sub add_DBEntry { | ||
| 684 | my $self = shift; | ||
| 685 | my $dbe = shift; | ||
| 686 | |||
| 687 | unless($dbe && ref($dbe) && $dbe->isa('Bio::EnsEMBL::DBEntry')) { | ||
| 688 | throw('Expected DBEntry argument'); | ||
| 689 | } | ||
| 690 | |||
| 691 | $self->{'dbentries'} ||= []; | ||
| 692 | push @{$self->{'dbentries'}}, $dbe; | ||
| 693 | } | ||
| 694 | |||
| 695 | |||
| 696 | =head2 get_all_DBLinks | ||
| 697 | |||
| 698 | Arg [1] : String database name (optional) | ||
| 699 | SQL wildcard characters (_ and %) can be used to | ||
| 700 | specify patterns. | ||
| 701 | |||
| 702 | Arg [2] : (optional) String, external database type, can be one of | ||
| 703 | ('ARRAY','ALT_TRANS','ALT_GENE','MISC','LIT','PRIMARY_DB_SYNONYM','ENSEMBL'), | ||
| 704 | SQL wildcard characters (_ and %) can be used to | ||
| 705 | specify patterns. | ||
| 706 | |||
| 707 | Example : my @dblinks = @{ $translation->get_all_DBLinks() }; | ||
| 708 | @dblinks = @{ $translation->get_all_DBLinks('Uniprot%') }; | ||
| 709 | @dblinks = @{ $translation->get_all_DBLinks('%', 'ENSEMBL') }; | ||
| 710 | |||
| 711 | Description: This is here for consistancy with the Transcript | ||
| 712 | and Gene classes. It is a synonym for the | ||
| 713 | get_all_DBEntries() method. | ||
| 714 | |||
| 715 | Return type: Listref to Bio::EnsEMBL::DBEntry objects | ||
| 716 | Exceptions : none | ||
| 717 | Caller : general | ||
| 718 | Status : Stable | ||
| 719 | |||
| 720 | =cut | ||
| 721 | |||
| 722 | sub get_all_DBLinks { | ||
| 723 | my $self = shift; | ||
| 724 | return $self->get_all_DBEntries(@_); | ||
| 725 | } | ||
| 726 | |||
| 727 | =head2 get_all_xrefs | ||
| 728 | |||
| 729 | Arg [1] : String database name (optional) | ||
| 730 | SQL wildcard characters (_ and %) can be used to | ||
| 731 | specify patterns. | ||
| 732 | |||
| 733 | Example : @xrefs = @{ $translation->get_all_xrefs() }; | ||
| 734 | @xrefs = @{ $translation->get_all_xrefs('Uniprot%') }; | ||
| 735 | |||
| 736 | Description: This method is here for consistancy with the Gene | ||
| 737 | and Transcript classes. It is an alias for the | ||
| 738 | get_all_DBLinks() method, which in turn directly | ||
| 739 | calls get_all_DBEntries(). | ||
| 740 | |||
| 741 | Return type: Listref of Bio::EnsEMBL::DBEntry objects | ||
| 742 | |||
| 743 | Status : Stable | ||
| 744 | |||
| 745 | =cut | ||
| 746 | |||
| 747 | sub get_all_xrefs { | ||
| 748 | my $self = shift; | ||
| 749 | return $self->get_all_DBLinks(@_); | ||
| 750 | } | ||
| 751 | |||
| 752 | =head2 get_all_ProteinFeatures | ||
| 753 | |||
| 754 | Arg [1] : (optional) string $logic_name | ||
| 755 | The analysis logic_name of the features to retrieve. If not | ||
| 756 | specified, all features are retrieved instead. | ||
| 757 | If no logic_name is found, looking for analysis db name instead. | ||
| 758 | Example : $features = $self->get_all_ProteinFeatures('PFam'); | ||
| 759 | Description: Retrieves all ProteinFeatures associated with this | ||
| 760 | Translation. If a logic_name is specified, only features with | ||
| 761 | that logic_name are returned. If no logic_name is provided all | ||
| 762 | associated protein_features are returned. | ||
| 763 | |||
| 764 | ProteinFeatures are lazy-loaded from the database unless they | ||
| 765 | added manually to the Translation or had already been loaded. | ||
| 766 | Returntype : Listref of Bio::EnsEMBL::ProteinFeature | ||
| 767 | Exceptions : none | ||
| 768 | Caller : general | ||
| 769 | Status : Stable | ||
| 770 | |||
| 771 | =cut | ||
| 772 | |||
| 773 | sub get_all_ProteinFeatures { | ||
| 774 | my $self = shift; | ||
| 775 | my $logic_name = shift; | ||
| 776 | |||
| 777 | my (%hash, %db_hash); | ||
| 778 | my $no_pf = 0; | ||
| 779 | |||
| 780 | if(!$self->{'protein_features'}) { | ||
| 781 | $no_pf = 1; | ||
| 782 | my $adaptor = $self->adaptor(); | ||
| 783 | my $dbID = $self->dbID(); | ||
| 784 | |||
| 785 | return [] if (!$adaptor || !$dbID); | ||
| 786 | |||
| 787 | $self->{'protein_features'} = \%hash; | ||
| 788 | |||
| 789 | my $pfa = $adaptor->db()->get_ProteinFeatureAdaptor(); | ||
| 790 | my ($name, $ana_db); | ||
| 791 | foreach my $f (@{$pfa->fetch_all_by_translation_id($dbID)}) { | ||
| 792 | my $analysis = $f->analysis(); | ||
| 793 | if($analysis) { | ||
| 794 | $name = lc($f->analysis->logic_name()); | ||
| 795 | $ana_db = lc($f->analysis->db()); | ||
| 796 | $db_hash{$ana_db} = $name; | ||
| 797 | } else { | ||
| 798 | warning("ProteinFeature has no attached analysis\n"); | ||
| 799 | $name = ''; | ||
| 800 | } | ||
| 801 | $hash{$name} ||= []; | ||
| 802 | push @{$hash{$name}}, $f; | ||
| 803 | } | ||
| 804 | } | ||
| 805 | |||
| 806 | # a specific type of protein feature was requested | ||
| 807 | if(defined($logic_name)) { | ||
| 808 | $logic_name = lc($logic_name); | ||
| 809 | if (!$hash{$logic_name} && $no_pf) { | ||
| 810 | $logic_name = $db_hash{$logic_name}; | ||
| 811 | } | ||
| 812 | return $self->{'protein_features'}->{$logic_name} || []; | ||
| 813 | } | ||
| 814 | |||
| 815 | my @features = (); | ||
| 816 | |||
| 817 | # all protein features were requested | ||
| 818 | foreach my $type (keys %{$self->{'protein_features'}}) { | ||
| 819 | push @features, @{$self->{'protein_features'}->{$type}}; | ||
| 820 | } | ||
| 821 | |||
| 822 | return \@features; | ||
| 823 | } | ||
| 824 | |||
| 825 | |||
| 826 | =head2 get_all_DomainFeatures | ||
| 827 | |||
| 828 | Example : @domain_feats = @{$translation->get_all_DomainFeatures}; | ||
| 829 | Description: A convenience method which retrieves all protein features | ||
| 830 | that are considered to be 'Domain' features. Features which | ||
| 831 | are 'domain' features are those with analysis logic names: | ||
| 832 | 'pfscan', 'scanprosite', 'superfamily', 'pfam', 'prints', | ||
| 833 | 'smart', 'pirsf', 'tigrfam'. | ||
| 834 | Returntype : listref of Bio::EnsEMBL::ProteinFeature | ||
| 835 | Exceptions : none | ||
| 836 | Caller : webcode (protview) | ||
| 837 | Status : Stable | ||
| 838 | |||
| 839 | =cut | ||
| 840 | |||
| 841 | sub get_all_DomainFeatures{ | ||
| 842 | my ($self) = @_; | ||
| 843 | |||
| 844 | my @features; | ||
| 845 | |||
| 846 | my @types = ('pfscan', #profile (prosite or pfam motifs) | ||
| 847 | 'scanprosite', #prosite | ||
| 848 | 'superfamily', | ||
| 849 | 'pfam', | ||
| 850 | 'smart', | ||
| 851 | 'tigrfam', | ||
| 852 | 'pirsf', | ||
| 853 | 'prints'); | ||
| 854 | |||
| 855 | foreach my $type (@types) { | ||
| 856 | push @features, @{$self->get_all_ProteinFeatures($type)}; | ||
| 857 | } | ||
| 858 | |||
| 859 | return \@features; | ||
| 860 | } | ||
| 861 | |||
| 862 | |||
| 863 | =head2 add_ProteinFeature | ||
| 864 | |||
| 865 | Arg [1] : Bio::EnsEMBL::ProteinFeature $pf | ||
| 866 | The ProteinFeature to be added | ||
| 867 | Example : $translation->add_ProteinFeature($pf); | ||
| 868 | Description: Associates a ProteinFeature with this translation. Note that | ||
| 869 | adding ProteinFeatures will prevent future lazy-loading of | ||
| 870 | ProteinFeatures for this translation (see | ||
| 871 | get_all_ProteinFeatures). | ||
| 872 | Returntype : none | ||
| 873 | Exceptions : thrown on incorrect argument type | ||
| 874 | Caller : general | ||
| 875 | Status : Stable | ||
| 876 | |||
| 877 | =cut | ||
| 878 | |||
| 879 | sub add_ProteinFeature { | ||
| 880 | my $self = shift; | ||
| 881 | my $pf = shift; | ||
| 882 | |||
| 883 | unless ($pf && ref($pf) && $pf->isa('Bio::EnsEMBL::ProteinFeature')) { | ||
| 884 | throw('Expected ProteinFeature argument'); | ||
| 885 | } | ||
| 886 | |||
| 887 | my $analysis = $pf->analysis; | ||
| 888 | throw("ProteinFeature has no attached Analysis.") unless $analysis; | ||
| 889 | |||
| 890 | push @{ $self->{'protein_features'}->{$analysis->logic_name} }, $pf; | ||
| 891 | } | ||
| 892 | |||
| 893 | |||
| 894 | =head2 display_id | ||
| 895 | |||
| 896 | Example : print $translation->display_id(); | ||
| 897 | Description: This method returns a string that is considered to be | ||
| 898 | the 'display' identifier. For translations this is (depending on | ||
| 899 | availability and in this order) the stable Id, the dbID or an | ||
| 900 | empty string. | ||
| 901 | Returntype : string | ||
| 902 | Exceptions : none | ||
| 903 | Caller : web drawing code | ||
| 904 | Status : Stable | ||
| 905 | |||
| 906 | =cut | ||
| 907 | |||
| 908 | sub display_id { | ||
| 909 | my $self = shift; | ||
| 910 | return $self->{'stable_id'} || $self->dbID || ''; | ||
| 911 | } | ||
| 912 | |||
| 913 | |||
| 914 | =head2 length | ||
| 915 | |||
| 916 | Example : print "Peptide length =", $translation->length(); | ||
| 917 | Description: Retrieves the length of the peptide sequence (i.e. number of | ||
| 918 | amino acids) represented by this Translation object. | ||
| 919 | Returntype : int | ||
| 920 | Exceptions : none | ||
| 921 | Caller : webcode (protview etc.) | ||
| 922 | Status : Stable | ||
| 923 | |||
| 924 | =cut | ||
| 925 | |||
| 926 | sub length { | ||
| 927 | my $self = shift; | ||
| 928 | my $seq = $self->seq(); | ||
| 929 | |||
| 930 | return ($seq) ? CORE::length($seq) : 0; | ||
| 931 | } | ||
| 932 | |||
| 933 | |||
| 934 | =head2 seq | ||
| 935 | |||
| 936 | Example : print $translation->seq(); | ||
| 937 | Description: Retrieves a string representation of the peptide sequence | ||
| 938 | of this Translation. This retrieves the transcript from the | ||
| 939 | database and gets its sequence, or retrieves the sequence which | ||
| 940 | was set via the constructor. | ||
| 941 | Returntype : string | ||
| 942 | Exceptions : warning if the sequence is not set and cannot be retrieved from | ||
| 943 | the database. | ||
| 944 | Caller : webcode (protview etc.) | ||
| 945 | Status : Stable | ||
| 946 | |||
| 947 | =cut | ||
| 948 | |||
| 949 | sub seq { | ||
| 950 | my ( $self, $sequence ) = @_; | ||
| 951 | |||
| 952 | if ( defined($sequence) ) { | ||
| 953 | |||
| 954 | $self->{'seq'} = $sequence; | ||
| 955 | |||
| 956 | } elsif ( !defined( $self->{'seq'} ) ) { | ||
| 957 | |||
| 958 | my $transcript = $self->transcript(); | ||
| 959 | |||
| 960 | my $canonical_translation = $transcript->translation(); | ||
| 961 | my $is_alternative; | ||
| 962 | if(!$canonical_translation) { | ||
| 963 | throw "Transcript does not have a canonical translation"; | ||
| 964 | } | ||
| 965 | if ( defined( $canonical_translation->stable_id() ) | ||
| 966 | && defined( $self->stable_id() ) ) | ||
| 967 | { | ||
| 968 | # Try stable ID. | ||
| 969 | $is_alternative = | ||
| 970 | ( $canonical_translation->stable_id() ne $self->stable_id() ); | ||
| 971 | } elsif ( defined( $canonical_translation->dbID() ) | ||
| 972 | && defined( $self->dbID() ) ) | ||
| 973 | { | ||
| 974 | # Try dbID. | ||
| 975 | $is_alternative = | ||
| 976 | ( $canonical_translation->dbID() != $self->dbID() ); | ||
| 977 | } else { | ||
| 978 | # Resort to using geomic start/end coordinates. | ||
| 979 | $is_alternative = ( ($canonical_translation->genomic_start() != | ||
| 980 | $self->genomic_start() ) | ||
| 981 | || ( $canonical_translation->genomic_end() != | ||
| 982 | $self->genomic_end() ) ); | ||
| 983 | } | ||
| 984 | |||
| 985 | if ($is_alternative) { | ||
| 986 | # To deal with non-canonical (alternative) translations, subsitute | ||
| 987 | # the canonical translation in the transcript with $self for a | ||
| 988 | # while. | ||
| 989 | |||
| 990 | $transcript->translation($self); | ||
| 991 | } | ||
| 992 | |||
| 993 | my $seq = $transcript->translate(); | ||
| 994 | if ( defined($seq) ) { | ||
| 995 | $self->{'seq'} = $seq->seq(); | ||
| 996 | } | ||
| 997 | |||
| 998 | if ($is_alternative) { | ||
| 999 | # Reinstate the real canonical translation. | ||
| 1000 | |||
| 1001 | $transcript->translation($canonical_translation); | ||
| 1002 | } | ||
| 1003 | |||
| 1004 | } ## end elsif ( !defined( $self->...)) | ||
| 1005 | |||
| 1006 | if ( !defined( $self->{'seq'} ) ) { | ||
| 1007 | return ''; # Empty string | ||
| 1008 | } | ||
| 1009 | |||
| 1010 | return $self->{'seq'}; | ||
| 1011 | |||
| 1012 | } ## end sub seq | ||
| 1013 | |||
| 1014 | |||
| 1015 | =head2 get_all_Attributes | ||
| 1016 | |||
| 1017 | Arg [1] : optional string $attrib_code | ||
| 1018 | The code of the attribute type to retrieve values for. | ||
| 1019 | Example : ($sc_attr) = @{$tl->get_all_Attributes('_selenocysteine')}; | ||
| 1020 | @tl_attributes = @{$translation->get_all_Attributes()}; | ||
| 1021 | Description: Gets a list of Attributes of this translation. | ||
| 1022 | Optionally just get Attrubutes for given code. | ||
| 1023 | Recognized attribute "_selenocysteine" | ||
| 1024 | Returntype : listref Bio::EnsEMBL::Attribute | ||
| 1025 | Exceptions : warning if translation does not have attached adaptor and | ||
| 1026 | attempts lazy load. | ||
| 1027 | Caller : general, modify_translation | ||
| 1028 | Status : Stable | ||
| 1029 | |||
| 1030 | =cut | ||
| 1031 | |||
| 1032 | sub get_all_Attributes { | ||
| 1033 | my $self = shift; | ||
| 1034 | my $attrib_code = shift; | ||
| 1035 | |||
| 1036 | if( ! exists $self->{'attributes' } ) { | ||
| 1037 | if(!$self->adaptor() ) { | ||
| 1038 | # warning('Cannot get attributes without an adaptor.'); | ||
| 1039 | return []; | ||
| 1040 | } | ||
| 1041 | |||
| 1042 | my $aa = $self->adaptor->db->get_AttributeAdaptor(); | ||
| 1043 | $self->{'attributes'} = $aa->fetch_all_by_Translation( $self ); | ||
| 1044 | } | ||
| 1045 | |||
| 1046 | if( defined $attrib_code ) { | ||
| 1047 | my @results = grep { uc($_->code()) eq uc($attrib_code) } | ||
| 1048 | @{$self->{'attributes'}}; | ||
| 1049 | return \@results; | ||
| 1050 | } else { | ||
| 1051 | return $self->{'attributes'}; | ||
| 1052 | } | ||
| 1053 | } | ||
| 1054 | |||
| 1055 | |||
| 1056 | =head2 add_Attributes | ||
| 1057 | |||
| 1058 | Arg [1..N] : Bio::EnsEMBL::Attribute $attribute | ||
| 1059 | Attributes to add. | ||
| 1060 | Example : $translation->add_Attributes($selenocysteine_attribute); | ||
| 1061 | Description: Adds an Attribute to the Translation. Usefull to | ||
| 1062 | do _selenocysteine. | ||
| 1063 | If you add an attribute before you retrieve any from database, | ||
| 1064 | lazy load will be disabled. | ||
| 1065 | Returntype : none | ||
| 1066 | Exceptions : throw on incorrect arguments | ||
| 1067 | Caller : general | ||
| 1068 | Status : Stable | ||
| 1069 | |||
| 1070 | =cut | ||
| 1071 | |||
| 1072 | sub add_Attributes { | ||
| 1073 | my $self = shift; | ||
| 1074 | my @attribs = @_; | ||
| 1075 | |||
| 1076 | if( ! exists $self->{'attributes'} ) { | ||
| 1077 | $self->{'attributes'} = []; | ||
| 1078 | } | ||
| 1079 | |||
| 1080 | for my $attrib ( @attribs ) { | ||
| 1081 | if( ! $attrib->isa( "Bio::EnsEMBL::Attribute" )) { | ||
| 1082 | throw( "Argument to add_Attribute must be a Bio::EnsEMBL::Attribute" ); | ||
| 1083 | } | ||
| 1084 | push( @{$self->{'attributes'}}, $attrib ); | ||
| 1085 | $self->{seq}=undef; | ||
| 1086 | } | ||
| 1087 | } | ||
| 1088 | |||
| 1089 | |||
| 1090 | =head2 get_all_SeqEdits | ||
| 1091 | |||
| 1092 | Arg [1] : ArrayRef $edits. Specify the name of the edits to fetch | ||
| 1093 | Example : my @seqeds = @{$translation->get_all_SeqEdits()}; | ||
| 1094 | my @seqeds = @{$translation->get_all_SeqEdits('_selenocysteine')}; | ||
| 1095 | Description: Retrieves all post transcriptional sequence modifications for | ||
| 1096 | this translation. | ||
| 1097 | Returntype : Bio::EnsEMBL::SeqEdit | ||
| 1098 | Exceptions : none | ||
| 1099 | Caller : spliced_seq() | ||
| 1100 | Status : Stable | ||
| 1101 | |||
| 1102 | =cut | ||
| 1103 | |||
| 1104 | sub get_all_SeqEdits { | ||
| 1105 | my $self = shift; | ||
| 1106 | my $edits = shift; | ||
| 1107 | |||
| 1108 | my @seqeds; | ||
| 1109 | |||
| 1110 | my $attribs; | ||
| 1111 | |||
| 1112 | $edits ||= ['initial_met', '_selenocysteine', 'amino_acid_sub', '_stop_codon_rt']; | ||
| 1113 | |||
| 1114 | |||
| 1115 | foreach my $edit(@{wrap_array($edits)}){ | ||
| 1116 | $attribs = $self->get_all_Attributes($edit); | ||
| 1117 | |||
| 1118 | # convert attributes to SeqEdit objects | ||
| 1119 | foreach my $a (@$attribs) { | ||
| 1120 | push @seqeds, Bio::EnsEMBL::SeqEdit->new(-ATTRIB => $a); | ||
| 1121 | } | ||
| 1122 | } | ||
| 1123 | return \@seqeds; | ||
| 1124 | } | ||
| 1125 | |||
| 1126 | =head2 get_all_selenocysteine_SeqEdits | ||
| 1127 | |||
| 1128 | Example : my @edits = @{$translation->get_all_selenocysteine_SeqEdits()}; | ||
| 1129 | Description: Retrieves all post transcriptional sequence modifications related | ||
| 1130 | to selenocysteine PTMs | ||
| 1131 | Returntype : Bio::EnsEMBL::SeqEdit | ||
| 1132 | Exceptions : none | ||
| 1133 | |||
| 1134 | =cut | ||
| 1135 | |||
| 1136 | sub get_all_selenocysteine_SeqEdits { | ||
| 1137 | my ($self) = @_; | ||
| 1138 | return $self->get_all_SeqEdits(['_selenocysteine']); | ||
| 1139 | } | ||
| 1140 | |||
| 1141 | =head2 get_all_stop_codon_SeqEdits | ||
| 1142 | |||
| 1143 | Example : my @edits = @{$translation->get_all_stop_codon_SeqEdits()}; | ||
| 1144 | Description: Retrieves all post transcriptional sequence modifications related | ||
| 1145 | to stop codon readthrough | ||
| 1146 | Returntype : Bio::EnsEMBL::SeqEdit | ||
| 1147 | Exceptions : none | ||
| 1148 | |||
| 1149 | =cut | ||
| 1150 | |||
| 1151 | sub get_all_stop_codon_SeqEdits { | ||
| 1152 | my ($self) = @_; | ||
| 1153 | return $self->get_all_SeqEdits(['_stop_codon_rt']); | ||
| 1154 | } | ||
| 1155 | |||
| 1156 | =head2 modify_translation | ||
| 1157 | |||
| 1158 | Arg [1] : Bio::Seq $peptide | ||
| 1159 | Example : my $seq = Bio::Seq->new(-SEQ => $dna)->translate(); | ||
| 1160 | $translation->modify_translation($seq); | ||
| 1161 | Description: Applies sequence edits such as selenocysteines to the Bio::Seq | ||
| 1162 | peptide thats passed in | ||
| 1163 | Returntype : Bio::Seq | ||
| 1164 | Exceptions : none | ||
| 1165 | Caller : Bio::EnsEMBL::Transcript->translate | ||
| 1166 | Status : Stable | ||
| 1167 | |||
| 1168 | =cut | ||
| 1169 | |||
| 1170 | sub modify_translation { | ||
| 1171 | my ( $self, $seq ) = @_; | ||
| 1172 | |||
| 1173 | my @seqeds = @{ $self->get_all_SeqEdits() }; | ||
| 1174 | |||
| 1175 | # Sort in reverse order to avoid complication of adjusting | ||
| 1176 | # downstream edits. | ||
| 1177 | # HACK: The translation ENSP00000420939 somehow makes the next line | ||
| 1178 | # bomb out ($a or $b becomes undef) if the start() method | ||
| 1179 | # is used. I haven't been able to find out why. It has 10 | ||
| 1180 | # Selenocysteine seqedits that looks correct. | ||
| 1181 | # /Andreas (release 59) | ||
| 1182 | @seqeds = sort { $b->{'start'} <=> $a->{'start'} } @seqeds; | ||
| 1183 | |||
| 1184 | # Apply all edits. | ||
| 1185 | my $peptide = $seq->seq(); | ||
| 1186 | foreach my $se (@seqeds) { | ||
| 1187 | $se->apply_edit( \$peptide ); | ||
| 1188 | } | ||
| 1189 | |||
| 1190 | $seq->seq($peptide); | ||
| 1191 | |||
| 1192 | return $seq; | ||
| 1193 | } | ||
| 1194 | |||
| 1195 | =head2 load | ||
| 1196 | |||
| 1197 | Arg [1] : Boolean $load_xrefs | ||
| 1198 | Load (or don't load) xrefs. Default is to load xrefs. | ||
| 1199 | Example : $translation->load(); | ||
| 1200 | Description : The Ensembl API makes extensive use of | ||
| 1201 | lazy-loading. Under some circumstances (e.g., | ||
| 1202 | when copying genes between databases), all data of | ||
| 1203 | an object needs to be fully loaded. This method | ||
| 1204 | loads the parts of the object that are usually | ||
| 1205 | lazy-loaded. | ||
| 1206 | Returns : none | ||
| 1207 | |||
| 1208 | =cut | ||
| 1209 | |||
| 1210 | sub load { | ||
| 1211 | my ( $self, $load_xrefs ) = @_; | ||
| 1212 | |||
| 1213 | if ( !defined($load_xrefs) ) { $load_xrefs = 1 } | ||
| 1214 | |||
| 1215 | $self->seq(); | ||
| 1216 | |||
| 1217 | $self->stable_id(); | ||
| 1218 | $self->get_all_Attributes(); | ||
| 1219 | $self->get_all_ProteinFeatures(); | ||
| 1220 | |||
| 1221 | if ($load_xrefs) { | ||
| 1222 | $self->get_all_DBEntries(); | ||
| 1223 | } | ||
| 1224 | } | ||
| 1225 | |||
| 1226 | |||
| 1227 | =head2 get_all_DASFactories | ||
| 1228 | |||
| 1229 | Function : Retrieves a listref of registered DAS objects | ||
| 1230 | Returntype: Listref of DAS Objects | ||
| 1231 | Exceptions: none | ||
| 1232 | Caller : webcode | ||
| 1233 | Example : $dasref = $prot->get_all_DASFactories; | ||
| 1234 | Status : Stable | ||
| 1235 | |||
| 1236 | =cut | ||
| 1237 | |||
| 1238 | sub get_all_DASFactories { | ||
| 1239 | my $self = shift; | ||
| 1240 | return [ $self->adaptor()->db()->_each_DASFeatureFactory ]; | ||
| 1241 | } | ||
| 1242 | |||
| 1243 | |||
| 1244 | =head2 get_all_DAS_Features | ||
| 1245 | |||
| 1246 | Example : $features = $prot->get_all_DAS_Features; | ||
| 1247 | Description: Retrieves a hash reference to a hash of DAS feature | ||
| 1248 | sets, keyed by the DNS, NOTE the values of this hash | ||
| 1249 | are an anonymous array containing: | ||
| 1250 | (1) a pointer to an array of features; | ||
| 1251 | (2) a pointer to the DAS stylesheet | ||
| 1252 | Returntype : hashref of Bio::SeqFeatures | ||
| 1253 | Exceptions : none | ||
| 1254 | Caller : webcode | ||
| 1255 | Status : Stable | ||
| 1256 | |||
| 1257 | =cut | ||
| 1258 | |||
| 1259 | sub get_all_DAS_Features{ | ||
| 1260 | my $self = shift; | ||
| 1261 | |||
| 1262 | my $db = $self->adaptor->db; | ||
| 1263 | my $GeneAdaptor = $db->get_GeneAdaptor; | ||
| 1264 | my $Gene = $GeneAdaptor->fetch_by_translation_stable_id($self->stable_id) || return; | ||
| 1265 | my $slice = $Gene->feature_Slice; | ||
| 1266 | |||
| 1267 | return $self->SUPER::get_all_DAS_Features($slice); | ||
| 1268 | } | ||
| 1269 | |||
| 1270 | =head2 summary_as_hash | ||
| 1271 | |||
| 1272 | Example : $translation_summary = $translation->summary_as_hash(); | ||
| 1273 | Description : Retrieves a textual summary of this Translation. | ||
| 1274 | Not inherited from Feature. | ||
| 1275 | Returns : hashref of arrays of descriptive strings | ||
| 1276 | Status : Intended for internal use | ||
| 1277 | =cut | ||
| 1278 | |||
| 1279 | sub summary_as_hash { | ||
| 1280 | my $self = shift; | ||
| 1281 | my %summary; | ||
| 1282 | my $id = $self->display_id; | ||
| 1283 | if ($self->version) { $id .= "." . $self->version; } | ||
| 1284 | $summary{'id'} = $id; | ||
| 1285 | $summary{'protein_id'} = $id; | ||
| 1286 | $summary{'genomic_start'} = $self->genomic_start; | ||
| 1287 | $summary{'genomic_end'} = $self->genomic_end; | ||
| 1288 | $summary{'length'} = $self->length; | ||
| 1289 | my $transcript = $self->transcript; | ||
| 1290 | $summary{'Parent'} = $transcript->display_id; | ||
| 1291 | return \%summary; | ||
| 1292 | } | ||
| 1293 | |||
| 1294 | 1; |