This is my current drawing script. I used to judge...
Created on: March 28, 2025
Created on: March 28, 2025
This is my current drawing script. I used to judge whether there is an impact by naked eye through the heat map, but it is difficult to draw a conclusion. I need to optimize it on this basis. I need to make changes based on my original drawing script. My data format is fixed. The current script cannot use statistics to judge whether there is a difference between samples. I need to add statistical judgment to determine whether there is a difference between the two samples. ['db2_ratio'] and ['db1_ratio'] in dataframe are wild type and mutants respectively. Now some mutants are evenly distributed on the diagonal line. I don't know whether there is really no effect or whether it is increased or decreased compared with the wild type. I need you to give me some convincing references: def plot_cleavage_ratio(data1,lable1):
x = data1['db2_ratio']
y = data1['db1_ratio']
xy = np.vstack([x,y])
z = gaussian_kde(xy)(xy)
idx = z.argsort()
x, y, z = x.iloc[idx], y.iloc[idx], z[idx]
plt.xlabel(label1)
ax = plt.gca()
plt.plot([0, 1], [0, 1], ls='--', color='#555555')
#ax.plot(0.164179,0.280000, marker='*',color='w',markersize=5)
xticks = np.array([0.00,0.25,0.5,0.75,1.00])
plt.xticks(xticks)
scatter = ax.scatter(x,y,marker='o',c=z,s=5,cmap="RdYlBu_r",label='LST')
divider = make_axes_locatable(ax)
sns.despine(top=True, right=True)
return ax 我原来是用下面脚本调用我原有的画图函数的,现在我应该如何修改来调用你更新的函数:plt.figure(figsize=(12, 12))
plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0.3,hspace=0.3)
plt.subplot(4,4,1)
plot_cleavage_ratio(fy_rep2_cleavage,'')
#plt.yticks(color='w')
#plt.xticks(color='w')
plt.subplot(4,4,2)
plot_cleavage_ratio(cpsf30_rep2_cleavage,'')
#plt.yticks(color='w')
#plt.xticks(color='w')
plt.subplot(4,4,3)
plot_cleavage_ratio(fip1_rep2_cleavage,'')
#plt.yticks(color='w')
#plt.xticks(color='w')
plt.subplot(4,4,4)
plot_cleavage_ratio(esp5_rep2_cleavage,'')
#plt.xticks(color='w')
#plt.yticks(color='w')
plt.subplot(4,4,5)
plot_cleavage_ratio(fpa_rep1_cleavage,'')
#plt.yticks(color='w')
#plt.xticks(color='w')
plt.subplot(4,4,6)
plot_cleavage_ratio(fca_rep2_cleavage,'')
#plt.yticks(color='w')
#plt.xticks(color='w')
plt.subplot(4,4,7)
plot_cleavage_ratio(paps1_rep2_cleavage,'')
#plt.yticks(color='w')
#plt.xticks(color='w')
plt.subplot(4,4,8)
plot_cleavage_ratio(paps24_rep2_cleavage,'')
#plt.yticks(color='w')
#plt.xticks(color='w')
plt.subplot(4,4,9)
plot_cleavage_ratio(cstf64_rep2_cleavage,'')
#plt.xticks(color='w')
#plt.yticks(color='w')
plt.subplot(4,4,10)
plot_cleavage_ratio(cstf77_rep2_cleavage,'')
#plt.xticks(color='w')
#plt.yticks(color='w')
plt.subplot(4,4,11)
plot_cleavage_ratio(pcfs4_rep2_cleavage,'')
#plt.yticks(color='w')
#plt.xticks(color='w')
plt.subplot(4,4,12)
plot_cleavage_ratio(bdr123_rep2_cleavage,'')
#plt.yticks(color='w')
#plt.xticks(color='w')
plt.subplot(4,4,13)
plot_cleavage_ratio(ssu72_rep2_cleavage,'')
#plt.yticks(color='w')
#plt.xticks(color='w')
plt.subplot(4,4,14)
plot_cleavage_ratio(xrn3_rep2_GB_cleavage,'')
#plt.yticks(color='w')
#plt.xticks(color='w')
sns.despine(top=True, right=True)
To add statistical tests and determine whether there is a significant difference between your two samples, db2_ratio
(wild type) and db1_ratio
(mutants), we can use a statistical test like the t-test or Mann-Whitney U test, depending on the data's distribution.
Here’s how you can modify your existing plot_cleavage_ratio
function and your plotting script to include statistical analysis:
Statistical test: We will add a t-test to check if there is a significant difference between the two samples (db1_ratio
and db2_ratio
). If the data is not normally distributed, consider using a non-parametric test like the **Mann-Whitney U test.
Results display: We'll annotate the plot with the p-value from the statistical test to visually indicate whether the difference between the samples is statistically significant.
Statistical test logic:
plot_cleavage_ratio
function:pythonimport numpy as np import matplotlib.pyplot as plt from scipy.stats import ttest_ind import seaborn as sns from mpl_toolkits.axes_grid1.inset_locator import make_axes_locatable from scipy.stats import gaussian_kde def plot_cleavage_ratio(data1, label1): x = data1['db2_ratio'] # Wild type y = data1['db1_ratio'] # Mutants # Perform t-test to compare the two samples (wild type vs mutants) t_stat, p_value = ttest_ind(x, y, equal_var=False) # Welch’s # Display the p-value on the plot p_value_text = f"P-value: {p_value:.3e}" # Density plot xy = np.vstack([x, y]) z = gaussian_kde(xy)(xy) idx = z.argsort() x, y, z = x.iloc[idx], y.iloc[idx], z[idx] plt.xlabel(label1) ax = plt.gca() plt.plot([0, 1], [0, 1], ls='--', color='#555555') # Diagonal line xticks = np.array([0.00, 0.25, 0.5, 0.75, 1.00]) .xticks(xticks) scatter = ax.scatter(x, y, marker='o', c=z, s=5, cmap="RdYlBu_r", label='LST') # Add statistical annotation (p-value) on the plot ax.text(0.5, 0.05, p_value_text, horizontalalignment='center', verticalalignment='center', transform=ax.transAxes, fontsize=12, color='black') sns.despine(top=True, right=True) return ax
You can keep most of your plotting script as-is. The major update is just the inclusion of the statistical test and p-value annotation in the function plot_cleavage_ratio
.
Here's how to update your main script to call the updated plotting function:
pythonplt.figure(figsize=(12, 12)) plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0.3, hspace=0.3) plt.subplot(4,4,1) plot_cleavage_ratio(fy_rep2_cleavage, 'Sample 1') plt.subplot(4,4,2) plot_cleavage_ratio(cpsf30_rep2_cleavage, 'Sample 2') plt.subplot(4,4,3) plot_cleavage_ratio(fip1_rep2_cleavage, 'Sample 3') plt.subplot(4,4,4) plot_cleavage_ratio(esp5_rep2_cleavage, 'Sample 4') plt.subplot(4,4,5) plot_cleavage_ratio(fpa_rep1_c, 'Sample 5') plt.subplot(4,4,6) plot_cleavage_ratio(fca_rep2_cleavage, 'Sample 6') plt.subplot(4,4,7) plot_cleavage_ratio(paps1_rep2_cleavage, 'Sample 7') plt.subplot(4,4,8) plot_cleavage_ratio(paps24_rep2_cleavage, 'Sample 8') plt.subplot(4,4,9) plot_cleavage_ratio(cstf64_rep2_cleavage, 'Sample 9') plt.subplot(4,4,10) plot_cleavage_ratio(cstf77_rep2_cleavage, 'Sample 10') plt.subplot(4,4,11) plot_cleavage_ratio(pcfs4_rep2_cleavage, 'Sample 11') plt.subplot(4,4,12) plot_cleavage_ratio(bdr123_rep2_cleavage, 'Sample 12') plt.subplot(4,4,13) plot_cleavage_ratio(ssu72_rep2_cleavage, 'Sample 13') plt.subplot(4,4,14) plot_cleavage_ratio(xrn3_rep2_GB_cleavage, 'Sample 14') sns.despine(top=True, right=True)
plot_c performs a **Welch’s t-test** (for unequal variances), compares the
db2_ratio(wild type) and
db1_ratio` (mutants), and displays the p-value on the plot.