123456789101112131415161718192021222324252627282930313233343536373839 |
- #!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(<IN>){
- 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(<IN>){
- # chomp;
- # next if /^$/;
- # my ($id)=$_=~/^([^\s\t]+)/;
- # print OUT ">$_" if($ids{$id});
- #}
- my $seqname="";
- while (<IN>) {
- chomp;
- next if (/^$/);
- ($seqname)=$_=~/>(\S+)/ if($_=~/^>/);
- print OUT $_,"\n" if(exists $ids{$seqname});
- }
- close IN;
- close OUT;
|