-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountGC.pl
38 lines (35 loc) · 895 Bytes
/
countGC.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!usr/bin/perl
#write by [email protected] 2011-5-20
#Useage : perl countGC.pl inputfile outputfile
use strict;
use warnings;
foreach my $inputfile(@ARGV){
open INPUTFILE,"< $inputfile" or die "can't open file!please check you file name!";
open OUTFILE,">> thePercentageOfGC.txt";
my @File=<INPUTFILE>;
close INPUTFILE;
#combain the data
my $DNA=join "",@File;
$DNA =~ s/\s//g;
my @DNA=split//,$DNA;
my $CountA=0;
my $CountG=0;
my $CountC=0;
my $CountT=0;
my $error=0;
#compute percentage
foreach (@DNA){
if (/A/){$CountA++}
elsif(/G/){$CountG++}
elsif(/C/){$CountC++}
elsif(/T/){$CountT++}
else{$error++}
}
#compute the GC count
my $GC=(($CountG+$CountC)*100)/($CountA+$CountC+$CountG+$CountT);
#sprinf
printf OUTFILE "The $inputfile file's GC%%\=%.4f%%,Attention!!!!I can't recognize bases total are $error\n",$GC;
}
close OUTFILE;
close INPUTFILE;
exit;