Skip to content
Snippets Groups Projects
Commit c76814ea authored by Andy Yates's avatar Andy Yates
Browse files

[ENSCORESW-745]. Homology endpoints no longer throws an error when querying the same species.

Before we had some bizarre behaviour by trying to query for a MLSS with the same species mentioned twice. That
no longer happens. We can query for self homologies if needed. Also we do not try to find bad MLSS sets.
parent 437a7f6e
No related branches found
No related tags found
No related merge requests found
......@@ -165,27 +165,72 @@ sub _method_link_species_sets {
else {
@types = qw/ENSEMBL_ORTHOLOGUES ENSEMBL_PARALOGUES/;
}
my %unique_genome_dbs;
my @mlss_queries;
my $registry = $c->model('Registry');
my $source_gdb = $member->genome_db();
my $source_gdb_id = $source_gdb->dbID();
#If someone has requested species then limit by MLSS
my @target_species = $c->request->param('target_species');
my $source_name = $member->genome_db()->name();
foreach my $target (@target_species) {
foreach my $ml_type (@types) {
my $r = $mlssa->fetch_by_method_link_type_registry_aliases($ml_type, [$source_name, $target]);
push(@mlss, $r);
my $species_name = $registry->get_alias($target);
if(! $species_name) {
$c->go('ReturnError', 'custom', "Nothing is known to this server about the species name '${target}'");
}
my $gdb;
try {
$gdb = $gdba->fetch_by_name_assembly($species_name);
} catch {
my $meta_c = $registry->get_adaptor($species_name, 'core', 'MetaContainer');
$gdb = $gdba->fetch_by_name_assembly($meta_c->get_production_name());
};
if($gdb) {
next if exists $unique_genome_dbs{$gdb->dbID()};
if($gdb->dbID() == $source_gdb_id) {
push(@mlss_queries, [$source_gdb]);
}
else {
push(@mlss_queries, [$source_gdb, $gdb]);
}
$unique_genome_dbs{$gdb->dbID()} = 1;
}
else {
$c->go('ReturnError', 'custom', "Cannot convert '${target}' into a valid GenomeDB object. Please try again with a different value");
}
}
#Could be taxon identifiers though
my @target_taxons = $c->request->param('target_taxon');
my $source_gdb = $member->genome_db();
foreach my $taxon (@target_taxons) {
my $gdb = $gdba->fetch_by_taxon_id($taxon);
foreach my $ml_type (@types) {
my $gdbs = [$source_gdb, $gdb];
if($gdb) {
next if exists $unique_genome_dbs{$gdb->dbID()};
if($gdb->dbID() == $source_gdb_id) {
push(@mlss_queries, [$source_gdb]);
}
else {
push(@mlss_queries, [$source_gdb, $gdb]);
}
$unique_genome_dbs{$gdb->dbID()} = 1;
}
else {
$c->go('ReturnError', 'custom', "Cannot convert taxon ID '${taxon}' into a valid GenomeDB object. Please try again with a different value");
}
}
# Now get the MLSSs
my $log = $c->log();
foreach my $ml_type (@types) {
foreach my $gdbs (@mlss_queries) {
my $genome_names = join(q{, }, map({$_->name()} @{$gdbs}));
if($log->is_debug()) {
$log->debug("Fetching MLSS for ${ml_type} and [${genome_names}]");
}
my $r = $mlssa->fetch_by_method_link_type_GenomeDBs($ml_type, $gdbs);
if(! $r) {
$c->log->info('Cannot get a MLSS for ', $ml_type, ' and [', map({$_->name()} @{$gdbs}), ']');
$log->debug("Cannot get a MLSS for ${ml_type} and [${genome_names}]");
next;
}
push(@mlss, $r);
......
......@@ -390,6 +390,15 @@ sub disconnect_DBAdaptors {
return;
}
sub get_alias {
my ($self, $alias) = @_;
my $reg = $self->_registry();
if($reg->alias_exists($alias)) {
return $reg->get_alias($alias);
}
return;
}
__PACKAGE__->meta->make_immutable;
1;
......
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