运行程序:perl calculateDNA_length_GCcontent.pl
——————————————————————————————————————————————————
#!/usr/bin/perl -w
use strict;
my $content="";
open In,"sampleDNA.fasta";
open Out,">sampleDNA.fasta.out";
while(<In>){
chomp;
if(/^>/){
if($content ne ""){
print Out "$content\n";
$content="";}
print Out "$_\n";
}
else{$content.=$_;}
}
print Out "$content\n";
close In;close Out;
open In,"sampleDNA.fasta.out";
open Out,">sampleDNAresult.out";
while(<In>){
chomp;
my $GC=0;my $length=0;my $GC_count=0;
if(/^>(\S+)/){
print Out "$1\t";}
else {$_=~s/\s//g;
$length=length($_);
while($_=~/c|g/ig){$GC++;};
$GC_count=$length?($GC/$length):0;
$GC_count*=100;
printf Out "%d\t%.2f",$length,$GC_count;
printf Out "%%\n";}
}
close In;close Out;