forked from 865699871/gCAnno
-
Notifications
You must be signed in to change notification settings - Fork 2
/
static.py
85 lines (68 loc) · 2.31 KB
/
static.py
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
import pandas as pd
import numpy as np
import os
import argparse
import matplotlib.pyplot as plt
def staticlabel(truelabelFile,resultFile,outdir):
truelabel = np.asarray(pd.read_csv(truelabelFile,sep='\t'))
result = pd.read_csv(resultFile,sep='\t',index_col=0)
print(truelabel)
print(result)
static = []
for i in truelabel:
predict = np.asarray(result.loc[result.index == i[0]])[0]
item = list(i)
for j in predict:
item.append(j)
static.append(item)
static = pd.DataFrame(static,columns=['cell.name','truelabel','predict'])
static.to_csv(outdir + 'staticinput.xls',sep='\t',index=None)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('outdir')
parser.add_argument('truelabelFile')
args = parser.parse_args()
outdir = args.outdir
truelabelFile = args.truelabelFile
if not os.path.exists(outdir):
os.makedirs(outdir)
resultFile = outdir + 'out_predict_cluster.xls'
staticlabel(truelabelFile, resultFile, outdir)
staticInputFile = outdir + 'staticinput.xls'
result = pd.read_csv(staticInputFile, sep='\t')[['truelabel', 'predict']]
listType = result['truelabel'].unique()
staticresult = []
sum = 0
for i in listType:
split = result.loc[result['truelabel'] == i]
error = split.loc[split['truelabel'] != split['predict']]
sum += len(split)
staticresult.append([i, len(error), len(split)])
print(sum)
sumerror = 0
sumtotal = 0
for i in staticresult:
sumerror += i[1]
sumtotal += i[2]
staticresult.append(['sum', sumerror, sumtotal])
print(len(staticresult))
outData = pd.DataFrame(staticresult, columns=['cluster', 'error', 'total'])
print(outData)
outData.to_csv(outdir + 'staticout.xls', sep='\t', index=None)
# 生成数据
labels = ['error', '']
share = [float(sumerror) / sumtotal,
float(sumtotal - sumerror) / sumtotal]
# 设置分裂属性
explode = [0.1, 0]
# 分裂饼图
plt.figure()
plt.pie(share, explode=explode,
labels=labels, autopct='%3.1f%%', shadow=True,
colors=['#FF3B30', '#C3CFE8'])
# 标题
plt.title('acc OUR')
plt.savefig(outdir + 'staticout.png')
plt.close()
if __name__ == '__main__':
main()