Perl probeDB的提取

[color=darkblue]开始做毕设了,导师给的题目是做关于siRNA的东西,具体我也不太清楚,总之,按部就班的来就好了。
第一步,是要将包含probeDB的31815个网页下载下来,这些网页保存在http://www.ncbi.nlm.nih.gov/projects /genome/probe/reports/probereport.cgi?uid=xxx的地址上,而能得到的关于xxx的是一个文件,保存在 probe.txt中,具有如下的结构:

1: Probe: Pr000029.1

2: Probe: Pr000030.1

3: Probe: Pr000031.1

4: Probe: Pr000032.1

5: Probe: Pr000033.1

6: Probe: Pr000034.1
而xx是为Pr000029.1等除去0的整数,所以第一步先处理probe.txt得到整数的文件uid.txt
代码如下:
#!/usr/bin/perl
open(RH,"probe.txt") or die "cannot read probe.txt:$!";
my @lines = <RH>; chomp @lines;
close RH or die "cannot close probe.txt:$!";
open(WH,">uid.txt") or die "cannot write uid.txt:$!";
for(my $i = 1; $i < @lines; $i += 2){
$lines[$i] =~ /.*Pr0*(d+).d/;
print WH "$1 ";
}

close WH or die "cannot close uid.txt:$!";

注意正则的匹配,经过处理,得到uid.txt。中保存有uid的整数值,下面就要下载该文件了
代码如下:
#!/usr/bin/perl
open(RH,"uid.txt") or die "can not open uid.txt:$!";
my @lines = <RH>; chomp @lines;
close RH or die "cannot close uid.txt:$!";
for(my $i = $#lines; $i > -1; $i --){
my $url = "http://www.ncbi.nlm.nih.gov/projects/genome/probe/reports/probereport.cgi?uid=$lines[$i]";
system("wget -O pr_htmls/$i.html '$url'");
}
print "done ";

运行该脚本,将所有网页下载到pr_htmls中,若没有该文件夹,

#mkdir pr_htmls
#perl htmlfetcher.pl
文件下载需要较长时间,完成下载后,开始着手文件的处理,观察文件结构,开始构造正则匹配,来提取需要的信息:
代码如下:

#!/usr/bin/perl
#use strict;
#先把文件读进来,参数1为读取的文件名
my $in = $ARGV[0];
my $id,$seq1,$seq2,$geneid,$pub;
die "没有读入的文件" if(!defined($in));
open(RH,$in) or die "Can not read $in";
my @lines = <RH>;
close RH or die "can not close $in:$!";
#读取第一个字段,Prxxxxx.x
$lines[49] =~ /(Prd+.d)</td>$/;
$id = $1;
for(my $i = 50; $i < @lines; $i ++){
if($lines[$i] =~ /<td class=Sequence>(.*?)</td>/){
while($lines[$i] =~ />([ATCG]+)</g){
$seq1 = $seq1.$1;
}
$i ++;
while($i < @lines && $lines[$i] !~ /<td class=Sequence>(.*?)</td>/){
$i ++;
}
while($lines[$i] =~ />([ATCG]+)</g){
$seq2 = $seq2.$1;
}
$i ++;
while($i < @lines && $lines[$i] !~ /Probe design is based on/){
$i ++;
}
while($lines[$i] =~ /[url=(.*?)](.*?)[/url]/g){
$geneid = $geneid.$2."($1)";
}

if($lines[$i] =~ /from published data <a class=intextlinks href="(.*)">((.*?))/){
$pub = $2."($1)";
}
last;
}
}
print "$id $seq1 $seq2 $geneid $pub ";

保存为probeDBfiller.pl
最后一步,开始提取需要的信息:
#for((i = 0; i < 31835;i++)); do echo $i; perl probeDBfiller.pl pr_htmls/$i.html >>probe.db;done
即将记录保存到probe.db中
[/color]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章