Skip to content

Commit ae8d137

Browse files
committed
avoid explicit Bio::Range
only using this to calculate intersection length, which can be done easily enough. This helps in compile test when BioPerl is not installed.
1 parent a816e91 commit ae8d137

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

scripts/get_intersecting_features.pl

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use strict;
77
use Getopt::Long qw(:config no_ignore_case bundling);
88
use Pod::Usage;
9-
use Bio::Range;
109
use Bio::ToolBox::Data;
1110
use Bio::ToolBox::db_helper qw(
1211
open_db_connection
@@ -15,7 +14,7 @@
1514
);
1615
use Bio::ToolBox::utility qw(format_with_commas);
1716

18-
our $VERSION = '2.00';
17+
our $VERSION = '2.04';
1918

2019
print "\n A script to pull out overlapping features\n\n";
2120

@@ -574,18 +573,22 @@ sub determine_overlap {
574573
# work (what!!!!????), intersection and overlap_extent fail to
575574
# give proper end values, just returns "-end"
576575

577-
# the workaround is to create a new simple Bio::Range object
578-
# using the coordinates from the reference region, and then determine the
579-
# overlap between it and the target feature
580-
my $a = Bio::Range->new(
581-
-start => $reference->start,
582-
-end => $reference->end,
583-
-strand => $ref_strand,
584-
);
585-
586-
# find the overlap
587-
my $int = $a->intersection($target);
588-
return $int->length;
576+
# the workaround is to just calculate the intersection ourself
577+
my ( $istart, $istop );
578+
if ( $reference->start <= $target->start ) {
579+
$istart = $reference->start;
580+
}
581+
else {
582+
$istart = $target->start;
583+
}
584+
if ( $reference->end >= $target->end ) {
585+
$istop = $reference->end;
586+
}
587+
else {
588+
$istop = $target->end;
589+
}
590+
return 0 if $istart > $istop;
591+
return ($istop - $istart + 1);
589592
}
590593

591594
sub summarize_found_features {

0 commit comments

Comments
 (0)