通过perl脚本将fasta格式转换为KaKs_Calculat
2021-10-26 本文已影响0人
qujingtao
这个perl脚本的作用是将Mega等软件比对保存的fasta格式的结果转化为KaKs_Calculator软件需要的AXT的输入格式。
可以通过下面的地址下载:
https://github.com/qujingtao/perl-scripts-in-bioinformatics/blob/master/convert_fasta_to_axt.pl
用法为:
perl convert_fasta_to_axt.pl example.fasta
或者将脚本拷贝使用。注意DOS与UNIX之间的转换。
#!/usr/bin/perl
#The function of this perl script converts the fasta format of MEGA software into the axt format required by the KaKs_Calculator software.
#Usage: perl convert_fasta_to_axt.pl example.fasta.
use warnings;
use strict;
open IN,"$ARGV[0]";
my ($name) = $ARGV[0] =~ /(.*)\.fas/;
open OUT,">$name.axt";
my %seq = ();
local $/ = ">";
<IN>;
while (<IN>) {
s/>//;
my @a = split/\n/,$_,2;
$a[1] =~ s/\n//g;
my @b = split/\s+/,$a[0];
$seq{$b[0]} = $a[1];
}
close IN;
my @keys = keys %seq;
foreach my $i (0..$#keys) {
foreach my $j (0..$#keys) {
if ($i < $j) {
print OUT "$keys[$i]&$keys[$j]\n$seq{$keys[$i]}\n$seq{$keys[$j]}\n\n";
}
}
}
close OUT;