聚类优化

2024-09-20 05:45:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试优化一个python函数来计算生物信息学中的聚类发现

我已经编写了函数,但是得到了一个TypeError

unsupported operand type(s) for -=: 'str' and 'int' 

我试过重铸成“int”

def ClumpFinding(genome, k, L, t):
    FrequentPatterns = []
    index = 0
    CLump = {}
    for i in range(0, 4**k):
        CLump[i] = 0
    Text = genome[0:L+1]
    FrequencyArray = Computing_Frequencies(Text, k) 
    for i in range(4**k):
        Value = int(FrequencyArray[i])
        if Value > t: 
            CLump[i] = 1
        elif Value == t:
            CLump[i] = 1
    for i in range(1, len(genome) - L):
        FirstPattern = genome[i-1:(i-1)+k]
        index = PatternToNumber(FirstPattern)
        FrequencyArray[index] -= 1
        LastPattern = (genome[i + L - k:(i + L - k)+k])   
        index = PatternToNumber(LastPattern)
        FrequencyArray[index] += 1
        Value = int(FrequencyArray[index])
        if Value > t: 
            CLump[index] = 1
        elif Value == t:
            CLump[index] = 1
    for i in range(4**k):
        if CLump(i) == 1:
            Pattern = NumberToPattern(i, k)
            FrequentPatterns.append(Pattern)
    return (' '.join(map(str, FrequentPatterns)))

以下是错误消息:

(Lines 19 and 23)
FrequencyArray[index] -= -1 and FrequencyArray[index] += 1
TypeError: unsupported operand type(s) for -=: 'str' and 'int'

Tags: and函数inforindexgenomeifvalue