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]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章