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
4c9ef652
Commit
4c9ef652
authored
14 years ago
by
Ian Longden
Browse files
Options
Downloads
Patches
Plain Diff
more changes to nearest gene to feature code
parent
4b3a1051
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm
+128
-39
128 additions, 39 deletions
modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm
modules/Bio/EnsEMBL/Feature.pm
+2
-1
2 additions, 1 deletion
modules/Bio/EnsEMBL/Feature.pm
with
130 additions
and
40 deletions
modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm
+
128
−
39
View file @
4c9ef652
...
@@ -1821,7 +1821,7 @@ sub fetch_all_by_exon_supporting_evidence {
...
@@ -1821,7 +1821,7 @@ sub fetch_all_by_exon_supporting_evidence {
Description: Gets all the genes with transcripts with evidence for a
Description: Gets all the genes with transcripts with evidence for a
specified hit on a particular type of feature. Optionally filter
specified hit on a particular type of feature. Optionally filter
by analysis.
by analysis.
Returntype : Listref of Bio::EnsEMBL::Gene
Returntype : Listref of Bio::EnsEMBL::Gene
.
Exceptions : If feature_type is not of correct type.
Exceptions : If feature_type is not of correct type.
Caller : general
Caller : general
Status : Stable
Status : Stable
...
@@ -1877,7 +1877,7 @@ sub fetch_all_by_transcript_supporting_evidence {
...
@@ -1877,7 +1877,7 @@ sub fetch_all_by_transcript_supporting_evidence {
Arg [1] : Feature object
Arg [1] : Feature object
Example : $genes = $gene_adaptor->fetch_nearest_Gene_by_Feature($feat);
Example : $genes = $gene_adaptor->fetch_nearest_Gene_by_Feature($feat);
Description: Gets the nearest gene to the feature
Description: Gets the nearest gene to the feature
Returntype : Listref of Bio::EnsEMBL::Gene
Returntype : Listref of Bio::EnsEMBL::Gene
, EMPTY list if no nearest
Caller : general
Caller : general
Status : UnStable
Status : UnStable
...
@@ -1887,60 +1887,149 @@ sub fetch_nearest_Gene_by_Feature{
...
@@ -1887,60 +1887,149 @@ sub fetch_nearest_Gene_by_Feature{
my
$self
=
shift
;
my
$self
=
shift
;
my
$feat
=
shift
;
my
$feat
=
shift
;
my
$stranded
=
shift
;
my
$stranded
=
shift
;
my
$stream
=
shift
;
# 1 up stream -1 downstream
my
@genes
;
my
$min_dist
=
0
;
my
$strand
=
$feat
->
strand
;
if
(
defined
(
$stream
)
and
!
$strand
){
warn
("
stream specified but feature has no strand so +ve strand will be used
");
$strand
=
1
;
}
my
$min_dist
=
999
;
my
$gene_id
=
0
;
my
$gene_id
=
0
;
my
$overlapping
=
$feat
->
get_overlapping_Genes
();
my
$overlapping
=
$feat
->
get_overlapping_Genes
();
return
@
{
$overlapping
}[
0
]
if
(
defined
(
@
{
$overlapping
}[
0
]));
return
$overlapping
if
(
defined
(
@
{
$overlapping
}[
0
]));
# print "found overlapping\n";
# }
# else{
# print "No overlapping trying nearest\n";
# }
my
$seq_region_id
=
$feat
->
slice
->
adaptor
->
get_seq_region_id
(
$feat
->
slice
);
my
$seq_region_id
=
$feat
->
slice
->
adaptor
->
get_seq_region_id
(
$feat
->
slice
);
my
$start
=
(
$feat
->
start
+
$feat
->
slice
->
start
)
-
1
;
my
$start
=
(
$feat
->
start
+
$feat
->
slice
->
start
)
-
1
;
my
$end
=
(
$feat
->
end
+
$feat
->
slice
->
start
)
-
1
;
my
$end
=
(
$feat
->
end
+
$feat
->
slice
->
start
)
-
1
;
my
$sql1
=
"
select g.gene_id, (? - g.seq_region_end) as 'dist' from gene g where
";
if
(
$stranded
){
$sql1
.=
"
g.seq_region_strand =
"
.
$feat
->
strand
.
"
and
";
}
$sql1
.=
"
seq_region_id = ? and g.seq_region_end < ? order by dist limit 1
";
my
@gene_ids
;
if
(
!
defined
(
$stream
)
or
$stream
==
0
){
my
$sql1
=
"
select g.gene_id, (? - g.seq_region_end) as 'dist' from gene g where
";
if
(
$stranded
){
$sql1
.=
"
g.seq_region_strand =
"
.
$strand
.
"
and
";
}
$sql1
.=
"
seq_region_id = ? and g.seq_region_end < ? order by dist limit 10
";
#
# MAYBE set the result of prepare to be static in case lots of calls.
#
my
$sql1_sth
=
$self
->
prepare
(
$sql1
)
||
die
"
Could not prepare
$sql1
";
$sql1_sth
->
execute
(
$start
,
$seq_region_id
,
$start
)
||
die
"
Could not execute sql
";
$sql1_sth
->
bind_columns
(
\
$gene_id
,
\
$min_dist
)
||
die
"
Could mot bin columns
";
my
$last_dist
=
99999999999999999
;
while
(
$sql1_sth
->
fetch
()){
if
(
$min_dist
<=
$last_dist
){
push
@gene_ids
,
$gene_id
;
$last_dist
=
$min_dist
;
}
}
$sql1_sth
->
finish
();
my
$sql2
=
"
select g.gene_id, (g.seq_region_start - ?) as 'dist' from gene g where
";
if
(
$stranded
){
$sql2
.=
"
g.seq_region_strand =
"
.
$feat
->
strand
.
"
and
";
}
$sql2
.=
"
seq_region_id = ? and g.seq_region_start > ? order by dist limit 10
";
my
$sql2_sth
=
$self
->
prepare
(
$sql2
)
||
die
"
could not prepare
$sql2
";
my
(
$tmp_min_dist
,
$tmp_gene_id
);
$sql2_sth
->
execute
(
$end
,
$seq_region_id
,
$end
)
||
die
"
Could not execute sql
";
$sql2_sth
->
bind_columns
(
\
$tmp_gene_id
,
\
$tmp_min_dist
)
||
die
"
Could mot bin columns
";
my
$first
=
1
;
while
(
$sql2_sth
->
fetch
()){
if
(
$tmp_min_dist
<=
$last_dist
){
if
(
$first
){
$first
=
0
;
if
(
$tmp_min_dist
<
$last_dist
){
@gene_ids
=
();
#reset
}
}
push
@gene_ids
,
$tmp_gene_id
;
$last_dist
=
$tmp_min_dist
;
}
}
$sql2_sth
->
finish
();
my
$sql1_sth
=
$self
->
prepare
(
$sql1
)
||
die
"
Could not prepare
$sql1
";
$sql1_sth
->
execute
(
$start
,
$seq_region_id
,
$start
)
||
die
"
Could not execute sql
";
$sql1_sth
->
bind_columns
(
\
$gene_id
,
\
$min_dist
)
||
die
"
Could mot bin columns
";
$sql1_sth
->
fetch
()
||
die
"
Could not fetch result
";
$sql1_sth
->
finish
();
my
$sql2
=
"
select g.gene_id, (g.seq_region_start - ?) as 'dist' from gene g where
";
}
if
(
$stranded
){
elsif
((
$stream*$strand
)
==
1
){
$sql2
.=
"
g.seq_region_strand =
"
.
$feat
->
strand
.
"
and
";
my
$sql1
=
"
select g.gene_id, (? - g.seq_region_end) as 'dist' from gene g where
";
if
(
$stranded
){
$sql1
.=
"
g.seq_region_strand =
"
.
$strand
.
"
and
";
}
$sql1
.=
"
seq_region_id = ? and g.seq_region_end < ? order by dist limit 10
";
#
# MAYBE set the result of prepare to be static in case lots of calls.
#
my
$sql1_sth
=
$self
->
prepare
(
$sql1
)
||
die
"
Could not prepare
$sql1
";
$sql1_sth
->
execute
(
$start
,
$seq_region_id
,
$start
)
||
die
"
Could not execute sql
";
$sql1_sth
->
bind_columns
(
\
$gene_id
,
\
$min_dist
)
||
die
"
Could mot bin columns
";
my
$last_dist
;
my
$first
=
1
;
while
(
$sql1_sth
->
fetch
()){
if
(
$first
){
$first
=
0
;
}
else
{
next
if
(
$min_dist
>
$last_dist
);
}
push
@gene_ids
,
$gene_id
;
$last_dist
=
$min_dist
;
}
$sql1_sth
->
finish
();
}
elsif
((
$stream
*
$strand
)
==
-
1
){
my
$sql2
=
"
select g.gene_id, (g.seq_region_start - ?) as 'dist' from gene g where
";
if
(
$stranded
){
$sql2
.=
"
g.seq_region_strand =
"
.
$feat
->
strand
.
"
and
";
}
$sql2
.=
"
seq_region_id = ? and g.seq_region_start > ? order by dist limit 10
";
my
$sql2_sth
=
$self
->
prepare
(
$sql2
)
||
die
"
could not prepare
$sql2
";
my
(
$tmp_min_dist
,
$tmp_gene_id
);
$sql2_sth
->
execute
(
$end
,
$seq_region_id
,
$end
)
||
die
"
Could not execute sql
";
$sql2_sth
->
bind_columns
(
\
$tmp_gene_id
,
\
$tmp_min_dist
)
||
die
"
Could mot bin columns
";
my
$first
=
1
;
my
$last_dist
;
while
(
$sql2_sth
->
fetch
()){
if
(
$first
){
$first
=
0
;
}
else
{
next
if
(
$tmp_min_dist
>
$last_dist
);
}
push
@gene_ids
,
$tmp_gene_id
;
$last_dist
=
$tmp_min_dist
;
}
$sql2_sth
->
finish
();
}
}
$sql2
.=
"
seq_region_id = ? and g.seq_region_start > ? order by dist limit 1
";
else
{
my
$sql2_sth
=
$self
->
prepare
(
$sql2
)
||
die
"
could not prepare
$sql2
";
die
"
Invalid stream or strand must be -1, 0 or 1
\n
";
my
(
$tmp_min_dist
,
$tmp_gene_id
);
$sql2_sth
->
execute
(
$end
,
$seq_region_id
,
$end
)
||
die
"
Could not execute sql
";
$sql2_sth
->
bind_columns
(
\
$tmp_gene_id
,
\
$tmp_min_dist
)
||
die
"
Could mot bin columns
";
$sql2_sth
->
fetch
()
||
die
"
Could not fetch result
";
$sql2_sth
->
finish
();
if
(
$tmp_min_dist
<
$min_dist
||
!
$gene_id
){
$gene_id
=
$tmp_gene_id
}
}
if
(
$gene_id
){
return
$self
->
fetch_by_dbID
(
$gene_id
);
foreach
my
$gene_id
(
@gene_ids
){
push
@genes
,
$self
->
fetch_by_dbID
(
$gene_id
);
}
}
return
\
@genes
;
return
undef
;
}
}
##########################
##########################
...
...
This diff is collapsed.
Click to expand it.
modules/Bio/EnsEMBL/Feature.pm
+
2
−
1
View file @
4c9ef652
...
@@ -1234,10 +1234,11 @@ sub get_overlapping_Genes{
...
@@ -1234,10 +1234,11 @@ sub get_overlapping_Genes{
sub
get_nearest_Gene
{
sub
get_nearest_Gene
{
my
$self
=
shift
;
my
$self
=
shift
;
my
$stranded
=
shift
;
my
$stranded
=
shift
;
my
$stream
=
shift
;
my
$ga
=
Bio::EnsEMBL::
Registry
->
get_adaptor
(
$self
->
adaptor
->
db
->
species
,"
core
","
Gene
");
my
$ga
=
Bio::EnsEMBL::
Registry
->
get_adaptor
(
$self
->
adaptor
->
db
->
species
,"
core
","
Gene
");
return
$ga
->
fetch_nearest_Gene_by_Feature
(
$self
,
$stranded
);
return
$ga
->
fetch_nearest_Gene_by_Feature
(
$self
,
$stranded
,
$stream
);
}
}
...
...
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