From f267c52399658c72dfe52876529c68c1855d57f2 Mon Sep 17 00:00:00 2001 From: Andrew Yates <ayates@ebi.ac.uk> Date: Thu, 15 Mar 2012 21:24:47 +0000 Subject: [PATCH] Module was not parsing our more interesting toplevel locations --- modules/Bio/EnsEMBL/DBSQL/SliceAdaptor.pm | 14 ++++++++++---- modules/t/sliceAdaptor.t | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/Bio/EnsEMBL/DBSQL/SliceAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/SliceAdaptor.pm index c41cf40179..f926e9af42 100644 --- a/modules/Bio/EnsEMBL/DBSQL/SliceAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/SliceAdaptor.pm @@ -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'; diff --git a/modules/t/sliceAdaptor.t b/modules/t/sliceAdaptor.t index d4190b48b1..353ebd890c 100644 --- a/modules/t/sliceAdaptor.t +++ b/modules/t/sliceAdaptor.t @@ -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"); -- GitLab