美文网首页
Python绘图-IC50-IC20-IC5计算

Python绘图-IC50-IC20-IC5计算

作者: 火卫控 | 来源:发表于2025-03-31 18:09 被阅读0次

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')

相关文章

网友评论

      本文标题:Python绘图-IC50-IC20-IC5计算

      本文链接:https://www.haomeiwen.com/subject/hmumvjtx.html