Skip to content
Snippets Groups Projects
Commit 0becd071 authored by Andy Yates's avatar Andy Yates
Browse files

[ENSCORESW-448]. new overlap algorithm and better test cases. supports...

[ENSCORESW-448]. new overlap algorithm and better test cases. supports overlaps when you do not want to normalise WRT the backing slice
parent 5111f026
No related branches found
No related tags found
No related merge requests found
......@@ -1367,10 +1367,13 @@ sub get_all_alt_locations {
Arg [1] : Bio::EnsEMBL::Feature $f
The other feature you want to check overlap with this feature
for.
Description: This method does a range comparison of this features start and
end and compares it with another features start and end. It will
return true if these ranges overlap and the features are on the
same seq_region.
Description: This method does a range comparison of this feature's C<seq_region_start> and
C<seq_region_end> and compares it with another feature's C<seq_region_start>
and C<seq_region_end>. It will return true if these ranges overlap
and the features are on the same seq_region.
For local coordinate overlaps tests (those values returned from
start and end) use C<overlaps_local()>.
Returntype : TRUE if features overlap, FALSE if they don't
Exceptions : warning if features are on different seq_regions
Caller : general
......@@ -1379,21 +1382,47 @@ sub get_all_alt_locations {
=cut
sub overlaps {
my $self = shift;
my $f = shift;
my ($self, $f) = @_;
my ($sr1, $sr2) = ($self->seq_region_name, $f->seq_region_name);
if($sr1 && $sr2 && ($sr1 ne $sr2)) {
warning("Bio::EnsEMBL::Feature->overlaps(): features are on different seq regions. \$self is on $sr1 and \$feature is on $sr2");
return 0;
}
return ($self->seq_region_end >= $f->seq_region_start and $self->seq_region_start <= $f->seq_region_end) ? 1 : 0;
}
my $sr1_name = $self->seq_region_name;
my $sr2_name = $f->seq_region_name;
=head2 overlaps_local
if ($sr1_name and $sr2_name and ($sr1_name ne $sr2_name)) {
warning("Bio::EnsEMBL::Feature->overlaps(): features are on different seq regions.");
return undef;
Arg [1] : Bio::EnsEMBL::Feature $f
The other feature you want to check overlap with this feature
for.
Description: This method does a range comparison of this feature's start and
end and compares it with another feature's and end. It will
return true if these ranges overlap and the features are
on the same seq_region.
This method will not attempt to resolve starts and ends with
reference to the feature's backing Slice.
For global coordinate overlaps tests (with reference to the feature's
backing sequence region) use C<overlaps()>.
Returntype : TRUE if features overlap, FALSE if they don't
Exceptions : warning if features are on different seq_regions
Caller : general
Status : Stable
=cut
sub overlaps_local {
my ($self, $f) = @_;
my ($sr1, $sr2) = ($self->seq_region_name, $f->seq_region_name);
if($sr1 && $sr2 && ($sr1 ne $sr2)) {
warning("Bio::EnsEMBL::Feature->overlaps_local(): features are on different seq regions. \$self is on $sr1 and \$feature is on $sr2");
return;
}
return ($self->seq_region_end >= $f->seq_region_start and $self->seq_region_start <= $f->seq_region_end);
return ($self->end >= $f->start and $self->start <= $f->end) ? 1 : 0;
}
=head2 get_overlapping_Genes
Description: Get all the genes that overlap this feature.
......
......@@ -463,6 +463,12 @@ my $chr_slice = $db->get_SliceAdaptor->fetch_by_region('chromosome',
'20',
30_249_935,
31_000_000);
my $all_chr_slice = $db->get_SliceAdaptor->fetch_by_region('chromosome', 20);
my $hap_chr_slice = $db->get_SliceAdaptor->fetch_by_region('chromosome',
'20_HAP1',
30_249_935,
31_000_000);
# my $sctg_slice = $db->get_SliceAdaptor->fetch_by_region('supercontig',
# 'NT_028392');
......@@ -490,8 +496,8 @@ my $f2 = new Bio::EnsEMBL::Feature( -start => 10,
# simple same coord system overlap
#
debug( "f1<->f2 overlap = ".($f1->overlaps( $f2 )));
ok( $f1->overlaps( $f2 ));
ok( $f1->overlaps( $f2 ), 'Overlaps: feature 1 <-> feature 2 overlap (1 ends @ 10. 2 starts @ 10)');
ok( $f1->overlaps_local( $f2 ), 'Overlaps Local: feature 1 <-> feature 2 overlap (1 ends @ 10. 2 starts @ 10)');
$f2 = new Bio::EnsEMBL::Feature( -start => 11,
-end => 20,
......@@ -500,10 +506,29 @@ $f2 = new Bio::EnsEMBL::Feature( -start => 11,
-analysis => $analysis
);
ok( ! $f2->overlaps( $f1 ));
ok( ! $f1->overlaps( $f2 ), 'Overlaps: feature 1 <-> new feature 2 do not overlap (1 ends @ 10. 2 starts @ 11)');
ok( ! $f1->overlaps_local( $f2 ), 'Overlaps Local: feature 1 <-> feature 2 overlap (1 ends @ 10. 2 starts @ 10)');
#
# Testing when seq_region overlaps do not return true but local ones do
#
my $f1_absolute = Bio::EnsEMBL::Feature->new(-start => 30_249_935, -end => 30_249_945, -strand => 1, -slice => $all_chr_slice);
ok($f1->overlaps($f1_absolute), 'Overlaps: feature 1 overlaps as both it and absolute feature are on the same chromsomal coordinate');
ok(!$f1->overlaps_local($f1_absolute), 'Overlaps Local: feature 1 does not overlap absolute feature; their starts and ends are different');
#
# Testing alternative seq region overlap
#
my $hap_feature_1 = Bio::EnsEMBL::Feature->new(-start => 1, -end => 10, -strand => 1, -slice => $hap_chr_slice);
warns_like
{ ok( ! $hap_feature_1->overlaps( $f1 ), 'Overlaps: feature 1 <-> new feature 2 do not overlap (different seq regions)') }
qr/different seq regions/,
'Error when using different seq regions as expected';
warns_like
{ ok( ! $hap_feature_1->overlaps_local( $f1 ), 'Overlaps Local: feature 1 <-> feature 2 overlap (different seq regions)') }
qr/different seq regions/,
'Error when using different seq regions as expected';
#
# test get_all_alt_locations
......
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