Like the other monks, I don't have a clue what your goals really are. (Try using shorter sentences when explaining things.) I took your code and data as posted, and put them together into a single file like this:
I had to edit the data to make it tab-delimited -- maybe the tabs were converted to spaces because of the way you posted it (or the way I downloaded it), but you may need to check and make sure whether your file really has the right number of tabs per line.
Anyway, your code ran and produced output with no errors. So what's the problem? If you were expecting some different sort of output, you'll need to explain how the actual output differs from the desired output.
I took the liberty of fixing the indentation in the code -- this really helps for making the code readable, and a good editor should make it easy to use proper indentation (e.g. emacs, vi, ...)
I also did some refactoring, to remove unnecessary variables, make the output more informative, and use loops where possible.
I couldn't tell what you were trying to do with your "$seq" variable... that (and the output format) is the only place where my version does something different from yours -- but I'm just guessing about what you really want.
#!/usr/bin/perl
use strict;
use warnings;
my %hash = (
1 => 'A',
2 => 'T',
3 => 'G',
4 => 'C',
12 => 'W', 21 => 'W',
13 => 'R', 31 => 'R',
14 => 'M', 41 => 'M',
23 => 'K', 32 => 'K',
24 => 'Y', 42 => 'Y',
);
while ( <DATA> ) {
next if ( /^#/ or /^\s*$/ );
chomp;
my @t = split /\t/;
my $seq = my $report = '';
my $countref = ( $t[8] =~ tr/.,// );
if ( $countref / $t[7] > 0.95 ) {
$seq .=$t[2];
}
else {
$t[8] =~ s/[.,]/$t[2]/g;
my %ratio;
my @letters = qw/a t g c/;
$report = " $t[1] : ";
for my $p ( @letters ) {
my $count = eval "lc( '$t[8]' ) =~ tr/$p//";
$ratio{$p} = $count / $t[7];
$report .= sprintf( "%s %5.3f ", uc( $p ), $ratio{$p} );
}
my $countnut = 0;
my @ncode;
for my $i ( 0 .. $#letters ) {
if ( $ratio{ $letters[$i] } >= 0.05 ) {
push @ncode, $i + 1;
$countnut++;
}
my $ccode = join ("", @ncode);
if ( ! exists( $hash{$ccode} )) {
$seq .= "N";
}
else {
$seq .= $hash{$ccode};
}
}
}
printf( "Data_line %5d : t1= %5s ; report= %s; seq= %s\n",
$., $t[1], $report, $seq );
}
__DATA__
#t0 t1 t2 t3 t4 t5 t6 t7 t8 t9
2L 1 G A 48 48 26 7 AAaaAAA ACCCD?@
2L 2 A A 48 0 26 7 ..,,... AACC@BC
2L 3 T K 18 18 26 7 .Ggg... ACCCCCC
2L 4 C C 57 0 37 16 .,..,,.,a.,,,,,^F, CBCC
+BBC@3CCBBD=?
2L 5 C C 54 0 37 17 .,..,,.,a.,,,,,,^F, CDC
+CDACB9CCA@B?@D
2L 6 c C 78 0 37 17 .,..,,.,,.,,,,,,, CBCCB
+AC>9CBB@BA?A
2L 7 c C 45 0 37 19 .,..,,.,,.+1A,,,,t,,^F,^Ft
+ CDCCDAC>;CBCBD*?DAA
2L 7 * */* 55 0 37 19 * A 18 1 0
+ 0 0
2L 8 a A 162 0 21 45 ,-4gtct,-4gtct,,....,,,,,
+,.,.,,,,.,,,,,,,,...,.,.,,,,.,,, CCCCA<;=/CCACDBCBCCCCDCCCCBBCCBDC
+CCCCDCDDCCAB
2L 8 * */* 173 0 21 45 * -gtct 43 2
+ 0 0 0
2L 9 g G 87 0 37 20 .,..,,.,,.,,,,,,,,,^F,
+CDCCCAC?BCBBCD?<DBBB
2L 10 a A 87 0 37 20 .,..,,.,,.,,,,,,,,,, C
+BCDABC>BCACBB:AC?4C
2L 11 g G 90 0 37 21 .,..,,.,,.,,,,,,,,,,^F.
+ CDCCCAC@@CDDCC<:DBABC
2L 12 c C 117 0 14 31 ...,,*.,,-2gt.,,.,,.,...
+.......,,.. ;B6CCBBCBCACDCCCB@DCDCC8CCCABCC
2L 12 * */-gt 21 21 14 31 * -gt 30 1
+ 0 0 0
2L 13 g G 90 0 37 21 .,..,,.,,.,,,,,,,,,,.
+CDCCCAC?:CDB5?<>BB>BC
2L 14 t T 45 0 37 6 ..,,,.-1T CCCCCC
2L 14 * -t/-t 56 59 37 6 -t * 1 5
+0 0 0
2L 15 t T 93 0 37 22 .,..,,.,,.,,,G,,,,,,.^F.
+ CDCDDDC<@CBB5B@ABC<ACC
2L 16 G G 178 0 36 50 .$,$,$,$,,,,,.,,,,..,.,,
+...,,,,.,,...,....,...,,,$,,,., BCCCCCCCCCCCCBDBCBCCB>8CCCCBCCBDBC
+8>ACCBB6CC?CCC6C
2L 17 A A 59 0 36 45 ,$,$,,,C,,,c..,.,,C..,,,,
+.,,...,....,..C,,,,,$., CCCCCBCCCBB8CACC>@;CCCCDCCCDAC-5ABCAA2CCCC
+?1A
2L 18 w T 54 54 37 9 tTTTTttTT CCDCCDCCC
2L 18 * A/+A 65 279 37 9 A * 8 1 0
+ 0 0
2L 19 g G 54 0 37 9 ....,,... >>@@CC>BB
2L 20 c C 57 0 37 10 ....,,...^F, CACCCC?CB
+B
2L 21 t T 57 0 37 10 ....,,..., BCDCCCCCB?
2L 650 t T 48 0 34 7 ..,.,,+4caaa,+4caaa C?
+CCA=?
2L 650 * */* 9 0 34 7 * +CAAA 5 2
+0 0 0
2L 654 A A 48 0 34 7 .$.$,.,+1g,, DBC?CCA
2L 654 * */* 19 0 34 7 * +G 6 1 0
+ 0 0
2L 2332 g G 60 0 14 33 .,...,,.-13GGCGCGCGTGCG
+C.,,A,,A,,A,..........aa.. DCBBBBDBCCCCBCCCDCBDCBCCCACCBABCC
2L 2332 * */* 61 0 14 33 * -ggcgcgcgtgcgc
+ 32 1 0 0 0
2L 3334 a A 163 0 15 49 ..$,..,,,t,.T,,,..,,,,
+T,-7attattt,,-7attattt,,,,,,....,,......,.,,.. BBCA>BCCCC:CCCC>ACC
+CCBCCCCBCCCCCCDCCCCCCCCBCBCDCC
2L 3334 * */-attattt 27 27 15 49 * -attattt
+ 47 2 0 0 0
2L 3928 c C 32 0 0 11 ,,-4tctt,,.-4TCTT...-4TC
+TT.^!.^!, CCC8CCCCBCA
2L 3928 * */-tctt 157 157 0 11 * -tctt 8
+ 3 0 0 0
(update: removed an unnecessary %count hash, now using just a $count variable instead; also reduced the scope for $ccode)