问题描述
我正在做一些关于蛋白质建模的教程,使用多个模板来建模相同的蛋白质。我目前正在尝试运行 align_all.py 但是输出变成这样
rmsd_list.sort(key=lambda x,y: cmp(x[1],y[1]))
TypeError: () 缺少 1 个必需的位置参数:'y'
我尝试了很多方法来纠正它,但仍然没有得到解决方案。我希望有人可以帮助我解决这个问题。我目前使用的是 Python 2.7。
以下是完整代码
from pymol import cmd
def align_all(target=None,mobile_selection='name ca',target_selection='name ca',cutoff=2,cycles=5,cgo_object=0,method='align'):
cutoff = int(cutoff)
cycles = int(cycles)
cgo_object = int(cgo_object)
object_list = cmd.get_names()
object_list.remove(target)
rmsd = {}
rmsd_list = []
for i in range(len(object_list)):
if cgo_object:
objectname = 'align_%s_on_%s' % (object_list[i],target)
if method == 'align':
rms = cmd.align('%s & %s'%(object_list[i],mobile_selection),'%s & %s'%(target,target_selection),cutoff=cutoff,cycles=cycles,object=objectname)
elif method == 'super':
rms = cmd.super('%s & %s'%(object_list[i],object=objectname)
elif method == 'cealign':
rmsdict = cmd.cealign('%s & %s' % (target,'%s & %s' % (object_list[i],mobile_selection))
rms = [rmsdict['RMSD'],rmsdict['alignment_length'],1,0]
else:
print ("only 'align','super' and 'cealign' are accepted as methods")
sys.exit(-1)
else:
if method == 'align':
rms = cmd.align('%s & %s'%(object_list[i],cycles=cycles)
elif method == 'super':
rms = cmd.super('%s & %s'%(object_list[i],cycles=cycles)
elif method == 'cealign':
rmsdict = cmd.cealign('%s & %s' % (target,'super' and 'cealign' are accepted as methods")
sys.exit(-1)
rmsd[object_list[i]] = (rms[0],rms[1])
rmsd_list.append((object_list[i],rms[0],rms[1]))
rmsd_list.sort(key=lambda x,y[1]))
# loop over dictionary and print out matrix of final rms values
print ("Aligning against:",target)
for object_name in object_list:
print ("%s: %6.3f using %d atoms" % (object_name,rmsd[object_name][0],rmsd[object_name][1]))
print ("\nSorted from best match to worst:")
for r in rmsd_list:
print ("%s: %6.3f using %d atoms" % r)
cmd.extend('align_all',align_all)
谢谢。
解决方法
排序函数键关键字被传递给对象,并期望返回该对象的比较键。旧版本的 python sort 使用 cmp 关键字比较两个要排序的元素。
我怀疑你想要rmsd_list.sort(key=lambda e: e[1])
。