Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ensembl
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
ensembl
Commits
04bdd5c1
Commit
04bdd5c1
authored
13 years ago
by
Andy Yates
Browse files
Options
Downloads
Patches
Plain Diff
Split the parsing of a location string away from the use case
parent
5c0b426b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/Bio/EnsEMBL/DBSQL/SliceAdaptor.pm
+60
-24
60 additions, 24 deletions
modules/Bio/EnsEMBL/DBSQL/SliceAdaptor.pm
with
60 additions
and
24 deletions
modules/Bio/EnsEMBL/DBSQL/SliceAdaptor.pm
+
60
−
24
View file @
04bdd5c1
...
...
@@ -470,17 +470,68 @@ sub fetch_by_region {
sub
fetch_by_toplevel_location
{
my
(
$self
,
$location
,
$no_warnings
)
=
@_
;
throw
'
You must specify a location
'
if
!
$location
;
my
(
$seq_region_name
,
$start
,
$end
,
$strand
)
=
$self
->
parse_location_to_values
(
$location
,
$no_warnings
);
if
(
!
$seq_region_name
)
{
return
;
}
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
';
my
$slice
=
$self
->
fetch_by_region
(
$coord_system_name
,
$seq_region_name
,
$start
,
$end
,
$strand
,
undef
,
0
);
return
unless
$slice
;
my
$srl
=
$slice
->
seq_region_length
();
my
$name
=
$slice
->
seq_region_name
();
if
(
defined
$start
&&
$start
>
$srl
)
{
throw
"
Cannot request a slice whose start (
$start
) is greater than
$srl
for
$name
.
";
}
if
(
defined
$end
&&
$end
>
$srl
)
{
warning
"
Requested end (
$end
) is greater than
$srl
for
$name
. Resetting to
$srl
"
if
!
$no_warnings
;
$slice
->
{
end
}
=
$srl
;
}
return
$slice
;
}
=head2 parse_location_to_values
Arg [1] : string $location
Ensembl formatted location. Can be a format like
C<name:start-end>, C<name:start..end>, C<name:start:end>,
C<name:start>, C<name>. We can also support strand
specification as a +/- or 1/-1.
Location names must be separated by a C<:>. All others can be
separated by C<..>, C<:> or C<->.
Arg[2] : boolean $no_warnings
Suppress warnings from this method
Example : my ($name, $start, $end, $strand) = $sa->parse_location_to_values('X:1..100:1);
Description : Takes in an Ensembl location String and returns the parsed
values
Returntype : List. Contains name, start, end and strand
=cut
sub
parse_location_to_values
{
my
(
$self
,
$location
,
$no_warnings
)
=
@_
;
throw
'
You must specify a location
'
if
!
$location
;
#cleanup any nomenclature like 1_000 or 1 000 or 1,000
my
$number_seps_regex
=
qr/\s+|,|_/
;
my
$separator
=
qr/(?:-|[.]{2}|\:)?/
;
my
$number
=
qr/[0-9,_ E]+/
xms
;
my
$strand
=
qr/[+-1]|-1/
xms
;
my
$separator
_regex
=
qr/(?:-|[.]{2}|\:)?/
;
my
$number
_regex
=
qr/[0-9,_ E]+/
xms
;
my
$strand
_regex
=
qr/[+-1]|-1/
xms
;
my
$regex
=
qr/^(\w+) \s* :? \s* ($number)? $separator ($number)? $separator ($strand)? $/
xms
;
if
(
my
(
$seq_region_name
,
$start
,
$end
,
$strand
)
=
$location
=~
$regex
)
{
my
$regex
=
qr/^(\w+) \s* :? \s* ($number
_regex
)? $separator
_regex
($number
_regex
)? $separator
_regex
($strand
_regex
)? $/
xms
;
my
(
$seq_region_name
,
$start
,
$end
,
$strand
);
if
((
$seq_region_name
,
$start
,
$end
,
$strand
)
=
$location
=~
$regex
)
{
if
(
defined
$strand
)
{
if
(
!
looks_like_number
(
$strand
))
{
...
...
@@ -505,24 +556,9 @@ sub fetch_by_toplevel_location {
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
';
my
$slice
=
$self
->
fetch_by_region
(
$coord_system_name
,
$seq_region_name
,
$start
,
$end
,
$strand
,
undef
,
0
);
return
unless
$slice
;
my
$srl
=
$slice
->
seq_region_length
();
my
$name
=
$slice
->
seq_region_name
();
if
(
defined
$start
&&
$start
>
$srl
)
{
throw
"
Cannot request a slice whose start (
$start
) is greater than
$srl
for
$name
.
";
}
if
(
defined
$end
&&
$end
>
$srl
)
{
warning
"
Requested end (
$end
) is greater than
$srl
for
$name
. Resetting to
$srl
"
if
!
$no_warnings
;
$slice
->
{
end
}
=
$srl
;
}
return
$slice
;
}
return
;
return
(
$seq_region_name
,
$start
,
$end
,
$strand
);
}
=head2 fetch_by_region_unique
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment