predTMscore.pm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/usr/bin/perl -w
  2. package TMscoreNN;
  3. require Exporter;
  4. use strict;
  5. use config;
  6. use PDBResolution;
  7. use utilities;
  8. {
  9. my $nhidden = 3;
  10. ## these are the original parameters
  11. my @bias = (-0.1635528802871704, -0.3720591366291046, 5.6198554039001465);
  12. my @weights = (-0.007, 11.739, 3.298, -0.008,
  13. -4.479, -1.674, 1.605, -0.041,
  14. -0.364, -17.33, -4.629, 0.161,
  15. 0.867, -0.405, -0.265);
  16. ## test parameters
  17. # my @bias = (-5.77800,-0.11515,-0.88430);
  18. # my @weights = ( 0.06798,6.66194,8.12909,-0.34054,
  19. # 0.17152,-8.21288,-3.86566,0.34767,
  20. # 0.28003,0.88483,13.91985,0.12512,
  21. # 0.30894,-0.25261,0.63520);
  22. sub _get_nhidden() {
  23. $nhidden;
  24. }
  25. sub _get_bias {
  26. my ($self, $i) = @_;
  27. $bias[$i];
  28. }
  29. sub _get_weight {
  30. my ($self, $i) = @_;
  31. $weights[$i];
  32. }
  33. }
  34. sub new {
  35. my ($caller, %arg) = @_;
  36. my $caller_is_obj = ref($caller);
  37. my $class = $caller_is_obj || $caller;
  38. no strict "refs";
  39. my $self = bless {}, $class;
  40. return $self;
  41. }
  42. sub read_from_file {
  43. my ($self, $paramFile) = @_;
  44. ## TODO
  45. }
  46. ## first predict TM score of each template in templateList with a NN
  47. ## which has as inputs score, sumProb/L, SS and template resolution (in A).
  48. ## Then sort templates wrt predicted TM score
  49. sub rank_templates {
  50. my ($self, $templateList, $queryLength, $config) = @_;
  51. # print "reading resolutions of templates...\n";
  52. my %resolutions = &extractAllPDBResolutions();
  53. for (my $i=0; $i<$templateList->size(); $i++) {
  54. my $template = $templateList->get($i);
  55. # print "single NN features of " . $template->get_Hit() . ":\n";
  56. # print "single NN features:\n";
  57. # print "score=" . $template->get_Score() . "\n";
  58. # print "ss=" . $template->get_SS() . "\n";
  59. # print "qLen=" . $templateList->get_queryLength() . "\n";
  60. # print "sumProbL=" . $template->get_SumProbL . "\n";
  61. my $TMscore = 0;
  62. my $templateName = $template->get_Hit();
  63. # print "resolution of " . $template->get_Hit() . "=" . $resolutions{$templateName} . "\n";
  64. for (my $unit = 0; $unit<$self->_get_nhidden(); $unit++) {
  65. #calculate input of hidden unit (sum of all inputs * weights)
  66. my $input = ($template->get_Score()/50) * $self->_get_weight(0 + $unit * 4) +
  67. $template->get_SS()/$queryLength * $self->_get_weight(1 + $unit * 4) +
  68. $template->get_SumProbL() * $self->_get_weight(2 + $unit * 4) +
  69. $resolutions{$templateName}/10 * $self->_get_weight(3 + $unit*4);
  70. #calculate output of hidden unit
  71. my $output = 1.0 / (1.0 + exp(-($input + $self->_get_bias($unit))));
  72. $TMscore += $output * $self->_get_weight( $self->_get_nhidden()*4 + $unit);
  73. }
  74. $TMscore = sprintf("%.6f", $TMscore);
  75. $template->set_predTM($TMscore);
  76. }
  77. $templateList->sort_by_predTM();
  78. }
  79. sub predict {
  80. my $self = shift;
  81. my $template = shift;
  82. my $queryLength = shift;
  83. my $config = shift;
  84. my $TMscore = 0;
  85. my %resolutions = &extractAllPDBResolutions();
  86. my $templateName = $template->get_Hit();
  87. print "templateName=$templateName\n";
  88. print "score=" . $template->get_Score() . "\n";
  89. for (my $unit = 0; $unit<$self->_get_nhidden(); $unit++) {
  90. #calculate input of hidden unit (sum of all inputs * weights)
  91. my $input = ($template->get_Score()/50) * $self->_get_weight(0 + $unit * 4) +
  92. $template->get_SS()/$queryLength * $self->_get_weight(1 + $unit * 4) +
  93. $template->get_SumProbL() * $self->_get_weight(2 + $unit * 4) +
  94. $resolutions{$templateName}/10 * $self->_get_weight(3 + $unit*4);
  95. #calculate output of hidden unit
  96. my $output = 1.0 / (1.0 + exp(-($input + $self->_get_bias($unit))));
  97. $TMscore += $output * $self->_get_weight( $self->_get_nhidden()*4 + $unit);
  98. }
  99. $TMscore = sprintf("%.6f", $TMscore);
  100. #$template->set_predTM($TMscore);
  101. print "predict->$TMscore\n";
  102. return $TMscore;
  103. }
  104. 1;