| 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::ArchiveStableId | ||
| 34 | |||
| 35 | =head1 DESCRIPTION | ||
| 36 | |||
| 37 | ArchiveStableId objects are the main workunit for retrieving stable id | ||
| 38 | archived information from EnsEMBL core database. | ||
| 39 | |||
| 40 | Attributes: | ||
| 41 | type: Gene, Transcript, Translation, Exon, other, undef | ||
| 42 | stable_id: eg. ENSG00000000001 | ||
| 43 | version: e.g. 1 | ||
| 44 | db_name: eg. homo_sapiens_core_12_31 | ||
| 45 | release: e.g. 35 | ||
| 46 | assembly: e.g. NCBI35 | ||
| 47 | successors: listref of Bio::EnsEMBL::ArchiveStableIds | ||
| 48 | adaptor: Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor | ||
| 49 | |||
| 50 | Status: At Risk. This module is in development. | ||
| 51 | |||
| 52 | =head1 SEE ALSO | ||
| 53 | |||
| 54 | Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor | ||
| 55 | Bio::EnsEMBL::StableIdEvent | ||
| 56 | Bio::EnsEMBL::StableIdHistoryTree | ||
| 57 | |||
| 58 | =cut | ||
| 59 | |||
| 60 | package Bio::EnsEMBL::ArchiveStableId; | ||
| 61 | $Bio::EnsEMBL::ArchiveStableId::VERSION = '114.0.0'; | ||
| 62 | use strict; | ||
| 63 | use warnings; | ||
| 64 | no warnings qw(uninitialized); | ||
| 65 | |||
| 66 | use Bio::EnsEMBL::Utils::Argument qw(rearrange); | ||
| 67 | use Scalar::Util qw(weaken isweak); | ||
| 68 | |||
| 69 | =head2 new | ||
| 70 | |||
| 71 | Arg [STABLE_ID] : String $stable_id | ||
| 72 | Arg [VERSION] : Int $version | ||
| 73 | Arg [CURRENT_VERSION]: Int $current_version | ||
| 74 | Arg [DB_NAME] : String $db_name | ||
| 75 | Arg [RELEASE] : String $release | ||
| 76 | Arg [ASSEMBLY_NAME] : String $assembly | ||
| 77 | Arg [TYPE] : String $type - "Gene", "Transcript", "Translation", "Exon" | ||
| 78 | Arg [ADAPTOR] : Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor $adaptor | ||
| 79 | Description : standard constructor with named arguments to create | ||
| 80 | ArchiveStableId | ||
| 81 | Returntype : Bio::EnsEMBL::ArchiveStableId | ||
| 82 | Exceptions : none | ||
| 83 | Caller : general, Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor | ||
| 84 | Status : At Risk | ||
| 85 | : under development | ||
| 86 | |||
| 87 | =cut | ||
| 88 | |||
| 89 | sub new { | ||
| 90 | my $class = shift; | ||
| 91 | $class = ref( $class ) || $class; | ||
| 92 | |||
| 93 | my $self = bless {}, $class; | ||
| 94 | |||
| 95 | my ($stable_id, $version, $current_version, $db_name, $release, $assembly, | ||
| 96 | $type, $adaptor) = rearrange([qw( STABLE_ID VERSION CURRENT_VERSION DB_NAME | ||
| 97 | RELEASE ASSEMBLY TYPE ADAPTOR)], @_ ); | ||
| 98 | |||
| 99 | $self->{'stable_id'} = $stable_id; | ||
| 100 | $self->{'version'} = $version; | ||
| 101 | $self->{'current_version'} = $current_version; | ||
| 102 | $self->{'db_name'} = $db_name; | ||
| 103 | $self->{'release'} = $release; | ||
| 104 | $self->{'assembly'} = $assembly; | ||
| 105 | $self->{'type'} = $type; | ||
| 106 | $self->adaptor($adaptor); | ||
| 107 | |||
| 108 | return $self; | ||
| 109 | } | ||
| 110 | |||
| 111 | |||
| 112 | =head2 new_fast | ||
| 113 | |||
| 114 | Arg [1] : String $stable_id | ||
| 115 | Arg [2] : Int $version | ||
| 116 | Arg [3] : String $db_name | ||
| 117 | Arg [4] : String $release | ||
| 118 | Arg [5] : String $assembly | ||
| 119 | Arg [6] : String $type - "Gene", "Transcript", "Translation", "Exon" | ||
| 120 | Arg [7] : Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor $adaptor | ||
| 121 | Arg [8] : Int $current_version | ||
| 122 | Description : faster version of above constructor | ||
| 123 | Returntype : Bio::EnsEMBL::ArchiveStableId | ||
| 124 | Exceptions : none | ||
| 125 | Caller : general, Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor | ||
| 126 | Status : At Risk | ||
| 127 | : under development | ||
| 128 | |||
| 129 | =cut | ||
| 130 | |||
| 131 | sub new_fast { | ||
| 132 | my $class = shift; | ||
| 133 | |||
| 134 | $class = ref ($class) || $class; | ||
| 135 | |||
| 136 | my $self = bless { | ||
| 137 | 'stable_id' => $_[0], | ||
| 138 | 'version' => $_[1], | ||
| 139 | 'db_name' => $_[2], | ||
| 140 | 'release' => $_[3], | ||
| 141 | 'assembly' => $_[4], | ||
| 142 | 'type' => $_[5], | ||
| 143 | 'adaptor' => $_[6], | ||
| 144 | 'current_version' => $_[7], | ||
| 145 | }, $class; | ||
| 146 | |||
| 147 | weaken($self->{adaptor}) if ( ! isweak($self->{adaptor}) ); | ||
| 148 | |||
| 149 | return $self; | ||
| 150 | } | ||
| 151 | |||
| 152 | |||
| 153 | =head2 get_history_tree | ||
| 154 | |||
| 155 | Arg[1] : (optional) Int $num_high_scorers | ||
| 156 | number of mappings per stable ID allowed when filtering | ||
| 157 | Arg[2] : (optional) Int $max_rows | ||
| 158 | maximum number of stable IDs in history tree (used for | ||
| 159 | filtering) | ||
| 160 | Example : my $history_tree = $archive_id->get_history_tree; | ||
| 161 | Description : Returns the history tree of this ArchiveStableId | ||
| 162 | Return type : Bio::EnsEMBL::StableIdHistoryTree | ||
| 163 | Exceptions : none | ||
| 164 | Caller : general | ||
| 165 | Status : At Risk | ||
| 166 | : under development | ||
| 167 | |||
| 168 | =cut | ||
| 169 | |||
| 170 | sub get_history_tree { | ||
| 171 | my ($self, $num_high_scorers, $max_rows) = @_; | ||
| 172 | |||
| 173 | unless ($self->{'history'}) { | ||
| 174 | $self->{'history'} = $self->adaptor->fetch_history_tree_by_stable_id( | ||
| 175 | $self->stable_id, $num_high_scorers, $max_rows); | ||
| 176 | } | ||
| 177 | |||
| 178 | return $self->{'history'}; | ||
| 179 | } | ||
| 180 | |||
| 181 | |||
| 182 | =head2 get_event | ||
| 183 | |||
| 184 | Args : stable_id | ||
| 185 | Description : Retrieve a specific event for this archive and a given stable id | ||
| 186 | Returntype : listref of Bio::EnsEMBL::StableIdEvent | ||
| 187 | Exceptions : none | ||
| 188 | Caller : general | ||
| 189 | Status : At Risk | ||
| 190 | : under development | ||
| 191 | |||
| 192 | =cut | ||
| 193 | |||
| 194 | sub get_event { | ||
| 195 | my ($self, $stable_id) = @_; | ||
| 196 | |||
| 197 | my $event = $self->adaptor->fetch_stable_id_event($self, $stable_id); | ||
| 198 | |||
| 199 | return $event; | ||
| 200 | } | ||
| 201 | |||
| 202 | |||
| 203 | =head2 get_all_predecessors | ||
| 204 | |||
| 205 | Args : none | ||
| 206 | Description : Retrieve a list of ArchiveStableIds that were mapped to this | ||
| 207 | one. | ||
| 208 | Returntype : listref of Bio::EnsEMBL::ArchiveStableId | ||
| 209 | Exceptions : none | ||
| 210 | Caller : general | ||
| 211 | Status : At Risk | ||
| 212 | : under development | ||
| 213 | |||
| 214 | =cut | ||
| 215 | |||
| 216 | sub get_all_predecessors { | ||
| 217 | my $self = shift; | ||
| 218 | |||
| 219 | my $predecessors = $self->adaptor->fetch_predecessors_by_archive_id($self); | ||
| 220 | |||
| 221 | foreach my $pre (@$predecessors) { | ||
| 222 | $pre->successors($self); | ||
| 223 | } | ||
| 224 | |||
| 225 | return $predecessors; | ||
| 226 | } | ||
| 227 | |||
| 228 | |||
| 229 | =head2 get_all_successors | ||
| 230 | |||
| 231 | Args : none | ||
| 232 | Description : Retrieve a list of ArchiveStableIds that this one was mapped to. | ||
| 233 | Returntype : listref Bio::EnsEMBL::ArchiveStableId | ||
| 234 | Exceptions : none | ||
| 235 | Caller : general | ||
| 236 | Status : At Risk | ||
| 237 | : under development | ||
| 238 | |||
| 239 | =cut | ||
| 240 | |||
| 241 | sub get_all_successors { | ||
| 242 | my $self = shift; | ||
| 243 | |||
| 244 | if ($self->{'successors'}) { | ||
| 245 | return $self->{'successors'}; | ||
| 246 | } else { | ||
| 247 | my $successors = $self->adaptor->fetch_successors_by_archive_id($self); | ||
| 248 | return $self->successors(@$successors); | ||
| 249 | } | ||
| 250 | } | ||
| 251 | |||
| 252 | |||
| 253 | =head2 get_peptide | ||
| 254 | |||
| 255 | Description : Retrieves the peptide string for this ArchiveStableId. | ||
| 256 | Returntype : String, or undef if this is not a Translation or cant be found | ||
| 257 | in the database. | ||
| 258 | Exceptions : none | ||
| 259 | Caller : general | ||
| 260 | Status : At Risk | ||
| 261 | : under development | ||
| 262 | |||
| 263 | =cut | ||
| 264 | |||
| 265 | sub get_peptide { | ||
| 266 | my $self = shift; | ||
| 267 | |||
| 268 | if ( lc( $self->type() ) eq 'translation' ) { | ||
| 269 | return $self->adaptor->get_peptide($self); | ||
| 270 | } else { | ||
| 271 | return undef; | ||
| 272 | } | ||
| 273 | } | ||
| 274 | |||
| 275 | |||
| 276 | =head2 get_all_associated_archived | ||
| 277 | |||
| 278 | Example : my ($arch_gene, $arch_tr, $arch_tl, $pep_seq) = | ||
| 279 | @{ $arch_id->get_all_associated_archived }; | ||
| 280 | Description : Fetches associated archived stable IDs from the db for this | ||
| 281 | ArchiveStableId (version is taken into account). | ||
| 282 | Return type : Listref of | ||
| 283 | ArchiveStableId archived gene | ||
| 284 | ArchiveStableId archived transcript | ||
| 285 | (optional) ArchiveStableId archived translation | ||
| 286 | (optional) peptide sequence | ||
| 287 | Caller : webcode, general | ||
| 288 | Status : At Risk | ||
| 289 | : under development | ||
| 290 | |||
| 291 | =cut | ||
| 292 | |||
| 293 | sub get_all_associated_archived { | ||
| 294 | my $self = shift; | ||
| 295 | return $self->adaptor->fetch_associated_archived($self); | ||
| 296 | } | ||
| 297 | |||
| 298 | |||
| 299 | =head2 get_all_gene_archive_ids | ||
| 300 | |||
| 301 | Example : my @archived_genes = @{ $arch_id->get_all_gene_archive_ids }; | ||
| 302 | Description : Returns gene ArchiveStableIds associated with this | ||
| 303 | ArchiveStableId. If this is a gene, it returns itself. | ||
| 304 | Returntype : listref of Bio::EnsEMBL::ArchiveStableId | ||
| 305 | Exceptions : none | ||
| 306 | Caller : general | ||
| 307 | Status : At Risk | ||
| 308 | : under development | ||
| 309 | |||
| 310 | =cut | ||
| 311 | |||
| 312 | sub get_all_gene_archive_ids { | ||
| 313 | my $self = shift; | ||
| 314 | |||
| 315 | if ($self->type eq "Gene") { | ||
| 316 | return [$self]; | ||
| 317 | } else { | ||
| 318 | return $self->adaptor->fetch_all_by_archive_id($self, 'Gene'); | ||
| 319 | } | ||
| 320 | } | ||
| 321 | |||
| 322 | |||
| 323 | =head2 get_all_transcript_archive_ids | ||
| 324 | |||
| 325 | Example : my @archived_transcripts = | ||
| 326 | @{ $arch_id->get_all_transcript_archive_ids }; | ||
| 327 | Description : Returns transcript ArchiveStableIds associated with this | ||
| 328 | ArchiveStableId. If this is a transcript, it returns itself. | ||
| 329 | Returntype : listref of Bio::EnsEMBL::ArchiveStableId | ||
| 330 | Exceptions : none | ||
| 331 | Caller : general | ||
| 332 | Status : At Risk | ||
| 333 | : under development | ||
| 334 | |||
| 335 | =cut | ||
| 336 | |||
| 337 | sub get_all_transcript_archive_ids { | ||
| 338 | my $self = shift; | ||
| 339 | |||
| 340 | if ($self->type eq "Transcript") { | ||
| 341 | return [$self]; | ||
| 342 | } else { | ||
| 343 | return $self->adaptor->fetch_all_by_archive_id($self, 'Transcript'); | ||
| 344 | } | ||
| 345 | } | ||
| 346 | |||
| 347 | |||
| 348 | =head2 get_all_translation_archive_ids | ||
| 349 | |||
| 350 | Example : my @archived_peptides = | ||
| 351 | @{ $arch_id->get_all_translation_archive_ids }; | ||
| 352 | Description : Returns translation ArchiveStableIds associated with this | ||
| 353 | ArchiveStableId. If this is a translation, it returns itself. | ||
| 354 | Returntype : listref of Bio::EnsEMBL::ArchiveStableId | ||
| 355 | Exceptions : none | ||
| 356 | Caller : general | ||
| 357 | Status : At Risk | ||
| 358 | : under development | ||
| 359 | |||
| 360 | =cut | ||
| 361 | |||
| 362 | sub get_all_translation_archive_ids { | ||
| 363 | my $self = shift; | ||
| 364 | |||
| 365 | if ($self->type eq "Translation") { | ||
| 366 | return [$self]; | ||
| 367 | } else { | ||
| 368 | return $self->adaptor->fetch_all_by_archive_id($self, 'Translation'); | ||
| 369 | } | ||
| 370 | } | ||
| 371 | |||
| 372 | |||
| 373 | =head2 current_version | ||
| 374 | |||
| 375 | Example : if (my $v = $arch_id->current_version) { | ||
| 376 | print "Current version of this stable ID ", $v, "\n"; | ||
| 377 | } else { | ||
| 378 | print "This stable ID is not in the current db.\n"; | ||
| 379 | } | ||
| 380 | Description : Lazy-loads the current version of stable ID | ||
| 381 | Return type : Boolean (TRUE is current version found, else FALSE) | ||
| 382 | Exceptions : none | ||
| 383 | Caller : general | ||
| 384 | Status : At Risk | ||
| 385 | : under development | ||
| 386 | |||
| 387 | =cut | ||
| 388 | |||
| 389 | sub current_version { | ||
| 390 | my $self = shift; | ||
| 391 | |||
| 392 | if (@_) { | ||
| 393 | $self->{'current_version'} = shift; | ||
| 394 | } elsif (! defined $self->{'current_version'}) { | ||
| 395 | if (defined $self->adaptor()) { | ||
| 396 | # lazy load | ||
| 397 | $self->adaptor()->lookup_current($self); | ||
| 398 | } | ||
| 399 | } | ||
| 400 | |||
| 401 | return $self->{'current_version'}; | ||
| 402 | } | ||
| 403 | |||
| 404 | |||
| 405 | =head2 is_current | ||
| 406 | |||
| 407 | Example : if ($arch_id->is_current) { | ||
| 408 | print $arch_id->version, " is the current version of this | ||
| 409 | stable ID.\n"; | ||
| 410 | } | ||
| 411 | Description : Determines if the version of this object is the current version | ||
| 412 | of this stable ID. Note that this method doesn't lazy-load the | ||
| 413 | current version of an ArchiveStableId; if you want to be sure, | ||
| 414 | use current_version() instead. | ||
| 415 | Return type : Boolean (TRUE if it is current, else FALSE) | ||
| 416 | Exceptions : none | ||
| 417 | Caller : general | ||
| 418 | Status : At Risk | ||
| 419 | : under development | ||
| 420 | |||
| 421 | =cut | ||
| 422 | |||
| 423 | sub is_current { | ||
| 424 | my $self = shift; | ||
| 425 | return ($self->{'version'} == $self->{'current_version'}); | ||
| 426 | } | ||
| 427 | |||
| 428 | |||
| 429 | =head2 get_latest_incarnation | ||
| 430 | |||
| 431 | Example : my $latest = $arch_id->get_latest_incarnation; | ||
| 432 | print "Latest version of ".$arch_id->stable_id." is ". | ||
| 433 | $latest->version."\n"; | ||
| 434 | Description : Returns the ArchiveStableId representing the latest version | ||
| 435 | of this stable ID. Returns itself if this already is the latest | ||
| 436 | version, otherwise fetches it from the db. | ||
| 437 | Return type : Bio::EnsEMBL::ArchiveStableId | ||
| 438 | Exceptions : none | ||
| 439 | Caller : general | ||
| 440 | Status : At Risk | ||
| 441 | : under development | ||
| 442 | |||
| 443 | =cut | ||
| 444 | |||
| 445 | sub get_latest_incarnation { | ||
| 446 | my $self = shift; | ||
| 447 | |||
| 448 | return $self if ($self->is_latest); | ||
| 449 | |||
| 450 | my $latest = $self->adaptor->fetch_by_stable_id($self->stable_id); | ||
| 451 | return $latest; | ||
| 452 | } | ||
| 453 | |||
| 454 | |||
| 455 | =head2 is_latest | ||
| 456 | |||
| 457 | Arg[1] : (optional) Boolean $is_latest | ||
| 458 | Example : if ($arch_id->is_latest) { | ||
| 459 | print "Version ".$arch_id->version." is the latest version | ||
| 460 | of ".$arch_id->stable_id."\n"; | ||
| 461 | } | ||
| 462 | Description : Indicates whether this is the latest version of this stable ID. | ||
| 463 | Can also be used as a setter if we know this is the latest | ||
| 464 | version. | ||
| 465 | Return type : Boolean (TRUE if yes, FALSE if no) | ||
| 466 | Exceptions : none | ||
| 467 | Caller : Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor->fetch_by_stable_id, general | ||
| 468 | Status : At Risk | ||
| 469 | : under development | ||
| 470 | |||
| 471 | =cut | ||
| 472 | |||
| 473 | sub is_latest { | ||
| 474 | my $self = shift; | ||
| 475 | $self->{'is_latest'} = shift if (@_); | ||
| 476 | return ($self->{'is_latest'} || $self->is_current); | ||
| 477 | } | ||
| 478 | |||
| 479 | |||
| 480 | # | ||
| 481 | # getter/setters for attributes | ||
| 482 | # | ||
| 483 | |||
| 484 | sub stable_id { | ||
| 485 | my $self = shift; | ||
| 486 | $self->{'stable_id'} = shift if (@_); | ||
| 487 | return $self->{'stable_id'}; | ||
| 488 | } | ||
| 489 | |||
| 490 | sub version { | ||
| 491 | my $self = shift; | ||
| 492 | $self->{'version'} = shift if (@_); | ||
| 493 | return $self->{'version'}; | ||
| 494 | } | ||
| 495 | |||
| 496 | sub db_name { | ||
| 497 | my $self = shift; | ||
| 498 | $self->{'db_name'} = shift if (@_); | ||
| 499 | return $self->{'db_name'}; | ||
| 500 | } | ||
| 501 | |||
| 502 | sub release { | ||
| 503 | my $self = shift; | ||
| 504 | $self->{'release'} = shift if (@_); | ||
| 505 | return $self->{'release'}; | ||
| 506 | } | ||
| 507 | |||
| 508 | sub assembly { | ||
| 509 | my $self = shift; | ||
| 510 | $self->{'assembly'} = shift if (@_); | ||
| 511 | return $self->{'assembly'}; | ||
| 512 | } | ||
| 513 | |||
| 514 | sub type { | ||
| 515 | my $self = shift; | ||
| 516 | $self->{'type'} = shift if (@_); | ||
| 517 | return $self->{'type'}; | ||
| 518 | } | ||
| 519 | |||
| 520 | sub adaptor { | ||
| 521 | my $self = shift; | ||
| 522 | weaken($self->{'adaptor'} = shift) if (@_); | ||
| 523 | return $self->{'adaptor'}; | ||
| 524 | } | ||
| 525 | |||
| 526 | sub successors { | ||
| 527 | my $self = shift; | ||
| 528 | $self->{'successors'} = \@_; | ||
| 529 | return $self->{'successors'}; | ||
| 530 | } | ||
| 531 | |||
| 532 | 1; | ||
| 533 |