109 lines
2.7 KiB
Python
109 lines
2.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Wed Sep 11 11:57:30 2024
|
|
|
|
永辉现场 1:1 比对测试
|
|
|
|
@author: ym
|
|
"""
|
|
import os
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
def read_one2one_data(filepath):
|
|
simiList = []
|
|
with open(filepath, 'r', encoding='utf-8') as f:
|
|
lines = f.readlines()
|
|
|
|
split_flag = False
|
|
simi_dict = {}
|
|
for i, line in enumerate(lines):
|
|
line = line.strip()
|
|
if not line:
|
|
if len(simi_dict): simiList.append(simi_dict)
|
|
simi_dict = {}
|
|
continue
|
|
|
|
label = line.split(':')[0].strip()
|
|
value = line.split(':')[1].strip()
|
|
|
|
if label.find("SeqDir") >= 0:
|
|
simi_dict["SeqDir"] = value
|
|
if label.isdigit() and len(label) >= 8:
|
|
|
|
simi_max, simi_min = value.strip(',').split('.')
|
|
simi_dict["barcode"] = label
|
|
simi_dict["simi_max"] = float(simi_max) / 1000
|
|
simi_dict["simi_min"] = float(simi_min) / 1000
|
|
|
|
if len(simi_dict): simiList.append(simi_dict)
|
|
|
|
return simiList
|
|
|
|
def main():
|
|
filepath = r"\\192.168.1.28\share\测试_202406\0910\images\OneToOneCompare.txt"
|
|
|
|
simiList = read_one2one_data(filepath)
|
|
simimax, simimean = [], []
|
|
small = []
|
|
for simidict in simiList:
|
|
simimax.append(simidict["simi_max"])
|
|
simimean.append(simidict["simi_min"])
|
|
if simidict["simi_max"]<0.6:
|
|
small.append(simidict)
|
|
|
|
|
|
simimax = np.array(simimax)
|
|
simimean = np.array(simimean)
|
|
|
|
|
|
|
|
TPFN_max = len(simimax)
|
|
TPFN_mean = len(simimean)
|
|
|
|
|
|
|
|
fig, axs = plt.subplots(2, 1)
|
|
axs[0].hist(simimax, bins=60, edgecolor='black')
|
|
axs[0].set_xlim([-0.2, 1])
|
|
axs[0].set_title(f'Same Barcode, Num: {TPFN_max}')
|
|
axs[1].hist(simimean, bins=60, edgecolor='black')
|
|
axs[1].set_xlim([-0.2, 1])
|
|
axs[1].set_title(f'Cross Barcode, Num: {TPFN_mean}')
|
|
# plt.savefig(f'./result/{file}_hist.png') # svg, png, pdf
|
|
|
|
|
|
|
|
Recall_Pos = []
|
|
Thresh = np.linspace(-0.2, 1, 100)
|
|
for th in Thresh:
|
|
TP = np.sum(simimax > th)
|
|
Recall_Pos.append(TP/TPFN_max)
|
|
|
|
fig, ax = plt.subplots()
|
|
ax.plot(Thresh, Recall_Pos, 'b', label='Recall_Pos: TP/TPFN')
|
|
ax.set_xlim([0, 1])
|
|
ax.set_ylim([0, 1])
|
|
ax.grid(True)
|
|
ax.set_title('Positive recall')
|
|
ax.set_xlabel(f"Num: {TPFN_max}")
|
|
ax.legend()
|
|
plt.show()
|
|
# plt.savefig(f'./result/{file}_pr.png') # svg, png, pdf
|
|
|
|
print("Have done!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |