-
Notifications
You must be signed in to change notification settings - Fork 2
API
tfuji edited this page Feb 14, 2017
·
10 revisions
- 入力: String
- 出力: JSON
- 入力: Stringのリスト
- 出力: JSON
- DDBJ登録アノテーションファイルを入力したときの便利なもの
- DDBJ登録形式 http://www.ddbj.nig.ac.jp/sub/mss/annotation_file-j.html
- https://github.com/ddbj/ddbj_validator/blob/annotated_sequence_validator/misc/tf/submission_tsv2json でパースしたコードをperlに書き換えたが、実際に必要なのは、qualifier = 'product' の時に qualifier_valueをTogoAnnotatorの入力とする部分のみ
#!perl
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Data::Dumper;
my $hash = {};
my $cache = {};
my $line = 1;
while (<>){
chomp;
my ($entry, $feature, $location, $qualifier, $qualifier_value) = split /\t/, $_, -1;
my $feature_id = '';
if ($line == 1) {
$cache = {'entry' => $entry, 'feature' => $feature, 'location' => $location };
$feature_id = $entry."#feature:".$location.":".$feature;
$hash->{$entry}->{$feature_id} = $cache;
}else{
my $idx = '';
$cache->{'entry'} = $entry if $entry;
$cache->{'feature'} = $feature if $feature;
$cache->{'location'} = $location if $location;
$feature_id = $cache->{'entry'}."#feature:".$cache->{'location'}.":".$cache->{'feature'}.".". $idx;
$hash->{$cache->{'entry'}}->{$feature_id}->{'location'} = $cache->{'location'};
$hash->{$cache->{'entry'}}->{$feature_id}->{'feature'} = $cache->{'feature'};
$hash->{$cache->{'entry'}}->{$feature_id}->{'entry'} = $cache->{'entry'};
#$hash->{$cache->{'entry'}}->{$feature_id} = $cache;
if ($qualifier eq 'product'){
print $qualifier_value."\n";
}
}
#$hash->{$cache->{'entry'}}->{$feature_id} = $cache;
push( @{$hash->{$cache->{'entry'}}->{$feature_id}->{'qualifiers'}}, {'key'=> $qualifier, 'value' => $qualifier_value}, 'line' => $line++);
#$line +=1;
}
#print Dumper $hash;
- annotation.psgiを実装
plackup -a annotation.psgi
[火 11 29 16:58] tf@/tmp
%curl -s -d 'query=XXX protein' -d 'query=YYY protein' http://togo.genes.nig.ac.jp:5000 |jq
[
{
"info": "SxtX protein [-1:sxtx] @@ GvpX protein [10001:gvpx] @@ PipX protein [10001:pipx] @@ Mvn protein [10001:mvn] @@ Doc protein [10001:doc]",
"query": "XXX protein",
"match": "cs",
"result_array": [
"SxtX protein",
"GvpX protein",
"PipX protein",
"Mvn protein",
"Doc protein"
],
"result": "SxtX protein"
},
{
"info": "Gp3 protein [-1:gp3] @@ ChpY protein [10001:chpy] @@ Mvn protein [10001:mvn] @@ Doc protein [10001:doc] @@ Bdr protein [10001:bdr]",
"query": "YYY protein",
"match": "cs",
"result_array": [
"Gp3 protein",
"ChpY protein",
"Mvn protein",
"Doc protein",
"Bdr protein"
],
"result": "Gp3 protein"
}
]
- サンプルデータ: misc/annotation_list.txt
%curl -s -F 'list=@annotation_list.txt' http://togo.genes.nig.ac.jp:5000 |jq
[
{
"info": "in_dictionary : abc transporter",
"query": "ABC transporter",
"match": "ex",
"result_array": [
"ABC transporter"
],
"result": "ABC transporter"
},
{
"info": "in_dictionary : histidine kinase [Enzyme name]",
"query": "histidine kinase",
"match": "ex",
"result_array": [
"Histidine kinase"
],
"result": "Histidine kinase"
},
{
"info": "in_dictionary : hypothetical protein",
"query": "hypothetical protein",
"match": "ex",
"result_array": [
"hypothetical protein"
],
"result": "hypothetical protein"
}
]
サンプルデータ: misc/NIES39_v17.ddbj
%curl -s -F 'ddbj=@/Users/tf/Dropbox/apl/DDBJ/NIES39_v17.ddbj' http://togo.genes.nig.ac.jp:5000 |jq
[
{
"info": "in_dictionary : hypothetical protein",
"query": "hypothetical protein",
"match": "ex",
"result_array": [
"hypothetical protein"
],
"result": "hypothetical protein"
},
{
"info": "in_dictionary : hypothetical protein",
"query": "hypothetical protein",
"match": "ex",
"result_array": [
"hypothetical protein"
],
"result": "hypothetical protein"
},
{
"info": "in_dictionary (prefix=putative ): hydrolase",
"query": "putative hydrolase",
"match": "ex",
"result_array": [
"putative hydrolase"
],
"result": "putative hydrolase"
},
(略)
- Mojoliciousで実装
- TogoAnnotatorでサービス提供
- 出力はJSON
- 入力1 (一つの入力):
#!sh
$ curl -s 'http://togoannotator.dbcls.jp/annotate/gene/XXX%20protein' | jq
{
"info": "Gp3 protein [-1:gp3] @@ GvpX protein [10001:gvpx] @@ SxtX protein [10001:sxtx] @@ PipX protein [10001:pipx] @@ Mvn protein [10001:mvn]",
"match": "cs",
"query": "XXX protein",
"result": "Gp3 protein",
"result_array": [
"Gp3 protein",
"GvpX protein",
"SxtX protein",
"PipX protein",
"Mvn protein"
]
}
- 入力2 (リストファイルをアップロード):
#!sh
$ curl -s -F 'upload=@/opt/services2/togoannot/togoannotator/misc/annotation_list.txt' 'http://togoannotator.dbcls.jp/annotate/genes' | jq
[
{
"info": "in_dictionary : abc transporter",
"match": "ex",
"query": "ABC transporter",
"result": "ABC transporter",
"result_array": [
"ABC transporter"
]
},
{
"info": "in_dictionary : histidine kinase [Enzyme name]",
"match": "ex",
"query": "histidine kinase",
"result": "Histidine kinase",
"result_array": [
"Histidine kinase"
]
},
{
"info": "in_dictionary : hypothetical protein",
"match": "ex",
"query": "hypothetical protein",
"result": "hypothetical protein",
"result_array": [
"hypothetical protein"
]
}
]
- 入力3 (DDBJファイルをアップロード):
#!sh
$ curl -s -F 'upload=@/opt/services2/togoannot/togoannotator/misc/NIES39_v17.ddbj' 'http://togoannotator.dbcls.jp/annotate/ddbj' | jq
OpenAPIとその実証を利用して、APIドキュメントおよび動作環境をMojolicious::Liteで実装したウェブサイトに組込む
- Swagger Editorで編集し、OpenAPI spec. で定義jsonを出力 > swagger.json
- Swagger UI](http://swagger.io/swagger-ui/) の https://github.com/swagger-api/swagger-ui/blob/master/dist/index.html
をテンプレートに移植
- オープンソースのテーマもあり http://meostrander.com/swagger-ui-themes/
- swagger.json内の共通定義を再利用する形式で記述、 http://apihandyman.io/writing-openapi-swagger-specification-tutorial-part-3-simplifying-specification-file/
- parameterを追加、dictionary=[uniprot, cyanobase]、curated_dictionary