| 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::AssemblyMapper - | ||
| 34 | Handles mapping between two coordinate systems using the information | ||
| 35 | stored in the assembly table. | ||
| 36 | |||
| 37 | =head1 SYNOPSIS | ||
| 38 | |||
| 39 | $db = Bio::EnsEMBL::DBSQL::DBAdaptor->new(...); | ||
| 40 | $asma = $db->get_AssemblyMapperAdaptor(); | ||
| 41 | $csa = $db->get_CoordSystemAdaptor(); | ||
| 42 | |||
| 43 | my $chr_cs = $cs_adaptor->fetch_by_name( 'chromosome', 'NCBI33' ); | ||
| 44 | my $ctg_cs = $cs_adaptor->fetch_by_name('contig'); | ||
| 45 | |||
| 46 | $asm_mapper = $map_adaptor->fetch_by_CoordSystems( $cs1, $cs2 ); | ||
| 47 | |||
| 48 | # Map to contig coordinate system from chromosomal. | ||
| 49 | @ctg_coords = | ||
| 50 | $asm_mapper->map( 'X', 1_000_000, 2_000_000, 1, $chr_cs ); | ||
| 51 | |||
| 52 | # Map to chromosome coordinate system from contig. | ||
| 53 | @chr_coords = | ||
| 54 | $asm_mapper->map( 'AL30421.1.200.92341', 100, 10000, -1, | ||
| 55 | $ctg_cs ); | ||
| 56 | |||
| 57 | # List contig names for a region of chromsome. | ||
| 58 | @ctg_ids = $asm_mapper->list_ids( '13', 1_000_000, 1, $chr_cs ); | ||
| 59 | |||
| 60 | # List chromosome names for a contig region. | ||
| 61 | @chr_ids = | ||
| 62 | $asm_mapper->list_ids( 'AL30421.1.200.92341', 1, 1000, -1, | ||
| 63 | $ctg_cs ); | ||
| 64 | |||
| 65 | =head1 DESCRIPTION | ||
| 66 | |||
| 67 | The AssemblyMapper is a database aware mapper which faciliates | ||
| 68 | conversion of coordinates between any two coordinate systems with an | ||
| 69 | relationship explicitly defined in the assembly table. In the future | ||
| 70 | it may be possible to perform multiple step (implicit) mapping between | ||
| 71 | coordinate systems. | ||
| 72 | |||
| 73 | It is implemented using the Bio::EnsEMBL::Mapper object, which is a | ||
| 74 | generic mapper object between disjoint coordinate systems. | ||
| 75 | |||
| 76 | =head1 METHODS | ||
| 77 | |||
| 78 | =cut | ||
| 79 | |||
| 80 | |||
| 81 | package Bio::EnsEMBL::AssemblyMapper; | ||
| 82 | $Bio::EnsEMBL::AssemblyMapper::VERSION = '114.0.0_50'; # TRIAL | ||
| 83 | $Bio::EnsEMBL::AssemblyMapper::VERSION = '114.0.050'; | ||
| 84 | use strict; | ||
| 85 | use warnings; | ||
| 86 | |||
| 87 | use Bio::EnsEMBL::Mapper; | ||
| 88 | use Bio::EnsEMBL::Utils::Exception qw(throw); | ||
| 89 | use Scalar::Util qw(weaken); | ||
| 90 | use Bio::EnsEMBL::Utils::Scalar qw( check_ref); | ||
| 91 | |||
| 92 | my $ASSEMBLED = 'assembled'; | ||
| 93 | my $COMPONENT = 'component'; | ||
| 94 | |||
| 95 | my $DEFAULT_MAX_PAIR_COUNT = 1000; | ||
| 96 | |||
| 97 | |||
| 98 | =head2 new | ||
| 99 | |||
| 100 | Arg [1] : Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor | ||
| 101 | Arg [2] : Bio::EnsEMBL::CoordSystem $asm_cs | ||
| 102 | Arg [3] : Bio::EnsEMBL::CoordSystem $cmp_cs | ||
| 103 | Example : Should use AssemblyMapperAdaptor->fetch_by_CoordSystems() | ||
| 104 | Description: Creates a new AssemblyMapper | ||
| 105 | Returntype : Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor | ||
| 106 | Exceptions : Throws if multiple coord_systems are provided | ||
| 107 | Caller : AssemblyMapperAdaptor | ||
| 108 | Status : Stable | ||
| 109 | |||
| 110 | =cut | ||
| 111 | |||
| 112 | sub new { | ||
| 113 | my ( $proto, $adaptor, @coord_systems ) = @_; | ||
| 114 | |||
| 115 | my $class = ref($proto) || $proto; | ||
| 116 | |||
| 117 | my $self = bless( {}, $class ); | ||
| 118 | |||
| 119 | $self->adaptor($adaptor); | ||
| 120 | |||
| 121 | $adaptor->cache_seq_ids_with_mult_assemblys(); | ||
| 122 | |||
| 123 | if ( @coord_systems != 2 ) { | ||
| 124 | throw( 'Can only map between two coordinate systems. ' | ||
| 125 | . scalar(@coord_systems) | ||
| 126 | . ' were provided' ); | ||
| 127 | } | ||
| 128 | |||
| 129 | # Set the component and assembled coordinate systems | ||
| 130 | $self->{'asm_cs'} = $coord_systems[0]; | ||
| 131 | $self->{'cmp_cs'} = $coord_systems[1]; | ||
| 132 | |||
| 133 | # We load the mapper calling the 'ASSEMBLED' the 'from' coord system | ||
| 134 | # and the 'COMPONENT' the 'to' coord system. | ||
| 135 | |||
| 136 | $self->{'mapper'} = Bio::EnsEMBL::Mapper->new( $ASSEMBLED, $COMPONENT, | ||
| 137 | $coord_systems[0], $coord_systems[1] ); | ||
| 138 | |||
| 139 | $self->{'max_pair_count'} = $DEFAULT_MAX_PAIR_COUNT; | ||
| 140 | |||
| 141 | return $self; | ||
| 142 | } ## end sub new | ||
| 143 | |||
| 144 | =head2 max_pair_count | ||
| 145 | |||
| 146 | Arg [1] : (optional) int $max_pair_count | ||
| 147 | Example : $mapper->max_pair_count(100000) | ||
| 148 | Description: Getter/Setter for the number of mapping pairs allowed | ||
| 149 | in the internal cache. This can be used to override | ||
| 150 | the default value (1000) to tune the performance and | ||
| 151 | memory usage for certain scenarios. Higher value | ||
| 152 | means bigger cache, more memory used. | ||
| 153 | Return type: int | ||
| 154 | Exceptions : None | ||
| 155 | Caller : General | ||
| 156 | Status : Stable | ||
| 157 | |||
| 158 | =cut | ||
| 159 | |||
| 160 | sub max_pair_count { | ||
| 161 | my ( $self, $value ) = @_; | ||
| 162 | |||
| 163 | if ( defined($value) ) { | ||
| 164 | $self->{'max_pair_count'} = $value; | ||
| 165 | } | ||
| 166 | |||
| 167 | return $self->{'max_pair_count'}; | ||
| 168 | } | ||
| 169 | |||
| 170 | =head2 register_all | ||
| 171 | |||
| 172 | Arg [1] : None | ||
| 173 | Example : $mapper->max_pair_count(10e6); | ||
| 174 | $mapper->register_all(); | ||
| 175 | Description: Pre-registers all assembly information in this | ||
| 176 | mapper. The cache size should be set to a | ||
| 177 | sufficiently large value so that all of the | ||
| 178 | information can be stored. This method is useful | ||
| 179 | when *a lot* of mapping will be done in regions | ||
| 180 | which are distributed around the genome. After | ||
| 181 | registration the mapper will consume a lot of memory | ||
| 182 | but will not have to perform any SQL and will be | ||
| 183 | faster. | ||
| 184 | Return type: None | ||
| 185 | Exceptions : None | ||
| 186 | Caller : Specialised programs doing a lot of mapping. | ||
| 187 | Status : Stable | ||
| 188 | |||
| 189 | =cut | ||
| 190 | |||
| 191 | sub register_all { | ||
| 192 | my ($self) = @_; | ||
| 193 | |||
| 194 | $self->adaptor()->register_all($self); | ||
| 195 | } | ||
| 196 | |||
| 197 | =head2 map | ||
| 198 | |||
| 199 | Arg [1] : string $frm_seq_region | ||
| 200 | The name of the sequence region to transform FROM. | ||
| 201 | Arg [2] : int $frm_start | ||
| 202 | The start of the region to transform FROM. | ||
| 203 | Arg [3] : int $frm_end | ||
| 204 | The end of the region to transform FROM. | ||
| 205 | Arg [4] : int $strand | ||
| 206 | The strand of the region to transform FROM. | ||
| 207 | Arg [5] : Bio::EnsEMBL::CoordSystem | ||
| 208 | The coordinate system to transform FROM | ||
| 209 | Arg [6] : Dummy placeholder to keep the interface consistent | ||
| 210 | across different mappers | ||
| 211 | Arg [7] : Bio::EnsEMBL::Slice | ||
| 212 | Target slice | ||
| 213 | Arg [8] : (optional) boolean | ||
| 214 | Whether to include the original coordinates or not | ||
| 215 | Example : @coords = | ||
| 216 | $asm_mapper->map( 'X', 1_000_000, 2_000_000, 1, | ||
| 217 | $chr_cs ); | ||
| 218 | Description: Transforms coordinates from one coordinate system to | ||
| 219 | another. | ||
| 220 | Return type: List of Bio::EnsEMBL::Mapper::Coordinate and/or | ||
| 221 | Bio::EnsEMBL::Mapper:Gap objects. | ||
| 222 | Exceptions : Throws if if the specified TO coordinat system is not | ||
| 223 | one of the coordinate systems associated with this | ||
| 224 | assembly mapper. | ||
| 225 | Caller : General | ||
| 226 | Status : Stable | ||
| 227 | |||
| 228 | =cut | ||
| 229 | |||
| 230 | sub map { | ||
| 231 | throw('Incorrect number of arguments.') if (!( @_ >= 6)); | ||
| 232 | |||
| 233 | my ( $self, $frm_seq_region_name, $frm_start, $frm_end, $frm_strand, | ||
| 234 | $frm_cs, $dummy, $to_slice, $include_org_coord ) | ||
| 235 | = @_; | ||
| 236 | |||
| 237 | my $mapper = $self->{'mapper'}; | ||
| 238 | my $asm_cs = $self->{'asm_cs'}; | ||
| 239 | my $cmp_cs = $self->{'cmp_cs'}; | ||
| 240 | my $adaptor = $self->{'adaptor'}; | ||
| 241 | my $frm; | ||
| 242 | |||
| 243 | |||
| 244 | my $seq_region_id = | ||
| 245 | $self->adaptor() | ||
| 246 | ->seq_regions_to_ids( $frm_cs, [$frm_seq_region_name] )->[0]; | ||
| 247 | |||
| 248 | # Speed critical section: | ||
| 249 | # Try to do simple pointer equality comparisons of the coord system | ||
| 250 | # objects first since this is likely to work most of the time and is | ||
| 251 | # much faster than a function call. | ||
| 252 | |||
| 253 | if ( $frm_cs == $cmp_cs | ||
| 254 | || ( $frm_cs != $asm_cs && $frm_cs->equals($cmp_cs) ) ) | ||
| 255 | { | ||
| 256 | if ( !$self->{'cmp_register'}->{$seq_region_id} ) { | ||
| 257 | $adaptor->register_component( $self, $seq_region_id ); | ||
| 258 | } | ||
| 259 | $frm = $COMPONENT; | ||
| 260 | |||
| 261 | } elsif ( $frm_cs == $asm_cs || $frm_cs->equals($asm_cs) ) { | ||
| 262 | |||
| 263 | # This can be probably be sped up some by only calling registered | ||
| 264 | # assembled if needed. | ||
| 265 | $adaptor->register_assembled( $self, $seq_region_id, $frm_start, | ||
| 266 | $frm_end ); | ||
| 267 | $frm = $ASSEMBLED; | ||
| 268 | |||
| 269 | } else { | ||
| 270 | |||
| 271 | throw( | ||
| 272 | sprintf( "Coordinate system %s %s is neither the assembled " | ||
| 273 | . "nor the component coordinate system " | ||
| 274 | . "of this AssemblyMapper", | ||
| 275 | $frm_cs->name(), $frm_cs->version() ) ); | ||
| 276 | |||
| 277 | } | ||
| 278 | |||
| 279 | my @coords = | ||
| 280 | $mapper->map_coordinates( $seq_region_id, $frm_start, $frm_end, | ||
| 281 | $frm_strand, $frm, $include_org_coord ); | ||
| 282 | |||
| 283 | # decorate (org,)mapped coordinates with their corresponding region names | ||
| 284 | if ($include_org_coord) { | ||
| 285 | map { | ||
| 286 | check_ref($_, 'Bio::EnsEMBL::Mapper::Coordinate') && # exclude gap | ||
| 287 | $_->{original}->name($adaptor->seq_ids_to_regions([$_->{original}->id])->[0]) && | ||
| 288 | $_->{mapped}->name($adaptor->seq_ids_to_regions([$_->{mapped}->id])->[0]) | ||
| 289 | } @coords; | ||
| 290 | } else { | ||
| 291 | map { | ||
| 292 | check_ref($_, 'Bio::EnsEMBL::Mapper::Coordinate') && # exclude gap | ||
| 293 | $_->name($adaptor->seq_ids_to_regions([$_->id])->[0]) | ||
| 294 | } @coords; | ||
| 295 | } | ||
| 296 | |||
| 297 | return @coords; | ||
| 298 | } ## end sub map | ||
| 299 | |||
| 300 | |||
| 301 | =head2 flush | ||
| 302 | |||
| 303 | Args : None | ||
| 304 | Example : None | ||
| 305 | Description: Remove all cached items from this AssemblyMapper. | ||
| 306 | Return type: None | ||
| 307 | Exceptions : None | ||
| 308 | Caller : AssemblyMapperAdaptor | ||
| 309 | Status : Stable | ||
| 310 | |||
| 311 | =cut | ||
| 312 | |||
| 313 | sub flush { | ||
| 314 | my ($self) = @_; | ||
| 315 | |||
| 316 | $self->{'mapper'}->flush(); | ||
| 317 | $self->{'cmp_register'} = {}; | ||
| 318 | $self->{'asm_register'} = {}; | ||
| 319 | } | ||
| 320 | |||
| 321 | =head2 size | ||
| 322 | |||
| 323 | Args : None | ||
| 324 | Example : $num_of_pairs = $mapper->size(); | ||
| 325 | Description: Returns the number of pairs currently stored. | ||
| 326 | Return type: int | ||
| 327 | Exceptions : None | ||
| 328 | Caller : General | ||
| 329 | Status : Stable | ||
| 330 | |||
| 331 | =cut | ||
| 332 | |||
| 333 | sub size { | ||
| 334 | my ($self) = @_; | ||
| 335 | |||
| 336 | return $self->{'mapper'}->{'pair_count'}; | ||
| 337 | } | ||
| 338 | |||
| 339 | =head2 fastmap | ||
| 340 | |||
| 341 | Arg [1] : string $frm_seq_region | ||
| 342 | The name of the sequence region to transform FROM. | ||
| 343 | Arg [2] : int $frm_start | ||
| 344 | The start of the region to transform FROM. | ||
| 345 | Arg [3] : int $frm_end | ||
| 346 | The end of the region to transform FROM. | ||
| 347 | Arg [4] : int $strand | ||
| 348 | The strand of the region to transform FROM. | ||
| 349 | Arg [5] : Bio::EnsEMBL::CoordSystem | ||
| 350 | The coordinate system to transform FROM. | ||
| 351 | Example : @coords = | ||
| 352 | $asm_mapper->map( 'X', 1_000_000, 2_000_000, 1, | ||
| 353 | $chr_cs ); | ||
| 354 | Description: Transforms coordinates from one coordinate system to | ||
| 355 | another. | ||
| 356 | Return type: List of Bio::EnsEMBL::Mapper::Coordinate and/or | ||
| 357 | Bio::EnsEMBL::Mapper:Gap objects. | ||
| 358 | Exceptions : Throws if the specified TO coordinat system is not | ||
| 359 | one of the coordinate systems associated with this | ||
| 360 | assembly mapper. | ||
| 361 | Caller : General | ||
| 362 | Status : Stable | ||
| 363 | |||
| 364 | =cut | ||
| 365 | |||
| 366 | sub fastmap { | ||
| 367 | if ( @_ != 6 ) { | ||
| 368 | throw('Incorrect number of arguments.'); | ||
| 369 | } | ||
| 370 | |||
| 371 | my ( $self, $frm_seq_region_name, $frm_start, $frm_end, $frm_strand, | ||
| 372 | $frm_cs ) | ||
| 373 | = @_; | ||
| 374 | |||
| 375 | my $mapper = $self->{'mapper'}; | ||
| 376 | my $asm_cs = $self->{'asm_cs'}; | ||
| 377 | my $cmp_cs = $self->{'cmp_cs'}; | ||
| 378 | my $adaptor = $self->adaptor(); | ||
| 379 | my $frm; | ||
| 380 | |||
| 381 | my @tmp; | ||
| 382 | push @tmp, $frm_seq_region_name; | ||
| 383 | |||
| 384 | my $seq_region_id = | ||
| 385 | $self->adaptor()->seq_regions_to_ids( $frm_cs, \@tmp )->[0]; | ||
| 386 | |||
| 387 | # Speed critical section: | ||
| 388 | # Try to do simple pointer equality comparisons of the coord system | ||
| 389 | # objects first since this is likely to work most of the time and is | ||
| 390 | # much faster than a function call. | ||
| 391 | |||
| 392 | if ( $frm_cs == $cmp_cs | ||
| 393 | || ( $frm_cs != $asm_cs && $frm_cs->equals($cmp_cs) ) ) | ||
| 394 | { | ||
| 395 | |||
| 396 | if ( !$self->{'cmp_register'}->{$seq_region_id} ) { | ||
| 397 | $adaptor->register_component( $self, $seq_region_id ); | ||
| 398 | } | ||
| 399 | $frm = $COMPONENT; | ||
| 400 | |||
| 401 | } elsif ( $frm_cs == $asm_cs || $frm_cs->equals($asm_cs) ) { | ||
| 402 | |||
| 403 | # This can be probably be sped up some by only calling registered | ||
| 404 | # assembled if needed | ||
| 405 | $adaptor->register_assembled( $self, $seq_region_id, $frm_start, | ||
| 406 | $frm_end ); | ||
| 407 | $frm = $ASSEMBLED; | ||
| 408 | |||
| 409 | } else { | ||
| 410 | |||
| 411 | throw( | ||
| 412 | sprintf( "Coordinate system %s %s is neither the assembled " | ||
| 413 | . "nor the component coordinate system " | ||
| 414 | . "of this AssemblyMapper", | ||
| 415 | $frm_cs->name(), $frm_cs->version() ) ); | ||
| 416 | |||
| 417 | } | ||
| 418 | |||
| 419 | return | ||
| 420 | $mapper->fastmap( $seq_region_id, $frm_start, $frm_end, $frm_strand, | ||
| 421 | $frm ); | ||
| 422 | } ## end sub fastmap | ||
| 423 | |||
| 424 | =head2 list_ids | ||
| 425 | |||
| 426 | Arg [1] : string $frm_seq_region | ||
| 427 | The name of the sequence region of interest. | ||
| 428 | Arg [2] : int $frm_start | ||
| 429 | The start of the region of interest. | ||
| 430 | Arg [3] : int $frm_end | ||
| 431 | The end of the region to transform of interest. | ||
| 432 | Arg [5] : Bio::EnsEMBL::CoordSystem $frm_cs | ||
| 433 | The coordinate system to obtain overlapping IDs of. | ||
| 434 | Example : foreach my $id ( | ||
| 435 | $asm_mapper->list_ids( 'X', 1, 1000, $ctg_cs ) ) | ||
| 436 | { ... } | ||
| 437 | Description: Retrieves a list of overlapping seq_region names of | ||
| 438 | another coordinate system. This is the same as the | ||
| 439 | list_ids method but uses seq_region names rather | ||
| 440 | internal IDs. | ||
| 441 | Return type: List of strings. | ||
| 442 | Exceptions : None | ||
| 443 | Caller : General | ||
| 444 | Status : Stable | ||
| 445 | |||
| 446 | =cut | ||
| 447 | |||
| 448 | sub list_ids { | ||
| 449 | if ( @_ != 5 ) { | ||
| 450 | throw('Incorrect number of arguments.'); | ||
| 451 | } | ||
| 452 | |||
| 453 | my ( $self, $frm_seq_region_name, $frm_start, $frm_end, $frm_cs ) = | ||
| 454 | @_; | ||
| 455 | |||
| 456 | my @tmp = ($frm_seq_region_name); | ||
| 457 | |||
| 458 | my $seq_region_id = | ||
| 459 | $self->adaptor()->seq_regions_to_ids( $frm_cs, \@tmp )->[0]; | ||
| 460 | |||
| 461 | if ( $frm_cs->equals( $self->component_CoordSystem() ) ) { | ||
| 462 | |||
| 463 | if ( !$self->have_registered_component($seq_region_id) ) { | ||
| 464 | $self->adaptor->register_component( $self, $seq_region_id ); | ||
| 465 | } | ||
| 466 | |||
| 467 | # Pull out the 'from' identifiers of the mapper pairs. The we | ||
| 468 | # loaded the assembled side as the 'from' side in the constructor. | ||
| 469 | |||
| 470 | return | ||
| 471 | map ( { $_->from()->id() } | ||
| 472 | $self->mapper()->list_pairs( | ||
| 473 | $seq_region_id, $frm_start, $frm_end, $COMPONENT | ||
| 474 | ) ); | ||
| 475 | |||
| 476 | } elsif ( $frm_cs->equals( $self->assembled_CoordSystem() ) ) { | ||
| 477 | |||
| 478 | $self->adaptor->register_assembled( $self, $seq_region_id, | ||
| 479 | $frm_start, $frm_end ); | ||
| 480 | |||
| 481 | # Pull out the 'to' identifiers of the mapper pairs we loaded the | ||
| 482 | # component side as the 'to' coord system in the constructor. | ||
| 483 | |||
| 484 | return | ||
| 485 | map ( { $_->to->id() } | ||
| 486 | $self->mapper()->list_pairs( | ||
| 487 | $seq_region_id, $frm_start, $frm_end, $ASSEMBLED | ||
| 488 | ) ); | ||
| 489 | |||
| 490 | } else { | ||
| 491 | |||
| 492 | throw( | ||
| 493 | sprintf( "Coordinate system %s %s is neither the assembled " | ||
| 494 | . "nor the component coordinate system " | ||
| 495 | . "of this AssemblyMapper", | ||
| 496 | $frm_cs->name(), $frm_cs->version() ) ); | ||
| 497 | |||
| 498 | } | ||
| 499 | } ## end sub list_ids | ||
| 500 | |||
| 501 | =head2 list_seq_regions | ||
| 502 | |||
| 503 | Arg [1] : string $frm_seq_region | ||
| 504 | The name of the sequence region of interest. | ||
| 505 | Arg [2] : int $frm_start | ||
| 506 | The start of the region of interest. | ||
| 507 | Arg [3] : int $frm_end | ||
| 508 | The end of the region to transform of interest. | ||
| 509 | Arg [5] : Bio::EnsEMBL::CoordSystem $frm_cs | ||
| 510 | The coordinate system to obtain overlapping IDs of. | ||
| 511 | Example : foreach my $id ( | ||
| 512 | $asm_mapper->list_seq_regions( | ||
| 513 | 'X', 1, 1000, $chr_cs | ||
| 514 | ) ) { ... } | ||
| 515 | Description: Retrieves a list of overlapping seq_region internal | ||
| 516 | identifiers of another coordinate system. This is | ||
| 517 | the same as the list_seq_regions method but uses | ||
| 518 | internal identfiers rather than seq_region strings. | ||
| 519 | Return type: List of ints. | ||
| 520 | Exceptions : None | ||
| 521 | Caller : General | ||
| 522 | Status : Stable | ||
| 523 | |||
| 524 | =cut | ||
| 525 | |||
| 526 | sub list_seq_regions { | ||
| 527 | if ( @_ != 5 ) { | ||
| 528 | throw('Incorrect number of arguments.'); | ||
| 529 | } | ||
| 530 | |||
| 531 | my ( $self, $frm_seq_region, $frm_start, $frm_end, $frm_cs ) = @_; | ||
| 532 | |||
| 533 | # Retrieve the seq_region names. | ||
| 534 | |||
| 535 | my @seq_ids = | ||
| 536 | $self->list_ids( $frm_seq_region, $frm_start, $frm_end, $frm_cs ); | ||
| 537 | |||
| 538 | # The seq_regions are from the 'to' coordinate system not the from | ||
| 539 | # coordinate system we used to obtain them. | ||
| 540 | |||
| 541 | my $to_cs; | ||
| 542 | if ( $frm_cs->equals( $self->assembled_CoordSystem() ) ) { | ||
| 543 | $to_cs = $self->component_CoordSystem(); | ||
| 544 | } else { | ||
| 545 | $to_cs = $self->assembled_CoordSystem(); | ||
| 546 | } | ||
| 547 | |||
| 548 | # Convert them to IDs. | ||
| 549 | return @{ $self->adaptor()->seq_ids_to_regions( \@seq_ids ) }; | ||
| 550 | } | ||
| 551 | |||
| 552 | |||
| 553 | =head2 have_registered_component | ||
| 554 | |||
| 555 | Arg [1] : string $cmp_seq_region | ||
| 556 | The name of the sequence region to check for | ||
| 557 | registration. | ||
| 558 | Example : if ( $asm_mapper->have_registered_component('AL240214.1') ) {} | ||
| 559 | Description: Returns true if a given component region has | ||
| 560 | been registered with this assembly mapper. This | ||
| 561 | should only be called by this class or the | ||
| 562 | AssemblyMapperAdaptor. In other words, do not use | ||
| 563 | this method unless you really know what you are | ||
| 564 | doing. | ||
| 565 | Return type: Boolean (0 or 1) | ||
| 566 | Exceptions : Throws on incorrect arguments. | ||
| 567 | Caller : Internal, AssemblyMapperAdaptor | ||
| 568 | Status : Stable | ||
| 569 | |||
| 570 | =cut | ||
| 571 | |||
| 572 | sub have_registered_component { | ||
| 573 | my ( $self, $cmp_seq_region ) = @_; | ||
| 574 | |||
| 575 | if ( !defined($cmp_seq_region) ) { | ||
| 576 | throw('cmp_seq_region argument is required'); | ||
| 577 | } | ||
| 578 | |||
| 579 | if ( exists( $self->{'cmp_register'}->{$cmp_seq_region} ) ) { | ||
| 580 | return 1; | ||
| 581 | } | ||
| 582 | |||
| 583 | return 0; | ||
| 584 | } | ||
| 585 | |||
| 586 | =head2 have_registered_assembled | ||
| 587 | |||
| 588 | Arg [1] : string $asm_seq_region | ||
| 589 | The name of the sequence region to check for | ||
| 590 | registration. | ||
| 591 | Arg [2] : int $chunk_id | ||
| 592 | The chunk number of the provided seq_region to check | ||
| 593 | for registration. | ||
| 594 | Example : if ( $asm_mapper->have_registered_component( 'X', 9 ) ) { } | ||
| 595 | Description: Returns true if a given assembled region chunk | ||
| 596 | has been registered with this assembly mapper. | ||
| 597 | This should only be called by this class or the | ||
| 598 | AssemblyMapperAdaptor. In other words, do not use | ||
| 599 | this method unless you really know what you are | ||
| 600 | doing. | ||
| 601 | Return type: Boolean (0 or 1) | ||
| 602 | Exceptions : Throws on incorrect arguments | ||
| 603 | Caller : Internal, AssemblyMapperAdaptor | ||
| 604 | Status : Stable | ||
| 605 | |||
| 606 | =cut | ||
| 607 | |||
| 608 | sub have_registered_assembled { | ||
| 609 | my ( $self, $asm_seq_region, $chunk_id ) = @_; | ||
| 610 | |||
| 611 | if ( !defined($asm_seq_region) ) { | ||
| 612 | throw('asm_seq_region argument is required'); | ||
| 613 | } | ||
| 614 | if ( !defined($chunk_id) ) { | ||
| 615 | throw('chunk_id is required'); | ||
| 616 | } | ||
| 617 | |||
| 618 | if ( | ||
| 619 | exists( $self->{'asm_register'}->{$asm_seq_region}->{$chunk_id} ) ) | ||
| 620 | { | ||
| 621 | return 1; | ||
| 622 | } | ||
| 623 | |||
| 624 | return 0; | ||
| 625 | } | ||
| 626 | |||
| 627 | |||
| 628 | =head2 register_component | ||
| 629 | |||
| 630 | Arg [1] : integer $cmp_seq_region | ||
| 631 | The dbID of the component sequence region to | ||
| 632 | register. | ||
| 633 | Example : $asm_mapper->register_component('AL312341.1'); | ||
| 634 | Description: Flags a given component sequence region as registered | ||
| 635 | in this assembly mapper. This should only be called | ||
| 636 | by this class or the AssemblyMapperAdaptor. | ||
| 637 | Return type: None | ||
| 638 | Exceptions : Throws on incorrect arguments | ||
| 639 | Caller : Internal, AssemblyMapperAdaptor | ||
| 640 | Status : Stable | ||
| 641 | |||
| 642 | =cut | ||
| 643 | |||
| 644 | sub register_component { | ||
| 645 | my ( $self, $cmp_seq_region ) = @_; | ||
| 646 | |||
| 647 | if ( !defined($cmp_seq_region) ) { | ||
| 648 | throw('cmp_seq_region argument is required'); | ||
| 649 | } | ||
| 650 | |||
| 651 | $self->{'cmp_register'}->{$cmp_seq_region} = 1; | ||
| 652 | } | ||
| 653 | |||
| 654 | =head2 register_assembled | ||
| 655 | |||
| 656 | Arg [1] : integer $asm_seq_region | ||
| 657 | The dbID of the sequence region to register. | ||
| 658 | Arg [2] : int $chunk_id | ||
| 659 | The chunk number of the provided seq_region to register. | ||
| 660 | Example : $asm_mapper->register_assembled( 'X', 4 ); | ||
| 661 | Description: Flags a given assembled region as registered in this | ||
| 662 | assembly mapper. This should only be called by this | ||
| 663 | class or the AssemblyMapperAdaptor. Do not call this | ||
| 664 | method unless you really know what you are doing. | ||
| 665 | Return type: None | ||
| 666 | Exceptions : Throws on incorrect arguments | ||
| 667 | Caller : Internal, AssemblyMapperAdaptor | ||
| 668 | Status : Stable | ||
| 669 | |||
| 670 | =cut | ||
| 671 | |||
| 672 | sub register_assembled { | ||
| 673 | my ( $self, $asm_seq_region, $chunk_id ) = @_; | ||
| 674 | |||
| 675 | if ( !defined($asm_seq_region) ) { | ||
| 676 | throw('asm_seq_region argument is required'); | ||
| 677 | } | ||
| 678 | if ( !defined($chunk_id) ) { | ||
| 679 | throw('chunk_id srgument is required'); | ||
| 680 | } | ||
| 681 | |||
| 682 | $self->{'asm_register'}->{$asm_seq_region}->{$chunk_id} = 1; | ||
| 683 | } | ||
| 684 | |||
| 685 | =head2 mapper | ||
| 686 | |||
| 687 | Arg [1] : None | ||
| 688 | Example : $mapper = $asm_mapper->mapper(); | ||
| 689 | Description: Retrieves the internal mapper used by this Assembly | ||
| 690 | Mapper. This is unlikely to be useful unless you | ||
| 691 | _really_ know what you are doing. | ||
| 692 | Return type: Bio::EnsEMBL::Mapper | ||
| 693 | Exceptions : None | ||
| 694 | Caller : Internal, AssemblyMapperAdaptor | ||
| 695 | Status : Stable | ||
| 696 | |||
| 697 | =cut | ||
| 698 | |||
| 699 | sub mapper { | ||
| 700 | my ($self) = @_; | ||
| 701 | |||
| 702 | return $self->{'mapper'}; | ||
| 703 | } | ||
| 704 | |||
| 705 | =head2 assembled_CoordSystem | ||
| 706 | |||
| 707 | Arg [1] : None | ||
| 708 | Example : $cs = $asm_mapper->assembled_CoordSystem(); | ||
| 709 | Description: Retrieves the assembled CoordSystem from this | ||
| 710 | assembly mapper. | ||
| 711 | Return type: Bio::EnsEMBL::CoordSystem | ||
| 712 | Exceptions : None | ||
| 713 | Caller : Internal, AssemblyMapperAdaptor | ||
| 714 | Status : Stable | ||
| 715 | |||
| 716 | =cut | ||
| 717 | |||
| 718 | sub assembled_CoordSystem { | ||
| 719 | my ($self) = @_; | ||
| 720 | |||
| 721 | return $self->{'asm_cs'}; | ||
| 722 | } | ||
| 723 | |||
| 724 | =head2 component_CoordSystem | ||
| 725 | |||
| 726 | Arg [1] : None | ||
| 727 | Example : $cs = $asm_mapper->component_CoordSystem(); | ||
| 728 | Description: Retrieves the component CoordSystem from this | ||
| 729 | assembly mapper. | ||
| 730 | Return type: Bio::EnsEMBL::CoordSystem | ||
| 731 | Exceptions : None | ||
| 732 | Caller : Internal, AssemblyMapperAdaptor | ||
| 733 | Status : Stable | ||
| 734 | |||
| 735 | =cut | ||
| 736 | |||
| 737 | sub component_CoordSystem { | ||
| 738 | my ($self) = @_; | ||
| 739 | |||
| 740 | return $self->{'cmp_cs'}; | ||
| 741 | } | ||
| 742 | |||
| 743 | =head2 adaptor | ||
| 744 | |||
| 745 | Arg [1] : Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor $adaptor | ||
| 746 | Description: Getter/set terfor this object's database adaptor. | ||
| 747 | Returntype : Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor | ||
| 748 | Exceptions : None | ||
| 749 | Caller : General | ||
| 750 | Status : Stable | ||
| 751 | |||
| 752 | =cut | ||
| 753 | |||
| 754 | sub adaptor { | ||
| 755 | my ( $self, $value ) = @_; | ||
| 756 | |||
| 757 | if ( defined($value) ) { | ||
| 758 | weaken($self->{'adaptor'} = $value); | ||
| 759 | } | ||
| 760 | |||
| 761 | return $self->{'adaptor'}; | ||
| 762 | } | ||
| 763 | |||
| 764 | 1; |