设计并编写了一个可以检测跨膜区域的程序,称为TMscanner.py。这个程序应该调用您编写的另外两个函数:getProteinRegion应该返回一个10个氨基酸窗口(最初捕获氨基酸1-10,下一个2-20,等等)。TMscanner还应该重复调用第二个函数,称为testForTM,它应该计算并返回这十个非极性氨基酸的十进制分数。非极性氨基酸为A,V,L,I,P,M,F,W
示例:
protein = 'AVLIPMFWGSTNQYDEKRH' #Only the first 9 are nonpolar
results = tmScanner(protein)
print "Results are", results它应该打印出来:
Results are [.8, .7, .6, .5, .4, .3, .2, .1, 0, 0]-#测试代码
def getProteinRegion(protein, start):
#return first 10 aa in protein
return protein[start:start+10]
def testForTM(protein):
#return ratio of nonpolar aa from a sample of first 10; move them up one step and repeat
nonpolar = 0
for aa in getProteinRegion(protein, start):
if aa in ['A', 'V', 'L', 'I', 'P', 'M', 'F', 'W']:
nonpolar = nonpolar + 1.0
return nonpolar / 10.0
def tmSCANNER(protein):
#while the tested in testForTM is less than 10, append testforTM function to results; print results
results = []
start = 0
while start <= 10:
results = results.append(testForTM(protein))
return results
start = start + 1
##TESTING
#print getProteinRegion('AVLIPMFWGSTCNQYDEKRH')
#print testForTM('AVLIPMFW')
print tmSCANNER('AVLIPMFWGSTCNQYDEKRH')--
Traceback (most recent call last):
File "TMscanner.py", line 29, in <module>
print tmSCANNER('AVLIPMFWGSTCNQYDEKRH')
File "TMscanner.py", line 21, in tmSCANNER
results = results.append(testForTM(protein))
File "TMscanner.py", line 10, in testForTM
for aa in getProteinRegion(protein, start):
NameError: global name 'start' is not defined发布于 2018-03-25 08:07:22
函数testForTM不接受start参数,不声明名为start的局部变量,但它调用getProteinRegion(protein, start)。因此,Python假定您必须使用全局-但您也没有这个名称的全局。所以它引发了一个例外。
您可能想要添加start作为参数:
def testForTM(protein, start):然后,在tmSCANNER内部的调用代码中,您确实有一个名为start的局部变量,这可能是您希望作为start参数传递的值:
results = results.append(testForTM(protein, start))https://stackoverflow.com/questions/49473671
复制相似问题