Our Sponsors



Download BioinformaticsOnline(BOL) Apps in your chrome browser.




Count the frequency of base G in a given DNA sequence

  • Public
By Nishi Singh 3152 days ago
#!/usr/bin/perl use strict; use warnings; my $DNA = "GATTACACAT"; #initialize $countG and $currentPos my $countG = 0; my $currentPos = 0; #calculate the length of $DNA my $DNAlength = length($DNA); #for each letter in the sequence check if it is the base G #if 'yes' increment $countG while($currentPos < $DNAlength){ my $base = substr($DNA,$currentPos,1); if($base eq "G"){ $countG++; } $currentPos++; } #end of while loop #print out the number of Gs print "There are $countG G bases\n";