[src]sub readSubMatFromFileName;
$filename = 'blosum62.txt';
$blosum = readSubMatFromFileName($filename);
print "Print Resultn";
while (($x,$X) = each %$blosum) {
while (($y,$z) = each %$X) {
printf "[%s,%s]=%2d ", $x, $y, $z;
}
print "n";
}
@topRow = keys %$blosum;
print sort @topRow;
#-------------------------------------------
# input : filename
# output : $matrix->{}{}
sub readSubMatFromFileName {
my $line, @topRow, @row, $firstCol, $col;
open(FILE,shift);
$line = <FILE>;
chomp $line;
$line =~ s/s//g;
@topRow = split ',', $line;
shift @topRow;
while ($line = <FILE>) {
chomp $line;
$line =~ s/s//g;
@row = split ',', $line;
$firstCol = shift @row;
foreach $col (@topRow) {
$result->{$firstCol}{$col} = shift @row;
}
}
return $result;
}
[/src]