16/score5.pl
#!/usr/bin/perl -w
use strict;
# read matrix
my $i = 0;
my @pssm = ();
my $infile = 'matrix5.txt';
open(MATRIX, $infile) or die "Could not open matrix file $infile\n";
while (<MATRIX>) {
chomp;
my @array = split;
for ( my $j = 0 ; $j < 9 ; $j++ ) { $pssm[$i][$j] = $array[$j]; }
$i++;
}
close MATRIX;
# read sequence to be analyzed
$infile = 'amyloid.fa';
open(IN, $infile) or die "Could not open $infile\n";
my $seq = '';
while (<IN>) {
unless (/>/) {
chomp;
$seq .= $_;
}
}
close IN;
print "pos\tscore\n"; # print header
$seq = uc($seq);
my @bases = ( 'A', 'T', 'C', 'G' );
# score with the matrix
for ( my $k = 0 ; $k < length($seq) - 8 ; $k++ ) {
my $test = substr( $seq, $k, 9 );
my $score = 0;
for ( my $j = 0 ; $j < 9 ; $j++ ) {
my $base = substr( $test, $j, 1 );
for ( my $b = 0 ; $b < 4 ; $b++ ) {
if ( $bases[$b] eq $base ) {
$score += $pssm[$b][$j];
}
}
}
$score = 2**$score; # convert log2 to real values
# ** is the exponentiation operator
my $pos = $k + 3; # We want to print a position
# next to the exon-intron
# junction
print "$pos\t$score\n";
}