Skip to content
Snippets Groups Projects
Commit 03e92fd4 authored by premanand17's avatar premanand17
Browse files

Updated fetch_all_by_Transcript method to optionally filter by feature_type...

Updated fetch_all_by_Transcript method to optionally filter by feature_type (dna_align or protein_align features)
parent 1f04333f
No related branches found
No related tags found
2 merge requests!147Updated fetch_all_by_Transcript method to optionally filter by featur…,!147Updated fetch_all_by_Transcript method to optionally filter by featur…
......@@ -75,14 +75,19 @@ use vars qw(@ISA);
=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
......@@ -99,23 +104,34 @@ sub fetch_all_by_Transcript {
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'){
} elsif($type eq 'dna_align_feature'){
$feature = $dna_adp->fetch_by_dbID($feature_id);
} else {
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;
}
......
......@@ -23,4 +23,4 @@
21738 18273 1282 469283 31166507 31196939 1 97759 ensembl protein_coding KNOWN \N 1 21738 ENST00000217347 1 2004-12-06 12:00:00 2004-12-06 12:00:00
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
21741 18276 1282 317101 20000 21000 1 \N ensembl protein_coding NOVEL weird 1 21741 ENST00000111111 1 2014-12-11 14:00:00 2014-12-11 14:00:00
\ No newline at end of file
21741 dna_align_feature 1449321
21741 dna_align_feature 11290104
21741 protein_align_feature 813252
21741 protein_align_feature 813424
21741 protein_align_feature 813184
\ No newline at end of file
# 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::Warnings;
use Bio::EnsEMBL::Test::MultiTestDB;
use Bio::EnsEMBL::DnaDnaAlignFeature;
use Bio::EnsEMBL::Test::TestUtils;
use Data::Dumper;
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( "ENST00000111111" );
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");
}
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