2
我想寫一個需要兩個列表作爲輸入的python函數:一個包含一些分子SMILES代碼和另一個包含分子名稱的代碼。基於Tanimoto係數丟棄過於相似的分子的python函數?
然後它計算所有分子對之間的TANIMOTO係數(我已經有了這個功能),並分別返回兩個新列表,其中所有分子的斯米爾和其他任何其他分子的名字都不高於a一定的閾值。
這是我迄今所做的,但它給錯誤的結果(最讓我得到分子幾乎是一樣的...):
def TanimotoFilter(molist,namelist,threshold):
# molist is the smiles list
# namelist is the name list (SURPRISE!) is this some global variable name?
# threshold is the tanimoto threshold (SURPRISE AGAIN!)
smilesout=[]
names=[]
tans=[]
exclude=[]
for i in range(1,len(molist)):
if i not in exclude:
smilesout.append(molist[i])
names.append(namelist[i])
for j in range(i,len(molist)):
if i==j:
tans.append('SAME')
else:
tanimoto=tanimoto_calc(molist[i],molist[j])
if tanimoto>threshold:
exclude.append(j)
#print 'breaking for '+str(i)+' '+str(j)
break
else:
tans.append(tanimoto)
return smilesout, names, tans
我會,如果修改非常感謝你提出的建議是儘可能基本的,因爲這些代碼適用於那些在他們的生活中幾乎看不到終端的人......無論它是否充滿循環,都會讓它變慢。
謝謝大家!
嗨Vivek!謝謝你的想法。它完美的工作(我認爲)。 tans list實際上是一個列表清單(我寫的函數是錯誤的)。多虧了你的想法,我才能夠獲得所有這些分子對之間的所有Tanimoto係數列表。 – user3091644