Skip to content
Snippets Groups Projects
Commit 10a3a9d6 authored by Kieron Taylor's avatar Kieron Taylor :angry:
Browse files

Preservation commit for taxonomy name endpoint

parent 354395b5
No related branches found
No related tags found
No related merge requests found
......@@ -111,6 +111,7 @@ msgpack=0 # control usage of Data::MessagePack as a serialisation option
taxon=9606
taxon_name=Homo sapiens
taxon_nameish=Homo%
target_taxon=10090
target_species=cow
......
......@@ -5,6 +5,7 @@ use namespace::autoclean;
use Try::Tiny;
use Bio::EnsEMBL::Utils::Scalar qw/check_ref/;
use Scalar::Util qw/looks_like_number/;
use URI::Escape;
require EnsEMBL::REST;
EnsEMBL::REST->turn_on_config_serialisers(__PACKAGE__);
......@@ -35,6 +36,17 @@ sub classification : Chained('taxonomy_root') PathPart('classification') Args(1)
$self->status_ok($c, entity => $entity);
}
sub name_get {}
sub name : Chained('taxonomy_root') PathPart('name') Args(1) ActionClass('REST') {
my ($self, $c, $id) = @_;
$id = uri_unescape($id);
my $taxons = $self->_name($c,$id);
# remove any duplicates in the list
my %list = map { $_ => 1 } @$taxons;
@$taxons = keys %list;
$self->status_ok($c, entity => $self->_encode_array($taxons));
}
sub taxon {
my ($self, $c, $id) = @_;
my $taxon;
......@@ -48,6 +60,14 @@ sub taxon {
return $taxon;
}
sub _name {
my ($self, $c, $name) = @_;
my @taxons;
@taxons = @{ $c->stash->{taxon_adaptor}->fetch_all_nodes_by_name($name) };
$c->go('ReturnError', 'custom', ["No taxons found with given name '$name'"]) if scalar(@taxons) == 0;
return \@taxons;
}
sub _encode_array {
my ($self, $taxons, $ignore_relations) = @_;
return [ map {$self->_encode($_, $ignore_relations)} @{$taxons}];
......
......@@ -66,5 +66,33 @@
</two>
</examples>
</taxonomy_classification>
<taxonomy_name>
description=Search for a taxonomic id by a non-scientific name
endpoint="taxonomy/name/:name"
method=GET
group=Ontologies and Taxonomy
output=json
output=xml
output=yaml
<params>
<name>
type=String
description=The non-scientific name to search for. Can include SQL wildcards
example=__VAR(taxon_nameish)__
required=1
</name>
</params>
<examples>
<one>
path=/taxonomy/name/
capture=__VAR(taxon_nameish)__
content=application/json
</one>
<two>
path=/taxonomy/name/
capture=__VAR(species_common)__
content=application/json
</two>
</examples>
</taxonomy_name>
</endpoints>
\ No newline at end of file
use strict;
use warnings;
BEGIN {
use FindBin qw/$Bin/;
use lib "$Bin/lib";
use RestHelper;
$ENV{CATALYST_CONFIG} = "$Bin/../ensembl_rest_testing.conf";
$ENV{ENS_REST_LOG4PERL} = "$Bin/../log4perl_testing.conf";
}
use Test::More;
use Catalyst::Test ();
use Bio::EnsEMBL::Test::MultiTestDB;
my $dba = Bio::EnsEMBL::Test::MultiTestDB->new();
Catalyst::Test->import('EnsEMBL::REST');
my $expected = qq();
#is_json_GET("/lookup/id/$basic_id?expand=1;format=condensed", $expanded_response, 'Get of a known ID with expanded option will return transcripts as well');
#is_json_GET("/taxonomy/classification/homo sapiens", $expected, 'Check taxonomy endpoint with valid data');
$expected = qq({"scientific_name":"Homo sapiens","name":"Homo sapiens","id":"9606","tags":{"ensembl alias name":["Human"],"scientific name":["Homo sapiens"],"genbank common name":["human"],"common name":["man"],"name":["Homo sapiens"],"authority":["Homo sapiens Linnaeus, 1758"]},"leaf":0});
is_json_GET("/taxonomy/id/9606?content-type=application/json;simple=1", $expected, 'Check id endpoint with valid data');
action_bad("/taxonomyid/11111111111111", 'ID should not be found. Fail');
done_testing();
\ No newline at end of file
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