Skip to content

Commit

Permalink
Merge pull request #209 from teharrison/develop
Browse files Browse the repository at this point in the history
new api resource m5nr, currently returns static data structures
  • Loading branch information
jaredbischof committed Dec 19, 2012
2 parents c2b5652 + e194215 commit 12df0ea
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 3 deletions.
121 changes: 121 additions & 0 deletions src/MGRAST/lib/resources2/m5nr.pm
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,121 @@
package resources2::m5nr;

use strict;
use warnings;
no warnings('once');

use MGRAST::Analysis;
use Conf;
use parent qw(resources2::resource);

# Override parent constructor
sub new {
my ($class, @args) = @_;

# Call the constructor of the parent class
my $self = $class->SUPER::new(@args);

# Add name / attributes
$self->{name} = "m5nr";
$self->{attributes} = { 'hierarchy' => { 'NCBI' => [ 'hash', '7 level NCBI taxonomy' ],
'COG' => [ 'hash', '3 level COG ontology' ],
'NOG' => [ 'hash', '3 level NOG ontology' ],
'KO' => [ 'hash', '4 level KEGG-KO ontology' ],
'Subsystems' => [ 'hash', '4 level SEED-Subsystems ontology' ] },
'sources' => [ 'hash', [['key', ['string', 'source name']],
['value', ['object', [ { 'name' => ['string', 'source name'],
'description' => ['string', 'description of source'],
'type' => ['string', 'type of source'],
'link' => ['string', 'link for source id'] },
'information about source' ]]]
]]
};
return $self;
}


# resource is called without any parameters
# this method must return a description of the resource
sub info {
my ($self) = @_;
my $content = { 'name' => $self->name,
'url' => $self->cgi->url."/".$self->name,
'description' => "M5NR provides data through a comprehensive non-redundant protein / rRNA database",
'type' => 'object',
'documentation' => '',
'requests' => [ { 'name' => "info",
'request' => $self->cgi->url."/".$self->name,
'description' => "Returns description of parameters and attributes.",
'method' => "GET",
'type' => "synchronous",
'attributes' => "self",
'parameters' => { 'options' => {},
'required' => {},
'body' => {} }
},
{ 'name' => "hierarchy",
'request' => $self->cgi->url."/".$self->name."/hierarchy",
'description' => "",
'method' => "GET",
'type' => "synchronous",
'attributes' => $self->attributes->{hierarchy},
'parameters' => { 'options' => { 'source' => ['cv', ['NCBI', 'returns 7 level NCBI taxonomy'],
['COG', 'returns 3 level COG ontology'],
['NOG', 'returns 3 level NOG ontology'],
['KO', 'returns 4 level KEGG-KO ontology' ],
['Subsystems', 'returns 4 level SEED-Subsystems ontology' ]]
},
'required' => {},
'body' => {} }
},
{ 'name' => "sources",
'request' => $self->cgi->url."/".$self->name."/sources",
'description' => "",
'method' => "GET",
'type' => "synchronous",
'attributes' => $self->attributes->{sources},
'parameters' => { 'options' => {},
'required' => {},
'body' => {} }
} ]
};
$self->return_data($content);
}

# Override parent request function
sub request {
my ($self) = @_;
# determine sub-module to use
if (scalar(@{$self->rest}) == 0) {
$self->info();
} elsif (($self->rest->[0] eq 'hierarchy') || ($self->rest->[0] eq 'sources')) {
$self->static($self->rest->[0]);
} else {
$self->info();
}
}

# return static data: hierarchy or source
sub static {
my ($self, $type) = @_;

# get database
my $master = $self->connect_to_datasource();
my $mgdb = MGRAST::Analysis->new( $master->db_handle );
unless (ref($mgdb)) {
$self->return_data({"ERROR" => "could not connect to analysis database"}, 500);
}

my $data = {};
if ($type eq 'hierarchy') {
my $source = $self->cgi->param('source') || 'NCBI';
$data = ($source eq 'NCBI') ? $mgdb->get_hierarchy('organism') : $mgdb->get_hierarchy('ontology', $source);
} elsif ($type eq 'sources') {
$data = $mgdb->_sources();
delete $data->{GO};
}
$self->return_data($data);
}

1;

6 changes: 3 additions & 3 deletions src/MGRAST/lib/resources2/metagenome_statistics.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ sub info {
'type' => "synchronous" , 'type' => "synchronous" ,
'attributes' => $self->attributes, 'attributes' => $self->attributes,
'parameters' => { 'options' => { 'verbosity' => ['cv', 'parameters' => { 'options' => { 'verbosity' => ['cv',
[['minimal','returns only sequence statistics'], [['minimal','returns only sequence_stats attribute'],
['verbose','returns all but qc statistics'], ['verbose','returns all but qc attribute'],
['full','returns all statistics']] ] }, ['full','returns all attributes']] ] },
'required' => { "id" => [ "string", "metagenome id" ] }, 'required' => { "id" => [ "string", "metagenome id" ] },
'body' => {} } } 'body' => {} } }
] ]
Expand Down

0 comments on commit 12df0ea

Please sign in to comment.