daily pastebin goal
41%
SHARE
TWEET

new

a guest May 24th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import biotite
  2. import biotite.structure as struc
  3. import biotite.structure.io as strucio
  4. import biotite.database.rcsb as rcsb
  5. import matplotlib.pyplot as plt
  6. from matplotlib.patches import Rectangle
  7. import numpy as np
  8.  
  9. def plot_gaps(pdb_id, chain_id, ax):
  10.     # Download and parse structure file
  11.     path = rcsb.fetch(pdb_id, "mmtf", biotite.temp_dir())
  12.     atom_array = strucio.get_structure_from(path)
  13.     # Consider only one chain
  14.     atom_array = atom_array[atom_array.chain_id == chain_id]
  15.     # Array for saving the 'green', 'yellow' and 'red' state
  16.     states = np.zeros(atom_array.res_id[-1], dtype=int)
  17.     for i in range(len(states)):
  18.         # Get array for only one residue ID
  19.         residue = atom_array[atom_array.res_id == i+1]
  20.         if len(residue) == 0:
  21.             # not existing
  22.             states[i] = 0
  23.         elif residue.res_name[0] == "UNK":
  24.             # exisiting but polyalanine
  25.             states[i] = 1
  26.         else:
  27.             # existing
  28.             states[i] = 2
  29.    
  30.     # Find the intervals for each state
  31.     state_intervals = []
  32.     curr_state = None
  33.     curr_start = None
  34.     for i in range(len(states)):
  35.         if curr_start is None:
  36.             curr_start = i
  37.             curr_state = states[i]
  38.         else:
  39.             if states[i] != states[i-1]:
  40.                 state_intervals.append((curr_start, i, curr_state))
  41.                 curr_start = i
  42.                 curr_state = states[i]
  43.     state_intervals.append((curr_start, i, curr_state))
  44.    
  45.     # Draw the state intervals as colored rectangles
  46.     for interval in state_intervals:
  47.         start = interval[0]
  48.         stop = interval[1]
  49.         state = interval[2]
  50.         if state == 0:
  51.             color = "firebrick"
  52.         elif state == 1:
  53.             color = "gold"
  54.         elif state == 2:
  55.             color = "forestgreen"
  56.         ax.add_patch(Rectangle((start+1-0.5, 0), stop-start, 1,
  57.                                 edgecolor="None", facecolor=color))
  58.     # Some other visual stuff
  59.     ax.spines["left"].set_visible(False)
  60.     ax.spines["bottom"].set_visible(False)
  61.     ax.yaxis.set_visible(False)
  62.     ax.set_xlim(0.5, len(states) + 0.5)
  63.     ax.set_ylim(0, 2)
  64.  
  65.  
  66. fig = plt.figure(figsize=(8.0, 2.5))
  67. ax = fig.add_subplot(211)
  68. ax.set_title("5luq", loc="left")
  69. plot_gaps("5luq", "A", ax)
  70. ax = fig.add_subplot(212)
  71. ax.set_title("5w1r", loc="left")
  72. plot_gaps("5w1r", "A", ax)
  73. ax.set_xlabel("$Residue \ number$")
  74. fig.tight_layout()
  75. plt.show()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top