Python绘图-IC50-IC20-IC5计算

Python绘图-IC50-IC20-IC5计算

绘图效果如下:


RSV-Remd-IC50-20-5-20250326.jpg

运行结果如下:

(gz_learn) PS E:\Coding\python_gzlab_docu> & D:/ruanjian/code/anaconda2406/envs/gz_learn/python.exe -X utf8 e:/Coding/python_gzlab_docu/gzlab_python_do/drug_info/IC50/IC50.py
IC50: 4.373241847910892
IC20: 2.263200265719886
IC5: 1.5152200610761104

代码如下:

import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

# 假设这是你的数据
# 药物浓度
concentrations = np.array([1.5625,3.125,6.25,12.5,25,50,100,200])
# 对应的抑制率
inhibition_rates = np.array([6.63,32.23,68.69,80.85,92.14,95.78,97.46,97.86])

# 定义四参数逻辑斯蒂方程
def four_param_logistic(x, a, b, c, d):
    return ((a - d) / (1 + ((x / c) ** b))) + d

# 进行曲线拟合
popt, pcov = curve_fit(four_param_logistic, concentrations, inhibition_rates)

# 提取拟合参数
a, b, c, d = popt

# 生成拟合曲线的数据
x_fit = np.linspace(min(concentrations), max(concentrations), 1000)
y_fit = four_param_logistic(x_fit, *popt)

# 计算IC50, IC20和IC5
def calculate_IC(y, a, b, c, d):
    return c * (((a - d) / (y - d)) - 1) ** (1 / b)

IC50 = calculate_IC(50, a, b, c, d)
IC20 = calculate_IC(20, a, b, c, d)
IC5 = calculate_IC(5, a, b, c, d)
# 在图上标注IC50, IC20和IC5的值
plt.text(IC50, 50, f'IC50: {IC50:.2f}', horizontalalignment='center', verticalalignment='bottom', color='g')
plt.text(IC20, 20, f'IC20: {IC20:.2f}', horizontalalignment='center', verticalalignment='bottom', color='m')
plt.text(IC5, 5, f'IC5: {IC5:.2f}', horizontalalignment='center', verticalalignment='bottom', color='c')



print(f"IC50: {IC50}")
print(f"IC20: {IC20}")
print(f"IC5: {IC5}")

# 绘图
plt.scatter(concentrations, inhibition_rates, label='Data')
plt.plot(x_fit, y_fit, label='Four-Param Fit', color='red')
plt.axhline(y=50, color='g', linestyle='--', label='IC50')
plt.axhline(y=20, color='m', linestyle='--', label='IC20')
plt.axhline(y=5, color='c', linestyle='--', label='IC5')
plt.xscale('log')
plt.xlabel('Drug Concentration (log scale)')
plt.ylabel('Inhibition Rate (%)')
plt.title('Four-Parameter Logistic Fit')
plt.legend()
plt.show()
# 保存图片为PDF和JPG格式
# plt.savefig('RSV-Remd-IC50-20-5-20250326.pdf', format='pdf')
# plt.savefig('RSV-Remd-IC50-20-5-20250326.jpg', format='jpg')
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容