「KEGG API はプログラムなどから KEGG を利用するためのウェブサービスです。」ということで、早速私も使ってみようと思い、説明書を読んでみた。例として、RubyとかJavaとかPerlとかPythonの使用例が載っているが、PHPはない。なぜだ。
SOAPは慣れていないので、私にはちょっと難しい。手始めに簡単なのを作ってみた。これだけでもいろいろ戸惑ったのだ。
<?php $query = $argv[1]; $wsdl = "http://soap.genome.jp/KEGG.wsdl"; $client = new SoapClient($wsdl); $top5 = $client->get_best_neighbors_by_gene($query,1,5); print_r($top5); ?>これをkegg.phpというような名前で保存して、php kegg.php eco:b0002とでも打ってみれば、
Array ( [0] => stdClass Object ( [genes_id1] => eco:b0002 [genes_id2] => ecv:APECO1_1976 [sw_score] => 5283 [bit_score] => 1210 [identity] => 1 [overlap] => 820 [start_position1] => 1 [end_position1] => 820 [start_position2] => 15 [end_position2] => 834 [best_flag_1to2] => 1 [best_flag_2to1] => 1 [definition1] => fused aspartokinase I and homoserine dehydrogenase I [definition2] => bifunctional aspartokinase I/homeserine dehydrogenase I [length1] => 820 [length2] => 834 ) [1] => stdClass Object ( [genes_id1] => eco:b0002 [genes_id2] => ecp:ECP_0002 [sw_score] => 5283 [bit_score] => 1210 [identity] => 1 [overlap] => 820 [start_position1] => 1 [end_position1] => 820 [start_position2] => 1 [end_position2] => 820 [best_flag_1to2] => 1 [best_flag_2to1] => [definition1] => fused aspartokinase I and homoserine dehydrogenase I [definition2] => aspartokinase I/homoserine dehydrogenase I [length1] => 820 [length2] => 820 ) ........ )という結果が返ってくる。なるほどねえ。なんだか判ったような、判らないような。
新納浩幸『Rで学ぶクラスタ解析』(3200円+税/オーム社)[amazon.co.jp, 紀伊國屋書店]を買ったので、Rで文字列を扱う練習をしてみようと思った。ダンセイニの『ペガーナの神々』のファイルを読込んで、Sishを含む行を抜きだしてみる。表示させるときには、Sishを#で挟んでみたりする。
> text <- scan(file="pegana.txt",sep="\n", what="") > for(i in 1:length(text)) if(any(grep("Sish",text[i]))){ + print(gsub("Sish","#Sish#",text[i])) + }とやると、下のような結果が表示された。
[1] "Concerning #Sish#" [1] "There are in Pegana Mung and #Sish# and Kib, and the maker of all" [1] "Time is the hound of #Sish#." [1] "At #Sish#'s bidding do the hours run before him as he goeth upon" [1] "Never hath #Sish# stepped backward nor ever hath he tarried; never" [1] "Before #Sish# is Kib, and behind him goeth Mung." [1] "Very pleasant are all things before the face of #Sish#, but behind" [1] "And #Sish# goeth ceaselessly upon his way." [1] "neither did #Sish# assail it with his hours." [1] "on the slopes of it #Sish# rested among the flowers when #Sish# was" [1] "Thence #Sish# went forth into the world to destroy its cities, and" [1] "And Time, which is the hound of #Sish#, devoured all things; and" [1] "#Sish# sent up the ivy and fostered weeds, and dust fell from the" [1] "hand of #Sish# and covered stately things. Only the valley where" [1] "#Sish# rested when he and Time were young did #Sish# not provoke his" [1] "beyond mountains, a garden exceeding fair with flowers; but #Sish#" [1] "And Mung said: \"With the gods it is always Now. And before #Sish#" [1] "And #Sish# throughout the Worlds hurled Time away, and slew the" [1] "to assail all things. And #Sish# cast a whiteness over the hairs of" [1] "And when #Sish# became a god less durable to Yun-Ilara than ever" [1] "Kib giveth but toil and trouble; and #Sish#, he sendeth regrets with" [1] "save One, Priest of Kib, Priest of #Sish#, and Priest of Mung," [1] "Priest of Kib, Priest of #Sish#, and Priest of Mung, Teller of the" [1] "may know.' And he showed me the paths of #Sish# stretching far down" [1] "walked with Dorozhand adown the paths of #Sish# into the future" [1] "that #Sish# dealt not too harshly with the hours, and that all the" 15 件の警告がありました (警告を見るには warnings() を使って下さい)Sishの位置が揃わないと見づらいのだ。位置を数えて、足りない文字分を左側に追加するやり方が判らなかった。一定の長さに切り詰める方法は判ったのだが。しかし、Rでkwicはあまり意味がないかも。もっと単語を集計してクラスター解析とかを練習した方がいいだろうか。