Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -329,20 +329,11 @@ def compute_shap_difference(shap1_norm, shap2_norm):
|
|
329 |
return shap2_norm - shap1_norm
|
330 |
|
331 |
def plot_comparative_heatmap(shap_diff, seq1_length, seq2_length, title="SHAP Difference Heatmap"):
|
332 |
-
"""
|
333 |
-
Plot heatmap using both relative positions (0-100%) and actual sequence positions
|
334 |
-
|
335 |
-
Parameters:
|
336 |
-
shap_diff: numpy array of SHAP differences
|
337 |
-
seq1_length: length of sequence 1
|
338 |
-
seq2_length: length of sequence 2
|
339 |
-
title: plot title
|
340 |
-
"""
|
341 |
heatmap_data = shap_diff.reshape(1, -1)
|
342 |
extent = max(abs(np.min(shap_diff)), abs(np.max(shap_diff)))
|
343 |
|
344 |
-
# Create figure with additional space for the second x-axis
|
345 |
-
fig, ax = plt.subplots(figsize=(12, 2
|
346 |
|
347 |
# Plot main heatmap
|
348 |
cmap = get_zero_centered_cmap()
|
@@ -379,8 +370,8 @@ def plot_comparative_heatmap(shap_diff, seq1_length, seq2_length, title="SHAP Di
|
|
379 |
ax2.set_xticks(tick_positions)
|
380 |
ax2.set_xticklabels([f"S1: {s1}\nS2: {s2}" for s1, s2 in zip(seq1_labels, seq2_labels)])
|
381 |
|
382 |
-
# Add colorbar
|
383 |
-
cbar = plt.colorbar(cax, orientation='horizontal', pad=0.
|
384 |
cbar.ax.tick_params(labelsize=8)
|
385 |
cbar.set_label('SHAP Difference (Seq2 - Seq1)', fontsize=9, labelpad=5)
|
386 |
|
@@ -390,8 +381,8 @@ def plot_comparative_heatmap(shap_diff, seq1_length, seq2_length, title="SHAP Di
|
|
390 |
ax2.set_xlabel('Sequence Positions', fontsize=10)
|
391 |
ax.set_title(title, pad=10)
|
392 |
|
393 |
-
# Adjust layout to prevent
|
394 |
-
plt.subplots_adjust(bottom=0.
|
395 |
|
396 |
return fig
|
397 |
|
|
|
329 |
return shap2_norm - shap1_norm
|
330 |
|
331 |
def plot_comparative_heatmap(shap_diff, seq1_length, seq2_length, title="SHAP Difference Heatmap"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
332 |
heatmap_data = shap_diff.reshape(1, -1)
|
333 |
extent = max(abs(np.min(shap_diff)), abs(np.max(shap_diff)))
|
334 |
|
335 |
+
# Create figure with additional space for the second x-axis and colorbar
|
336 |
+
fig, ax = plt.subplots(figsize=(12, 3.2)) # Increased height to accommodate everything
|
337 |
|
338 |
# Plot main heatmap
|
339 |
cmap = get_zero_centered_cmap()
|
|
|
370 |
ax2.set_xticks(tick_positions)
|
371 |
ax2.set_xticklabels([f"S1: {s1}\nS2: {s2}" for s1, s2 in zip(seq1_labels, seq2_labels)])
|
372 |
|
373 |
+
# Add colorbar with adjusted position
|
374 |
+
cbar = plt.colorbar(cax, orientation='horizontal', pad=0.35, aspect=40, shrink=0.8)
|
375 |
cbar.ax.tick_params(labelsize=8)
|
376 |
cbar.set_label('SHAP Difference (Seq2 - Seq1)', fontsize=9, labelpad=5)
|
377 |
|
|
|
381 |
ax2.set_xlabel('Sequence Positions', fontsize=10)
|
382 |
ax.set_title(title, pad=10)
|
383 |
|
384 |
+
# Adjust layout to prevent overlap - increased bottom margin
|
385 |
+
plt.subplots_adjust(bottom=0.45, left=0.05, right=0.95, top=0.85)
|
386 |
|
387 |
return fig
|
388 |
|