in reply to Count every 3rd base occurence
Here is my solution:
use strict; use warnings; my $string = "CTCCGGATCTAT"; my $sets = length($string)/3; # we want to know how man +y sets of 3 there are my $unpacker = 'A3' x $sets; # create our unpack templ +ate my @dna = unpack($unpacker, $string); # create the array of set +s my $counter = 0; # initialize the counter for my $set (@dna) { # for each $set in @dna d +o... my $check = substr($set, 2, 1); # get the 3rd char of the + $set ++$counter if ($check =~ /[GC]/i); # increment the counter, +ignore case } print "$counter/$sets was either C or G.\n"; # print results
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: for loops
by Aristotle (Chancellor) on Dec 16, 2002 at 20:30 UTC | |
by Aristotle (Chancellor) on Dec 17, 2002 at 00:05 UTC | |
by BrowserUk (Patriarch) on Dec 17, 2002 at 00:47 UTC | |
by BrowserUk (Patriarch) on Dec 16, 2002 at 22:08 UTC | |
by Mr. Muskrat (Canon) on Dec 16, 2002 at 21:58 UTC |