Skip to content
Snippets Groups Projects
Commit 5ef84030 authored by Kieron Taylor's avatar Kieron Taylor :angry:
Browse files

Added constrain_to_seq_region for web rendering reasons, where requested...

Added constrain_to_seq_region for web rendering reasons, where requested slice->expand were flying off the end of chromosomes.
parent cf700c06
No related branches found
No related tags found
No related merge requests found
......@@ -1194,6 +1194,33 @@ sub expand {
return bless \%new_slice, ref($self);
} ## end sub expand
=head2 constrain_to_seq_region
Example : $new_slice = $slice->expand(1000,10000);
$new_slice = $new_slice->constrain_to_seq_region();
Description: Used to prevent overly zealous expand calls going off the end of
the sequence region. It contracts the start and end where needed
and produces a slice copy with the tweaked coordinates.
Returntype : Bio::EnsEMBL::Slice
=cut
sub constrain_to_seq_region {
my ($self) = @_;
# circular calculations should already be taken care of
if ($self->is_circular) {return $self}
my $new_start = $self->start;
my $new_end = $self->end;
my $seq_region = $self->seq_region_Slice;
if ($new_start < $seq_region->start) {$new_start = $seq_region->start}
if ($new_end > $seq_region->end) {$new_end = $seq_region->end}
my %new_slice = %$self;
$new_slice{'start'} = $new_start;
$new_slice{'end'} = $new_end;
return bless \%new_slice, ref($self);
}
=head2 sub_Slice
......@@ -1202,8 +1229,8 @@ sub expand {
Arg 2 : int $end
Arge [3] : int $strand
Example : none
Description: Makes another Slice that covers only part of this slice
If a slice is requested which lies outside of the boundaries
Description: Makes another Slice that covers only part of this Slice
If a Slice is requested which lies outside of the boundaries
of this function will return undef. This means that
behaviour will be consistant whether or not the slice is
attached to the database (i.e. if there is attached sequence
......
......@@ -188,6 +188,17 @@ ok(($clone->start == 1) && ($clone->end() == $len + 1000));
$clone = $clone->expand(-1000, 0);
ok(($clone->start == 1001) && ($clone->end() == $len + 1000));
#
# Test constrain_to_seq_region
#
my $tidy_clone = $clone->expand(1000000,10000000);
$tidy_clone = $tidy_clone->constrain_to_seq_region;
ok($tidy_clone->start == 1 && $tidy_clone->end == 84710, 'Huge expand call truncates nicely');
$tidy_clone = $clone->expand(0,-1000);
$tidy_clone = $tidy_clone->constrain_to_seq_region;
note($tidy_clone->start."-".$tidy_clone->end());
ok(($tidy_clone->start == 1001) && ($tidy_clone->end() == 84710), 'constrain_to_seq_region does no harm');
#
# Test Slice::invert
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment