参考网上资源,得到两种实现方式:
#! /usr/bin/perl
use strict;
use warnings;
open A_SPEC, $ARGV[0] or die;
open DATA, $ARGV[1] or die;
my %list;
while (<A_SPEC>) {
chomp;
$list{$_}++;
}
my $select;
while (<DATA>) {
if (/^>(\S+)/) {
$select = exists $list{$1} ? 1 : 0;
}
print $_ if $select;
}
2. 前边读取列表方式一样,参考http://blog.sina.com.cn/s/blog_7d001f3d0101nw69.html
#! /usr/bin/perl
use strict;
use warnings;
open A_SPEC, $ARGV[0] or die;
open DATA, $ARGV[1] or die;
my %list;
while (<A_SPEC>) {
chomp;
$list{$_}++;
}
# 把默认的行间隔符号"\n"改为">";那么每个里面,读进来的一行数据是比如 "seq1\nATCGAGCDGACGTACG>"
local $/ = ">"; # $/在perl中是输入记录分隔符,影响perl对"行"的理解。默认是换行符"\n".也可以定义为其他的内容
<DATA>; # 跳过首行
while (<DATA>) {
chomp;
/^(\S+)/;
if (exists $list{$1}) {
print ">$_";}
}
$/ = "\n";
如有侵权,请告知删除。