Chinaunix首页 | 论坛 | 博客
  • 博客访问: 459510
  • 博文数量: 118
  • 博客积分: 4015
  • 博客等级: 上校
  • 技术积分: 1233
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-24 22:11
文章分类

全部博文(118)

文章存档

2013年(5)

2011年(61)

2010年(52)

分类:

2010-12-13 17:34:49

开始做毕设了,导师给的题目是做关于siRNA的东西,具体我也不太清楚,总之,按部就班的来就好了。
第一步,是要将包含probeDB的31815个网页下载下来,这些网页保存在的地址上,而能得到的关于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 = ; 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 = ; chomp @lines;
close RH or die "cannot close uid.txt:$!";
for(my $i = $#lines; $i > -1; $i --){
    my $url = "[$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 = ;
close RH or die "can not close $in:$!";
#读取第一个字段,Prxxxxx.x
$lines[49] =~ /(Prd+.d)$/;
$id = $1;
for(my $i = 50; $i < @lines; $i ++){
    if($lines[$i] =~ /(.*?)/){
        while($lines[$i] =~ />([ATCG]+)            $seq1 = $seq1.$1;
        }
        $i ++;
        while($i < @lines && $lines[$i] !~ /(.*?)/){
            $i ++;
        }
        while($lines[$i] =~ />([ATCG]+)            $seq2 = $seq2.$1;
        }
        $i ++;
        while($i < @lines && $lines[$i] !~ /Probe design is based on/){
            $i ++;
        }
        while($lines[$i] =~ /(.*?)/g){
            $geneid = $geneid.$2."($1)";
        }

        if($lines[$i] =~ /from published data  ((.*?))/){
            $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中



阅读(697) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~