Dear all,
I am new in programming. I wrote a script to calculate the A,T,G,C frequency for each position in an alignment. Take the following alignment for example, in the position 1 the A frequency is 33.3% and G freqeuncy is 66.6%.
This script is based on others' suggestions, using hash of hash. However, I am in trouble to debug it. Would you please help to indicate where are my errors? THANK YOU VERY MUCH.
I am new in programming. I wrote a script to calculate the A,T,G,C frequency for each position in an alignment. Take the following alignment for example, in the position 1 the A frequency is 33.3% and G freqeuncy is 66.6%.
Code:
ATGCATGC GGTCACGT GTAGCGTA
Code:
#!/usr/bin/perl use strict; use warnings; open SEQ, $ARGV[0]; my %hash = 0; while (<SEQ>){ chomp; my @seq = split (/ /, $_); for (my $i=0; $i<=$#seq; $i++){ $hash {$i}{$seq[$i]} +=1; } } close SEQ; foreach my $posi (keys %hash){ foreach my $nt ('A', 'T', 'G', 'C'){ print "$posi", "$nt", %hash{$posi}{$nt}/4, "\n"; } }
Comment