Linux: 根据 ID 提取 fasta
2023-09-18 本文已影响0人
LET149
perl
脚本根据ID
提取fasta
序列文件
perl id2fasta input.fasta ID.txt output.fasta
#!/bin/perl
#unless(@ARGV==3){
# die "usage: $0 <input.fa> <lst> <output.fas>\n";
#}
$file=shift;
$lst=shift;
$out=shift;
open FILE,$file;
open LST,$lst;
open OUT,">".$out;
while(<FILE>){
chomp;
my $line=$_;
if($line=~/^>/){
my @line=split /[ |\t]/,$line;
our $name=$line[0];
#print "$name\n";
}
else{
$seq_hash{$name}.=$line;
}
}
while(<LST>){
chomp;
my $line=$_;
if($line=~/^>/){
$ID=$line;
if(exists $seq_hash{$ID}){
print OUT "$ID\n$seq_hash{$ID}\n";
}
else{
print OUT "error1: ".$ID." no found.\n";
}
}
else{
my $ID=">".$line;
if(exists $seq_hash{$ID}){
print OUT "$ID\n$seq_hash{$ID}\n";
}
else{
print OUT "error2: ".$ID." no found.\n";
}
}
}