Untitled

 avatar
unknown
plain_text
a month ago
3.1 kB
8
Indexable
import numpy as np
import matplotlib.pyplot as plt

# Data setup
x_labels = ["WT", "F402I", "E396K", "P470L", "F439I", "P440L", "F439I/\nP440L"]
bar_colors = ['red']

WT = [67.856, 66.908, 52.268, 49.443]
WT_ERROR = [2.463, 0, 5.920, 1.469]
F402I = [np.nan, 64.132, 49.481, np.nan]
F402I_ERROR = [np.nan, 4.614, 2.969, np.nan]
P470L = [52.183, 50.200, 36.948, 37.93]
P470L_ERROR = [5.749, 3.453, 0.448, 4.311]
F439I = [49.864, 50.544, 46.687, 39.781]
F439I_ERROR = [2.939, 0.994, 0.858, 2.675]
P440L = [53.635, 47.356, 36.105, np.nan]
P440L_ERROR = [8.248, 2.128, 0.562, np.nan]
E396K = [67.493, 65.56, 55.102, 45.62]
E396K_ERROR = [2.244, 0.15, 2.873, 3.04]
FIPL = [36.618, 39.324, 36.277, 34.86]
FIPL_ERROR = [0, 0, 1.437, 1.14]

data = [WT, F402I, E396K, P470L, F439I, P440L, FIPL]
errors = [WT_ERROR, F402I_ERROR, E396K_ERROR, P470L_ERROR, F439I_ERROR, P440L_ERROR, FIPL_ERROR]

# Only the 230 mM values (index 1)
values = [group[1] if not np.isnan(group[1]) else 0 for group in data]
error_values = [group[1] if not np.isnan(group[1]) else 0 for group in errors]

# Significance info (dummy p-values for WT comparisons)
# Format: [(WT_index, group_index, p-value), ...]
p_values = [
    (0, 1, 0.01),  # WT vs. F402I
    (0, 2, 0.001),  # WT vs. E396K
    (0, 3, 0.05),   # WT vs. P470L
    (0, 4, 0.05),   # WT vs. F439I
    (0, 5, 0.001),  # WT vs. P440L
    (0, 6, 0.001),  # WT vs. F439I/P440L
]

# Plot
fig, ax = plt.subplots(figsize=(10, 6))
x = np.arange(len(x_labels))
bar_width = 0.4

# Plot bars
ax.bar(x, values, bar_width, color=bar_colors[0], yerr=error_values, capsize=5, label="230 mM")

# Adding significance bars
def add_significance_bar(ax, x1, x2, base_height, offset, p_value):
    """Add a significance bar with asterisks between two bars."""
    significance = ""
    if p_value < 0.001:
        significance = "***"
    elif p_value < 0.01:
        significance = "**"
    elif p_value < 0.05:
        significance = "*"
    
    bar_height = base_height + offset  # Stagger the bars
    ax.plot([x1, x1, x2, x2], [bar_height, bar_height + 0.5, bar_height + 0.5, bar_height], lw=1.5, color='red')
    ax.text((x1 + x2) * 0.5, bar_height + 0.5, significance, ha='center', va='bottom', fontsize=12, color='red')

# Add significance bars for each WT comparison
base_height = max([v + e for v, e in zip(values, error_values)])  # Find the tallest bar + error
offset = 2  # Initial offset
for i, (wt_idx, group_idx, p_val) in enumerate(p_values):
    add_significance_bar(ax, x[wt_idx], x[group_idx], base_height, offset * (i + 1), p_val)

# Customization
ax.set_xticks(x)
ax.set_xticklabels(x_labels)
ax.set_ylabel('D₀ (nm)')
ax.set_title('D₀ Values at 230 mM with WT Comparisons')
ax.set_ylim(20, base_height + offset * (len(p_values) + 2))  # Extend ylim for readability
ax.spines['top'].set_visible(False)
ax.grid(True, axis='y', linestyle='--', linewidth=0.5, color='gray', alpha=0.7)

# Save and show
plt.tight_layout()
plt.savefig('D_for_230mM_WT_comparisons_staggered.svg', dpi=800)
plt.show()
Leave a Comment