in reply to Re: Can't think of an algorithm to go..
in thread Can't think of an algorithm to go..

Thanks a lot to both of you!
Ikegami, although I am still trying to figure out what you code means, it works perfect!
Thanks for your trouble!
  • Comment on Re^2: Can't think of an algorithm to go..

Replies are listed 'Best First'.
Re^3: Can't think of an algorithm to go..
by ikegami (Patriarch) on Jun 03, 2009 at 21:23 UTC

    For each index (for my $i (0..length($seq)-1)), it gets the letter at that index in each label (map substr($_, $i, 1), @lbls).

    To calculate the consensus, the number of instances of each letter is counted ($counts{$_}++ for @_;). Then the letters (keys(%counts)) are sorted by descending number of instances (sort { $counts{$b} <=> $counts{$a} }), and one of those with the highest count is returned (( )[0]).