小编分享一个从fasta中提取序列的perl脚本(需要安装bioperl):
die "perl $0 <id> <fa> <OUT>" unless(@ARGV==3);
use Bio::SeqIO;
use Bio::Seq;
$in = Bio::SeqIO->new(-file => "$ARGV[1]" ,
-format => 'Fasta');
$out = Bio::SeqIO->new(-file => ">$ARGV[2]" ,
-format => 'Fasta');
my%keep=();
open IN ,"$ARGV[0]" or die "$!";
while(<IN>){
chomp;
next if /^#/;
$keep{$_}=1;
}
close(IN);
while ( my $seq = $in->next_seq() ) {
my($id,$sequence,$desc,$len)=($seq->id,$seq->seq,$seq->desc,$seq->length);
if(exists $keep{$id}){
$out->write_seq($seq);
}
}
$in->close();
$out->close();
网友评论