Saturday, 14 September 2013

Perl: Using regular expressions with hashes

Perl: Using regular expressions with hashes

I cannot pinpoint a bug in this submodule I'm writing for analyzing a
yeast genome. Help anyone?
The sub should use the hash key as a regular expression to check for a
certain pair of capital letters. If we have a match, return the associated
value. However, it seems to only match "TT" and return the value 5. I have
no idea why it would jump to the TT hash element; everything else seems to
be the same between the different elements. I would think it would return
each of the values, or none, but it only returns TT.
The full code is here on github: https://github.com/bsima/yeast-TRX
Here is the relevant code (line 159 of script.pl):
sub trxScore {
my ( $dinucleotide ) = @_;
my %trxScores = (
qr/(CG)/ => 43,
qr/(CA)/ => 42,
qr/(TG)/ => 42,
qr/(GG)/ => 42,
qr/(CC)/ => 42,
qr/(GC)/ => 25,
qr/(GA)/ => 22,
qr/(TC)/ => 22,
qr/(TA)/ => 14,
qr/(AG)/ => 9,
qr/(CT)/ => 9,
qr/(AA)/ => 5,
qr/(TT)/ => 5,
qr/(AC)/ => 4,
qr/(GT)/ => 4,
qr/(AT)/ => 0
);
foreach my $re (keys %trxScores) {
if ( match($re,$dinucleotide) ) {
return $trxScores{$re};
} else {
return "null";
}
}
}
The output is in bayanus-TRXscore.csv:
Saccharomyces bayanus
gene,gene pair,position,trx score
...
eYAL001C,TA,23,null
eYAL001C,AT,24,null
eYAL001C,TT,25,5
eYAL001C,TT,26,5
eYAL001C,TT,27,5
eYAL001C,TA,28,null

No comments:

Post a Comment