统计fasta文件GC含量【Perl】

#!/usr/bin/perl -w 
use strict;
my $file="myseq.fa";
open(FH,$file) or die $!;
my $G_num=0;
my $C_num=0;
my $g_num=0;
my $c_num=0;
my $bases=0;
while(){
	if($_=~/^>/){next;}
	if(/C/){$C_num+= $_ =~ tr/C/C/;}
	if(/c/){$c_num+= $_ =~ tr/c/c/;}
	if(/G/){$G_num+= $_ =~ tr/G/G/;}
	if(/g/){$g_num+= $_ =~ tr/g/g/;}
	chomp($_);
	$bases+=length($_);
}
close FH;
my $GC=($G_num+$C_num+$g_num+$c_num)/$bases;
$GC=sprintf"%0.2f",$GC;
print "GC content is: $GC\n";

你可能感兴趣的:(Perl)