Maximilian Zinke commited on
Commit Β·
af2fccd
1
Parent(s): 9c0592a
feat(ui): rename residual-SS tabs, add "when to use" captions, stacked-bar figure
Browse filesRenames tabs to disambiguate the three SS readouts:
"Residual SS β geometric (IDP fingerprint)" -> "Basin sampling (Ο/Ο fingerprint)"
"Residual SS β structural (d2D-style)" -> "Cooperative SS β retrieval-based"
Adds a short "When to use" caption under each tab explaining which
readout to consult for folded proteins vs IDPs vs ensemble-reweighting
work, and where each can mislead (retrieval-based cooperative mode
over-estimates helix on pure IDPs).
Figure title strings match the new tab labels.
visualization.plot_residual_ss is now a single stacked-bar track per
row (Ξ±/Ξ²/PPII/other stacked bottom-up, total height 1.0) instead of
four tracks β denser and easier to read as a per-residue mixture.
Files changed (2)
- app.py+30-4
- facet/visualization.py+38-51
685 unmodified lines68668768868968969069169213 unmodified lines706707708709709710711712285 unmodified lines99899910001001100210031004100510061007100810091010100610111012101310141015101610171018101910201021102210231024102510261012102710281029103010311032103310341035103610371038103910401041685 unmodified lines try: fig_residual = plot_residual_ss( result, residual_path, mode="geometric", title=f"Residual SS populations (geometric basins) β {input_label}", title=f"Basin sampling (Ο/Ο fingerprint) β {input_label}", ) plt.close(fig_residual) except Exception as e:13 unmodified lines try: fig_struct = plot_residual_ss( result, residual_struct_path, mode="structural", title=f"Structural SS populations (d2D-style) β {input_label}", title=f"Cooperative SS β retrieval-based β {input_label}", ) plt.close(fig_struct) except Exception as e:285 unmodified lines # IDPs and flexible regions). Users switch via tabs. with gr.Tabs(): with gr.TabItem("Sequence + SS"): gr.Markdown( "**When to use:** folded / well-structured proteins. " "Shows the canonical H/E/C cartoon along the sequence. " "Degenerates to mostly-C on IDPs β use the other tabs there." ) sequence_plot = gr.Image( label="", interactive=False, show_label=False, ) with gr.TabItem("Residual SS β geometric (IDP fingerprint)"): with gr.TabItem("Basin sampling (Ο/Ο fingerprint)"): gr.Markdown( "**When to use:** IDPs and ensemble reweighting " "(BME / ENSEMBLE / flexible-meccano). Shows which " "Ramachandran region the retrieved neighbours fall " "in per residue β Ξ±_R / Ξ² / PPII / other. " "Reads transient-helix propensity directly off the " "Ξ± column. **This is the honest per-residue " "conformational fingerprint, not a cooperative-SS " "claim.**" ) residual_plot = gr.Image( label="", interactive=False, show_label=False, ) with gr.TabItem("Residual SS β structural (d2D-style)"): with gr.TabItem("Cooperative SS β retrieval-based"): gr.Markdown( "**When to use:** cross-check against published " "Gaussian / HMM SS-population tools on folded or " "partially-folded samples. Kernel-weighted Bayesian " "posterior over DSSP-state labels from the 220 K " "reference index. On pure IDPs this mode slightly " "over-estimates helix (neighbour DSSP labels carry " "folded-protein context) β compare against the " "Gaussian FACET-D2 number shown in the per-residue " "inspector for a retrieval-free cross-check." ) residual_struct_plot = gr.Image( label="", interactive=False,683 unmodified lines6846856866876886896876886896906916922 unmodified lines6956966976986997006986997007017027037047057067047057067077087097107117127077087097107117127137142 unmodified lines71771871972172272372472572672772872972072172272372472572672772873373473572973073173273373473974074174274374474574674774874975073573675275375475575673773873974074174274374474574618 unmodified lines7657667677817827687697707714 unmodified lines776777778793794779780796781782783784785786802787788789790791805792793794795683 unmodified lines other_arr[pos] = o
n_rows = math.ceil(total_positions / residues_per_row) # Match plot_sequence_ss row-height budget so the two figures visually # stack at the same cadence. row_height_in = 1.6 # Stacked-bar layout is more compact than the old 4-track version β # one track per row instead of four β so row height shrinks accordingly. row_height_in = 0.95
fig, axes = plt.subplots( n_rows, 1,2 unmodified lines ) axes = axes.flatten()
# Track layout inside each row: four tracks stacked vertically with # a small gap, each track 1.0 unit tall. Y_SEQ/Y_NUM mirror the # sequence-plot offsets so the two figures line up visually. # Single stacked-bar track per row: each residue is one vertical bar # of total height 1.0, segmented by basin fraction (alpha at bottom, # then beta, PPII, other at top). The stack order is the d2D/CheSPI # convention β alpha/beta are the "structured" fractions, PPII and # other are the "flexible" fractions, so they read bottom-up from # structured to flexible. _labels_for_mode = ( BASIN_LABELS_STRUCT if mode == "structural" else BASIN_LABELS_GEOM ) track_order = ["other", "ppii", "beta", "alpha"] TRACK_HEIGHT = 1.0 TRACK_GAP = 0.15 track_bases = { name: i * (TRACK_HEIGHT + TRACK_GAP) for i, name in enumerate(track_order) } Y_TOP = track_bases["alpha"] + TRACK_HEIGHT Y_SEQ_IDP = -0.7 Y_NUM_IDP = -1.35 STACK_ORDER = ("alpha", "beta", "ppii", "other") STACK_HEIGHT = 1.0 Y_TOP = STACK_HEIGHT Y_SEQ_IDP = -0.32 Y_NUM_IDP = -0.72
for row_idx in range(n_rows): ax = axes[row_idx]2 unmodified lines row_len = p1 - p0 xs = np.arange(row_len)
for name, values in [ ("alpha", alpha_arr), ("beta", beta_arr), ("ppii", ppii_arr), ("other", other_arr), ]: color = BASIN_COLORS[name] base = track_bases[name] vals = values[p0:p1] # Draw stacked bars, alpha at the bottom. bottom = np.zeros(row_len, dtype=np.float64) arr_by_name = {"alpha": alpha_arr, "beta": beta_arr, "ppii": ppii_arr, "other": other_arr} for name in STACK_ORDER: vals = arr_by_name[name][p0:p1] heights = np.where(np.isnan(vals), 0.0, vals) ax.bar( xs, heights, width=0.82, # match sequence-plot bar width bottom=base, color=color, width=0.9, # wider bars (one track means no stacking gap) bottom=bottom, color=BASIN_COLORS[name], edgecolor="none", zorder=2, ) # Track baseline ax.plot( [-0.5, row_len - 0.5], [base, base], color="#D5D8DC", linewidth=0.7, zorder=1, ) # Track label β match sequence-plot label font size (9, bold) ax.text( -1.5, base + TRACK_HEIGHT / 2, _labels_for_mode[name], ha="right", va="center", fontsize=9, fontweight="bold", color=color, ) bottom = bottom + heights
# Sequence letters β match plot_sequence_ss exactly: # assigned residue β bold one-letter code in near-black # unassigned (gap) β one-letter code in light gray if a # reader-supplied sequence is available, # else a dot placeholder. Also in light gray. # Light baseline under the bar band. ax.plot( [-0.5, row_len - 0.5], [0.0, 0.0], color="#D5D8DC", linewidth=0.7, zorder=1, )
# Sequence letters below the bar band. for i, pos in enumerate(range(p0, p1)): r = position_to_residue.get(pos) if r is None:18 unmodified lines color=COLOR_SEQ, )
# Residue numbers β same cadence + style as plot_sequence_ss # (every 10 + row termini). # Residue numbers β every 10 + row termini. for i, pos in enumerate(range(p0, p1)): seq_id = pos + seq_id_base if seq_id % 10 == 0 or i == 0 or i == row_len - 1:4 unmodified lines color=COLOR_NUM, )
# Keep the x-range identical across rows so the two figures align # when stacked (partial last row β short content but full x-extent). # Keep x-range identical across rows so partial last row aligns. ax.set_xlim(-2.5, residues_per_row) ax.set_ylim(Y_NUM_IDP - 0.25, Y_TOP + 0.15) ax.set_ylim(Y_NUM_IDP - 0.18, Y_TOP + 0.08) ax.axis("off")
if title is None: source = result.source or "FACET" mode_suffix = ( "structural (d2D-style)" if mode == "structural" else "geometric basins" "Cooperative SS β retrieval-based" if mode == "structural" else "Basin sampling (Ο/Ο fingerprint)" ) title = ( f"Residual SS populations ({mode_suffix}) β " f"{mode_suffix} β " f"{Path(source).stem if source else 'prediction'}" ) # Match plot_sequence_ss title styling.app.py+30-4
facet/visualization.py+38-51