Commit f267c523 authored by Andy Yates's avatar Andy Yates
Browse files

Module was not parsing our more interesting toplevel locations

parent 63895fd4
......@@ -466,23 +466,29 @@ sub fetch_by_region {
sub fetch_by_toplevel_location {
my ($self, $location, $no_warnings) = @_;
throw 'You must specify a location' if ! $location;
my $regex = qr/^(\w+) :? (\d+)? (?:-|[.]{2})? (\d+)?$/xms;
#cleanup any nomenclature like 1_000 or 1 000 or 1,000
my $number_seps_regex = qr/\s+|,|_/;
my $number = qr/[0-9,_ E]+/xms;
my $regex = qr/^(\w+) \s* :? \s* ($number)? (?:-|[.]{2})? ($number)?$/xms;
if(my ($seq_region_name, $start, $end) = $location =~ $regex) {
if(defined $start) {
$start =~ s/$number_seps_regex//g;
if($start < 1) {
warning "Start was less than 1 (${start}) which is not allowed. Resetting to 1" if ! $no_warnings;
$start = 1;
}
$start =~ s/$number_seps_regex//g; #cleanup any nomenclature like 1_000 or 1 000 or 1,000
}
if(defined $end) {
$end =~ s/$number_seps_regex//g;
if($end < 1) {
throw "Cannot request negative or 0 end indexes through this interface. Given $end but expected something greater than 0";
}
$end =~ s/$number_seps_regex//g; #cleanup any nomenclature like 1_000 or 1 000 or 1,000
}
if(defined $start && defined $end && $start > $end) {
throw "Cannot request a slice whose start is greater than its end. Start: $start. End: $end";
}
my $coord_system_name = 'toplevel';
......
......@@ -466,6 +466,7 @@ test_toplevel_location('1: 1', 'chromosome', '1', 1, 246874334);
test_toplevel_location('1: -10', 'chromosome', '1', 1, 10);
test_toplevel_location('1: 100', 'chromosome', '1', 100, 246874334);
test_toplevel_location('1:100..2_000_000_000', 'chromosome', '1', 100, 246874334);
test_toplevel_location('1:100..2E9', 'chromosome', '1', 100, 246874334);
dies_ok { $slice_adaptor->fetch_by_toplevel_location(); } 'Checking calling without a location fails';
dies_ok { $slice_adaptor->fetch_by_toplevel_location('', 1); } 'Checking calling with a blank location fails';
......@@ -476,7 +477,7 @@ ok(!defined $slice_adaptor->fetch_by_toplevel_location('1:-100--50', 1), 'Checki
sub test_toplevel_location {
my ($location, $cs_name, $seq_region_name, $start, $end) = @_;
my $incoming_slice = $slice_adaptor->fetch_by_toplevel_location($location, 1);
my $def = ok(defined $incoming_slice, "Slice is defined for $location");
my $def = ok(defined $incoming_slice, "We expect a defined Slice for location: $location");
SKIP : {
skip 'Incoming slice is undefined', 5 if ! $def;
is($incoming_slice->coord_system_name(), $cs_name, "Checking coord system name for $location");
......
Markdown is supported
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