import matplotlib.pyplot as plt
import numpy as np
def Curve_Fitting(x, y, deg):
parameter = np.polyfit(x, y, deg)
p = np.poly1d(parameter)
aa=''
for i in range(deg+1):
bb=round(parameter[i], 2)
if bb>0:
if i==0:
bb=str(bb)
else:
bb='+'+str(bb)
else:
bb=str(bb)
if deg==i:
aa=aa+bb
else:
aa=aa+bb+'x^'+str(deg-i)
r2 = round(np.corrcoef(y, p(x))[0,1]**2,2)
plt.scatter(x, y, label="Comparison", color='b', marker='o')
plt.plot(x, p(x), color='r')
plt.legend([f"R^2: {r2}", f"Fitting Equation: {aa}"])
plt.xlabel("Old Normalized_TMB Values")
plt.ylabel("New Normalized_TMB Values")
plt.title("Comparison of Normalized_TMB")
plt.savefig('./tmp.jpg')
plt.show()
print('曲线方程为:',aa)
print(' r^2为:', r2)
def plot_scatter(old_list, new_list):
run1_values = old_list
run2_values = new_list
plt.scatter(run1_values, run2_values, label="Comparison", color='b', marker='o')
plt.xlabel("Old Normalized_TMB Values")
plt.ylabel("New Normalized_TMB Values")
plt.title("Comparison of Normalized_TMB")
plt.plot([min(run1_values), max(run1_values)], [min(run1_values), max(run1_values)], linestyle='--', color='r', label="1:1 Line")
plt.legend()
plt.savefig('./tmp.jpg')
plt.show()
normalzed_tmb_compare_file = 'normalzed_tmb.txt'
old_FFPE_list, new_FFPE_list = [], []
old_CF_list, new_CF_list = [], []
with open(normalzed_tmb_compare_file) as f:
next(f)
for line in f:
line_list = line.strip('\n').split('\t')
old, type_, new = line_list
if type_ == 'FFPE':
old_FFPE_list.append(float(line_list[0]))
new_FFPE_list.append(float(line_list[-1]))
if type_ == 'CF':
old_CF_list.append(float(line_list[0]))
new_CF_list.append(float(line_list[-1]))
Curve_Fitting(old_CF_list+old_FFPE_list, new_CF_list+new_FFPE_list, 1)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84