PDBResolution.pm 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/user/bin/perl -w
  2. use strict;
  3. package PDBResolution;
  4. require Exporter;
  5. require File::Temp;
  6. use config;
  7. my $config = HHpredConfig->instance();
  8. our @ISA = qw(Exporter);
  9. our @EXPORT = qw(extractAllPDBResolutions getTMscore getResolutionFor);
  10. ## extract resolutions for all proteins in .fas file "fasFile"
  11. ## and save them in hash %results
  12. sub extractAllPDBResolutions {
  13. my $pdbdb = $config->get_pdbdir() . "/db/pdb.hhm";
  14. my %result;
  15. ## read pdb database file and extract resolutions
  16. open (FIN, "< $pdbdb") or die "Cant open $pdbdb: $!\n";
  17. while (my $line = <FIN>) {
  18. my $resolution = 10;
  19. my $ID = "dummy";
  20. if ($line =~ /^NAME\s+(\S+).*;\s(\d+\.\d\d?\d?)A\s/) {
  21. $ID = $1;
  22. $resolution = $2;
  23. } elsif ($line =~ /^NAME\s+(\S+).*;\s(\d+)A\s/) {
  24. $ID = $1;
  25. $resolution = $2;
  26. } elsif ($line =~ /^NAME\s+(\S+).*;\sNMR\s/) {
  27. $ID = $1;
  28. $resolution = 10;
  29. }
  30. $result{$ID} = $resolution;
  31. }
  32. close(FIN);
  33. return %result;
  34. }
  35. ## read resolution of protein with id "id" from
  36. ## resolutions file (each row has the format: <id> <resolution>)
  37. ## and return it
  38. sub getResolutionFor {
  39. my $id = shift;
  40. my $resolFile = shift;
  41. my $resol = 10;
  42. open (RES, "< $resolFile") or die "Cant open $resolFile: $!\n";
  43. while(my $line = <RES>) {
  44. if ($line =~ /^(\S+)\s+(\S+)/) {
  45. if ($1 eq $id) {
  46. $resol = $2;
  47. last;
  48. }
  49. }
  50. }
  51. close(RES);
  52. return $resol;
  53. }
  54. sub getTMscore {
  55. my $modelFile = shift;
  56. my $nativeFile = shift;
  57. my $tmscore = $config->get_TMscore();
  58. my $fh = File::Temp->new();
  59. my $outfile = $fh->filename;
  60. my $TM = 0;
  61. system("$tmscore $modelFile $nativeFile > $outfile");
  62. open (TM, "< $outfile") or die "Cant open $outfile: $!\n";
  63. while(my $line = <TM>) {
  64. if ($line =~ /^TM-score\s+=\s+(\S+)/) {
  65. $TM = $1;
  66. last;
  67. }
  68. }
  69. close(TM);
  70. return $TM;
  71. }
  72. 1;