走进转录组Linux与生物信息

从fasta序列中提取特定ID的序列

2022-05-07  本文已影响0人  geneonto

小编分享一个从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();
上一篇下一篇

猜你喜欢

热点阅读