-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpae_boltz_plot_1.py
More file actions
executable file
·196 lines (177 loc) · 4.8 KB
/
pae_boltz_plot_1.py
File metadata and controls
executable file
·196 lines (177 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env python3
"""
Take pae*.npz file from Boltz run and return pAE plot.
Works only for a single .npz file. doesn't do anything else fancy
"""
import sys
import numpy as np
import pandas as pd
from pathlib import Path
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from matplotlib.ticker import FormatStrFormatter
from matplotlib import rcParams
import matplotlib.font_manager as fm
# ===================================
# set font
arial_font = "/home/james/Downloads/arial.ttf"
arial_font_bold = "/home/james/Downloads/Arial Bold.ttf"
fm.fontManager.addfont(arial_font)
fm.fontManager.addfont(arial_font_bold)
rcParams["font.sans-serif"] = "Arial"
rcParams["font.family"] = "Arial"
rcParams["font.size"] = 10
# ===================================
# import table
file = sys.argv[1]
file = Path(file)
# ===================================
# load pae, plddt, and image data
pae = np.load(file)
paedf = pd.DataFrame(
pae["pae"]
) # boltz pae data is stored under the key "pae" in npz datafile
data_max = np.max(pae["pae"])
data_min = np.min(pae["pae"])
data_med = (data_min + data_max) / 2
# load ptm and iptm scores
# scores = np.load(score)
# add protein name from file.stem to add to left of figure
# file.stem = score.stem
# file.stem = file.stem.replace("_scores_0", "")
# file.stem = re.sub(r"_0$", "", file.stem)
# set figure
fig, ax = plt.subplots(1, 1, figsize=(10, 10))
# set heatmap colorscheme
purp = sns.light_palette("#918edb", as_cmap=True, reverse=False)
# add pae heatmap
im = ax.imshow(
paedf,
cmap="coolwarm",
# cmap=purp,
extent=[0, len(paedf), len(paedf), 0],
aspect="equal",
)
# add colorbar to pae heatmap
cbar = fig.colorbar(
im,
ax=ax,
label="pAE (Å)",
fraction=0.045,
ticks=[data_min, 10, 20, data_max],
location="right",
)
# change heatmap and colorbar tick and axis settings
cbar.ax.yaxis.set_major_formatter(FormatStrFormatter("%.0f"))
ax.xaxis.set_major_locator(ticker.LinearLocator(5))
ax.yaxis.set_major_locator(ticker.LinearLocator(5))
ax.yaxis.set_major_formatter(FormatStrFormatter("%.0f"))
ax.xaxis.set_major_formatter(FormatStrFormatter("%.0f"))
ax.set_xlabel("Scored residue")
ax.set_ylabel("Aligned residue")
ax.spines["top"].set_visible(False)
ax.spines["right"].set_visible(False)
# # add text of protein name to left of figure
# fig.text(
# 0.05,
# 0.5,
# file.stem,
# rotation=90,
# verticalalignment="center",
# horizontalalignment="center",
# fontsize=12,
# fontweight="normal",
# # bbox=dict(boxstyle="round,pad=0.5", facecolor='lightgrey', edgecolor='lightgrey', alpha=0.8)
# )
# # make plddt legend with colored circles
# legend_elements = [
# Line2D(
# [0],
# [0],
# marker="o",
# color="w",
# markerfacecolor="#1e66f5",
# markersize=14,
# label="[100, 90)",
# ),
# Line2D(
# [0],
# [0],
# marker="o",
# color="w",
# markerfacecolor="#04a5e5",
# markersize=14,
# label="[90, 70)",
# ),
# Line2D(
# [0],
# [0],
# marker="o",
# color="w",
# markerfacecolor="#f8e1ae",
# markersize=14,
# label="[70, 50)",
# ),
# Line2D(
# [0],
# [0],
# marker="o",
# color="w",
# markerfacecolor="#f9b286",
# markersize=14,
# label="[50, 0]",
# ),
# ]
# # add plddt legend
# ax[0].legend(
# handles=legend_elements,
# title="pLDDT",
# alignment="center",
# loc="upper center",
# frameon=False,
# fancybox=False,
# shadow=False,
# ncol=4,
# bbox_to_anchor=(0.5, 1.15),
# )
# # format ptm and iptm numbers into a string if they're more than 0
# ptm = scores["ptm"]
# iptm = scores["iptm"]
# ptm = ptm[0] if ptm[0] > 0 else "n/a"
# iptm = iptm[0] if iptm[0] > 0 else "n/a"
# ptm_formatted = f"{ptm:.2f}" if isinstance(ptm, (int, float, np.number)) else ptm
# iptm_formatted = f"{iptm:.2f}" if isinstance(iptm, (int, float, np.number)) else iptm
# # print ptm and iptm text
# ptm_text = f"pTM = {ptm_formatted} ipTM = {iptm_formatted}"
# # put ptm and iptm label on figure
# fig.text(
# 0.71,
# 0.890,
# ptm_text,
# rotation=0,
# verticalalignment="center",
# horizontalalignment="center",
# fontsize=12,
# fontweight="normal",
# )
# create output dir
# outdir = Path("./output_plots")
# outdir.mkdir(parents=True, exist_ok=True)
# save figures
# plt.savefig(
# f"{outdir}/{file.stem}_summary_plot.svg",
# format="svg",
# dpi=300,
# bbox_inches="tight",
# )
plt.tight_layout()
plt.savefig(
f"./pae_plot_boltz_{file.stem}.png",
format="png",
dpi=300,
bbox_inches="tight",
)
# be sure to close plot each time to avoid consuming lots of memory
plt.show()
plt.close("all")