python中的共识序列帮助

时间:2012-03-05 06:30:10

标签: python bioinformatics

我很难让这个得分功能起作用。我的程序的目标是制作一个t x n矩阵并找到一致的序列。

我一直收到错误:

  

TypeError:'int'对象不可订阅。

任何帮助都将不胜感激。

  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

1 个答案:

答案 0 :(得分:0)

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

如果是int变量,则无法以dna[j][s[j]:s[j]+l]

的形式访问它