in reply to Tallying overall frequency of characters in a set of strings by position

Like this?:

Perhaps this is closer to what you are after (Updated: corrected output ordering):

#! perl -slw use strict; use Data::Dump qw[ pp ]; my @freq; my @data = qw[ AABBC BAABC AABBD AACBB ]; for my $s ( @data ) { ++$freq[ $_ ]{ substr $s, $_, 1 } for 0 .. length( $s ) -1; } ##pp \@freq; for my $pos ( @freq ) { ( $pos->{ $_ } //= 0 ) /= 4 for 'A' .. 'D'; } ##pp \@freq; print join "\t", '', 'A'..'D'; for my $pos ( 0 .. $#freq ) { printf "%2d\t%s\n", $pos+1, join "\t", map sprintf("%.2f", $_ ), + @{ $freq[ $pos ] }{ 'A' .. 'D' }; } __DATA__ C:\test>1162755 A B C D 1 0.75 0.25 0.00 0.00 2 1.00 0.00 0.00 0.00 3 0.25 0.50 0.25 0.00 4 0.00 1.00 0.00 0.00 5 0.00 0.25 0.50 0.25

Another variations that doesn't hard code the keys:

#! perl -slw use strict; use Data::Dump qw[ pp ]; my( @freq, %c, $c ); #my @data = qw[ AABBC BAABC AABBD AACBB ]; my @data = qw[ AABBC BAABC AABBD AECBBF ]; for my $s ( @data ) { ++$freq[ $_ ]{ $c = substr $s, $_, 1 }, undef $c{ $c } for 0 .. le +ngth( $s ) -1; } ##pp \@freq; my @oK = sort keys %c; for my $pos ( @freq ) { ( $pos->{ $_ } //= 0 ) /= 4 for @oK; } ##pp \@freq; print join "\t", '', @oK; for my $pos ( 0 .. $#freq ) { printf "%2d\t%s\n", $pos+1, join "\t", map sprintf("%.2f", $_ ), + @{ $freq[ $pos ] }{ @oK }; } __DATA__ C:\test>1162755 A B C D E F 1 0.75 0.25 0.00 0.00 0.00 0.00 2 0.75 0.00 0.00 0.00 0.25 0.00 3 0.25 0.50 0.25 0.00 0.00 0.00 4 0.00 1.00 0.00 0.00 0.00 0.00 5 0.00 0.25 0.50 0.25 0.00 0.00 6 0.00 0.00 0.00 0.00 0.00 0.25

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Tallying overall frequency of characters in a set of strings by position
by Anonymous Monk on May 11, 2016 at 15:43 UTC
    Awesome, thanks! Lots of things for me to learn here.
      Lots of things for me to learn here.

      Feel free to ask questions :)

      It's much quicker and easier to answer your specific queries, than to waste my time, and bore you, with my explanations of all the things I think you might not understand, only to miss the ones that you don't.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Thanks :) I'm still making my way through all of the things you've used and done and will return with any questions if I can't figure it out myself.