我写这个东西,就是为了给自己一个激励,防止自己半途而废。KEGG(Kyoto Encyclopedia of Genes and Genomes)写的这个API是基于SOAP的,一开始本来打算用C来学习的,试了两天一直没有搞定SOAP客户端怎么弄,只好发个懒,学习Perl吧,以前因为一些机缘,了解一点正则,深感Perl的方便,也正好是个机会。
先搭建环境,在WindowsXP下,先安装了一个ActivePerl,然后进入cmd,输入命令:
结果运行后遇到错误:t\SOAP\Transport\HTTP\CGI.t过不去,没办法,只好先把SOAP-Lite-0.710.08软件包下载下来,解压后找到CGI.t文件,改名为CGI.t_backup。去微软的网站下载了nmake的安装包,解压后将解压文件拷贝至perl的bin文件夹内,然后再cmd下转到SOAP-Lite-0.710.08的解压目录下,输入命令:
会提示找不着cgi.t找不着,不管那些了,反正强制安装上就行了,有什么不良后果,暂时我还不清楚。
接着安装LWP,进入cmd,输入命令:
它就会自动完成安装。之后得下载一下perl编辑器,当然我很穷,只好下载一个不要钱的,下了个Perl Express(感觉好象用了Express做名字的就是不要钱的),开始写程序吧。
1 | #!/usr/bin/env perl |
这个是KEGG API的示例程序,在Perl Express中按F9运行一下,会得到如下结果:
我们就来分析一下这个程序。
#!/usr/bin/perl 这一句声明了环境。如果是直接在cmd下使用perl xx.pl来运行的话可以不要。
use SOAP::Lite; 使用软件包SOAP::Lite,这个很象C当中的include <xx.h>和use namespace xxx,声明了后就可以使用相关的属性和方法。
$wsdl = ‘http://soap.genome.jp/KEGG.wsdl’; 定义变量wsdl,这个变量的值是KEGG API提供的接口地址,关于什么是wsdl可以用百度google一下就知道了。
$serv = SOAP::Lite->service($wsdl); 定义变量serv,这个变量有点象C当中的指针,里面存取了一个结构体的指针,这是一个特殊的结构体,自身带着属性和方法,有个特定的名,叫类(class)。
$offset = 1; 变量offset
$limit = 5; 变量limit,这两个变量名在KEGG API有特殊的意义,都是整型变量,用于控制一次返回结果的个数和起始偏移量。
$top5 = $serv->get_best_neighbors_by_gene(‘eco:b0002′, $offset, $limit); 定义变量top5,变量serv前面讲过是个指针,指向一个自带属性和方法的类,这里使用了这个类的ArrayOfSSDBRelation get_best_neighbors_by_gene(string:genes_id, int:offset, int:limit)方法,这个方法可以在KEGG SSDB (Sequence Similarity DataBase)当中找到其它基因组当中最相近的基因。这个数据库可以提供两个方法的相似,一个是从gene1到gene2最相近,一个是反向最相近,还有双向都相近。这里使用的方法是找到顺向最相近的。offset和limit已经定义好了,基因名genes_id定义为eco:b0002,这里的eco指的是 Escherichia coli K-12 MG1655,具体的内容可以参见:http://www.genome.jp/kegg/catalog/org_list.html。get_best_neighbors_by_gene的返回值为结构体数组ArrayOfSSDBRelation,依据KEGG API的定义,SSDBRelation结构体包含如下变量:
boolean | equals(java.lang.Object obj) |
float | getBit_score() Gets the bit_score value for this SSDBRelation. |
java.lang.String | getDefinition1() Gets the definition1 value for this SSDBRelation. |
java.lang.String | getDefinition2() Gets the definition2 value for this SSDBRelation. |
static org.apache.axis.encoding.Deserializer | getDeserializer(java.lang.String mechType, java.lang.Class _javaType, javax.xml.namespace.QName _xmlType) Get Custom Deserializer |
int | getEnd_position1() Gets the end_position1 value for this SSDBRelation. |
int | getEnd_position2() Gets the end_position2 value for this SSDBRelation. |
java.lang.String | getGenes_id1() Gets the genes_id1 value for this SSDBRelation. |
java.lang.String | getGenes_id2() Gets the genes_id2 value for this SSDBRelation. |
float | getIdentity() Gets the identity value for this SSDBRelation. |
int | getLength1() Gets the length1 value for this SSDBRelation. |
int | getLength2() Gets the length2 value for this SSDBRelation. |
int | getOverlap() Gets the overlap value for this SSDBRelation. |
static org.apache.axis.encoding.Serializer | getSerializer(java.lang.String mechType, java.lang.Class _javaType, javax.xml.namespace.QName _xmlType) Get Custom Serializer |
int | getStart_position1() Gets the start_position1 value for this SSDBRelation. |
int | getStart_position2() Gets the start_position2 value for this SSDBRelation. |
int | getSw_score() Gets the sw_score value for this SSDBRelation. |
static org.apache.axis.description.TypeDesc | getTypeDesc() メタデータオブジェクトの型を返却 / [en]-(Return type metadata object) |
int | hashCode() |
boolean | isBest_flag_1To2() Gets the best_flag_1To2 value for this SSDBRelation. |
boolean | isBest_flag_2To1() Gets the best_flag_2To1 value for this SSDBRelation. |
void | setBest_flag_1To2(boolean best_flag_1To2) Sets the best_flag_1To2 value for this SSDBRelation. |
void | setBest_flag_2To1(boolean best_flag_2To1) Sets the best_flag_2To1 value for this SSDBRelation. |
void | setBit_score(float bit_score) Sets the bit_score value for this SSDBRelation. |
void | setDefinition1(java.lang.String definition1) Sets the definition1 value for this SSDBRelation. |
void | setDefinition2(java.lang.String definition2) Sets the definition2 value for this SSDBRelation. |
void | setEnd_position1(int end_position1) Sets the end_position1 value for this SSDBRelation. |
void | setEnd_position2(int end_position2) Sets the end_position2 value for this SSDBRelation. |
void | setGenes_id1(java.lang.String genes_id1) Sets the genes_id1 value for this SSDBRelation. |
void | setGenes_id2(java.lang.String genes_id2) Sets the genes_id2 value for this SSDBRelation. |
void | setIdentity(float identity) Sets the identity value for this SSDBRelation. |
void | setLength1(int length1) Sets the length1 value for this SSDBRelation. |
void | setLength2(int length2) Sets the length2 value for this SSDBRelation. |
void | setOverlap(int overlap) Sets the overlap value for this SSDBRelation. |
void | setStart_position1(int start_position1) Sets the start_position1 value for this SSDBRelation. |
void | setStart_position2(int start_position2) Sets the start_position2 value for this SSDBRelation. |
void | setSw_score(int sw_score) Sets the sw_score value for this SSDBRelation. |
foreach $hit (@{$top5}) {
print “$hit->{genes_id1}\t$hit->{genes_id2}\t$hit->{sw_score}\n”;
} 这句用了个循环,foreach就不用解释了,这里先定义了一个结构体数组,它的变量从指针top5中取出。之后,对于在hit中的每个返回的结果,打印出其中的genes_id1,genes_id2和sw_score的值。
接下来再看这个运行的结果,就一目了然了:
genes_id1 genes_id2 sw_score
eco:b0002 ebw:BWG_0002 5283
eco:b0002 elf:LF82_2259 5283
eco:b0002 ecz:ECS88_0002 5283
eco:b0002 ect:ECIAI39_0001 5283
eco:b0002 ecg:E2348C_0002 5283
到这里,KEGG API为我们已经打开了大门,我们已经可以从中获取数据了。
评论