in reply to Finding Consensus String
Then it's your task to turn the array of array references into the string you want.sub consensus { my $len = length($_[0]); # all strands are of one length, right? my @cons; # loop over the positions in the strands for my $i (0 .. $len - 1) { my %freq; my $max = 0; # loop over character $i in each of the strands for (map substr($_, $i, 1), @_) { $freq{$_}++; # save the max value $max = $freq{$_} if $freq{$_} > $max; } # store only those who occur the most times push @cons, [grep $freq{$_} == $max, keys %freq]; } return \@cons; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Finding Consensus String
by monkfan (Curate) on Oct 19, 2005 at 16:31 UTC | |
by japhy (Canon) on Oct 19, 2005 at 19:18 UTC |