BoHuangLab commited on
Commit
0167225
·
verified ·
1 Parent(s): 48261ce

Trim the section text to one line; let the flow diagram carry the explanation

Browse files
Files changed (1) hide show
  1. app.py +65 -51
app.py CHANGED
@@ -99,71 +99,97 @@ def _schematic_curve():
99
 
100
 
101
  def plot_explainer():
102
- """The pipeline as a flow: inputs -> CELL-FM -> image -> ViT -> curve -> areas."""
 
 
 
 
103
  x, curve = _schematic_curve()
104
  flat = metrics.no_reentrant_curve(curve)
105
 
106
- fig = plt.figure(figsize=(11.2, 2.35), facecolor=SURFACE)
107
  stage = fig.add_axes([0, 0, 1, 1]); stage.set_axis_off()
108
  stage.set_xlim(0, 1); stage.set_ylim(0, 1)
109
 
110
- # node centres and the panel each one draws into
111
  xs = [0.098, 0.368, 0.632, 0.902]
112
- box_y, box_h, box_w = 0.06, 0.70, 0.155
113
 
114
- def node(cx, title):
115
  stage.add_patch(FancyBboxPatch(
116
  (cx - box_w / 2, box_y), box_w, box_h,
117
  boxstyle="round,pad=0.012,rounding_size=0.02",
118
  linewidth=1.1, edgecolor=MUTED, facecolor="white", zorder=2))
119
- stage.text(cx, box_y + box_h + 0.045, title, ha="center", va="bottom",
120
  fontsize=11, color=INK, fontweight="bold", zorder=4)
 
 
 
121
 
122
  def arrow(x0, x1, label):
123
  stage.annotate("", xy=(x1, box_y + box_h / 2), xytext=(x0, box_y + box_h / 2),
124
  arrowprops=dict(arrowstyle="-|>", lw=1.6, color=INK,
125
  shrinkA=0, shrinkB=0), zorder=3)
126
- if label:
127
- stage.text((x0 + x1) / 2, box_y + box_h / 2 + 0.05, label, ha="center",
128
- va="bottom", fontsize=8.5, color=CURVE, fontweight="bold",
129
- linespacing=1.35, zorder=4)
 
 
 
 
130
 
131
- for cx, title in zip(xs, ["IDP sequence\n+ expression level", "Image", "Curve", "AUC, AAC"]):
132
- node(cx, title)
133
  arrow(xs[0] + box_w / 2, xs[1] - box_w / 2, "CELL-FM")
134
  arrow(xs[1] + box_w / 2, xs[2] - box_w / 2, "ViT classification\nmodel")
135
  arrow(xs[2] + box_w / 2, xs[3] - box_w / 2, "integrate")
136
 
137
- def panel(cx, pad_x=0.022, pad_y=0.05):
 
 
 
 
 
 
 
138
  return fig.add_axes([cx - box_w / 2 + pad_x, box_y + pad_y,
139
  box_w - 2 * pad_x, box_h - 2 * pad_y])
140
 
141
- # 1. the two inputs
 
 
 
 
 
 
 
 
 
142
  a = panel(xs[0]); a.set_axis_off(); a.set_xlim(0, 1); a.set_ylim(0, 1)
143
- a.text(0.5, 0.78, "KSFGTPFGGG…", ha="center", va="center", fontsize=8.5,
144
  family="monospace", color=INK)
145
- a.text(0.5, 0.58, "66 aa", ha="center", va="center", fontsize=7.5, color=MUTED)
146
- grad = np.linspace(0, 1, 128)[None, :]
147
- a.imshow(grad, cmap="magma", extent=(0.06, 0.94, 0.16, 0.34), aspect="auto")
148
- a.text(0.5, 0.05, "low → high expression", ha="center", va="center",
149
- fontsize=7.5, color=MUTED)
150
-
151
- # 2. one generated image
152
- b = panel(xs[1])
153
- b.imshow(_synthetic_cell(0.85, seed=3), cmap="magma", vmin=0, vmax=1)
154
- b.set_xticks([]); b.set_yticks([])
155
- for sp in b.spines.values():
156
- sp.set_visible(False)
157
-
158
- # 3. the curve those images produce
159
- c = panel(xs[2])
160
- c.plot(x, curve, color=CURVE, linewidth=2.0)
161
- c.set_xscale("log"); c.set_xlim(x.min(), x.max()); c.set_ylim(-0.05, 1.08)
162
- c.set_xticks([]); c.set_yticks([]); c.minorticks_off()
163
- c.tick_params(which="both", length=0)
164
- c.set_facecolor("white")
165
- for sp in c.spines.values():
166
- sp.set_color(MUTED); sp.set_linewidth(0.6)
 
 
167
 
168
  # 4. the same curve, split into the two areas
169
  d = panel(xs[3])
@@ -172,12 +198,8 @@ def plot_explainer():
172
  d.plot(x, curve, color=CURVE, linewidth=1.6)
173
  d.plot(x, flat, color=GAP, linewidth=1.0, linestyle="--", alpha=0.85)
174
  d.set_xscale("log"); d.set_xlim(x.min(), x.max()); d.set_ylim(-0.05, 1.08)
175
- d.set_xticks([]); d.set_yticks([]); d.minorticks_off()
176
- d.tick_params(which="both", length=0)
177
- d.set_facecolor("white")
178
- for sp in d.spines.values():
179
- sp.set_color(MUTED); sp.set_linewidth(0.6)
180
- d.text(0.34, 0.30, "AUC", transform=d.transAxes, fontsize=9, color=CURVE,
181
  fontweight="bold", ha="center")
182
  d.text(0.80, 0.62, "AAC", transform=d.transAxes, fontsize=9, color=GAP,
183
  fontweight="bold", ha="center")
@@ -310,14 +332,6 @@ def build_condensate_titration_section():
310
  gr.Markdown(
311
  """
312
  Predict how an Intrinsically Disordered Peptide (IDP) behaves as its concentration rises.
313
-
314
- CELL-FM generates a ladder of microscopy images for your sequence, one per
315
- protein-intensity level; a ViT classifier calls each **condensed** or **diffuse**;
316
- a moving average over those calls is the **titration curve**. Integrating it gives:
317
-
318
- * **AUC** — how much of the concentration range the sequence spends condensed.
319
- * **AAC** — the area above the curve, i.e. condensation lost to **reentrant
320
- dissolution** at high concentration. Zero when the curve never comes back down.
321
  """
322
  )
323
 
 
99
 
100
 
101
  def plot_explainer():
102
+ """The pipeline as a flow, captioned so it stands alone without body text.
103
+
104
+ Nodes carry the artefact at each stage; captions beneath say what it is; the
105
+ last node defines AUC and AAC in the same colours the results plot uses.
106
+ """
107
  x, curve = _schematic_curve()
108
  flat = metrics.no_reentrant_curve(curve)
109
 
110
+ fig = plt.figure(figsize=(11.6, 3.15), facecolor=SURFACE)
111
  stage = fig.add_axes([0, 0, 1, 1]); stage.set_axis_off()
112
  stage.set_xlim(0, 1); stage.set_ylim(0, 1)
113
 
 
114
  xs = [0.098, 0.368, 0.632, 0.902]
115
+ box_y, box_h, box_w = 0.30, 0.50, 0.155
116
 
117
+ def node(cx, title, caption):
118
  stage.add_patch(FancyBboxPatch(
119
  (cx - box_w / 2, box_y), box_w, box_h,
120
  boxstyle="round,pad=0.012,rounding_size=0.02",
121
  linewidth=1.1, edgecolor=MUTED, facecolor="white", zorder=2))
122
+ stage.text(cx, box_y + box_h + 0.06, title, ha="center", va="bottom",
123
  fontsize=11, color=INK, fontweight="bold", zorder=4)
124
+ if caption:
125
+ stage.text(cx, box_y - 0.05, caption, ha="center", va="top",
126
+ fontsize=8.2, color=MUTED, linespacing=1.5, zorder=4)
127
 
128
  def arrow(x0, x1, label):
129
  stage.annotate("", xy=(x1, box_y + box_h / 2), xytext=(x0, box_y + box_h / 2),
130
  arrowprops=dict(arrowstyle="-|>", lw=1.6, color=INK,
131
  shrinkA=0, shrinkB=0), zorder=3)
132
+ stage.text((x0 + x1) / 2, box_y + box_h / 2 + 0.045, label, ha="center",
133
+ va="bottom", fontsize=8.5, color=CURVE, fontweight="bold",
134
+ linespacing=1.35, zorder=4)
135
+
136
+ node(xs[0], "IDP sequence\n+ expression level", f"{pipeline.SEQUENCE_LENGTH} aa, scanned over\n{pipeline.NUM_IMAGES} concentrations")
137
+ node(xs[1], "Images", f"one generated image\nper concentration")
138
+ node(xs[2], "Curve", "moving average of the\ncondensed / diffuse calls")
139
+ node(xs[3], "AUC, AAC", None)
140
 
 
 
141
  arrow(xs[0] + box_w / 2, xs[1] - box_w / 2, "CELL-FM")
142
  arrow(xs[1] + box_w / 2, xs[2] - box_w / 2, "ViT classification\nmodel")
143
  arrow(xs[2] + box_w / 2, xs[3] - box_w / 2, "integrate")
144
 
145
+ # the last node's caption replaces the bullets that used to sit under the title
146
+ stage.text(xs[3], box_y - 0.05, "AUC — range spent condensed", ha="center", va="top",
147
+ fontsize=8.2, color=CURVE, fontweight="bold", zorder=4)
148
+ stage.text(xs[3], box_y - 0.16, "AAC — condensation lost to\nreentrant dissolution",
149
+ ha="center", va="top", fontsize=8.2, color=GAP, fontweight="bold",
150
+ linespacing=1.5, zorder=4)
151
+
152
+ def panel(cx, pad_x=0.020, pad_y=0.055):
153
  return fig.add_axes([cx - box_w / 2 + pad_x, box_y + pad_y,
154
  box_w - 2 * pad_x, box_h - 2 * pad_y])
155
 
156
+ def frame(ax, boxed=True):
157
+ ax.set_xticks([]); ax.set_yticks([]); ax.minorticks_off()
158
+ ax.tick_params(which="both", length=0)
159
+ for sp in ax.spines.values():
160
+ if boxed:
161
+ sp.set_color(MUTED); sp.set_linewidth(0.6)
162
+ else:
163
+ sp.set_visible(False)
164
+
165
+ # 1. inputs: the sequence, and the concentration ladder it is scanned over
166
  a = panel(xs[0]); a.set_axis_off(); a.set_xlim(0, 1); a.set_ylim(0, 1)
167
+ a.text(0.5, 0.80, "KSFGTPFGGG…", ha="center", va="center", fontsize=8.5,
168
  family="monospace", color=INK)
169
+ a.imshow(np.linspace(0, 1, 128)[None, :], cmap="magma",
170
+ extent=(0.06, 0.94, 0.30, 0.50), aspect="auto")
171
+ a.text(0.5, 0.13, "low → high", ha="center", va="center", fontsize=7.5, color=MUTED)
172
+
173
+ # 2. a ladder of images, not one -- three rungs stand in for all 512.
174
+ # Size the axes square in inches; imshow would otherwise letterbox each frame
175
+ # inside a tall axes and leave dead space above and below.
176
+ fig_w, fig_h = fig.get_size_inches()
177
+ left, width = xs[1] - box_w / 2 + 0.014, box_w - 0.028
178
+ cell_w = width / 3 * 0.94
179
+ cell_h = cell_w * fig_w / fig_h
180
+ y0 = box_y + (box_h - cell_h) / 2 + 0.035
181
+ for k, c in enumerate((0.05, 0.9, 0.15)):
182
+ ax = fig.add_axes([left + k * width / 3, y0, cell_w, cell_h])
183
+ ax.imshow(_synthetic_cell(c, seed=k + 1), cmap="magma", vmin=0, vmax=1)
184
+ frame(ax, boxed=False)
185
+ stage.text(xs[1], y0 - 0.035, "low → high concentration", ha="center", va="top",
186
+ fontsize=7.2, color=MUTED, zorder=4)
187
+
188
+ # 3. the curve those calls become
189
+ c_ax = panel(xs[2])
190
+ c_ax.plot(x, curve, color=CURVE, linewidth=2.0)
191
+ c_ax.set_xscale("log"); c_ax.set_xlim(x.min(), x.max()); c_ax.set_ylim(-0.05, 1.08)
192
+ c_ax.set_facecolor("white"); frame(c_ax)
193
 
194
  # 4. the same curve, split into the two areas
195
  d = panel(xs[3])
 
198
  d.plot(x, curve, color=CURVE, linewidth=1.6)
199
  d.plot(x, flat, color=GAP, linewidth=1.0, linestyle="--", alpha=0.85)
200
  d.set_xscale("log"); d.set_xlim(x.min(), x.max()); d.set_ylim(-0.05, 1.08)
201
+ d.set_facecolor("white"); frame(d)
202
+ d.text(0.33, 0.28, "AUC", transform=d.transAxes, fontsize=9, color=CURVE,
 
 
 
 
203
  fontweight="bold", ha="center")
204
  d.text(0.80, 0.62, "AAC", transform=d.transAxes, fontsize=9, color=GAP,
205
  fontweight="bold", ha="center")
 
332
  gr.Markdown(
333
  """
334
  Predict how an Intrinsically Disordered Peptide (IDP) behaves as its concentration rises.
 
 
 
 
 
 
 
 
335
  """
336
  )
337