生物信息学 - “全球名称'开始'未定义”?

时间:2020-12-03 16:48:27

Design and write a program that could detect transmembrane domains called TMscanner.py. This program should call two other functions that you write: getProteinRegion should return a ten amino acid window (initially grabs amino acid 1-10, the next time 2-20, etc.) The TMscanner should also repeatedly call a second function called testForTM which should calculate and return the decimal fraction of those ten amino acids which are nonpolar. The nonpolar amino acids are [A,V,L,I,P,M,F,W]

设计并编写一个可以检测称为TMscanner.py的跨膜域的程序。这个程序应该调用你写的另外两个函数:getProteinRegion应该返回一个10个氨基酸的窗口(最初抓取1-10个氨基酸,下次2-20个等)TMscanner也应该重复调用第二个函数testForTM,应计算并返回非极性的十个氨基酸的小数部分。非极性氨基酸是[A,V,L,I,P,M,F,W]

Example:

例:

protein = 'AVLIPMFWGSTNQYDEKRH' #Only the first 9 are nonpolar
results = tmScanner(protein)
print "Results are", results

It should print out:

它应该打印出来:

Results are [.8, .7, .6, .5, .4, .3, .2, .1, 0, 0]

-- #Test code

- #Test代码

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

1 个解决方案

#1


1  

Your function testForTM doesn't take a start parameter, doesn't declare a local variable named start, and yet it calls getProteinRegion(protein, start). So, Python assumes you must be using a global—but you don't have a global with that name either. So it raises an exception.

你的函数testForTM不带一个start参数,不会声明一个名为start的局部变量,而是调用getProteinRegion(protein,start)。因此,Python假设您必须使用全局 - 但您也没有具有该名称的全局。所以它提出了一个例外。

What you probably want is to add start as a parameter:

你可能想要的是添加start作为参数:

def testForTM(protein, start):

And then, in the calling code inside tmSCANNER, where you do have a local variable named start, that's probably the value you want to pass as the start argument:

然后,在tmSCANNER中的调用代码中,你有一个名为start的局部变量,这可能是你要作为start参数传递的值:

results = results.append(testForTM(protein, start))

#1


1  

Your function testForTM doesn't take a start parameter, doesn't declare a local variable named start, and yet it calls getProteinRegion(protein, start). So, Python assumes you must be using a global—but you don't have a global with that name either. So it raises an exception.

你的函数testForTM不带一个start参数,不会声明一个名为start的局部变量,而是调用getProteinRegion(protein,start)。因此,Python假设您必须使用全局 - 但您也没有具有该名称的全局。所以它提出了一个例外。

What you probably want is to add start as a parameter:

你可能想要的是添加start作为参数:

def testForTM(protein, start):

And then, in the calling code inside tmSCANNER, where you do have a local variable named start, that's probably the value you want to pass as the start argument:

然后,在tmSCANNER中的调用代码中,你有一个名为start的局部变量,这可能是你要作为start参数传递的值:

results = results.append(testForTM(protein, start))