我正在尝试优化一个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'
频率数组是字符串数组,因此不能用int进行减法或加法
像这样做
之后
将其转换为int数组
相关问题 更多 >
编程相关推荐