【问题标题】:Consensus sequence help in pythonpython中的共识序列帮助
【发布时间】:2014-04-19 18:44:01
【问题描述】:

我很难让这个评分功能发挥作用。我的程序的目标是制作一个 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

【问题讨论】:

  • 认为这就是缩进的意思。不管怎样,先看错误信息,确定错误发生在哪里

标签: python bioinformatics


【解决方案1】:

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

如果是int变量,则不能作为dna[j][s[j]:s[j]+l]访问

【讨论】:

  • 不,我没有把我的变量作为字典。有帮助吗......我的 dna 由这个 dna= "tactagcaat", "acgcttgcgt", "cggtggttaa"
猜你喜欢
  • 1970-01-01
  • 2015-08-25
  • 1970-01-01
  • 2019-05-21
  • 2012-02-21
  • 2019-07-13
  • 2017-08-22
  • 2010-11-14
  • 1970-01-01
相关资源
最近更新 更多