Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ensembl-gh-mirror
ensembl
Commits
9972cdee
Commit
9972cdee
authored
Sep 15, 2011
by
Andy Yates
Browse files
Bringing a method to convert from an ensembl location to a slice for region report
parent
6581d3c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
8 deletions
+59
-8
modules/Bio/EnsEMBL/DBSQL/SliceAdaptor.pm
modules/Bio/EnsEMBL/DBSQL/SliceAdaptor.pm
+24
-0
modules/t/sliceAdaptor.t
modules/t/sliceAdaptor.t
+35
-8
No files found.
modules/Bio/EnsEMBL/DBSQL/SliceAdaptor.pm
View file @
9972cdee
...
...
@@ -436,6 +436,30 @@ sub fetch_by_region {
}
}
## end sub fetch_by_region
=head2 fetch_by_toplevel_location
Arg [1] : string $location
Example : my $slice = $sa->fetch_by_toplevel_location('X:1-10000')
Description : Converts an Ensembl location/region into the sequence region
name, start and end and passes them onto C<fetch_by_region()>.
The code assumes that the required slice is on the top level
coordinate system.
Returntype : Bio::EnsEMBL::Slice
Exceptions : If $location is false otherwise see C<fetch_by_region()>
Caller : General
Status : Beta
=cut
sub
fetch_by_toplevel_location
{
my
(
$self
,
$location
)
=
@_
;
throw
'
You must specify a location
'
if
!
$location
;
my
$regex
=
qr/^(\w+) :? (\d+)? (?:-|[.]{2})? (\d+)?/
xms
;
my
(
$seq_region_name
,
$start
,
$end
)
=
$location
=~
$regex
;
my
$coord_system_name
=
'
toplevel
';
return
$self
->
fetch_by_region
(
$coord_system_name
,
$seq_region_name
,
$start
,
$end
,
undef
,
undef
,
0
);
}
=head2 fetch_by_region_unique
Arg [1] : string $coord_system_name (optional)
...
...
modules/t/sliceAdaptor.t
View file @
9972cdee
use
strict
;
use
warnings
;
BEGIN
{
$|
=
1
;
use
Test
;
plan
tests
=>
66
;
}
use
Test::
More
tests
=>
129
;
use
Bio::EnsEMBL::Test::
MultiTestDB
;
use
Bio::EnsEMBL::DBSQL::
SliceAdaptor
;
use
Bio::EnsEMBL::
Slice
;
use
Bio::EnsEMBL::Test::
TestUtils
;
use
Test::
Exception
;
our
$verbose
=
0
;
...
...
@@ -363,13 +360,13 @@ ok($slice->strand == -1);
#default no duplicates and reference only
my
$slices
=
$slice_adaptor
->
fetch_all
('
chromosome
',
undef
);
print_slices
(
$slices
);
ok
(
@$slices
==
64
);
is
(
@$slices
,
63
,
'
References slices for coord system chromosome
'
);
# include duplicates
$slices
=
$slice_adaptor
->
fetch_all
('
chromosome
',
undef
,
0
,
1
);
print_slices
(
$slices
);
ok
(
@$slices
==
63
);
is
(
@$slices
,
62
,
'
References slices for coord system chromosome when including duplicates (Y should become 1 region not 2)
'
);
$slices
=
$slice_adaptor
->
fetch_all
('
contig
',
undef
);
...
...
@@ -447,7 +444,37 @@ ok($slice->coord_system()->name() eq 'chromosome');
$multi
->
restore
('
core
',
'
seq_region
');
###### FETCH BY LOCATION
test_toplevel_location
('
1:1-1000
',
'
chromosome
',
'
1
',
1
,
1000
);
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:
',
'
chromosome
',
'
1
',
1
,
246874334
);
test_toplevel_location
('
1
',
'
chromosome
',
'
1
',
1
,
246874334
);
test_toplevel_location
('
1:1..1000
',
'
chromosome
',
'
1
',
1
,
1000
);
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:
',
'
chromosome
',
'
1
',
1
,
246874334
);
test_toplevel_location
('
1
',
'
chromosome
',
'
1
',
1
,
246874334
);
dies_ok
{
$slice_adaptor
->
fetch_by_toplevel_location
();
}
'
Checking calling without a location fails
';
dies_ok
{
$slice_adaptor
->
fetch_by_toplevel_location
('');
}
'
Checking calling with a blank location fails
';
ok
(
!
defined
$slice_adaptor
->
fetch_by_toplevel_location
('
wibble
'),
'
Checking with a bogus region returns undef
');
sub
test_toplevel_location
{
my
(
$location
,
$cs_name
,
$seq_region_name
,
$start
,
$end
)
=
@_
;
my
$incoming_slice
=
$slice_adaptor
->
fetch_by_toplevel_location
(
$location
);
my
$def
=
ok
(
defined
$incoming_slice
,
"
Slice is defined for
$location
");
SKIP
:
{
skip
'
Incoming slice is undefined
',
5
if
!
$def
;
is
(
$incoming_slice
->
coord_system_name
(),
$cs_name
,
"
Checking coord system name for
$location
");
is
(
$incoming_slice
->
seq_region_name
(),
$seq_region_name
,
'
Checking seq region name for $location
');
is
(
$incoming_slice
->
start
(),
$start
,
"
Checking start for
$location
");
is
(
$incoming_slice
->
end
(),
$end
,
"
Checking end for
$location
");
}
return
;
}
sub
print_slices
{
my
$slices
=
shift
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment