-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGC-content.pl
More file actions
56 lines (43 loc) · 1.01 KB
/
Copy pathGC-content.pl
File metadata and controls
56 lines (43 loc) · 1.01 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl
#read file in from input line
$infile = $ARGV[0];
open(TXT, "<$infile");
#read in the DNA string using the fasta subfunction
$DNA = &read_fasta();
$len = length($DNA);
print "\n DNA Length is: $len \n";
$numG=0;
$numC=0;
$numT=0;
$numA=0;
@bases=split(//,$DNA);
foreach $bp(@bases)
{
if($bp =~ m/G/i){$numG++};
if($bp =~ m/C/i){$numC++};
if($bp =~ m/T/i){$numT++};
if($bp =~ m/A/i){$numA++};
}
print "\n Number of G bases: $numG";
print "\n Number of C bases: $numC";
print "\n Number of T bases: $numT";
print "\n Number of A bases: $numA";
$GC_content = (($numG+$numC)/$len)*100;
print "\n\n GC Content is: $GC_content % \n";
close(TXT);
sub read_fasta
{
$sequence = "";
while(<TXT>)
{
$line = $_;
print " $line \n";
#remove newline characters
chomp($line);
# discard fasta header line
if($line =~ />/){ next }
# append the line to the DNA sequence
else{ $sequence .= $line }
}
return($sequence);
}