config.pm 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. package HHpredConfig;
  2. use lib $ENV{"HHLIB"}."/scripts";
  3. use HHPaths;
  4. use strict;
  5. use vars qw($AUTOLOAD);
  6. use Carp;
  7. use base 'Class::Singleton';
  8. {
  9. ## default values
  10. my %_attr_data = (
  11. _cpus => [4, 'read/write'],
  12. _hhsearch_mact => [0.05, 'read/write'],
  13. _hhblits_mact => [0.5, 'read/write'],
  14. _hhblits_rounds => [3, 'read/write'],
  15. _numberOfGeneratedModels => [3, 'read/write'],
  16. _maxNumOfTemplates => [8, 'read/write'],
  17. _doFiltering => [1, 'read/write'],
  18. _parallelFiltering => [0, 'read/write'],
  19. _replaceDistanceRestraints => [1, 'read/write'],
  20. _multiTemplate => [1, 'read/write'],
  21. _templateWeightStrategy => [1, 'read/write'],
  22. _preselectTemplates => [1, 'read/write'],
  23. _rankTemplates => [1, 'read/write'],
  24. _realignProbcons => [0, 'read/write'],
  25. _assessModel => [1, 'read/write'],
  26. _doParallelModeller => [0, 'read/write'],
  27. _hhlib => ["$hhlib", 'read'],
  28. _hhalign => ["$hhbin/hhalign", 'read'],
  29. _hhsearch => ["$hhbin/hhsearch", 'read'],
  30. _hhblits => ["$hhbin/hhblits", 'read'],
  31. _hhmake => ["$hhbin/hhmake", 'read'],
  32. _hhfilter => ["$hhbin/hhfilter", 'read'],
  33. _hhmakemodel => ["$hhlib/scripts/hhpred/dependencies/hhmakemodel.pl", 'read'],
  34. _addss => ["$hhscripts/addss.pl", 'read'],
  35. _multithread => ["$hhscripts/multithread.pl", 'read'],
  36. _TMscore => ["$hhlib/scripts/hhpred/bin/TMscore", 'read'],
  37. _TMalign => ["$hhlib/scripts/hhpred/bin/TMalign", 'read'],
  38. _repairPDB => ["$hhlib/scripts/hhpred/bin/repair_pdb.pl", 'read'],
  39. _modellerParallel => ["$hhlib/scripts/hhpred/bin/modeller9.13/bin/modpy.sh python2.7 ", 'read'],
  40. _modeller => ["$hhlib/scripts/hhpred/bin/modeller9.13/bin/modpy.sh python2.7", 'read'],
  41. _pdbdir => ["XXXXX", 'read'],
  42. _uniprot20 => ["XXXXX", 'read'],
  43. _MDNWeightsLayer1CACA => ["$hhlib/scripts/hhpred/share/neural-net/MDNWeightsLayer1CACAminP.dat", 'read'],
  44. _MDNWeightsLayer2CACA => ["$hhlib/scripts/hhpred/share/neural-net/MDNWeightsLayer2CACAminP.dat", 'read'],
  45. _MDNWeightsLayer1NO => ["$hhlib/scripts/hhpred/share/neural-net/MDNWeightsLayer1NOminP.dat", 'read'],
  46. _MDNWeightsLayer2NO => ["$hhlib/scripts/hhpred/share/neural-net/MDNWeightsLayer2NOminP.dat", 'read'],
  47. _MDNWeightsLayer1SCMC => ["$hhlib/scripts/hhpred/share/neural-net/MDNWeightsLayer1SCMCminP.dat", 'read'],
  48. _MDNWeightsLayer2SCMC => ["$hhlib/scripts/hhpred/share/neural-net/MDNWeightsLayer2SCMCminP.dat", 'read'],
  49. _MDNWeightsLayer1SCSC => ["$hhlib/scripts/hhpred/share/neural-net/MDNWeightsLayer1SCSCminP.dat", 'read'],
  50. _MDNWeightsLayer2SCSC => ["$hhlib/scripts/hhpred/share/neural-net/MDNWeightsLayer2SCSCminP.dat", 'read'],
  51. );
  52. sub _accessible {
  53. my ($self, $attr, $mode) = @_;
  54. $_attr_data{$attr}[1] =~ /$mode/;
  55. }
  56. sub _default_for {
  57. my ($self, $attr) = @_;
  58. $_attr_data{$attr}[0];
  59. }
  60. sub _standard_keys {
  61. keys %_attr_data;
  62. }
  63. }
  64. my $matchKeyValue = qr/^\s*(\S+)\s*=\s*(.+?)\s*$/;
  65. ## configFile is contains entries of the form
  66. ## key = value
  67. sub _new_instance {
  68. my ($caller) = @_;
  69. my $caller_is_obj = ref($caller);
  70. my $class = $caller_is_obj || $caller;
  71. my $self = bless {}, $class;
  72. my %argsInFile;
  73. my $configFile = $ENV{'HHPRED_CONFIG'};
  74. if (defined($configFile) && $configFile ne "") {
  75. open(CH, "< $configFile") or die("Cant open $configFile: $!\n");
  76. while(my $line = <CH>) {
  77. next if ($line =~ /^\s*#/); ## skip comments
  78. if ($line =~ /$matchKeyValue/) {
  79. my $key = $1;
  80. my $value = $2;
  81. $argsInFile{$key} = $value;
  82. }
  83. }
  84. close(CH);
  85. }
  86. foreach my $attrname ( $self->_standard_keys() ) {
  87. my ($argname) = ($attrname =~ /^_(.*)/);
  88. ## take value from file (if available)
  89. if (exists $argsInFile{$argname}) {
  90. $self->{$attrname} = $argsInFile{$argname};
  91. } elsif ($caller_is_obj) { ## copy values
  92. $self->{$attrname} = $caller->{$attrname};
  93. } else { ## take default values
  94. $self->{$attrname} = $self->_default_for($attrname)
  95. }
  96. }
  97. return $self;
  98. }
  99. sub read_from_file {
  100. my ($self, $configFile) = @_;
  101. my %argsInFile;
  102. open(CH, "< $configFile") or die("Cant open $configFile: $!\n");
  103. while(my $line = <CH>) {
  104. next if ($line =~ /^\s*#/); ## skip comments
  105. if ($line =~ /$matchKeyValue/) {
  106. my $key = $1;
  107. my $value = $2;
  108. $argsInFile{$key} = $value;
  109. }
  110. }
  111. close(CH);
  112. foreach my $attrname ( $self->_standard_keys() ) {
  113. my ($argname) = ($attrname =~ /^_(.*)/);
  114. if (exists $argsInFile{$argname}) {
  115. $self->{$attrname} = $argsInFile{$argname};
  116. }
  117. }
  118. }
  119. sub write_to_file {
  120. my ($self, $outFile) = @_;
  121. open(OH, "> $outFile") or die("Cant write to $outFile: $!\n");
  122. my $out = $self->to_string();
  123. print(OH $out);
  124. close(OH);
  125. }
  126. sub print {
  127. my $self = shift;
  128. my $out = $self->to_string();
  129. print $out;
  130. }
  131. sub to_string {
  132. my $self = shift;
  133. ## find longest key and value
  134. my $maxKeyLen = -99999;
  135. my $maxValLen = -99999;
  136. foreach my $attrname ( $self->_standard_keys() ) {
  137. $maxKeyLen = length($attrname) if (length($attrname) > $maxKeyLen);
  138. $maxValLen = length($self->{$attrname}) if (length($self->{$attrname}) > $maxValLen);
  139. }
  140. my $out = "";
  141. $out .= "-" x ($maxKeyLen + $maxValLen + 4) . "\n";
  142. $out .= "HHpred configuration parameters:\n";
  143. $out .= "-" x ($maxKeyLen + $maxValLen + 4) . "\n";
  144. foreach my $attrname ( sort $self->_standard_keys() ) {
  145. my ($argname) = ($attrname =~ /^_(.*)/);
  146. my $entry = sprintf("%-*s => %-s\n", $maxKeyLen, $argname, $self->{$attrname});
  147. $out .= $entry;
  148. }
  149. $out .= "-" x ($maxKeyLen + $maxValLen + 4) . "\n";
  150. return $out;
  151. }
  152. ## automatically generated getters and setters:
  153. ## $AUTOLOAD contains full name of a routine and is checked for name/accessiblity
  154. ## then an anonymous routine (names e.g. get_name) is created and stored
  155. ## in table for future use
  156. sub AUTOLOAD {
  157. no strict "refs";
  158. my ($self, $newval) = @_;
  159. if ($AUTOLOAD =~ /.*::get(_\w+)/ && $self->_accessible($1, 'read')) {
  160. my $attr_name = $1;
  161. *{$AUTOLOAD} = sub { return $_[0]->{$attr_name} };
  162. return $self->{$attr_name}
  163. }
  164. if ($AUTOLOAD =~ /.*::set(_\w+)/ && $self->_accessible($1, 'write')) {
  165. my $attr_name = $1;
  166. *{$AUTOLOAD} = sub { $_[0]->{$attr_name} = $_[1]; return };
  167. $self->{$1} = $newval;
  168. return
  169. }
  170. ## mistaken?
  171. croak("No such method: $AUTOLOAD");
  172. }
  173. sub DESTROY {
  174. }
  175. 1;