Bio-EnsEMBL
view release on metacpan or search on metacpan
lib/Bio/EnsEMBL/TopLevelAssemblyMapper.pm view on Meta::CPAN
=head1 CONTACT
Please email comments or questions to the public Ensembl
developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
Questions may also be sent to the Ensembl help desk at
<http://www.ensembl.org/Help/Contact>.
=cut
=head1 NAME
Bio::EnsEMBL::TopLevelAssemblyMapper -
Handles mapping between a given coordinate system and the toplevel
pseudo coordinate system.
=head1 SYNOPSIS
$db = Bio::EnsEMBL::DBSQL::DBAdaptor->new(...);
$asma = $db->get_AssemblyMapperAdaptor();
$csa = $db->get_CoordSystemAdaptor();
my $toplevel = $cs_adaptor->fetch_by_name('toplevel');
my $ctg_cs = $cs_adaptor->fetch_by_name('contig');
$asm_mapper = $map_adaptor->fetch_by_CoordSystems( $toplevel, $ctg_cs );
# map to toplevel coord system for this region
@chr_coords =
$asm_mapper->map( 'AL30421.1.200.92341', 100, 10000, -1, $ctg_cs );
# list toplevel seq_region_ids for this region
@chr_ids =
$asm_mapper->list_ids( 'AL30421.1.200.92341', 1, 1000, -1,
$ctg_cs );
=head1 DESCRIPTION
The TopLevelAssemblyMapper performs mapping between a provided
coordinate system and the toplevel pseudo cooordinate system. The
toplevel coordinate system is not a real coordinate system, but
represents the highest coordinate system that can be mapped to in a
given region. It is only possible to perform unidirectional mapping
using this mapper, because it does not make sense to map from the
toplevel coordinate system to another coordinate system.
=head1 METHODS
=cut
use strict;
use warnings;
package Bio::EnsEMBL::TopLevelAssemblyMapper;
$Bio::EnsEMBL::TopLevelAssemblyMapper::VERSION = '114.0.0';
use Bio::EnsEMBL::Utils::Exception qw(throw);
use Bio::EnsEMBL::Mapper;
use Bio::EnsEMBL::CoordSystem;
use Scalar::Util qw(weaken);
=head2 new
Arg [1] : Bio::EnsEMBL::DBAdaptor $dbadaptor the adaptor for
the database this mapper is using.
Arg [2] : Toplevel CoordSystem
Arg [3] : Other CoordSystem
Description: Creates a new TopLevelAssemblyMapper object
Returntype : Bio::EnsEMBL::DBSQL::TopLevelAssemblyMapper
Exceptions : throws if any of the 3 arguments are missing/ not
: of the correct type.
Caller : Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor
Status : Stable
=cut
sub new {
my ($caller, $adaptor, $toplevel_cs, $other_cs) = @_;
my $class = ref($caller) || $caller;
if(!ref($toplevel_cs)) {
throw('Toplevel CoordSystem argument expected.');
}
if(!ref($other_cs)) {
throw('Other CoordSystem argument expected.');
}
if(!$toplevel_cs->is_top_level()) {
throw($toplevel_cs->name() . " is not the toplevel CoordSystem.");
}
if($other_cs->is_top_level()) {
throw("Other CoordSystem argument should not be toplevel CoordSystem.");
}
my $cs_adaptor = $adaptor->db()->get_CoordSystemAdaptor();
my $coord_systems = $cs_adaptor->fetch_all();
my $self = bless {'coord_systems' => $coord_systems,
'toplevel_cs' => $toplevel_cs,
'other_cs' => $other_cs}, $class;
$self->adaptor($adaptor);
return $self;
}
sub adaptor {
my $self = shift;
weaken($self->{'adaptor'} = shift) if(@_);
return $self->{'adaptor'};
}
=head2 map
Arg [1] : string $frm_seq_region
The name of the sequence region to transform FROM
Arg [2] : int $frm_start
The start of the region to transform FROM
Arg [3] : int $frm_end
The end of the region to transform FROM
Arg [4] : int $strand
The strand of the region to transform FROM
Arg [5] : Bio::EnsEMBL::CoordSystem
The coordinate system to transform FROM
Arg [6] : if set will do a fastmap
Arg [7] : (optional) dummy placeholder to keep the interface
consistent across different mappers
Arg [8] : (optional) boolean
Whether or not to include the original coordinates
Example : @coords = $mapper->map('X', 1_000_000, 2_000_000,
1, $chr_cs);
Description: Transforms coordinates from one coordinate system
to another.
Returntype : List of Bio::EnsEMBL::Mapper::Coordinate and/or
Bio::EnsEMBL::Mapper:Gap objects
Exceptions : thrown if if the specified TO coordinate system is not one
of the coordinate systems associated with this mapper
Caller : general
Status : Stable
=cut
sub map {
throw('Incorrect number of arguments.') if @_ < 6;
my($self, $frm_seq_region_name, $frm_start, $frm_end, $frm_strand, $frm_cs,
$fastmap, $dummy, $include_org_coord) = @_;
if($frm_cs->is_top_level()) {
throw("The toplevel CoordSystem can only be mapped TO, not FROM.");
}
my @tmp;
push @tmp, $frm_seq_region_name;
my $seq_region_id = @{$self->adaptor()->seq_regions_to_ids($frm_cs, \@tmp)}[0];
my $mapper = $self->{'mapper'};
my $toplevel_cs = $self->{'toplevel_cs'};
my $other_cs = $self->{'other_cs'};
my $adaptor = $self->adaptor;
if($frm_cs != $other_cs && !$frm_cs->equals($other_cs)) {
throw("Coordinate system " . $frm_cs->name . " " . $frm_cs->version .
" is neither the assembled nor the component coordinate system " .
" of this AssemblyMapper");
}
( run in 1.498 second using v1.01-cache-2.11-cpan-39bf76dae61 )