File size: 7,778 Bytes
4d20b62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
import argparse
import textwrap

import matplotlib.font_manager as fm
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from server_constant import *


def str2bool(v):
    if isinstance(v, bool):
        return v
    if v.lower() in ("yes", "true", "t", "y", "1"):
        return True
    elif v.lower() in ("no", "false", "f", "n", "0"):
        return False
    else:
        raise argparse.ArgumentTypeError("Error")


def plot(args):
    out_ptx_sr = args.out_ptx_sr
    length = args.length
    use_temp_model = args.use_temp_model

    out_af2_sr = args.out_af2_sr

    if out_af2_sr > 40:
        out_af2_sr = 40
    if out_af2_sr < 5:
        out_af2_sr = 5
    if out_ptx_sr > 40:
        out_ptx_sr = 40
    if out_ptx_sr < 5:
        out_ptx_sr = 5

    length = args.length
    hard_afsr_cutoff = args.hard_afsr_cutoff

    fig = plt.figure(figsize=(14, 2))

    wrapped = "\n".join(textwrap.wrap(text_preview, width=170))  # 每行20字符

    prop = fm.FontProperties(
        fname=os.path.join(os.path.dirname(font_path), "TimesNewRoman.ttf")
    )
    plt.figtext(
        0.5,
        0.750,
        wrapped,
        wrap=True,
        ha="center",
        multialignment="left",
        fontproperties=prop,
        fontsize=13,
        color="navy",
    )

    prop = fm.FontProperties(fname=font_path)
    easy = "easy"
    hard = "hard"
    plt.figtext(
        0.472,
        0.340,
        easy,
        wrap=True,
        ha="center",
        multialignment="left",
        fontproperties=prop,
        fontsize=11,
        color="#086BFFE8",
    )
    plt.figtext(
        0.081,
        0.340,
        hard,
        wrap=True,
        ha="center",
        multialignment="left",
        fontproperties=prop,
        fontsize=11,
        color="#086BFFE8",
    )
    plt.figtext(
        0.522,
        0.340,
        hard,
        wrap=True,
        ha="center",
        multialignment="left",
        fontproperties=prop,
        fontsize=11,
        color="#086BFFE8",
    )
    plt.figtext(
        0.912,
        0.340,
        easy,
        wrap=True,
        ha="center",
        multialignment="left",
        fontproperties=prop,
        fontsize=11,
        color="#086BFFE8",
    )

    AF2_SR = get_information(length)["AF2_SR"]
    AF2_SR = np.array(AF2_SR)
    AF2_SR[AF2_SR > 40] = 40
    AF2_SR[AF2_SR < 5] = 5

    length_count = get_information(length)["count"]

    ax1 = fig.add_axes([0.075, 0.2, 0.40, 0.3])
    ax1.set_title(
        f"AF2-IG-easy Passing Rate  ({length_count})",
        fontproperties=prop,
        fontsize=10,
    )
    ax1.hlines(y=0, xmin=3, xmax=42, color="black", linewidth=1.5, alpha=0.7)
    placed_positions = []
    y_add = 0.01

    for x, label in zip(AF2_SR, labels):
        ax1.plot(x, 0, "o", color="dimgray", markersize=6, alpha=0.7)
        if label:
            for px, py in placed_positions:
                if abs(x - px) < 0.5:
                    x = x + 0.7
            placed_positions.append((x, y_add))
            ax1.text(
                x,
                y_add,
                label,
                fontsize=5,
                rotation=70,
                ha="center",
                va="bottom",
                fontproperties=prop,
            )

    description = "Your job is here."
    if out_af2_sr > hard_afsr_cutoff[-1]:
        color_sr = difficulty_to_color["easy"]
    elif out_af2_sr > hard_afsr_cutoff[0] and out_af2_sr <= hard_afsr_cutoff[-1]:
        color_sr = difficulty_to_color["hard"]
    else:
        color_sr = difficulty_to_color["very_hard"]

    ax1.plot(out_af2_sr, 0, "o", color=color_sr, markersize=6)
    ax1.annotate(
        description,
        xy=(out_af2_sr, 0),
        xytext=(out_af2_sr, -0.04),
        ha="center",
        color=color_sr,
        arrowprops=dict(
            arrowstyle="->",
            color=color_sr,
            connectionstyle="angle,angleA=90,angleB=180,rad=0",
        ),
        fontproperties=prop,
        fontsize=6,
    )
    ax1.spines["top"].set_visible(False)
    ax1.spines["right"].set_visible(False)
    ax1.spines["left"].set_visible(False)
    x_tick_labels = ax1.get_xticklabels()
    for label in x_tick_labels:
        label.set_fontproperties(prop)
        label.set_fontsize(8)
    ax1.set_yticks([])
    ax1.set_xticks([5, 10, 20, 30, 40])
    ax1.set_xticklabels([r"$\leq 5$%", "10%", "20%", "30%", r"$\geq 40$%"])

    ax2 = fig.add_axes([0.5175, 0.2, 0.40, 0.3])
    if_template_model = " (Template Model) " if use_temp_model else " "
    ax2.set_title(
        f"Protenix-basic Passing Rate  {if_template_model}({length_count})",
        fontproperties=prop,
        fontsize=10,
    )
    ax2.hlines(y=0, xmin=3, xmax=42.0, color="black", linewidth=1.5, alpha=0.7)
    ptx_SR = (
        get_information(length)["ptx_temp_sr"]
        if use_temp_model
        else get_information(length)["ptx_sr"]
    )

    ptx_SR = np.array(ptx_SR)
    ptx_SR[ptx_SR < 5] = 5
    ptx_SR[ptx_SR > 40] = 40

    placed_positions = []
    y_add = 0.01
    for x, label in zip(ptx_SR, labels):
        ax2.plot(x, 0, "o", color="dimgray", markersize=6, alpha=0.7)
        if label:
            for px, py in placed_positions:
                if abs(x - px) < 0.5:
                    x = px + 0.7
            placed_positions.append((x, y_add))
            ax2.text(
                x,
                y_add,
                label,
                fontsize=5,
                rotation=70,
                ha="center",
                va="bottom",
                fontproperties=prop,
            )

    ax2.plot(out_ptx_sr, 0, "o", color=color_sr, markersize=6)
    ax2.annotate(
        description,
        xy=(out_ptx_sr, 0),
        xytext=(out_ptx_sr, -0.04),
        ha="center",
        color=color_sr,
        arrowprops=dict(
            arrowstyle="->",
            color=color_sr,
            connectionstyle="angle,angleA=90,angleB=180,rad=0",
        ),
        fontproperties=prop,
        fontsize=6,
    )
    ax2.spines["top"].set_visible(False)
    ax2.spines["right"].set_visible(False)
    ax2.spines["left"].set_visible(False)
    x_tick_labels = ax2.get_xticklabels()
    for label in x_tick_labels:
        label.set_fontproperties(prop)
        label.set_fontsize(8)
    ax2.set_yticks([])
    ax2.set_xticks(
        [
            5,
            10,
            20,
            30,
            40,
        ]
    )
    ax2.set_xticklabels([r"$\leq 5$%", "10%", "20%", "30%", r"$\geq 40$%"])

    # plt.savefig(args.save_path, dpi=800, bbox_inches="tight")
    plt.savefig(args.save_path, dpi=400)
    print(f"Save difficulty fig to {args.save_path}!")


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--out_af2_sr", type=float, default=20, help="af2 sr")
    parser.add_argument("--out_ptx_sr", type=float, default=22, help="ptx iptm")
    parser.add_argument(
        "--use_temp_model",
        type=str2bool,
        default=False,
        help="use large model or template model",
    )
    parser.add_argument("--length", type=int, default=100, help="binder length")
    parser.add_argument(
        "--hard_AF2_ipae_cutoff",
        type=float,
        default=[10, 15],
        help="hard case ipae cutoff (<10, 10-15, >15)",
    )

    parser.add_argument(
        "--hard_ptx_iptm_template_cutoff",
        type=float,
        default=[0.6, 0.3],
        help="iptm cutoff (0.6-1.0, 0.3-0.6, <0.3)",
    )
    parser.add_argument(
        "--hard_afsr_cutoff",
        type=float,
        default=[15, 5],
        help="hard case sr cutoff (0-5%, 5-15%, >15%)",
    )
    parser.add_argument("--save_path", type=str, default="./server_extended_mode.png")

    args = parser.parse_args()

    plot(args)