<lambda>() 是否有任何解决方案缺少 1 个必需的位置参数:'y'
Are there any solution for this <lambda>() missing 1 required positional argument: 'y'
我正在做一些关于蛋白质建模的教程,方法是使用多个模板对相同的蛋白质进行建模。我目前正在尝试 运行 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],mobile_selection),'%s & %s'%(target,target_selection),cutoff=cutoff,cycles=cycles,object=objectname)
elif method == 'cealign':
rmsdict = cmd.cealign('%s & %s' % (target,target_selection),'%s & %s' % (object_list[i],mobile_selection))
rms = [rmsdict['RMSD'],rmsdict['alignment_length'],1,0,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],mobile_selection),'%s & %s'%(target,target_selection),cutoff=cutoff,cycles=cycles)
elif method == 'super':
rms = cmd.super('%s & %s'%(object_list[i],mobile_selection),'%s & %s'%(target,target_selection),cutoff=cutoff,cycles=cycles)
elif method == 'cealign':
rmsdict = cmd.cealign('%s & %s' % (target,target_selection),'%s & %s' % (object_list[i],mobile_selection))
rms = [rmsdict['RMSD'],rmsdict['alignment_length'],1,0,0]
else:
print ("only 'align', '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: cmp(x[1],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)
谢谢。
排序函数键关键字已传递给对象,预计return该对象的比较键。 python 排序的旧版本使用 cmp 关键字比较两个要排序的元素。
你想要rmsd_list.sort(key=lambda e: e[1])
我怀疑。
我正在做一些关于蛋白质建模的教程,方法是使用多个模板对相同的蛋白质进行建模。我目前正在尝试 运行 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],mobile_selection),'%s & %s'%(target,target_selection),cutoff=cutoff,cycles=cycles,object=objectname)
elif method == 'cealign':
rmsdict = cmd.cealign('%s & %s' % (target,target_selection),'%s & %s' % (object_list[i],mobile_selection))
rms = [rmsdict['RMSD'],rmsdict['alignment_length'],1,0,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],mobile_selection),'%s & %s'%(target,target_selection),cutoff=cutoff,cycles=cycles)
elif method == 'super':
rms = cmd.super('%s & %s'%(object_list[i],mobile_selection),'%s & %s'%(target,target_selection),cutoff=cutoff,cycles=cycles)
elif method == 'cealign':
rmsdict = cmd.cealign('%s & %s' % (target,target_selection),'%s & %s' % (object_list[i],mobile_selection))
rms = [rmsdict['RMSD'],rmsdict['alignment_length'],1,0,0]
else:
print ("only 'align', '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: cmp(x[1],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)
谢谢。
排序函数键关键字已传递给对象,预计return该对象的比较键。 python 排序的旧版本使用 cmp 关键字比较两个要排序的元素。
你想要rmsd_list.sort(key=lambda e: e[1])
我怀疑。