diff --git a/modules/Bio/EnsEMBL/DBSQL/TranscriptSupportingFeatureAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/TranscriptSupportingFeatureAdaptor.pm index 0ab9c3dbcf3c9a0137b33d622a3e194525d45763..95569f01aaa1e7d5e8dfea1c369b47850671de9a 100644 --- a/modules/Bio/EnsEMBL/DBSQL/TranscriptSupportingFeatureAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/TranscriptSupportingFeatureAdaptor.pm @@ -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; } diff --git a/modules/t/intronSupportingEvidence.t b/modules/t/intronSupportingEvidence.t index 7c9e036d18aa006b47c9a58f6e7397eccd6dcdad..92858ebf006dff494f726728f3487dd6013147fc 100644 --- a/modules/t/intronSupportingEvidence.t +++ b/modules/t/intronSupportingEvidence.t @@ -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) diff --git a/modules/t/test-genome-DBs/homo_sapiens/core/transcript.txt b/modules/t/test-genome-DBs/homo_sapiens/core/transcript.txt index b590a5f7226ffb4daead1a3f727c0f2dd201bd23..6b93997130dfbee3c5ffb02e70c339f4fb08cbf6 100644 --- a/modules/t/test-genome-DBs/homo_sapiens/core/transcript.txt +++ b/modules/t/test-genome-DBs/homo_sapiens/core/transcript.txt @@ -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 diff --git a/modules/t/test-genome-DBs/homo_sapiens/core/transcript_supporting_feature.txt b/modules/t/test-genome-DBs/homo_sapiens/core/transcript_supporting_feature.txt new file mode 100644 index 0000000000000000000000000000000000000000..ba54133daf016314c839cb1078a694c1484f0f5a --- /dev/null +++ b/modules/t/test-genome-DBs/homo_sapiens/core/transcript_supporting_feature.txt @@ -0,0 +1,5 @@ +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 diff --git a/modules/t/transcript.t b/modules/t/transcript.t index 3e267f9f57f68609f9829294a256da28d45a4ea5..7d5bc6c0327bae0584cbebebd0f14d8e7341c9a3 100644 --- a/modules/t/transcript.t +++ b/modules/t/transcript.t @@ -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 diff --git a/modules/t/transcriptSupportingFeatureAdaptor.t b/modules/t/transcriptSupportingFeatureAdaptor.t new file mode 100644 index 0000000000000000000000000000000000000000..9292f39d16d5104cd69cd2a44ae4fe00b4d2abb5 --- /dev/null +++ b/modules/t/transcriptSupportingFeatureAdaptor.t @@ -0,0 +1,72 @@ +# 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();