Commit 61093b6e authored by Matthew Laird's avatar Matthew Laird
Browse files

Jira ENSCORESW-1381

- Added support in the Registry for version ids (\.\d+) support in stable_id when determining idenfitier type
- Added support to the ArchiveStableIdAdaptor for versions in stable_ids on object creation
- Test cases for identifiers with and without versions when doing lookups
parent c5d6508b
......@@ -131,7 +131,9 @@ use constant NUM_HIGH_SCORERS => 20;
Arg [2] : (optional) string $type
Example : none
Description : Retrives an ArchiveStableId that is the latest incarnation of
given stable_id.
given stable_id. If the lookup fails, attempts to check for a
version id delimited by a period (.) and lookup again using the
version id.
Returntype : Bio::EnsEMBL::ArchiveStableId or undef if not in database
Exceptions : none
Caller : general
......@@ -143,6 +145,39 @@ use constant NUM_HIGH_SCORERS => 20;
sub fetch_by_stable_id {
my $self = shift;
my $stable_id = shift;
my $arch_id = $self->_fetch_by_stable_id($stable_id, @_);
# If we didn't get anything back, desperately try to see if there's
# a version number in the stable_id
if(!defined($arch_id) && (my $vindex = rindex($stable_id, '.'))) {
$arch_id = $self->fetch_by_stable_id_version(substr($stable_id,0,$vindex),
substr($stable_id,$vindex+1),
@_);
}
return $arch_id;
}
=head2 _fetch_by_stable_id
Arg [1] : string $stable_id
Arg [2] : (optional) string $type
Example : none
Description : Retrives an ArchiveStableId that is the latest incarnation of
given stable_id. Helper function to fetch_by_stable_id, should
not be directly called.
Returntype : Bio::EnsEMBL::ArchiveStableId or undef if not in database
Exceptions : none
Caller : general
Status : At Risk
: under development
=cut
sub _fetch_by_stable_id {
my $self = shift;
my $stable_id = shift;
my $arch_id = Bio::EnsEMBL::ArchiveStableId->new(
-stable_id => $stable_id,
......@@ -1598,13 +1633,13 @@ sub _resolve_type {
}
# standard Ensembl IDs
} elsif ($stable_id =~ /.*G\d+$/) {
} elsif ($stable_id =~ /.*G\d+(\.\d+)?$/) {
$id_type = "Gene";
} elsif ($stable_id =~ /.*T\d+$/) {
} elsif ($stable_id =~ /.*T\d+(\.\d+)?$/) {
$id_type = "Transcript";
} elsif ($stable_id =~ /.*P\d+$/) {
} elsif ($stable_id =~ /.*P\d+(\.\d+)?$/) {
$id_type = "Translation";
} elsif ($stable_id =~ /.*E\d+$/) {
} elsif ($stable_id =~ /.*E\d+(\.\d+)?$/) {
$id_type = "Exon";
# if guessing fails, look in db
......
......@@ -3159,10 +3159,28 @@ sub archive_id_lookup {
}
# A level of abstraction because we need to test the stable_id as-is and then
# try to chop off a version id if nothing is return, and try again
# Loop over a known set of object types for a core DB until we find a hit
sub _core_get_species_and_object_type {
my ($self, $stable_id, $known_type, $dba) = @_;
# Try looking up the species with the stable_is, as-is
my @results = $self->_core_get_species_and_object_type_worker($stable_id, $known_type, $dba);
if(@results) {
return @results;
} elsif(my $vindex = rindex($stable_id, '.')) {
return $self->_core_get_species_and_object_type_worker(substr($stable_id,0,$vindex), $known_type, $dba);
}
return;
}
# Loop over a known set of object types for a core DB until we find a hit
sub _core_get_species_and_object_type_worker {
my ($self, $stable_id, $known_type, $dba) = @_;
my @types = defined $known_type ? ($known_type) : ('Gene', 'Transcript', 'Translation', 'Exon', 'Operon', 'OperonTranscript');
my ($species, $final_type, $final_db_type);
foreach my $type (@types) {
......@@ -3183,9 +3201,28 @@ sub _core_get_species_and_object_type {
return;
}
# Loop over a known set of object types for a compara DB until we find a hit
# A level of abstraction because we need to test the stable_id as-is and then
# try to chop off a version id if nothing is return, and try again
sub _compara_get_species_and_object_type {
my ($self, $stable_id, $known_type, $dba) = @_;
# Try looking up the species with the stable_is, as-is
my @results = $self->_compara_get_species_and_object_type_worker($stable_id, $known_type, $dba);
if(@results) {
return @results;
} elsif(my $vindex = rindex($stable_id, '.')) {
return $self->_compara_get_species_and_object_type_worker(substr($stable_id,0,$vindex), $known_type, $dba);
}
return;
}
# Loop over a known set of object types for a compara DB until we find a hit
sub _compara_get_species_and_object_type_worker {
my ($self, $stable_id, $known_type, $dba) = @_;
my @types = defined $known_type ? ($known_type) : ('GeneTree');
my ($species, $final_type, $final_db_type);
foreach my $type (@types) {
......
......@@ -215,6 +215,16 @@ ok( scalar(@assoc) == 2 and
$asi = $asia->fetch_by_stable_id_version("P2", 1);
ok( $asi->get_peptide eq 'PTWOVERSIONONE*' );
#
# Test looking up active ids
#
my $archive_obj = $asia->fetch_by_stable_id('ENSG00000171456');
is($archive_obj->stable_id, 'ENSG00000171456', 'fetch_by_stable_id with active stable_id');
ok($archive_obj->is_current, 'Is the current stable_id');
$archive_obj = $asia->fetch_by_stable_id('ENSG00000171456.1');
is($archive_obj->stable_id, 'ENSG00000171456', 'fetch_by_stable_id with active stable_id with version');
ok($archive_obj->is_latest, 'Is the latest stable_id');
#
# debug helper
......
......@@ -939,7 +939,16 @@ SKIP: {
#test the get_species_and_object_type method from the Registry
my $registry = 'Bio::EnsEMBL::Registry';
my ( $species, $object_type, $db_type ) = $registry->get_species_and_object_type('ENSG00000355555');
ok( $species eq 'homo_sapiens' && $object_type eq 'Gene');
is( $species, 'homo_sapiens', 'Test the get_species_and_object_type method from the Registry, species');
is( $object_type, 'Gene', 'Test the get_species_and_object_type method from the Registry, object_type');
( $species, $object_type, $db_type ) = $registry->get_species_and_object_type('ENSG00000355555.1');
is( $species, 'homo_sapiens', 'Test the get_species_and_object_type method from the Registry with version, species');
is( $object_type, 'Gene', 'Test the get_species_and_object_type method from the Registry with version, object_type');
( $species, $object_type, $db_type ) = $registry->get_species_and_object_type('ENSG00000355555.2');
ok( !defined($species), 'Test the get_species_and_object_type method from the Registry with wrong version, species');
}
# Testing compara dba retrieval
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment