2
import distance
from collections import defaultdict
my_list = ['ACAA', 'TCAA','TCAT','TGAT','TCGA','TGGA','GCGA','AAAA','GGGG','GGGC']
counts = {'ACAA':60, 'TCAA':3,'TCAT':30,'TGAT':8,'TCGA':1,'TGGA':1,'GCGA':8,'AAAA':5,'GGGG':8,'GGGC':1}
adj_list = defaultdict(list)
for strng1 in my_list:
for strng2 in my_list:
if distance.hamming(strng1, strng2) == 1 and counts[strng1] >= (counts[strng2]*2):
adj_list[strng1].append(strng2)
我對得到一個定向鄰接表此實現。預期結果:定向鄰接錶快速實現
ACAA: TCAA
TCAA: TCGA
TCAT: TCAA, TGAT
TGAT
TCGA: TGGA
TGGA: TCGA
GCGA: TCGA
AAAA
GGGG: GGGC
GGGC
是否有更快的實施?對於大型數據集,這會變得非常緩慢。在cython中重寫它會加速它嗎?如果是的話,有人可以幫我開始使用cython嗎?
@ crysis405巨大的豎起大拇指你那證明我的觀點:)我們需要更多的編輯像你這樣優秀的編輯。 –