python 函数根据 Tanimoto 系数丢弃过于相似的分子?
A python function that discards molecules that are too similar based on Tanimoto coefficient?
我正在尝试编写一个 python 函数,它将两个列表作为输入:一个包含一些分子 SMILES 代码,另一个包含分子名称。
然后它计算所有分子对之间的 TANIMOTO 系数(我已经有一个函数)和 returns 两个新列表,分别包含所有 Tanimoto 与任何其他分子的 SMILES 和名称不高于某个阈值。
这是我目前所做的,但它给出了错误的结果(我得到的大多数分子几乎相同......):
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
如果您提出的修改尽可能基本,我将不胜感激,因为这段代码是为那些在生活中几乎没有见过终端的人准备的……如果它充满了也没关系使它变慢的循环。
谢谢大家!
我对函数的逻辑做了一些修改。如问题中所述,它 returns 包含 SMILES 和名称的两个列表。我不确定 tan 的用途,因为 tanimoto 值是针对元组而不是针对单个分子的。无法在没有数据的情况下测试代码,如果可行请告诉我。
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(0, len(molist)):
if i not in exclude:
temp_exclude = []
for j in range(i + 1, len(molist)):
tanimoto = tanimoto_calc(molist[i], molist[j])
if tanimoto > threshold:
temp_exclude.append(j)
if temp_exclude:
temp_exclude.append(i)
exclude.extend(temp_exclude)
else:
smilesout.append(molist[i])
names.append(namelist[i])
return smilesout, names
我正在尝试编写一个 python 函数,它将两个列表作为输入:一个包含一些分子 SMILES 代码,另一个包含分子名称。
然后它计算所有分子对之间的 TANIMOTO 系数(我已经有一个函数)和 returns 两个新列表,分别包含所有 Tanimoto 与任何其他分子的 SMILES 和名称不高于某个阈值。
这是我目前所做的,但它给出了错误的结果(我得到的大多数分子几乎相同......):
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
如果您提出的修改尽可能基本,我将不胜感激,因为这段代码是为那些在生活中几乎没有见过终端的人准备的……如果它充满了也没关系使它变慢的循环。
谢谢大家!
我对函数的逻辑做了一些修改。如问题中所述,它 returns 包含 SMILES 和名称的两个列表。我不确定 tan 的用途,因为 tanimoto 值是针对元组而不是针对单个分子的。无法在没有数据的情况下测试代码,如果可行请告诉我。
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(0, len(molist)):
if i not in exclude:
temp_exclude = []
for j in range(i + 1, len(molist)):
tanimoto = tanimoto_calc(molist[i], molist[j])
if tanimoto > threshold:
temp_exclude.append(j)
if temp_exclude:
temp_exclude.append(i)
exclude.extend(temp_exclude)
else:
smilesout.append(molist[i])
names.append(namelist[i])
return smilesout, names