• API
• FAQ
• Tools
• Archive
A Pastebin account makes a great Christmas gift
SHARE
TWEET

# new

a guest May 24th, 2018 61 Never
ENDING IN00days00hours00mins00secs

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):
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"
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))