diff --git a/modules/EnsEMBL/Draw/GlyphSet/Vsynteny.pm b/modules/EnsEMBL/Draw/GlyphSet/Vsynteny.pm index 1325f8383a..32ba86487f 100644 --- a/modules/EnsEMBL/Draw/GlyphSet/Vsynteny.pm +++ b/modules/EnsEMBL/Draw/GlyphSet/Vsynteny.pm @@ -101,19 +101,55 @@ sub _init { my $highlights_main = { $chr => [] }; my $CANSEE_OTHER = $config->{'other_species_installed'}; + # When working with a synteny dataset such as the Hsap synteny, we need to be able to distinguish + # between the main and other synteny regions, even if both are from the same genome. Moreover, we + # may encounter synteny pairs between two regions on the same chromosome in the same genome. In + # such cases, the Compara API may return the same synteny pair twice, without distinction between + # the two syntenic regions. To help make sense of all this, we generate a synteny region key for + # each region of the main chromosome that is in a synteny pair, so that we can then sort the + # synteny regions in order to 'thread' them along the main chromosome. + my %syntenies_by_main_region; foreach my $synteny_region (@$synteny_data) { - my ($main_dfr, $other_dfr); + my ($dfr1, $dfr2) = @{$synteny_region->get_all_DnaFragRegions}; - foreach my $dfr (@{$synteny_region->get_all_DnaFragRegions}) { - if (lc($self_production_name) eq lc($dfr->dnafrag->genome_db->name) and $dfr->dnafrag->genome_db->name eq $other_production_name) { - $main_dfr = $dfr; - $other_dfr = $dfr; - } elsif ($dfr->dnafrag->genome_db->name eq $other_production_name) { - $other_dfr = $dfr; - } else { - $main_dfr = $dfr; - } + if (lc($dfr1->dnafrag->genome_db->name) eq lc($self_production_name) && $dfr1->dnafrag->name eq $chr) { + + my $dfr1_synteny_region_key = join( + ':', + $synteny_region->dbID, + $dfr1->dnafrag->dbID, + $dfr1->dnafrag_start, + $dfr1->dnafrag_end, + $dfr1->dnafrag_strand, + ); + + $syntenies_by_main_region{$dfr1_synteny_region_key} = [$dfr1_synteny_region_key, $dfr1, $dfr2]; } + + if (lc($dfr2->dnafrag->genome_db->name) eq lc($self_production_name) && $dfr2->dnafrag->name eq $chr) { + + my $dfr2_synteny_region_key = join( + ':', + $synteny_region->dbID, + $dfr2->dnafrag->dbID, + $dfr2->dnafrag_start, + $dfr2->dnafrag_end, + $dfr2->dnafrag_strand, + ); + + $syntenies_by_main_region{$dfr2_synteny_region_key} = [$dfr2_synteny_region_key, $dfr2, $dfr1]; + } + } + + my @synteny_regions = sort { + $a->[1]->dnafrag_start <=> $b->[1]->dnafrag_start + || $b->[1]->dnafrag_end <=> $a->[1]->dnafrag_end + || $b->[1]->dnafrag_strand <=> $a->[1]->dnafrag_strand + || $a->[0] cmp $b->[0] + } values %syntenies_by_main_region; + + foreach my $synteny_region (@synteny_regions) { + my ($synteny_region_key, $main_dfr, $other_dfr) = @$synteny_region; my $other_chr = $other_dfr->dnafrag->name; @@ -148,7 +184,7 @@ sub _init { }); push @{$highlights_main->{$chr}}, { - 'id' => $synteny_region->dbID, + 'id' => $synteny_region_key, 'start' => $main_dfr->dnafrag_start, 'end' => $main_dfr->dnafrag_end, 'col' => $COL, @@ -173,7 +209,7 @@ sub _init { push @{$highlights_secondary->{$other_chr}}, { 'rel_ori' => $main_dfr->dnafrag_strand * $other_dfr->dnafrag_strand, - 'id' => $synteny_region->dbID, + 'id' => $synteny_region_key, 'start' => $other_dfr->dnafrag_start, 'end' => $other_dfr->dnafrag_end, 'col' => $COL, diff --git a/modules/EnsEMBL/Web/Component/Location/SyntenyImage.pm b/modules/EnsEMBL/Web/Component/Location/SyntenyImage.pm index 2a56013916..6f5d2c579c 100644 --- a/modules/EnsEMBL/Web/Component/Location/SyntenyImage.pm +++ b/modules/EnsEMBL/Web/Component/Location/SyntenyImage.pm @@ -37,6 +37,7 @@ sub content { my $hub = $self->hub; my $object = $self->object || $self->hub->core_object('location'); my $species = $hub->species; + my $this_prodname = $hub->species_defs->get_config($species, 'SPECIES_PRODUCTION_NAME'); my %synteny = $hub->species_defs->multi('DATABASE_COMPARA', 'SYNTENY'); my $other = $self->hub->otherspecies; my $other_prodname = $hub->species_defs->get_config($other, 'SPECIES_PRODUCTION_NAME'); @@ -44,7 +45,7 @@ sub content { my %chr_1 = map { $_, 1 } @{$hub->species_defs->ENSEMBL_CHROMOSOMES || []}; my %chr_2 = map { $_, 1 } @{$hub->species_defs->get_config($other, 'ENSEMBL_CHROMOSOMES') || []}; - unless ($synteny{$other_prodname}) { + unless ($synteny{$this_prodname}{$other_prodname}) { $hub->problem('fatal', "Can't display synteny", "There is no synteny data for these two species ($species and $other)"); return undef; } @@ -52,23 +53,19 @@ sub content { my $ka = $hub->get_adaptor('get_KaryotypeBandAdaptor', 'core', $species); my $ka2 = $hub->get_adaptor('get_KaryotypeBandAdaptor', 'core', $other); my $compara_db = $hub->database('compara'); - my $raw_data = $object->chromosome->get_all_compara_Syntenies($other, undef, $compara_db); my $chr_length = $object->chromosome->length; - my $other_chr; - - OUTER: - foreach my $synteny_region (@$raw_data) { - foreach my $dfr (@{$synteny_region->get_all_DnaFragRegions}) { - # Check if any of the synteny regions map to a chromosome in the other species - if ($dfr->dnafrag->genome_db->name eq $other_prodname && $chr_2{$dfr->dnafrag->name}) { - $other_chr = 1; - last OUTER; - } - } + + my $genome_dba = $compara_db->get_GenomeDBAdaptor(); + my @synteny_gdbs = ($genome_dba->fetch_by_name_assembly($this_prodname)); + if ($other_prodname ne $this_prodname) { + push(@synteny_gdbs, $genome_dba->fetch_by_name_assembly($other_prodname)); } + my $mlss = $compara_db->get_MethodLinkSpeciesSetAdaptor->fetch_by_method_link_type_GenomeDBs('SYNTENY', \@synteny_gdbs); + my $raw_data = $compara_db->get_SyntenyRegionAdaptor->fetch_all_by_MethodLinkSpeciesSet_Slice($mlss, $object->chromosome); + my $image_html; - if ($chr_1{$chr} && $other_chr) { + if (scalar(@$raw_data) > 0) { my ($localgenes, $offset) = $object->get_synteny_local_genes; my $loc = (@$localgenes ? $localgenes->[0]->start + $object->seq_region_start : 1); # Jump loc to the location of the genes @@ -102,7 +99,7 @@ sub content { $image_html = $image->render; } else { - $image_html = $self->info_panel("Unassembled chromosomes", "
No image can be drawn, because the syntenous species has no assembled chromosomes.
"); + $image_html = $self->info_panel("Unavailable synteny regions", "No image can be drawn, because this chromosome lacks synteny regions with the selected species.
"); } my $chr_form = $self->chromosome_form('Vsynteny');