Skip to content

Commit 58a4b97

Browse files
authored
Get basal tree when accessing supertree and supertree homologies (#1098)
1 parent 8f192c4 commit 58a4b97

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

modules/EnsEMBL/Web/Object/Gene.pm

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,10 @@ sub get_homologies {
778778
my $hub = $self->hub;
779779
my $strain_tree = $hub->species_defs->get_config($hub->species,'RELATED_TAXON') if($hub->param('data_action') =~ /strain_/i);
780780
my $tree = $self->get_GeneTree($compara_db, 1, $strain_tree);
781+
$tree = $self->_get_basal_gene_tree($compara_db, $tree);
782+
$tree->expand_subtrees if $tree->tree_type eq 'supertree';
781783
my %members_to_keep = map { $_->dbID => 1 } @{$tree->get_all_Members()};
784+
$tree->release_tree;
782785

783786
my @gene_tree_homologies;
784787
foreach my $homology (@$homologies_array) {
@@ -920,16 +923,9 @@ sub get_homologue_alignments {
920923
push @params, $species if scalar @$species;
921924

922925
## Make sure we use the correct tree
923-
if ($tree->root->is_supertree) {
924-
$msa = $tree->get_alignment_of_homologues(@params);
925-
} else {
926-
my $supertree = $database->get_GeneTreeAdaptor->fetch_parent_tree($tree);
927-
if ($supertree and $supertree->tree_type ne 'clusterset') {
928-
$msa = $supertree->get_alignment_of_homologues(@params);
929-
} else {
930-
$msa = $tree->get_alignment_of_homologues(@params);
931-
}
932-
}
926+
my $tree = $self->get_GeneTree($compara_db, 1, $strain_tree);
927+
$tree = $self->_get_basal_gene_tree($compara_db, $tree);
928+
$msa = $tree->get_alignment_of_homologues(@params);
933929
$tree->release_tree;
934930
}
935931
return $msa;
@@ -962,13 +958,8 @@ sub get_GeneTree {
962958
my $parent = $adaptor->fetch_parent_tree($tree);
963959
if ($parent->tree_type ne 'clusterset') {
964960

965-
# To get the full supertree, we need to keep fetching
966-
# the next parent up until we reach the clusterset.
967-
my $next_parent = $parent;
968-
do {
969-
$parent = $next_parent;
970-
$next_parent = $adaptor->fetch_parent_tree($parent);
971-
} until ($next_parent->tree_type eq 'clusterset');
961+
# To get the full supertree, we need to get the basal tree.
962+
$parent = $self->_get_basal_gene_tree($compara_db, $parent);
972963

973964
my %subtrees;
974965
my $total_leaves = 0;
@@ -1013,6 +1004,25 @@ sub get_GeneTree {
10131004
return $self->{$cache_key};
10141005
}
10151006

1007+
# Method to fetch the basal gene tree,
1008+
# whose root is linked to the clusterset.
1009+
sub _get_basal_gene_tree {
1010+
my ($self, $compara_db, $next_tree) = @_;
1011+
1012+
# The basal tree can be a regular tree, a supertree, or even a
1013+
# supertree of a supertree, so in order to make sure we get it,
1014+
# we fetch successive parent trees until we reach the clusterset.
1015+
my $gene_tree_adaptor = $self->database($compara_db)->get_GeneTreeAdaptor();
1016+
my $curr_tree;
1017+
do {
1018+
$curr_tree = $next_tree;
1019+
$next_tree = $gene_tree_adaptor->fetch_parent_tree($curr_tree);
1020+
} until ($next_tree->tree_type eq 'clusterset');
1021+
$next_tree->release_tree;
1022+
1023+
return $curr_tree;
1024+
}
1025+
10161026
sub get_gene_slices {
10171027
my ($self, $master_config, @slice_configs) = @_;
10181028
foreach my $array (@slice_configs) {

0 commit comments

Comments
 (0)