#!perl -w die "Usage:\n\tperl $0 id_list input.fa output.fa\n" if(@ARGV !=3); my ($id_list,$fa,$out_fa)=@ARGV; my %ids; open IN,$id_list||die $!; while(){ chomp; next if /^$/; $ids{$_}=1; } close IN; open OUT,">$out_fa" || die $!; if($fa=~/.gz$/){ open IN,"pigz -p 4 -dc $fa"||die $!; }else{ open IN,$fa||die $!; } # 改输入符;提取序列会有问题 #$/=">"; #while(){ # chomp; # next if /^$/; # my ($id)=$_=~/^([^\s\t]+)/; # print OUT ">$_" if($ids{$id}); #} my $seqname=""; while () { chomp; next if (/^$/); ($seqname)=$_=~/>(\S+)/ if($_=~/^>/); print OUT $_,"\n" if(exists $ids{$seqname}); } close IN; close OUT;