Archive Ensembl HomeArchive Ensembl Home
AssemblyMapper.pm
Go to the documentation of this file.
00001 =head1 LICENSE
00002 
00003   Copyright (c) 1999-2012 The European Bioinformatics Institute and
00004   Genome Research Limited.  All rights reserved.
00005 
00006   This software is distributed under a modified Apache license.
00007   For license details, please see
00008 
00009     http://www.ensembl.org/info/about/code_licence.html
00010 
00011 =head1 CONTACT
00012 
00013   Please email comments or questions to the public Ensembl
00014   developers list at <dev@ensembl.org>.
00015 
00016   Questions may also be sent to the Ensembl help desk at
00017   <helpdesk@ensembl.org>.
00018 
00019 =cut
00020 
00021 =head1 NAME
00022 
00023 Bio::EnsEMBL::AssemblyMapper - 
00024 Handles mapping between two coordinate systems using the information
00025 stored in the assembly table.
00026 
00027 =head1 SYNOPSIS
00028 
00029     $db   = Bio::EnsEMBL::DBSQL::DBAdaptor->new(...);
00030     $asma = $db->get_AssemblyMapperAdaptor();
00031     $csa  = $db->get_CoordSystemAdaptor();
00032 
00033     my $chr_cs = $cs_adaptor->fetch_by_name( 'chromosome', 'NCBI33' );
00034     my $ctg_cs = $cs_adaptor->fetch_by_name('contig');
00035 
00036     $asm_mapper = $map_adaptor->fetch_by_CoordSystems( $cs1, $cs2 );
00037 
00038     # Map to contig coordinate system from chromosomal.
00039     @ctg_coords =
00040       $asm_mapper->map( 'X', 1_000_000, 2_000_000, 1, $chr_cs );
00041 
00042     # Map to chromosome coordinate system from contig.
00043     @chr_coords =
00044       $asm_mapper->map( 'AL30421.1.200.92341', 100, 10000, -1,
00045       $ctg_cs );
00046 
00047     # List contig names for a region of chromsome.
00048     @ctg_ids = $asm_mapper->list_ids( '13', 1_000_000, 1, $chr_cs );
00049 
00050     # List chromosome names for a contig region.
00051     @chr_ids =
00052       $asm_mapper->list_ids( 'AL30421.1.200.92341', 1, 1000, -1,
00053       $ctg_cs );
00054 
00055 =head1 DESCRIPTION
00056 
00057 The AssemblyMapper is a database aware mapper which faciliates
00058 conversion of coordinates between any two coordinate systems with an
00059 relationship explicitly defined in the assembly table.  In the future
00060 it may be possible to perform multiple step (implicit) mapping between
00061 coordinate systems.
00062 
00063 It is implemented using the Bio::EnsEMBL::Mapper object, which is a
00064 generic mapper object between disjoint coordinate systems.
00065 
00066 =head1 METHODS
00067 
00068 =cut
00069 
00070 
00071 package Bio::EnsEMBL::AssemblyMapper;
00072 
00073 use strict;
00074 use warnings;
00075 
00076 use Bio::EnsEMBL::Mapper;
00077 use Bio::EnsEMBL::Utils::Exception qw(throw deprecate);
00078 use Scalar::Util qw(weaken);
00079 
00080 my $ASSEMBLED = 'assembled';
00081 my $COMPONENT = 'component';
00082 
00083 my $DEFAULT_MAX_PAIR_COUNT = 1000;
00084 
00085 
00086 =head2 new
00087 
00088   Arg [1]    : Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor
00089   Arg [2]    : Bio::EnsEMBL::CoordSystem $asm_cs
00090   Arg [3]    : Bio::EnsEMBL::CoordSystem $cmp_cs
00091   Example    : Should use AssemblyMapperAdaptor->fetch_by_CoordSystems()
00092   Description: Creates a new AssemblyMapper
00093   Returntype : Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor
00094   Exceptions : Throws if multiple coord_systems are provided
00095   Caller     : AssemblyMapperAdaptor
00096   Status     : Stable
00097 
00098 =cut
00099 
00100 sub new {
00101   my ( $proto, $adaptor, @coord_systems ) = @_;
00102 
00103   my $class = ref($proto) || $proto;
00104 
00105   my $self = bless( {}, $class );
00106 
00107   $self->adaptor($adaptor);
00108 
00109   $adaptor->cache_seq_ids_with_mult_assemblys();
00110 
00111   if ( @coord_systems != 2 ) {
00112     throw(   'Can only map between two coordinate systems. '
00113            . scalar(@coord_systems)
00114            . ' were provided' );
00115   }
00116 
00117   # Set the component and assembled coordinate systems
00118   $self->{'asm_cs'} = $coord_systems[0];
00119   $self->{'cmp_cs'} = $coord_systems[1];
00120 
00121   # We load the mapper calling the 'ASSEMBLED' the 'from' coord system
00122   # and the 'COMPONENT' the 'to' coord system.
00123 
00124   $self->{'mapper'} = Bio::EnsEMBL::Mapper->new( $ASSEMBLED, $COMPONENT,
00125                                  $coord_systems[0], $coord_systems[1] );
00126 
00127   $self->{'max_pair_count'} = $DEFAULT_MAX_PAIR_COUNT;
00128 
00129   return $self;
00130 } ## end sub new
00131 
00132 =head2 max_pair_count
00133 
00134   Arg [1]    : (optional) int $max_pair_count
00135   Example    : $mapper->max_pair_count(100000)
00136   Description: Getter/Setter for the number of mapping pairs allowed
00137                in the internal cache.  This can be used to override
00138                the default value (1000) to tune the performance and
00139                memory usage for certain scenarios.  Higher value
00140                means bigger cache, more memory used.
00141   Return type: int
00142   Exceptions : None
00143   Caller     : General
00144   Status     : Stable
00145 
00146 =cut
00147 
00148 sub max_pair_count {
00149   my ( $self, $value ) = @_;
00150 
00151   if ( defined($value) ) {
00152     $self->{'max_pair_count'} = $value;
00153   }
00154 
00155   return $self->{'max_pair_count'};
00156 }
00157 
00158 =head2 register_all
00159 
00160   Arg [1]    : None
00161   Example    : $mapper->max_pair_count(10e6);
00162                $mapper->register_all();
00163   Description: Pre-registers all assembly information in this
00164                mapper.  The cache size should be set to a
00165                sufficiently large value so that all of the
00166                information can be stored.  This method is useful
00167                when *a lot* of mapping will be done in regions
00168                which are distributed around the genome.  After
00169                registration the mapper will consume a lot of memory
00170                but will not have to perform any SQL and will be
00171                faster.
00172   Return type: None
00173   Exceptions : None
00174   Caller     : Specialised programs doing a lot of mapping.
00175   Status     : Stable
00176 
00177 =cut
00178 
00179 sub register_all {
00180   my ($self) = @_;
00181 
00182   $self->adaptor()->register_all($self);
00183 }
00184 
00185 =head2 map
00186 
00187   Arg [1]    : string $frm_seq_region
00188                The name of the sequence region to transform FROM.
00189   Arg [2]    : int $frm_start
00190                The start of the region to transform FROM.
00191   Arg [3]    : int $frm_end
00192                The end of the region to transform FROM.
00193   Arg [4]    : int $strand
00194                The strand of the region to transform FROM.
00195   Arg [5]    : Bio::EnsEMBL::CoordSystem
00196                The coordinate system to transform FROM
00197   Example    : @coords =
00198                 $asm_mapper->map( 'X', 1_000_000, 2_000_000, 1,
00199                                   $chr_cs );
00200   Description: Transforms coordinates from one coordinate system to
00201                another.
00202   Return type: List of Bio::EnsEMBL::Mapper::Coordinate and/or
00203                Bio::EnsEMBL::Mapper:Gap objects.
00204   Exceptions : Throws if if the specified TO coordinat system is not
00205                one of the coordinate systems associated with this
00206                assembly mapper.
00207   Caller     : General
00208   Status     : Stable
00209 
00210 =cut
00211 
00212 sub map {
00213   throw('Incorrect number of arguments.') if (!( @_ >= 6));
00214 
00215   my ( $self, $frm_seq_region_name, $frm_start, $frm_end, $frm_strand,
00216        $frm_cs, $to_slice )
00217     = @_;
00218 
00219   my $mapper  = $self->{'mapper'};
00220   my $asm_cs  = $self->{'asm_cs'};
00221   my $cmp_cs  = $self->{'cmp_cs'};
00222   my $adaptor = $self->{'adaptor'};
00223   my $frm;
00224 
00225 
00226   my $seq_region_id =
00227     $self->adaptor()
00228     ->seq_regions_to_ids( $frm_cs, [$frm_seq_region_name] )->[0];
00229 
00230   # Speed critical section:
00231   # Try to do simple pointer equality comparisons of the coord system
00232   # objects first since this is likely to work most of the time and is
00233   # much faster than a function call.
00234 
00235   if ( $frm_cs == $cmp_cs
00236        || ( $frm_cs != $asm_cs && $frm_cs->equals($cmp_cs) ) )
00237   {
00238     if ( !$self->{'cmp_register'}->{$seq_region_id} ) {
00239       $adaptor->register_component( $self, $seq_region_id );
00240     }
00241     $frm = $COMPONENT;
00242 
00243   } elsif ( $frm_cs == $asm_cs || $frm_cs->equals($asm_cs) ) {
00244 
00245     # This can be probably be sped up some by only calling registered
00246     # assembled if needed.
00247     $adaptor->register_assembled( $self, $seq_region_id, $frm_start,
00248                                   $frm_end );
00249     $frm = $ASSEMBLED;
00250 
00251   } else {
00252 
00253     throw(
00254            sprintf( "Coordinate system %s %s is neither the assembled "
00255                       . "nor the component coordinate system "
00256                       . "of this AssemblyMapper",
00257                     $frm_cs->name(), $frm_cs->version() ) );
00258 
00259   }
00260 
00261   return
00262     $mapper->map_coordinates( $seq_region_id, $frm_start, $frm_end,
00263                               $frm_strand, $frm );
00264 } ## end sub map
00265 
00266 
00267 =head2 flush
00268 
00269   Args       : None
00270   Example    : None
00271   Description: Remove all cached items from this AssemblyMapper.
00272   Return type: None
00273   Exceptions : None
00274   Caller     : AssemblyMapperAdaptor
00275   Status     : Stable
00276 
00277 =cut
00278 
00279 sub flush {
00280   my ($self) = @_;
00281 
00282   $self->{'mapper'}->flush();
00283   $self->{'cmp_register'} = {};
00284   $self->{'asm_register'} = {};
00285 }
00286 
00287 =head2 size
00288 
00289   Args       : None
00290   Example    : $num_of_pairs = $mapper->size();
00291   Description: Returns the number of pairs currently stored.
00292   Return type: int
00293   Exceptions : None
00294   Caller     : General
00295   Status     : Stable
00296 
00297 =cut
00298 
00299 sub size {
00300   my ($self) = @_;
00301 
00302   return $self->{'mapper'}->{'pair_count'};
00303 }
00304 
00305 =head2 fastmap
00306 
00307   Arg [1]    : string $frm_seq_region
00308                The name of the sequence region to transform FROM.
00309   Arg [2]    : int $frm_start
00310                The start of the region to transform FROM.
00311   Arg [3]    : int $frm_end
00312                The end of the region to transform FROM.
00313   Arg [4]    : int $strand
00314                The strand of the region to transform FROM.
00315   Arg [5]    : Bio::EnsEMBL::CoordSystem
00316                The coordinate system to transform FROM.
00317   Example    : @coords =
00318                 $asm_mapper->map( 'X', 1_000_000, 2_000_000, 1,
00319                                   $chr_cs );
00320   Description: Transforms coordinates from one coordinate system to
00321                another.
00322   Return type: List of Bio::EnsEMBL::Mapper::Coordinate and/or
00323                Bio::EnsEMBL::Mapper:Gap objects.
00324   Exceptions : Throws if the specified TO coordinat system is not
00325                one of the coordinate systems associated with this
00326                assembly mapper.
00327   Caller     : General
00328   Status     : Stable
00329 
00330 =cut
00331 
00332 sub fastmap {
00333   if ( @_ != 6 ) {
00334     throw('Incorrect number of arguments.');
00335   }
00336 
00337   my ( $self, $frm_seq_region_name, $frm_start, $frm_end, $frm_strand,
00338        $frm_cs )
00339     = @_;
00340 
00341   my $mapper  = $self->{'mapper'};
00342   my $asm_cs  = $self->{'asm_cs'};
00343   my $cmp_cs  = $self->{'cmp_cs'};
00344   my $adaptor = $self->adaptor();
00345   my $frm;
00346 
00347   my @tmp;
00348   push @tmp, $frm_seq_region_name;
00349 
00350   my $seq_region_id =
00351     $self->adaptor()->seq_regions_to_ids( $frm_cs, \@tmp )->[0];
00352 
00353   # Speed critical section:
00354   # Try to do simple pointer equality comparisons of the coord system
00355   # objects first since this is likely to work most of the time and is
00356   # much faster than a function call.
00357 
00358   if ( $frm_cs == $cmp_cs
00359        || ( $frm_cs != $asm_cs && $frm_cs->equals($cmp_cs) ) )
00360   {
00361 
00362     if ( !$self->{'cmp_register'}->{$seq_region_id} ) {
00363       $adaptor->register_component( $self, $seq_region_id );
00364     }
00365     $frm = $COMPONENT;
00366 
00367   } elsif ( $frm_cs == $asm_cs || $frm_cs->equals($asm_cs) ) {
00368 
00369     # This can be probably be sped up some by only calling registered
00370     # assembled if needed
00371     $adaptor->register_assembled( $self, $seq_region_id, $frm_start,
00372                                   $frm_end );
00373     $frm = $ASSEMBLED;
00374 
00375   } else {
00376 
00377     throw(
00378            sprintf( "Coordinate system %s %s is neither the assembled "
00379                       . "nor the component coordinate system "
00380                       . "of this AssemblyMapper",
00381                     $frm_cs->name(), $frm_cs->version() ) );
00382 
00383   }
00384 
00385   return
00386     $mapper->fastmap( $seq_region_id, $frm_start, $frm_end, $frm_strand,
00387                       $frm );
00388 } ## end sub fastmap
00389 
00390 =head2 list_ids
00391 
00392   Arg [1]    : string $frm_seq_region
00393                The name of the sequence region of interest.
00394   Arg [2]    : int $frm_start
00395                The start of the region of interest.
00396   Arg [3]    : int $frm_end
00397                The end of the region to transform of interest.
00398   Arg [5]    : Bio::EnsEMBL::CoordSystem $frm_cs
00399                The coordinate system to obtain overlapping IDs of.
00400   Example    : foreach my $id (
00401                         $asm_mapper->list_ids( 'X', 1, 1000, $ctg_cs ) )
00402                 { ... }
00403   Description: Retrieves a list of overlapping seq_region names of
00404                another coordinate system.  This is the same as the
00405                list_ids method but uses seq_region names rather
00406                internal IDs.
00407   Return type: List of strings.
00408   Exceptions : None
00409   Caller     : General
00410   Status     : Stable
00411 
00412 =cut
00413 
00414 sub list_ids {
00415   if ( @_ != 5 ) {
00416     throw('Incorrect number of arguments.');
00417   }
00418 
00419   my ( $self, $frm_seq_region_name, $frm_start, $frm_end, $frm_cs ) =
00420     @_;
00421 
00422   my @tmp = ($frm_seq_region_name);
00423 
00424   my $seq_region_id =
00425     $self->adaptor()->seq_regions_to_ids( $frm_cs, \@tmp )->[0];
00426 
00427   if ( $frm_cs->equals( $self->component_CoordSystem() ) ) {
00428 
00429     if ( !$self->have_registered_component($seq_region_id) ) {
00430       $self->adaptor->register_component( $self, $seq_region_id );
00431     }
00432 
00433     # Pull out the 'from' identifiers of the mapper pairs.  The we
00434     # loaded the assembled side as the 'from' side in the constructor.
00435 
00436     return
00437       map ( { $_->from()->id() }
00438             $self->mapper()->list_pairs(
00439                         $seq_region_id, $frm_start, $frm_end, $COMPONENT
00440             ) );
00441 
00442   } elsif ( $frm_cs->equals( $self->assembled_CoordSystem() ) ) {
00443 
00444     $self->adaptor->register_assembled( $self, $seq_region_id,
00445                                         $frm_start, $frm_end );
00446 
00447     # Pull out the 'to' identifiers of the mapper pairs we loaded the
00448     # component side as the 'to' coord system in the constructor.
00449 
00450     return
00451       map ( { $_->to->id() }
00452             $self->mapper()->list_pairs(
00453                         $seq_region_id, $frm_start, $frm_end, $ASSEMBLED
00454             ) );
00455 
00456   } else {
00457 
00458     throw(
00459            sprintf( "Coordinate system %s %s is neither the assembled "
00460                       . "nor the component coordinate system "
00461                       . "of this AssemblyMapper",
00462                     $frm_cs->name(), $frm_cs->version() ) );
00463 
00464   }
00465 } ## end sub list_ids
00466 
00467 #sub list_seq_regions {
00468 #  throw('Incorrect number of arguments.') if(@_ != 5);
00469 #  my($self, $frm_seq_region_name, $frm_start, $frm_end, $frm_cs) = @_;
00470 
00471 #  if($frm_cs->equals($self->component_CoordSystem())) {
00472 
00473 #    if(!$self->have_registered_component($seq_region_id)) {
00474 #      $self->adaptor->register_component($self,$seq_region_id);
00475 #    }
00476 
00477 #    #pull out the 'from' identifiers of the mapper pairs.  The
00478 #    #we loaded the assembled side as the 'from' side in the constructor
00479 #    return
00480 #      map {$_->from()->id()}
00481 #      $self->mapper()->list_pairs($seq_region_id, $frm_start,
00482 #                                  $frm_end, $COMPONENT);
00483 
00484 #  } elsif($frm_cs->equals($self->assembled_CoordSystem())) {
00485 
00486 #    $self->adaptor->register_assembled($self,
00487 #                                       $frm_seq_region,$frm_start,$frm_end);
00488 
00489 #    #pull out the 'to' identifiers of the mapper pairs
00490 #    #we loaded the component side as the 'to' coord system in the constructor
00491 #    return
00492 #      map {$_->to->id()}
00493 #        $self->mapper()->list_pairs($frm_seq_region, $frm_start,
00494 #                                    $frm_end, $ASSEMBLED);
00495 #  } else {
00496 #    throw("Coordinate system " . $frm_cs->name . " " . $frm_cs->version .
00497 #          " is neither the assembled nor the component coordinate system " .
00498 #          " of this AssemblyMapper");
00499 #  }
00500 #}
00501 
00502 
00503 =head2 list_seq_regions
00504 
00505   Arg [1]    : string $frm_seq_region
00506                The name of the sequence region of interest.
00507   Arg [2]    : int $frm_start
00508                The start of the region of interest.
00509   Arg [3]    : int $frm_end
00510                The end of the region to transform of interest.
00511   Arg [5]    : Bio::EnsEMBL::CoordSystem $frm_cs
00512                The coordinate system to obtain overlapping IDs of.
00513   Example    : foreach my $id (
00514                                  $asm_mapper->list_seq_regions(
00515                                                    'X', 1, 1000, $chr_cs
00516                                  ) ) { ... }
00517   Description: Retrieves a list of overlapping seq_region internal
00518                identifiers of another coordinate system.  This is
00519                the same as the list_seq_regions method but uses
00520                internal identfiers rather than seq_region strings.
00521   Return type: List of ints.
00522   Exceptions : None
00523   Caller     : General
00524   Status     : Stable
00525 
00526 =cut
00527 
00528 sub list_seq_regions {
00529   if ( @_ != 5 ) {
00530     throw('Incorrect number of arguments.');
00531   }
00532 
00533   my ( $self, $frm_seq_region, $frm_start, $frm_end, $frm_cs ) = @_;
00534 
00535   # Retrieve the seq_region names.
00536 
00537   my @seq_ids =
00538     $self->list_ids( $frm_seq_region, $frm_start, $frm_end, $frm_cs );
00539 
00540   # The seq_regions are from the 'to' coordinate system not the from
00541   # coordinate system we used to obtain them.
00542 
00543   my $to_cs;
00544   if ( $frm_cs->equals( $self->assembled_CoordSystem() ) ) {
00545     $to_cs = $self->component_CoordSystem();
00546   } else {
00547     $to_cs = $self->assembled_CoordSystem();
00548   }
00549 
00550   # Convert them to IDs.
00551   return @{ $self->adaptor()->seq_ids_to_regions( \@seq_ids ) };
00552 }
00553 
00554 #sub list_ids {
00555 #  throw('Incorrect number of arguments.') if(@_ != 5);
00556 #  my($self, $frm_seq_region, $frm_start, $frm_end, $frm_cs) = @_;
00557 
00558 #  #retrieve the seq_region names
00559 #  my @seq_regs =
00560 #    $self->list_seq_regions($frm_seq_region,$frm_start,$frm_end,$frm_cs);
00561 
00562 #  #The seq_regions are from the 'to' coordinate system not the
00563 #  #from coordinate system we used to obtain them
00564 #  my $to_cs;
00565 #  if($frm_cs->equals($self->assembled_CoordSystem())) {
00566 #    $to_cs = $self->component_CoordSystem();
00567 #  } else {
00568 #    $to_cs = $self->assembled_CoordSystem();
00569 #  }
00570 
00571 #  #convert them to ids
00572 #  return @{$self->adaptor()->seq_regions_to_ids($to_cs, \@seq_regs)};
00573 #}
00574 
00575 =head2 have_registered_component
00576 
00577   Arg [1]    : string $cmp_seq_region
00578                The name of the sequence region to check for
00579                registration.
00580   Example    : if ( $asm_mapper->have_registered_component('AL240214.1') ) {}
00581   Description: Returns true if a given component region has
00582                been registered with this assembly mapper.  This
00583                should only be called by this class or the
00584                AssemblyMapperAdaptor.  In other words, do not use
00585                this method unless you really know what you are
00586                doing.
00587   Return type: Boolean (0 or 1)
00588   Exceptions : Throws on incorrect arguments.
00589   Caller     : Internal, AssemblyMapperAdaptor
00590   Status     : Stable
00591 
00592 =cut
00593 
00594 sub have_registered_component {
00595   my ( $self, $cmp_seq_region ) = @_;
00596 
00597   if ( !defined($cmp_seq_region) ) {
00598     throw('cmp_seq_region argument is required');
00599   }
00600 
00601   if ( exists( $self->{'cmp_register'}->{$cmp_seq_region} ) ) {
00602     return 1;
00603   }
00604 
00605   return 0;
00606 }
00607 
00608 =head2 have_registered_assembled
00609 
00610   Arg [1]    : string $asm_seq_region
00611                The name of the sequence region to check for
00612                registration.
00613   Arg [2]    : int $chunk_id
00614                The chunk number of the provided seq_region to check
00615                for registration.
00616   Example    : if ( $asm_mapper->have_registered_component( 'X', 9 ) ) { }
00617   Description: Returns true if a given assembled region chunk
00618                has been registered with this assembly mapper.
00619                This should only be called by this class or the
00620                AssemblyMapperAdaptor.  In other words, do not use
00621                this method unless you really know what you are
00622                doing.
00623   Return type: Boolean (0 or 1)
00624   Exceptions : Throws on incorrect arguments
00625   Caller     : Internal, AssemblyMapperAdaptor
00626   Status     : Stable
00627 
00628 =cut
00629 
00630 sub have_registered_assembled {
00631   my ( $self, $asm_seq_region, $chunk_id ) = @_;
00632 
00633   if ( !defined($asm_seq_region) ) {
00634     throw('asm_seq_region argument is required');
00635   }
00636   if ( !defined($chunk_id) ) {
00637     throw('chunk_id is required');
00638   }
00639 
00640   if (
00641      exists( $self->{'asm_register'}->{$asm_seq_region}->{$chunk_id} ) )
00642   {
00643     return 1;
00644   }
00645 
00646   return 0;
00647 }
00648 
00649 
00650 =head2 register_component
00651 
00652   Arg [1]    : integer $cmp_seq_region
00653                The dbID of the component sequence region to
00654                register.
00655   Example    : $asm_mapper->register_component('AL312341.1');
00656   Description: Flags a given component sequence region as registered
00657                in this assembly mapper.  This should only be called
00658                by this class or the AssemblyMapperAdaptor.
00659   Return type: None
00660   Exceptions : Throws on incorrect arguments
00661   Caller     : Internal, AssemblyMapperAdaptor
00662   Status     : Stable
00663 
00664 =cut
00665 
00666 sub register_component {
00667   my ( $self, $cmp_seq_region ) = @_;
00668 
00669   if ( !defined($cmp_seq_region) ) {
00670     throw('cmp_seq_region argument is required');
00671   }
00672 
00673   $self->{'cmp_register'}->{$cmp_seq_region} = 1;
00674 }
00675 
00676 =head2 register_assembled
00677 
00678   Arg [1]    : integer $asm_seq_region
00679                The dbID of the sequence region to register.
00680   Arg [2]    : int $chunk_id
00681                The chunk number of the provided seq_region to register.
00682   Example    : $asm_mapper->register_assembled( 'X', 4 );
00683   Description: Flags a given assembled region as registered in this
00684                assembly mapper.  This should only be called by this
00685                class or the AssemblyMapperAdaptor.  Do not call this
00686                method unless you really know what you are doing.
00687   Return type: None
00688   Exceptions : Throws on incorrect arguments
00689   Caller     : Internal, AssemblyMapperAdaptor
00690   Status     : Stable
00691 
00692 =cut
00693 
00694 sub register_assembled {
00695   my ( $self, $asm_seq_region, $chunk_id ) = @_;
00696 
00697   if ( !defined($asm_seq_region) ) {
00698     throw('asm_seq_region argument is required');
00699   }
00700   if ( !defined($chunk_id) ) {
00701     throw('chunk_id srgument is required');
00702   }
00703 
00704   $self->{'asm_register'}->{$asm_seq_region}->{$chunk_id} = 1;
00705 }
00706 
00707 =head2 mapper
00708 
00709   Arg [1]    : None
00710   Example    : $mapper = $asm_mapper->mapper();
00711   Description: Retrieves the internal mapper used by this Assembly
00712                Mapper.  This is unlikely to be useful unless you
00713                _really_ know what you are doing.
00714   Return type: Bio::EnsEMBL::Mapper
00715   Exceptions : None
00716   Caller     : Internal, AssemblyMapperAdaptor
00717   Status     : Stable
00718 
00719 =cut
00720 
00721 sub mapper {
00722   my ($self) = @_;
00723 
00724   return $self->{'mapper'};
00725 }
00726 
00727 =head2 assembled_CoordSystem
00728 
00729   Arg [1]    : None
00730   Example    : $cs = $asm_mapper->assembled_CoordSystem();
00731   Description: Retrieves the assembled CoordSystem from this
00732                assembly mapper.
00733   Return type: Bio::EnsEMBL::CoordSystem
00734   Exceptions : None
00735   Caller     : Internal, AssemblyMapperAdaptor
00736   Status     : Stable
00737 
00738 =cut
00739 
00740 sub assembled_CoordSystem {
00741   my ($self) = @_;
00742 
00743   return $self->{'asm_cs'};
00744 }
00745 
00746 =head2 component_CoordSystem
00747 
00748   Arg [1]    : None
00749   Example    : $cs = $asm_mapper->component_CoordSystem();
00750   Description: Retrieves the component CoordSystem from this
00751                assembly mapper.
00752   Return type: Bio::EnsEMBL::CoordSystem
00753   Exceptions : None
00754   Caller     : Internal, AssemblyMapperAdaptor
00755   Status     : Stable
00756 
00757 =cut
00758 
00759 sub component_CoordSystem {
00760   my ($self) = @_;
00761 
00762   return $self->{'cmp_cs'};
00763 }
00764 
00765 =head2 adaptor
00766 
00767   Arg [1]    : Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor $adaptor
00768   Example    : None
00769   Description: Getter/set terfor this object's database adaptor.
00770   Returntype : Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor
00771   Exceptions : None
00772   Caller     : General
00773   Status     : Stable
00774 
00775 =cut
00776 
00777 sub adaptor {
00778   my ( $self, $value ) = @_;
00779 
00780   if ( defined($value) ) {
00781     weaken($self->{'adaptor'} = $value);
00782   }
00783 
00784   return $self->{'adaptor'};
00785 }
00786 
00787 =head2 in_assembly
00788 
00789   Description: DEPRECATED, use map() or list_ids() instead.
00790 
00791 =cut
00792 
00793 sub in_assembly {
00794   my ( $self, $object ) = @_;
00795 
00796   deprecate('Use map() or list_ids() instead.');
00797 
00798   my $csa = $self->db->get_CoordSystemAdaptor();
00799 
00800   my $top_level = $csa->fetch_top_level();
00801 
00802   my $asma =
00803     $self->adaptor->fetch_by_CoordSystems( $object->coord_system(),
00804                                            $top_level );
00805 
00806   my @list = $asma->list_ids( $object->seq_region(),
00807                               $object->start(),
00808                               $object->end(),
00809                               $object->coord_system() );
00810 
00811   return ( @list > 0 );
00812 }
00813 
00814 =head2 map_coordinates_to_assembly
00815 
00816   Description: DEPRECATED, use map() instead.
00817 
00818 =cut
00819 
00820 sub map_coordinates_to_assembly {
00821   my ( $self, $contig_id, $start, $end, $strand ) = @_;
00822 
00823   deprecate('Use map() instead.');
00824 
00825   # Not sure if contig_id is seq_region_id or name...
00826   return
00827     $self->map( $contig_id, $start, $end, $strand,
00828                 $self->contig_CoordSystem() );
00829 
00830 }
00831 
00832 =head2 fast_to_assembly
00833 
00834   Description: DEPRECATED, use map() instead.
00835 
00836 =cut
00837 
00838 sub fast_to_assembly {
00839   my ( $self, $contig_id, $start, $end, $strand ) = @_;
00840 
00841   deprecate('Use map() instead.');
00842 
00843   # Not sure if contig_id is seq_region_id or name...
00844   return
00845     $self->map( $contig_id, $start, $end, $strand,
00846                 $self->contig_CoordSystem() );
00847 }
00848 
00849 =head2 map_coordinates_to_rawcontig
00850 
00851   Description: DEPRECATED, use map() instead.
00852 
00853 =cut
00854 
00855 sub map_coordinates_to_rawcontig {
00856   my ( $self, $chr_name, $start, $end, $strand ) = @_;
00857 
00858   deprecate('Use map() instead.');
00859 
00860   return
00861     $self->map( $chr_name, $start, $end, $strand,
00862                 $self->assembled_CoordSystem() );
00863 }
00864 
00865 =head2 list_contig_ids
00866 
00867   Description: DEPRECATED, use list_ids() instead.
00868 
00869 =cut
00870 
00871 sub list_contig_ids {
00872   my ( $self, $chr_name, $start, $end ) = @_;
00873 
00874   deprecate('Use list_ids() instead.');
00875 
00876   return
00877     $self->list_ids( $chr_name, $start, $end,
00878                      $self->assembled_CoordSystem() );
00879 }
00880 
00881 1;