| 1 | package Bio::KEGG::API; | ||
| 2 | |||
| 3 | use v5.12; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use Moose; | ||
| 7 | use namespace::autoclean; | ||
| 8 | use REST::Client; | ||
| 9 | use Net::FTP::Tiny qw(ftp_get); | ||
| 10 | |||
| 11 | our $VERSION = '0.01'; | ||
| 12 | |||
| 13 | has 'client' => ( | ||
| 14 | is => 'rw', | ||
| 15 | isa => 'REST::Client', | ||
| 16 | default => sub { | ||
| 17 | my $self = shift; | ||
| 18 | return my $obj = REST::Client->new({host=> "http://rest.kegg.jp", timeout => 30,}); | ||
| 19 | } | ||
| 20 | ); | ||
| 21 | |||
| 22 | has 'operation' => ( | ||
| 23 | is => 'rw', | ||
| 24 | isa => 'Str', | ||
| 25 | ); | ||
| 26 | |||
| 27 | has 'database' => ( | ||
| 28 | is => 'rw', | ||
| 29 | isa => 'Str', | ||
| 30 | ); | ||
| 31 | |||
| 32 | has 'organism' => ( | ||
| 33 | is => 'rw', | ||
| 34 | isa => 'Str', | ||
| 35 | ); | ||
| 36 | |||
| 37 | |||
| 38 | sub database_info { | ||
| 39 | my $self = shift; | ||
| 40 | my %param = @_; | ||
| 41 | |||
| 42 | $self->operation('/info/'); | ||
| 43 | $self->database($param{'database'}) if defined $param{'database'}; | ||
| 44 | $self->organism($param{'organism'}) if defined $param{'organism'}; | ||
| 45 | |||
| 46 | if ( $param{'database'} ) { | ||
| 47 | |||
| 48 | $self->client->GET($self->operation.$param{'database'}); | ||
| 49 | |||
| 50 | } elsif ( $param{'organism'} ) { | ||
| 51 | |||
| 52 | $self->client->GET($self->operation.$param{'organism'}); | ||
| 53 | } | ||
| 54 | |||
| 55 | return $self->client->responseContent; | ||
| 56 | } | ||
| 57 | |||
| 58 | |||
| 59 | sub entry_list { | ||
| 60 | my $self = shift; | ||
| 61 | my %param = @_; | ||
| 62 | |||
| 63 | $self->operation('/list/'); | ||
| 64 | $self->database($param{'database'}) if defined $param{'database'}; | ||
| 65 | $self->organism($param{'organism'}) if defined $param{'organism'}; | ||
| 66 | |||
| 67 | if ( $param{'database'} && $param{'organism'} ) { | ||
| 68 | |||
| 69 | $self->client->GET($self->operation.$param{'database'}."/".$param{'organism'}); | ||
| 70 | |||
| 71 | } elsif ( $param{'database'} ) { | ||
| 72 | |||
| 73 | $self->client->GET($self->operation.$param{'database'}); | ||
| 74 | |||
| 75 | } elsif ( $param{'organism'} ) { | ||
| 76 | |||
| 77 | $self->client->GET($self->operation.$param{'organism'}); | ||
| 78 | |||
| 79 | } | ||
| 80 | |||
| 81 | my @result = split(/\n/, $self->client->responseContent); | ||
| 82 | return @result; | ||
| 83 | |||
| 84 | } | ||
| 85 | |||
| 86 | |||
| 87 | sub data_search { | ||
| 88 | my $self = shift; | ||
| 89 | my %param = @_; | ||
| 90 | |||
| 91 | $self->operation('/find/'); | ||
| 92 | |||
| 93 | $self->database($param{'database'}) if defined $param{'database'}; | ||
| 94 | $self->organism($param{'organism'}) if defined $param{'organism'}; | ||
| 95 | $self->organism($param{'query'}) if defined $param{'query'}; | ||
| 96 | |||
| 97 | if ( $param{'database'} && $param{'query'} ) { | ||
| 98 | |||
| 99 | $self->client->GET($self->operation . $param{'database'} . "/" . $param{'query'}); | ||
| 100 | |||
| 101 | } elsif ( $param{'organism'} && $param{'query'}) { | ||
| 102 | |||
| 103 | $self->client->GET($self->operation . $param{'organism'} . "/" . $param{'query'}); | ||
| 104 | |||
| 105 | } elsif ( $param{'database'} && $param{'organism'}) { | ||
| 106 | |||
| 107 | $self->client->GET($self->operation.$param{'database'}."/".$param{'organism'}); | ||
| 108 | |||
| 109 | }; | ||
| 110 | |||
| 111 | my @result = split(/\n/, $self->client->responseContent); | ||
| 112 | return @result; | ||
| 113 | |||
| 114 | } | ||
| 115 | |||
| 116 | |||
| 117 | sub id_convertion { | ||
| 118 | my $self = shift; | ||
| 119 | my %param = @_; | ||
| 120 | |||
| 121 | $self->operation('/conv/'); | ||
| 122 | |||
| 123 | $self->database($param{'target'}) if defined $param{'target'}; | ||
| 124 | $self->organism($param{'source'}) if defined $param{'source'}; | ||
| 125 | |||
| 126 | if ( $param{'target'} && $param{'source'} ) { | ||
| 127 | |||
| 128 | $self->client->GET($self->operation.$param{'target'}."/".$param{'source'}); | ||
| 129 | |||
| 130 | } | ||
| 131 | |||
| 132 | my @result = split(/\t/, $self->client->responseContent ); | ||
| 133 | |||
| 134 | for my $elem ( @result ) { | ||
| 135 | |||
| 136 | $elem =~ s/\n/\t/g; | ||
| 137 | } | ||
| 138 | |||
| 139 | return @result; | ||
| 140 | |||
| 141 | } | ||
| 142 | |||
| 143 | |||
| 144 | sub data_retrieval { | ||
| 145 | my $self = shift; | ||
| 146 | my $param = @_; | ||
| 147 | |||
| 148 | } | ||
| 149 | |||
| 150 | |||
| 151 | sub linked_entries { | ||
| 152 | my $self = shift; | ||
| 153 | my %param = @_; | ||
| 154 | |||
| 155 | $self->operation('/link/'); | ||
| 156 | |||
| 157 | $self->database($param{'target'}) if defined $param{'target'}; | ||
| 158 | $self->organism($param{'source'}) if defined $param{'source'}; | ||
| 159 | |||
| 160 | if ( $param{'target'} && $param{'source'} ) { | ||
| 161 | |||
| 162 | $self->client->GET($self->operation.$param{'target'}."/".$param{'source'}); | ||
| 163 | |||
| 164 | } | ||
| 165 | |||
| 166 | my @result = split(/\t/, $self->client->responseContent ); | ||
| 167 | |||
| 168 | for my $elem ( @result ) { | ||
| 169 | |||
| 170 | $elem =~ s/\n/\t/g; | ||
| 171 | } | ||
| 172 | |||
| 173 | return @result; | ||
| 174 | |||
| 175 | } | ||
| 176 | |||
| 177 | |||
| 178 | |||
| 179 | 1; |