in reply to Re: To count letters (%identity) in DNA alignment
in thread To count letters (%identity) in DNA alignment

Thanks for your input - very useful. I skipped the BioPerl modules as I wanted the script to be passed around non-BioPerl users. After further help and modification the final product was.
use strict; use warnings; my $in = $ARGV[0]; my $frequencies; my $maxCol = 0; open (IN, "$in") or die "cannot open $in!\n"; while (my $line = <IN>) { chomp $line; my ($name, $seq) = split ("\t", $line); if (defined $seq) { my @bases = split '', $seq; $maxCol=@bases; for (my $i=0; $i<@bases; $i++) { ++$frequencies->{$bases[$i]}[$i]; # if ($maxCol < @bases) { # $maxCol = @bases; # } } } } print_hoa($frequencies, $maxCol); #foreach my $base (keys %frequencies) { # $frequencies{$base}[$_] ||= 0 for 0 .. $maxCol; # print "$base @{$frequencies{$base}}\n"; #} ##Subroutine that prints a hash fo arrays reference. sub print_hoa { my ($hashref, $len) = @_; for my $person (sort keys %{$hashref}) { my $array = $hashref->{$person}; my @array_print = @$array; print "$person\t"; foreach my $num (@array_print) { if (defined $num) { print "$num "; } else { print "0 "; } } my $i =@array_print; if ($i<$len) { my $z_pr = $len-$i; print "0 " x $z_pr, "\n"; } else { print "\n"; } } }