Commit c5d6508b authored by Matthew Laird's avatar Matthew Laird
Browse files

Jira ENSCORESW-1381

- handlers in Exon, Gene, Operon, OperonTranscript and Transcript Adaptors for a versions fetch_by_stable_id call and new handler for fetch_by_stable_id_version
- Translation is handled implicitly through calls to Transcript
- Test cases for the new handlers and functionality
parent 2211c7ed
......@@ -156,10 +156,51 @@ sub fetch_by_stable_id {
$self->bind_param_generic_fetch($stable_id,SQL_VARCHAR);
my ($exon) = @{ $self->generic_fetch($constraint) };
# If we didn't get anything back, desperately try to see if there's
# a version number in the stable_id
if(!defined($exon) && (my $vindex = rindex($stable_id, '.'))) {
$exon = $self->fetch_by_stable_id_version(substr($stable_id,0,$vindex),
substr($stable_id,$vindex+1));
}
return $exon;
}
=head2 fetch_by_stable_id_version
Arg [1] : String $id
The stable ID of the exon to retrieve
Arg [2] : Integer $version
The version of the stable_id to retrieve
Example : $exon = $exon_adaptor->fetch_by_stable_id('ENSE0000988221', 3);
Description: Retrieves an exon object from the database via its stable id and version.
The exon will be retrieved in its native coordinate system (i.e.
in the coordinate system it is stored in the database). It may
be converted to a different coordinate system through a call to
transform() or transfer(). If the exon is not found
undef is returned instead.
Returntype : Bio::EnsEMBL::Exon or undef
Exceptions : if we cant get the exon in given coord system
Caller : general
Status : Stable
=cut
sub fetch_by_stable_id_version {
my ($self, $stable_id, $version) = @_;
# Enforce that version be numeric
return unless($version =~ /^\d+$/);
my $constraint = "e.stable_id = ? AND e.version = ? AND e.is_current = 1";
$self->bind_param_generic_fetch($stable_id, SQL_VARCHAR);
$self->bind_param_generic_fetch($version, SQL_INTEGER);
my ($exon) = @{$self->generic_fetch($constraint)};
return $exon;
}
=head2 fetch_all_versions_by_stable_id
Arg [1] : String $stable_id
......
......@@ -248,9 +248,50 @@ sub fetch_by_stable_id {
$self->bind_param_generic_fetch($stable_id, SQL_VARCHAR);
my ($gene) = @{$self->generic_fetch($constraint)};
# If we didn't get anything back, desperately try to see if there's
# a version number in the stable_id
if(!defined($gene) && (my $vindex = rindex($stable_id, '.'))) {
$gene = $self->fetch_by_stable_id_version(substr($stable_id,0,$vindex),
substr($stable_id,$vindex+1));
}
return $gene;
}
=head2 fetch_by_stable_id_version
Arg [1] : String $id
The stable ID of the gene to retrieve
Arg [2] : Integer $version
The version of the stable_id to retrieve
Example : $gene = $gene_adaptor->fetch_by_stable_id('ENSG00000148944', 14);
Description: Retrieves a gene object from the database via its stable id and version.
The gene will be retrieved in its native coordinate system (i.e.
in the coordinate system it is stored in the database). It may
be converted to a different coordinate system through a call to
transform() or transfer(). If the gene or exon is not found
undef is returned instead.
Returntype : Bio::EnsEMBL::Gene or undef
Exceptions : if we cant get the gene in given coord system
Caller : general
Status : Stable
=cut
sub fetch_by_stable_id_version {
my ($self, $stable_id, $version) = @_;
# Enforce that version be numeric
return unless($version =~ /^\d+$/);
my $constraint = "g.stable_id = ? AND g.version = ? AND g.is_current = 1";
$self->bind_param_generic_fetch($stable_id, SQL_VARCHAR);
$self->bind_param_generic_fetch($version, SQL_INTEGER);
my ($gene) = @{$self->generic_fetch($constraint)};
return $gene;
}
=head2 fetch_all_by_source
Arg [1] : String $source
......
......@@ -190,6 +190,13 @@ sub fetch_by_stable_id {
$self->bind_param_generic_fetch( $stable_id, SQL_VARCHAR );
my ($operon) = @{ $self->generic_fetch($constraint) };
# If we didn't get anything back, desperately try to see if there's
# a version number in the stable_id
if(!defined($operon) && (my $vindex = rindex($stable_id, '.'))) {
$operon = $self->fetch_by_stable_id_version(substr($stable_id,0,$vindex),
substr($stable_id,$vindex+1));
}
return $operon;
}
......@@ -204,6 +211,40 @@ sub fetch_by_stable_id {
=cut
=head2 fetch_by_stable_id_version
Arg [1] : String $id
The stable ID of the operon to retrieve
Arg [2] : Integer $version
The version of the stable_id to retrieve
Example : $operon = $operon_adaptor->fetch_by_stable_id('16152-16153-4840', 2);
Description: Retrieves an operon object from the database via its stable id and version.
The operon will be retrieved in its native coordinate system (i.e.
in the coordinate system it is stored in the database). It may
be converted to a different coordinate system through a call to
transform() or transfer(). If the operon is not found
undef is returned instead.
Returntype : Bio::EnsEMBL::Operon or undef
Exceptions : if we cant get the operon in given coord system
Caller : general
Status : Stable
=cut
sub fetch_by_stable_id_version {
my ($self, $stable_id, $version) = @_;
# Enforce that version be numeric
return unless($version =~ /^\d+$/);
my $constraint = "o.stable_id = ? AND o.version = ?";
$self->bind_param_generic_fetch($stable_id, SQL_VARCHAR);
$self->bind_param_generic_fetch($version, SQL_INTEGER);
my ($operon) = @{$self->generic_fetch($constraint)};
return $operon;
}
sub fetch_all {
my ($self) = @_;
......
......@@ -150,12 +150,12 @@ sub list_seq_region_ids {
Arg [1] : String $id
The stable ID of the operon_transcript to retrieve
Example : $operon_transcript = $operon_transcript_adaptor->fetch_by_stable_id('ENSG00000148944');
Example : $operon_transcript = $operon_transcript_adaptor->fetch_by_stable_id('T16152-16153-4840');
Description: Retrieves a operon_transcript object from the database via its stable id.
The operon_transcript will be retrieved in its native coordinate system (i.e.
in the coordinate system it is stored in the database). It may
be converted to a different coordinate system through a call to
transform() or transfer(). If the operon_transcript or exon is not found
transform() or transfer(). If the operon_transcript is not found
undef is returned instead.
Returntype : Bio::EnsEMBL::OperonTranscript or undef
Exceptions : if we cant get the operon_transcript in given coord system
......@@ -171,9 +171,50 @@ sub fetch_by_stable_id {
$self->bind_param_generic_fetch( $stable_id, SQL_VARCHAR );
my ($operon_transcript) = @{ $self->generic_fetch($constraint) };
# If we didn't get anything back, desperately try to see if there's
# a version number in the stable_id
if(!defined($operon_transcript) && (my $vindex = rindex($stable_id, '.'))) {
$operon_transcript = $self->fetch_by_stable_id_version(substr($stable_id,0,$vindex),
substr($stable_id,$vindex+1));
}
return $operon_transcript;
}
=head2 fetch_by_stable_id_version
Arg [1] : String $id
The stable ID of the operon_transcript to retrieve
Arg [2] : Integer $version
The version of the stable_id to retrieve
Example : $operon_transcript = $operon_transcript_adaptor->fetch_by_stable_id('T16152-16153-4840', 2);
Description: Retrieves an operon_transcript object from the database via its stable id and version.
The operon_transcript will be retrieved in its native coordinate system (i.e.
in the coordinate system it is stored in the database). It may
be converted to a different coordinate system through a call to
transform() or transfer(). If the operon_transcript is not found
undef is returned instead.
Returntype : Bio::EnsEMBL::OperonTranscript or undef
Exceptions : if we cant get the operon_transcript in given coord system
Caller : general
Status : Stable
=cut
sub fetch_by_stable_id_version {
my ($self, $stable_id, $version) = @_;
# Enforce that version be numeric
return unless($version =~ /^\d+$/);
my $constraint = "o.stable_id = ? AND o.version = ?";
$self->bind_param_generic_fetch($stable_id, SQL_VARCHAR);
$self->bind_param_generic_fetch($version, SQL_INTEGER);
my ($operon_transcript) = @{$self->generic_fetch($constraint)};
return $operon_transcript;
}
=head2 fetch_by_name
Arg [1] : String $label - name of operon transcript to fetch
......
......@@ -169,10 +169,52 @@ sub fetch_by_stable_id {
my ($transcript) = @{ $self->generic_fetch($constraint) };
# If we didn't get anything back, desperately try to see if there's
# a version number in the stable_id
if(!defined($transcript) && (my $vindex = rindex($stable_id, '.'))) {
$transcript = $self->fetch_by_stable_id_version(substr($stable_id,0,$vindex),
substr($stable_id,$vindex+1));
}
return $transcript;
}
=head2 fetch_by_stable_id_version
Arg [1] : String $id
The stable ID of the transcript to retrieve
Arg [2] : Integer $version
The version of the stable_id to retrieve
Example : $tr = $tr_adaptor->fetch_by_stable_id('ENST00000309301', 3);
Description: Retrieves a transcript object from the database via its
stable id and version.
The transcript will be retrieved in its native coordinate system (i.e.
in the coordinate system it is stored in the database). It may
be converted to a different coordinate system through a call to
transform() or transfer(). If the transcript is not found
undef is returned instead.
Returntype : Bio::EnsEMBL::Transcript or undef
Exceptions : if we cant get the transcript in given coord system
Caller : general
Status : Stable
=cut
sub fetch_by_stable_id_version {
my ($self, $stable_id, $version) = @_;
# Enforce that version be numeric
return unless($version =~ /^\d+$/);
my $constraint = "t.stable_id = ? AND t.version = ? AND t.is_current = 1";
$self->bind_param_generic_fetch($stable_id, SQL_VARCHAR);
$self->bind_param_generic_fetch($version, SQL_INTEGER);
my ($transcript) = @{$self->generic_fetch($constraint)};
return $transcript;
}
sub fetch_all {
my ($self) = @_;
......@@ -216,7 +258,7 @@ sub fetch_all_versions_by_stable_id {
('ENSP00000311007');
Description: Retrieves a Transcript object using the stable identifier of
its translation.
Returntype : Bio::EnsEMBL::Transcript
Returntype : Bio::EnsEMBL::Transcript or undef
Exceptions : none
Caller : general
Status : Stable
......@@ -242,11 +284,60 @@ sub fetch_by_translation_stable_id {
$sth->finish;
if ($id){
return $self->fetch_by_dbID($id);
} elsif(my $vindex = rindex($transl_stable_id, '.')) {
return $self->fetch_by_translation_stable_id_version(substr($transl_stable_id,0,$vindex),
substr($transl_stable_id,$vindex+1));
} else {
return undef;
return undef;
}
}
=head2 fetch_by_translation_stable_id_version
Arg [1] : String $transl_stable_id
The stable identifier of the translation of the transcript to
retrieve
Arg [2] : Integer $version
The version of the translation of the transcript to retrieve
Example : my $tr = $tr_adaptor->fetch_by_translation_stable_id_version
('ENSP00000311007', 2);
Description: Retrieves a Transcript object using the stable identifier and
version of its translation.
Returntype : Bio::EnsEMBL::Transcript or undef
Exceptions : none
Caller : general
Status : Stable
=cut
sub fetch_by_translation_stable_id_version {
my ($self, $transl_stable_id, $transl_version ) = @_;
# Enforce that version be numeric
return unless($transl_version =~ /^\d+$/);
my $sth = $self->prepare(qq(
SELECT t.transcript_id
FROM translation tl,
transcript t
WHERE tl.stable_id = ?
AND tl.version = ?
AND tl.transcript_id = t.transcript_id
AND t.is_current = 1
));
$sth->bind_param(1, $transl_stable_id, SQL_VARCHAR);
$sth->bind_param(2, $transl_version, SQL_INTEGER);
$sth->execute();
my ($id) = $sth->fetchrow_array;
$sth->finish;
if ($id){
return $self->fetch_by_dbID($id);
} else {
return undef;
}
}
=head2 fetch_by_translation_id
......
......@@ -242,6 +242,18 @@ $exon = $exonad->fetch_by_stable_id('ENSE00001109603');
debug("fetch_by_stable_id");
ok( $exon->dbID == 162033 );
$exon = $exonad->fetch_by_stable_id('ENSE00001109603.1');
ok($exon->dbID == 162033, 'fetch_by_stable_id with version');
$exon = $exonad->fetch_by_stable_id('ENSE00001109603.1a');
ok(!defined($exon), 'fetch_by_stable_id with bad version');
$exon = $exonad->fetch_by_stable_id_version('ENSE00001109603', 1);
ok($exon->dbID == 162033, 'fetch_by_stable_id_version with version');
$exon = $exonad->fetch_by_stable_id_version('ENSE00001109603', '1a');
ok(!defined($exon), 'fetch_by_stable_id_version with bad version');
my @exons = @{ $exonad->fetch_all_versions_by_stable_id('ENSE00001109603') };
debug("fetch_all_versions_by_stable_id");
ok( scalar(@exons) == 1 );
......
......@@ -840,6 +840,18 @@ $gene = $ga->fetch_by_stable_id('ENSG00000355555');
debug("fetch_by_stable_id");
ok($gene->dbID == 18275);
$gene = $ga->fetch_by_stable_id("ENSG00000171456.1");
ok($gene->stable_id eq 'ENSG00000171456', "Fetch by stable_id with version");
$gene = $ga->fetch_by_stable_id_version("ENSG00000171456", 1);
ok($gene->stable_id eq 'ENSG00000171456', "fetch_by_stable_id_version");
$gene = $ga->fetch_by_stable_id("ENSG00000171456.1a");
ok(! defined($gene), "Fetch by stable_id with bad version");
$gene = $ga->fetch_by_stable_id_version("ENSG00000171456", '1a');
ok(! defined($gene), "fetch_by_stable_id_version, with bad version");
@genes = @{$ga->fetch_all_versions_by_stable_id('ENSG00000355555')};
debug("fetch_all_versions_by_stable_id");
ok(scalar(@genes) == 1);
......
......@@ -99,6 +99,18 @@ $operon = $operon_adaptor->fetch_by_stable_id('16152-16153-4840');
debug( "Operon->fetch_by_stable_id()" );
ok( $operon );
$operon = $operon_adaptor->fetch_by_stable_id('16152-16153-4840.1');
ok($operon->stable_id eq '16152-16153-4840', 'fetch_by_stable_id with version');
$operon = $operon_adaptor->fetch_by_stable_id('16152-16153-4840.1a');
ok(! defined($operon), 'fetch_by_stable_id with bad version');
$operon = $operon_adaptor->fetch_by_stable_id_version('16152-16153-4840', 1);
ok($operon->stable_id eq '16152-16153-4840', 'fetch_by_stable_id_version with version');
$operon = $operon_adaptor->fetch_by_stable_id_version('16152-16153-4840', '1a');
ok(! defined($operon), 'fetch_by_stable_id_version with bad version');
#19
my @operons = @{ $operon_adaptor->fetch_all_versions_by_stable_id('16152-16153-4840') };
debug("fetch_all_versions_by_stable_id");
......
......@@ -237,6 +237,18 @@ $operon_transcript = $ota->fetch_by_stable_id('T16152-16153-4840');
debug( "OperonTranscript->fetch_by_stable_id()" );
ok( $operon_transcript );
$operon_transcript = $ota->fetch_by_stable_id('T16152-16153-4840.1');
ok($operon_transcript->stable_id eq 'T16152-16153-4840', 'fetch_by_stable_id with version');
$operon_transcript = $ota->fetch_by_stable_id('T16152-16153-4840.1a');
ok(! defined($operon_transcript), 'fetch_by_stable_id with bad version');
$operon_transcript = $ota->fetch_by_stable_id_version('T16152-16153-4840', 1);
ok($operon_transcript->stable_id eq 'T16152-16153-4840', 'fetch_by_stable_id_version with version');
$operon_transcript = $ota->fetch_by_stable_id_version('T16152-16153-4840', '1a');
ok(! defined($operon_transcript), 'fetch_by_stable_id with bad version');
#49
@operon_transcripts = @{ $ota->fetch_all_versions_by_stable_id('T16152-16153-4840') };
debug("fetch_all_versions_by_stable_id");
......
......@@ -609,6 +609,18 @@ is( scalar(@transcripts), 1, 'Fetched all transcripts by stable_id' );
$tr = $ta->fetch_by_translation_stable_id('ENSP00000355555');
is( $tr->dbID, 21740, 'Fetched transcript by translation stable id' );
$tr = $ta->fetch_by_translation_stable_id('ENSP00000355555.1');
is( $tr->dbID, 21740, 'Fetched transcript by translation stable id with version' );
$tr = $ta->fetch_by_translation_stable_id('ENSP00000355555.1a');
ok( ! defined($tr), 'Fetched transcript by translation stable id with bad version' );
$tr = $ta->fetch_by_translation_stable_id_version('ENSP00000355555', 1);
is( $tr->dbID, 21740, 'Fetched transcript by translation stable id (version) with version' );
$tr = $ta->fetch_by_translation_stable_id_version('ENSP00000355555', '1a');
ok( ! defined($tr), 'Fetched transcript by translation stable id (version) with bad version' );
@transcripts = @{ $ta->fetch_all_by_exon_stable_id('ENSE00001109603') };
is( scalar(@transcripts), 1);
is( $transcripts[0]->dbID, 21740, 'Fetched transcript by exon stable id' );
......@@ -669,6 +681,18 @@ is($tr->is_current, 1, 'Transcript is now current'); # 151
$multi->restore;
$tr = $ta->fetch_by_stable_id('ENST00000310998.1');
ok($tr->stable_id eq 'ENST00000310998', 'Fetch by stable_id with version');
$tr = $ta->fetch_by_stable_id('ENST00000310998.1a');
ok(! defined($tr), 'Fetch by stable_id with bad version');
$tr = $ta->fetch_by_stable_id_version('ENST00000310998', 1);
ok($tr->stable_id eq 'ENST00000310998', 'fetch_by_stable_id_version');
$tr = $ta->fetch_by_stable_id_version('ENST00000310998', '1a');
ok(! defined($tr), 'fetch_by_stable_id_version with bad version');
# UTR Tests
{
my $utr_testing = sub {
......
......@@ -107,6 +107,12 @@ ok($translation && $translation->stable_id() eq 'ENSP00000201961');
$translation = $ta->fetch_by_stable_id('ENSP00000201961');
ok($translation && $translation->dbID() == 21734);
$translation = $ta->fetch_by_stable_id('ENSP00000201961.1');
ok($translation && $translation->dbID() == 21734, 'fetch_by_stable_id with version');
$translation = $ta->fetch_by_stable_id('ENSP00000201961.1a');
ok(!defined($translation), 'fetch_by_stable_id with bad version');
#
# test fetch_by_external_name
#
......
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