I would like count number of A's, C's and G's in a sequence or string. I have written the following code.
But when I print the values, only A's get printed. C's and G's are displayed as zero. In the code below I'm evaluating A's first, but if I switch the order by evaluating C's first, I get the values of C, but now A's and G's are printed out as zero.
Can anyone tell me what is wrong with my code? Thanks!
#! /usr/bin/perl
use strict;
use warnings;
open(IN, "200BP_junctions_fasta.faa") or die "Cannot open the file: $!\n";
while(<IN>)
next if $_ =~ /\>/;
my $a = ($_ = tr/A//);
my $c = ($_ = tr/C//);
my $g = ($_ = tr/G//);
print "A:$a, C:$c, G:$g\n";
}
The file looks like the following:
> A_Seq ATGCTAGCTAGCTAGCTAGTC > B_Seq ATGCGATCGATCGATCGATAG