sub _remap
{ my ($self, $features, $mapper, $slice) = @_;
if(@$features && (!$features->[0]->isa('Bio::EnsEMBL::Feature') ||
$features->[0]->slice == $slice)) {
return $features;
}
my @out;
my $slice_start = $slice->start();
my $slice_end = $slice->end();
my $slice_strand = $slice->strand();
my $slice_cs = $slice->coord_system();
my ($seq_region, $start, $end, $strand);
my $slice_seq_region = $slice->seq_region_name();
foreach my $f (@$features) {
my $fslice = $f->slice();
if(!$fslice) {
throw("Feature does not have attached slice.\n");
}
my $fseq_region = $fslice->seq_region_name();
my $fcs = $fslice->coord_system();
if(!$slice_cs->equals($fcs)) {
($seq_region, $start, $end, $strand) =
$mapper->fastmap($fseq_region,$f->start(),$f->end(),$f->strand(),$fcs);
next if(!defined $start);
} else {
$start = $f->start();
$end = $f->end();
$strand = $f->strand();
$seq_region = $f->slice->seq_region_name();
}
next if ($start > $slice_end) || ($end < $slice_start) ||
($slice_seq_region ne $seq_region);
my ($new_start, $new_end);
if($slice_strand == -1) {
$new_start = $slice_end - $end + 1;
$new_end = $slice_end - $start + 1;
} else {
$new_start = $start - $slice_start + 1;
$new_end = $end - $slice_start + 1;
}
push @out, Bio::EnsEMBL::AssemblyExceptionFeature->new(
'-dbID' => $f->dbID,
'-start' => $new_start,
'-end' => $new_end,
'-strand' => $strand * $slice_strand,
'-adaptor' => $self,
'-slice' => $slice,
'-alternate_slice' => $f->alternate_slice,
'-type' => $f->type,
);
}
return\@ out;
}
1; } |
sub fetch_all
{ my $self = shift;
if(defined($self->{'_aexc_cache'})) {
return $self->{'_aexc_cache'};
}
my $statement = qq(
SELECT ae.assembly_exception_id,
ae.seq_region_id,
ae.seq_region_start,
ae.seq_region_end,
ae.exc_type,
ae.exc_seq_region_id,
ae.exc_seq_region_start,
ae.exc_seq_region_end,
ae.ori
FROM assembly_exception ae,
coord_system cs,
seq_region sr
WHERE cs.species_id = ?
AND sr.coord_system_id = cs.coord_system_id
AND sr.seq_region_id = ae.seq_region_id);
my $sth = $self->prepare($statement);
$sth->bind_param( 1, $self->species_id(), SQL_INTEGER );
$sth->execute();
my ($ax_id, $sr_id, $sr_start, $sr_end,
$x_type, $x_sr_id, $x_sr_start, $x_sr_end, $ori);
$sth->bind_columns(\$ax_id,\$ sr_id,\$ sr_start,\$ sr_end,\$
x_type,\$ x_sr_id,\$ x_sr_start,\$ x_sr_end,\$ ori);
my @features;
my $sa = $self->db()->get_SliceAdaptor();
$self->{'_aexc_dbID_cache'} = {};
while($sth->fetch()) {
my $slice = $sa->fetch_by_seq_region_id($sr_id);
my $x_slice = $sa->fetch_by_seq_region_id($x_sr_id);
my $a = Bio::EnsEMBL::AssemblyExceptionFeature->new
('-dbID' => $ax_id,
'-start' => $sr_start,
'-end' => $sr_end,
'-strand' => 1,
'-adaptor' => $self,
'-slice' => $slice,
'-alternate_slice' => $x_slice->sub_Slice($x_sr_start, $x_sr_end),
'-type' => $x_type);
push @features, $a;
$self->{'_aexc_dbID_cache'}->{$ax_id} = $a;
push @features, Bio::EnsEMBL::AssemblyExceptionFeature->new
('-dbID' => $ax_id,
'-start' => $x_sr_start,
'-end' => $x_sr_end,
'-strand' => 1,
'-adaptor' => $self,
'-slice' => $x_slice,
'-alternate_slice' => $slice->sub_Slice($sr_start, $sr_end),
'-type' => "$x_type REF" );
}
$sth->finish();
$self->{'_aexc_cache'} =\@ features;
return\@ features; } |
sub fetch_all_by_Slice
{ my $self = shift;
my $slice = shift;
my $key= uc($slice->name());
if(exists($self->{'_aexc_slice_cache'}->{$key})) {
return $self->{'_aexc_slice_cache'}->{$key};
}
my $all_features = $self->fetch_all();
my $mcc = $self->db()->get_MetaCoordContainer();
my $css = $mcc->fetch_all_CoordSystems_by_feature_type('assembly_exception');
my @features;
my $ma = $self->db()->get_AssemblyMapperAdaptor();
foreach my $cs (@$css) {
my $mapper;
if($cs->equals($slice->coord_system)) {
$mapper = undef;
} else {
$mapper = $ma->fetch_by_CoordSystems($cs,$slice->coord_system());
}
push @features, @{ $self->_remap($all_features, $mapper, $slice) };
}
$self->{'_aexc_slice_cache'}->{$key} =\@ features;
return\@ features;
}
} |