Guest User

Untitled

a guest
Jan 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3.  
  4. u"""Gō plot of residue-to-residue distances in a protein structure.
  5.  
  6. Usage:
  7. go1981.py <PDB_file> [<chain_ID>] [<junction_position> ...]
  8.  
  9. Example:
  10. ./go1981.py 3ONZ.pdb B 30 68 104
  11.  
  12. See:
  13.  
  14. Mitiko Gō
  15. Correlation of DNA exonic regions with protein structural units in haemoglobin
  16. Nature 291, 90 - 92 (07 May 1981)
  17. doi:10.1038/291090a0
  18.  
  19. """
  20.  
  21. import sys
  22.  
  23. from Bio.PDB import PDBParser
  24.  
  25. try:
  26. import matplotlib.pyplot as plt
  27. except ImportError:
  28. import pylab as plt
  29.  
  30.  
  31. def posn(residue):
  32. atoms = residue.child_dict
  33. # Beta carbon is a better representative of side chain position, but
  34. # glycine has no beta carbon atom
  35. return (atoms['CB'] if 'CB' in atoms else atoms['CA'])
  36.  
  37.  
  38. def go1981plot(fname, chain=None, threshold=None, junctions=(), do_show=True):
  39. struct = PDBParser().get_structure(fname, fname)
  40. thischain = (struct[0][chain] if chain
  41. else struct[0].child_list[0])
  42. # Filter for amino acids (remove hetatms)
  43. residues = tuple(r for r in thischain if 'CA' in r.child_dict)
  44. distances = {}
  45. for y, resA in enumerate(residues):
  46. distances.update(
  47. # Lower-left triangle
  48. dict(((x,y), posn(resA) - posn(resB))
  49. for x, resB in enumerate(residues[:y])))
  50.  
  51. # ENH: use shading to indicate greater distances
  52. if not threshold:
  53. threshold = max(distances.itervalues())/2.0 + 2.5
  54. sys.stderr.write("Calculated radius: %f\n" % threshold)
  55. coords = ((xy[0] + 1, xy[1] + 1)
  56. for xy, dist in distances.iteritems()
  57. if dist > threshold)
  58. for x, y in coords:
  59. plt.plot(x, y, 'ko', alpha=.2)
  60.  
  61. # Draw the diagonal
  62. plt.plot([1,len(residues)], [1,len(residues)], 'k-')
  63. # Draw the junctions
  64. for junc in junctions:
  65. plt.vlines(junc, junc, len(residues), color='k')
  66. plt.hlines(junc, 1, junc, color='k')
  67. plt.text(junc, junc, str(junc), fontsize=12)
  68. # Set the axes
  69. plt.xlim(1, len(residues))
  70. # Invert the y-axis (1 at the top)
  71. plt.ylim(len(residues), 1)
  72. # ENH: remove the right and top axis lines & ticks
  73. plt.title(fname)
  74. plt.xlabel('Residue number')
  75. plt.ylabel('Residue number')
  76. if do_show:
  77. plt.show()
  78.  
  79.  
  80. if __name__ == '__main__':
  81. fname = sys.argv[1]
  82. if len(sys.argv) == 2:
  83. go1981plot(sys.argv[1])
  84. elif sys.argv[2].isalpha():
  85. go1981plot(sys.argv[1], sys.argv[2], junctions=map(int, sys.argv[3:]))
  86. else:
  87. go1981plot(sys.argv[1], junctions=map(int, sys.argv[2:]))
Add Comment
Please, Sign In to add comment