2012-03-05 64 views
0

我很难让这个评分函数工作。我的程序的目标是制作一个t×n矩阵并找到一个共识序列。python中的共识序列帮助

我不断收到一个错误:

TypeError: 'int' object is not subscriptable.

任何帮助,将不胜感激。

def Score(s, i, l, dna): 
    t = len(dna) # t = number of dna sequences 

    # Step 1: Extract the alignment corresponding to starting positions in s 

    alignment = [] 
    for j in range(0, i): 
     alignment.append(dna[j][s[j]:s[j]+l]) 

    # Step 2: Create the corresponding profile matrix 

    profile = [[],[],[],[]]  # prepare an empty 4 x l profile matrix first 
    for j in range(0, 4): 
     profile[j] = [0] * l 

    for c in range(0, l):  # for each column number c 
     for r in range(0, i):  # for each row number r in column c 
      if alignment[r][c] == 'a': 
       profile[0][c] = profile[0][c] + 1 
      elif alignment[r][c] == 't': 
       profile[1][c] = profile[1][c] + 1 
      elif alignment[r][c] == 'g': 
       profile[2][c] = profile[2][c] + 1 
      else: 
       profile[3][c] = profile[3][c] + 1 


    # Step 3: Compute the score from the profile matrix 

    score = 0 
    for c in range(0, l): 
     score = score + max([profile[0][c], profile[1][c], profile[2][c], profile[3][c]]) 

    return score 
+2

我认为* *你这是怎么了的意思它是缩进的。无论如何,首先查看错误消息并确定**错误发生在哪里。 – 2012-03-05 06:33:09

回答

0

是您的变量dna一本字典, 如果是使用def Score(s, i, l, **dna)

如果int变量,你不能访问它dna[j][s[j]:s[j]+l]

+0

不,我没有把我的变量作为字典。这有助于......我的DNA由这个dna =“tactagcaat”,“acgcttgcgt”,“cggtggttaa” – user1238097 2012-03-05 17:25:52

+0

是'dna'字符串列表 – avasal 2012-03-06 11:42:06