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