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
98782778
Commit
98782778
authored
Dec 04, 2012
by
Andy Yates
Browse files
[
ENSCORESW-313
]. Adding support for external db id lookup and filtering by them on synonyms
parent
f9db1c3f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
32 deletions
+84
-32
modules/Bio/EnsEMBL/DBSQL/DBEntryAdaptor.pm
modules/Bio/EnsEMBL/DBSQL/DBEntryAdaptor.pm
+46
-28
modules/Bio/EnsEMBL/Slice.pm
modules/Bio/EnsEMBL/Slice.pm
+19
-4
modules/t/dbEntries.t
modules/t/dbEntries.t
+7
-0
modules/t/slice.t
modules/t/slice.t
+12
-0
No files found.
modules/Bio/EnsEMBL/DBSQL/DBEntryAdaptor.pm
View file @
98782778
...
...
@@ -781,6 +781,38 @@ sub _store_object_xref_mapping {
return
$object_xref_id
;
}
=head2 get_external_db_id
Arg [1] : External DB name
Arg [2] : External DB release
Arg [3] : Ignore version flag
Description: Looks for the internal identifier of an external DB
Exceptions : None
Returntype : Int
=cut
sub
get_external_db_id
{
my
(
$self
,
$db_name
,
$db_release
,
$ignore_release
)
=
@_
;
my
$sql_helper
=
$self
->
dbc
->
sql_helper
;
my
$sql
=
'
SELECT external_db_id FROM external_db WHERE db_name = ?
';
my
@bound_params
;
push
@bound_params
,
$db_name
;
unless
(
$ignore_release
)
{
if
(
$db_release
)
{
$sql
.=
'
AND db_release = ?
';
push
@bound_params
,
$db_release
;
}
else
{
$sql
.=
'
AND db_release is NULL
';
}
}
my
(
$db_id
)
=
@
{
$sql_helper
->
execute_simple
(
-
SQL
=>
$sql
,
-
PARAMS
=>
\
@bound_params
)
};
return
$db_id
;
}
=head2 _check_external_db
Arg [1] : DBEntry object
...
...
@@ -792,34 +824,20 @@ sub _store_object_xref_mapping {
=cut
sub
_check_external_db
{
my
(
$self
,
$db_entry
,
$ignore
)
=
@_
;
my
(
$sql
,
@bound_params
,
$sql_helper
,
$db_name
,
$db_release
);
$db_name
=
$db_entry
->
dbname
();
$db_release
=
$db_entry
->
release
();
$sql_helper
=
$self
->
dbc
->
sql_helper
;
$sql
=
'
SELECT external_db_id FROM external_db WHERE db_name = ?
';
push
@bound_params
,
$db_name
;
unless
(
$ignore
)
{
if
(
$db_release
)
{
$sql
.=
'
AND db_release = ?
';
push
@bound_params
,
$db_release
;
}
else
{
$sql
.=
'
AND db_release is NULL
';
}
}
my
(
$db_id
)
=
@
{
$sql_helper
->
execute_simple
(
-
SQL
=>
$sql
,
-
PARAMS
=>
\
@bound_params
)
};
if
(
$db_id
)
{
return
$db_id
;
}
else
{
throw
(
sprintf
(
"
external_db [%s] release [%s] does not exist
",
$db_name
,
$db_release
)
);
}
my
(
$self
,
$db_entry
,
$ignore
)
=
@_
;
my
(
$db_name
,
$db_release
);
$db_name
=
$db_entry
->
dbname
();
$db_release
=
$db_entry
->
release
();
my
$db_id
=
$self
->
get_external_db_id
(
$db_name
,
$db_release
,
$ignore
);
if
(
$db_id
)
{
return
$db_id
;
}
else
{
throw
(
sprintf
(
"
external_db [%s] release [%s] does not exist
",
$db_name
,
$db_release
)
);
}
}
=head2 _store_or_fetch_xref
...
...
modules/Bio/EnsEMBL/Slice.pm
View file @
98782778
...
...
@@ -3607,8 +3607,12 @@ sub project_to_slice {
=head2 get_all_synonyms
Args : none.
Args [1] : String external_db_name The name of the database to retrieve
the synonym for
Args [2] : Integer external_db_version The version of the database to retrieve
the synonym for. If not specified then we will ignore any versions
Example : my @alternative_names = @{$slice->get_all_synonyms()};
@alternative_names = @{$slice->get_all_synonyms('EMBL')};
Description: get a list of alternative names for this slice
Returntype : reference to list of SeqRegionSynonym objects.
Exception : none
...
...
@@ -3618,16 +3622,27 @@ sub project_to_slice {
=cut
sub
get_all_synonyms
{
my
$self
=
shift
;
my
$external_db_id
=
shift
;
my
(
$self
,
$external_db_name
,
$external_db_version
)
=
@_
;
if
(
!
defined
(
$self
->
{'
synonym
'}
)
)
{
my
$adap
=
$self
->
adaptor
->
db
->
get_SeqRegionSynonymAdaptor
();
$self
->
{'
synonym
'}
=
$adap
->
get_synonyms
(
$self
->
get_seq_region_id
(
$self
)
);
}
if
(
!
$external_db_name
)
{
return
$self
->
{'
synonym
'};
}
my
@args
=
(
$external_db_version
)
?
(
$external_db_name
,
$external_db_version
)
:
(
$external_db_name
,
undef
,
1
);
my
$external_db_id
=
$self
->
adaptor
->
db
()
->
get_DBEntryAdaptor
()
->
get_external_db_id
(
@args
);
if
(
!
$external_db_id
)
{
my
$extra
=
(
$external_db_version
)
?
"
and version
$external_db_version
"
:
q{}
;
throw
"
The external database
$external_db_name
${extra}
did not result in a valid identifier
";
}
return
$self
->
{
'
synonym
'
};
return
[
grep
{
$_
->
external_db_id
()
==
$external_db_id
}
@
{
$self
->
{
synonym
}
}
]
;
}
=head2 add_synonym
...
...
modules/t/dbEntries.t
View file @
98782778
...
...
@@ -509,6 +509,13 @@ $multi->restore();
$multi
->
restore
('
core
',
'
xref
',
'
object_xref
');
}
# Test for external DB ids
{
is
(
$dbEntryAdaptor
->
get_external_db_id
('
RFAM
',
1
),
4200
,
'
RFAM ID as expected
');
ok
(
!
defined
$dbEntryAdaptor
->
get_external_db_id
('
RFAM
',
'
wibble
'),
'
RFAM with a version of wibble means nothing
');
is
(
$dbEntryAdaptor
->
get_external_db_id
('
RFAM
',
'
wibble
',
1
),
4200
,
'
RFAM ID with a version of wibble but ignoring versions as expected
');
}
sub
print_dbEntries
{
my
$dbes
=
shift
;
...
...
modules/t/slice.t
View file @
98782778
...
...
@@ -8,6 +8,7 @@ use IO::String;
use
Bio::EnsEMBL::Test::
MultiTestDB
;
use
Bio::EnsEMBL::
Slice
;
use
Bio::EnsEMBL::
ProjectionSegment
;
use
Test::
Exception
;
our
$verbose
=
0
;
...
...
@@ -444,6 +445,17 @@ ok(@alt_names == 1);
$multi
->
restore
();
# Testing synonym searching
{
my
$chr_20
=
$slice_adaptor
->
fetch_by_region
('
chromosome
',
20
);
my
(
$syn
)
=
@
{
$chr_20
->
get_all_synonyms
('
RFAM
')};
is
(
$syn
->
name
(),
'
anoth_20
',
'
We have the right synonym
');
dies_ok
{
$chr_20
->
get_all_synonyms
('
RFAM
',
'
wibble
')
}
'
Bad external DB version means dying code
';
dies_ok
{
$chr_20
->
get_all_synonyms
('
RFAMing
',
'
wibble
')
}
'
Bad external DB name means dying code
';
(
$syn
)
=
@
{
$chr_20
->
get_all_synonyms
('
RFAM
',
1
)};
is
(
$syn
->
name
(),
'
anoth_20
',
'
We have the right synonym
');
}
#Test assembly exception type on HAP
my
$hap_slice
=
$slice_adaptor
->
fetch_by_region
(
undef
,
'
20_HAP1
');
...
...
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