Skip to content
Snippets Groups Projects
Commit 5ea4fc55 authored by Magali Ruffier's avatar Magali Ruffier Committed by GitHub
Browse files

Merge pull request #147 from Ensembl/ENSCORESW-1884

Updated fetch_all_by_Transcript method to optionally filter by featur…
parents 2438a80c a2faffcc
No related branches found
No related tags found
No related merge requests found
......@@ -63,26 +63,34 @@ use vars qw(@ISA);
Arg [1] : Bio::EnsEMBL::Transcript $transcript
The transcript to fetch supporting features for
Arg [2] : String (optional)
Feature type to filter upon (either 'dna_align_feature' or 'protein_align_feature')
Example : @sfs = @{$supporting_feat_adaptor->fetch_all_by_Transcript($transcript)};
@sfs = @{$supporting_feat_adaptor->fetch_all_by_Transcript($transcript, $feature_type)};
Description: Retrieves supporting features (evidence) for a given transcript.
Returntype : list of Bio::EnsEMBL::BaseAlignFeatures in the same coordinate
system as the $transcript argument
Exceptions : warning if $transcript is not in the database (i.e. dbID not defined)
throw if a retrieved supporting feature is of unknown type
throw if a retrieved or requested supporting feature is of unknown type
Caller : Bio::EnsEMBL::Transcript
Status : Stable
=cut
sub fetch_all_by_Transcript {
my ( $self, $transcript ) = @_;
my ( $self, $transcript, $feature_type ) = @_;
my $out = [];
my $out_feature_type = {};
unless($transcript->dbID) {
warning("Cannot retrieve evidence for transcript without dbID");
return [];
}
if(defined $feature_type && $feature_type !~ /(dna)|(protein)_align_feature/) {
throw("feature type must be dna_align_feature or protein_align_feature");
}
my $sth = $self->prepare("SELECT tsf.feature_type, tsf.feature_id
FROM transcript_supporting_feature tsf
......@@ -97,25 +105,36 @@ sub fetch_all_by_Transcript {
my $feature;
while(my ($type, $feature_id) = $sth->fetchrow){
if($type eq 'protein_align_feature'){
$feature = $prot_adp->fetch_by_dbID($feature_id);
} elsif($type eq 'dna_align_feature'){
$feature = $dna_adp->fetch_by_dbID($feature_id);
if ($type eq 'protein_align_feature') {
$feature = $prot_adp-> fetch_by_dbID($feature_id);
}
elsif($type eq 'dna_align_feature') {
$feature = $dna_adp-> fetch_by_dbID($feature_id);
} else {
warning("Unknown feature type [$type]\n");
warning("Unknown feature type [$type]\n");
}
if(!$feature) {
warning("Supporting feature $type $feature_id does not exist in DB");
} else {
my $new_feature = $feature->transfer($transcript->slice());
push @$out, $new_feature if( $new_feature );
push @{$out_feature_type->{$type}}, $new_feature if ($new_feature);
}
}
$sth->finish();
return $out;
}
$sth->finish();
if(defined $feature_type){
return $out_feature_type->{$feature_type};
}else{
while(my ($feature_type, $new_features) = each(%$out_feature_type)){
push @$out, @{$new_features};
}
}
return $out;
}
......
......@@ -244,7 +244,7 @@ $assert_ise_vs_intron->(21719, 30326248, 30327734, -1);
$db->restore('core');
note 'All tables restored';
$assert_table_counts->(26,173,0,0);
$assert_table_counts->(27,173,0,0);
}
############# Feature transformation (asserting what occurs when we try to project to something else)
......
......@@ -24,3 +24,4 @@
21739 18274 1282 469283 31210077 31225346 1 0 ensembl protein_coding NOVEL \N 1 21739 ENST00000300425 1 2004-12-06 12:00:00 2004-12-06 12:00:00
21740 18275 1282 965899 10060 10405 1 0 ensembl protein_coding NOVEL \N 1 21740 ENST00000355555 1 2004-12-06 12:00:00 2004-12-06 12:00:00
21741 18276 1282 469290 1 150 1 \N ensembl protein_coding NOVEL weird 1 21741 ENST00000111111 1 2014-12-11 14:00:00 2014-12-11 14:00:00
21742 18276 1282 317101 20000 21000 1 \N ensembl protein_coding NOVEL weird 1 21742 ENST00000222222 1 2016-08-15 14:00:00 2016-08-15 17:00:00
\ No newline at end of file
21742 dna_align_feature 1449321
21742 dna_align_feature 11290104
21742 protein_align_feature 813252
21742 protein_align_feature 813424
21742 protein_align_feature 813184
\ No newline at end of file
......@@ -270,13 +270,13 @@ is($tr->display_id(), $tr->stable_id(), 'Transcript stable id and display id are
#
note("Test fetch_all_by_biotype");
my @transcripts = @{$ta->fetch_all_by_biotype('protein_coding')};
is(@transcripts, 26, 'Fetching all protein coding transcript');
is(@transcripts, 27, 'Fetching all protein coding transcript');
my $transcriptCount = $ta->count_all_by_biotype('protein_coding');
is($transcriptCount, 26, 'Counting all protein coding');
is($transcriptCount, 27, 'Counting all protein coding');
@transcripts = @{$ta->fetch_all_by_biotype(['protein_coding','pseudogene'])};
is(@transcripts, 26, 'Got 25 transcript');
is(@transcripts, 27, 'Got 27 transcript');
$transcriptCount = $ta->count_all_by_biotype(['protein_coding', 'pseudogene']);
is($transcriptCount, 26, 'Count by biotype is correct');
is($transcriptCount, 27, 'Count by biotype is correct');
#
......@@ -293,9 +293,9 @@ is(@transcripts, $transcriptCount, "Counted as many transcripts as were fetched
note("Test fetch_all_by_source");
@transcripts = @{$ta->fetch_all_by_source('ensembl')};
note "Got ".scalar(@transcripts)." ensembl transcripts\n";
is(23, scalar(@transcripts));
is(24, scalar(@transcripts));
$transcriptCount = $ta->count_all_by_source('ensembl');
is(23, $transcriptCount);
is(24, $transcriptCount);
@transcripts = @{$ta->fetch_all_by_source(['havana','vega'])};
note "Got ".scalar(@transcripts)." (havana, vega) transcripts\n";
is(3, scalar(@transcripts));
......@@ -307,7 +307,7 @@ is(3, $transcriptCount);
#
note("Test fetch_all");
@transcripts = @{ $ta->fetch_all() };
is(26, scalar(@transcripts), "Got 26 transcripts");
is(27, scalar(@transcripts), "Got 27 transcripts");
#
# test TranscriptAdaptor::fetch_all_by_GOTerm
......
# Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
# Copyright [2016] EMBL-European Bioinformatics Institute
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
use strict;
use Test::More;
use Test::Exception;
use Test::Warnings;
use Bio::EnsEMBL::Test::MultiTestDB;
our $verbose = 0;
my $multi = Bio::EnsEMBL::Test::MultiTestDB->new();
ok(1);
#Fetch Transcript by stable_id and ensure it has a slice
my $db = $multi->get_DBAdaptor('core');
my $ta = $db->get_TranscriptAdaptor();
my $tr = $ta->fetch_by_stable_id( "ENST00000222222" );
ok($tr, "Fetched the Transcript by stable_id");
ok($tr->slice(), "Transcript has slice");
#Get TranscriptSupportingFeatureAdaptor
my $tsf_adaptor = $db->get_TranscriptSupportingFeatureAdaptor;
#Fetch all transcript supporting features
my $supporting_features = $tsf_adaptor->fetch_all_by_Transcript($tr);
isa_ok( $supporting_features, 'ARRAY' );
ok(5 == scalar(@$supporting_features), "Fetched all transcript supporting features");
#Fetch all transcript supporting features of type 'protein_align_feature'
my $supporting_features_proteins = $tsf_adaptor->fetch_all_by_Transcript($tr, "protein_align_feature");
isa_ok( $supporting_features_proteins, 'ARRAY' );
ok(3 == scalar(@$supporting_features_proteins), "Fetched all transcript supporting features (protein_align_features) ");
foreach my $supporting_feature(@$supporting_features_proteins){
ok('Bio::EnsEMBL::DnaPepAlignFeature' eq ref $supporting_feature, "Got back the right ref type: Bio::EnsEMBL::DnaPepAlignFeature");
}
#Fetch all transcript supporting features of type 'dna_align_feature'
my $supporting_features_dnas = $tsf_adaptor->fetch_all_by_Transcript($tr, "dna_align_feature");
isa_ok( $supporting_features_dnas, 'ARRAY' );
ok(2 == scalar(@$supporting_features_dnas), "Fetched all transcript supporting features (dna_align_features) ");
foreach my $supporting_feature(@$supporting_features_dnas){
ok('Bio::EnsEMBL::DnaDnaAlignFeature' eq ref $supporting_feature, "Got back the right ref type: Bio::EnsEMBL::DnaDnaAlignFeature");
}
#Test exceptions with unknown feature_types
dies_ok { $tsf_adaptor->fetch_all_by_Transcript($tr, "unknown_feature_type") } 'fetch_all_by_Transcript dies with unknown feature_type';
throws_ok {$tsf_adaptor->fetch_all_by_Transcript($tr, "unknown_feature_type") } qr/feature type must be dna_align_feature or protein_align_feature/,
'feature type must be dna_align_feature or protein_align_feature';
done_testing();
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