Oh, pshaw!

 

Perl Lipocalins

Page history last edited by Anonymous 2 years, 2 months ago
# [NAME WITHHELD] HMM Script
#!/usr/bin/perl
%file  = ();  # file hash variable
%table = ();  # table hash variable
$strings = 0; # counter scalar variable for lines in program
$inp = "yes"; # automatic assignment of "yes" to user input value
# reads in file line by line
while (<>)
{
$line = $_;     # pre-defined variable for storage of current input line
chomp( $line ); # removes automatic new line charachter
$j = 0;         # column position scalar variable
# this loops reads through the line and builds hash table of character table positions
foreach $i (split //, $line)
{
$file{$i} .= "$j,"; # takes current string and adds position value to hash table
$j++;               # increments column variable
} # End foreach
$strings++; # increments line counter variable
} # End while
$numColumns = $j;
foreach $i (qw/ G T L R E W Y F A S /) # makes an array of desired table values in specific order
{
print "p($i)  "; # prints p in front of desired value
for ( $k = 0; $k < $numColumns; $k++ )
{
$l = 0;
# loop for computing total occurrences of desired values
foreach $m ( split (/,/, $file{$i}) )
{
if ( $m == $k )
{
$l++;
}
} # End foreach
# if l equals 0, print nothing and assign value of 0 to position i in table
if ( $l == 0 )
{
print "     ";
$table{$i} .= "0,";
} # End if
# otherwise with floating point of .1, computer division by number of lines in file and add to table
else
{
printf ("  %0.1f", $l / $strings );
$table{$i} .= ($l / $strings) . ",";
} # End else
} # End for
print "\n"; # new line
} # End foreach
while ($inp ne "no")
{
# being user input
print "\n\nPlease input a lipocalin string: ";
$input = <STDIN>;
chomp ($input);
$x = 1; # accumulator scalar variable
$j = 0; # counter character scalar variable
$logoddsscore = 0; # log-odds counter variable
# performs computation
foreach $i ( split //, $input )
{
@tableValues = split ( /,/, $table{$i} ); # put values of table into a standard array
$x *= $tableValues[$j]; # multiplies jth location value to accumulator
$logoddsscore += log($tableValues[$j]); # computes log-odds score
printf ( "%d: %0.3f\n", $i, $tableValues[$j]); # prints with desired formatting
$j++; # increments column
} # End foreach
printf ("The raw probability is %0.3f\n", $x); # prints the final result
printf ("The log-odds score is %0.3f\n", $logoddsscore); # prints the log-odds score
print "\nWould you like to input another string? (yes / no): ";
$inp = <STDIN>;
chomp ($inp);
} # End while
</pre>

Comments (0)

You don't have permission to comment on this page.