Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 48 additions & 12 deletions modules/EnsEMBL/Draw/GlyphSet/Vsynteny.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
27 changes: 12 additions & 15 deletions modules/EnsEMBL/Web/Component/Location/SyntenyImage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,35 @@ 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');
my $chr = $object->seq_region_name;
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;
}

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
Expand Down Expand Up @@ -102,7 +99,7 @@ sub content {
$image_html = $image->render;
}
else {
$image_html = $self->info_panel("Unassembled chromosomes", "<p>No image can be drawn, because the syntenous species has no assembled chromosomes.</p>");
$image_html = $self->info_panel("Unavailable synteny regions", "<p>No image can be drawn, because this chromosome lacks synteny regions with the selected species.</p>");
}
my $chr_form = $self->chromosome_form('Vsynteny');

Expand Down