in reply to Count # of occurrences per column

my @cols; while (<DATA>) { chomp; my ($id, @markers) = split; for my $i (0..$#markers) { $cols[$i]{$markers[$i]}++; } } for my $i (0..$#cols) { print "column $i\n"; print "$_ $cols[$i]{$_} " for sort keys %{$cols[$i]}; print "\n"; } __DATA__ 3851 A A G G T T A A C C 3854 A A G G T T A A C C 3871 A A G G T T A A G G

Replies are listed 'Best First'.
Re^2: Count # of occurrences per column
by ikegami (Patriarch) on May 11, 2011 at 18:07 UTC

    The column number off by two in your output. The count and character order is reversed in your output. And while it's not clear from the OP, it looks to me the output should be sorted by descending count.

      True, but ... from OP:

      The output does not need to be as specific as I have put, as long as it gives the column number and how many occurrences of each character.

      I prefer to simply demonstrate general concepts and not distract with needless or potentially implied minutia. Obviously it's easy enough for the OP to add 2 to the column if that's what he desires, along with adding sorting or pretty printing.

      *Shrug* Good thing I'm not a perfectionist ;)