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