-
Notifications
You must be signed in to change notification settings - Fork 8
/
compute_error_rate_from_decoded_lists.py
56 lines (50 loc) · 1.87 KB
/
compute_error_rate_from_decoded_lists.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
import helper
import os
# PARAMETERS TO BE SET BEFORE RUNNING THE CODE
LIST_SIZE = 8
DECODED_LISTS_DIR = '../nanopore_dna_storage_data/decoded_lists/exp_7/'
CONV_INPUT_FILE = '../nanopore_dna_storage_data/oligo_files/conv_input_7.txt'
pad = False
bytes_per_oligo = 18
print('list size:',LIST_SIZE)
with open(CONV_INPUT_FILE) as f:
conv_input_list = [s.rstrip('\n') for s in f.readlines()]
num_oligos = len(conv_input_list)
print('num_oligos',num_oligos)
num_reads = 0
num_correct = 0
num_erasure_CRC_index = 0
num_error_CRC_index = 0
decoded_index_dict = {}
# map from index to [[decoded_msg,count]]
for filename in os.listdir(DECODED_LISTS_DIR):
if not filename.startswith("list_"):
continue
num_reads += 1
with open(os.path.join(DECODED_LISTS_DIR,filename)) as f:
decoded_msg_list = [l.rstrip('\n') for l in f.readlines()]
decoded_msg_list = decoded_msg_list[:LIST_SIZE]
(index, payload_bytes, decoded_msg) = helper.decode_list_CRC_index(decoded_msg_list,bytes_per_oligo,num_oligos,pad)
if index == None:
num_erasure_CRC_index += 1
else:
if index in decoded_index_dict:
found = False
for tup in decoded_index_dict[index]:
if tup[0] == decoded_msg:
tup[1] += 1
found = True
break
if not found:
decoded_index_dict[index].append([decoded_msg,1])
decoded_index_dict[index] = sorted(decoded_index_dict[index],key=lambda x: -x[1])
else:
decoded_index_dict[index] = [[decoded_msg,1]]
if decoded_msg == conv_input_list[index]:
num_correct += 1
else:
num_error_CRC_index += 1
print('num_reads:',num_reads)
print('num_correct:',num_correct)
print('num_erasure_CRC_index:',num_erasure_CRC_index)
print('num_error_CRC_index:',num_error_CRC_index)