2 つの DNA 配列の LCS を見つけようとしています。行列形式と、最長の共通シーケンスを含む文字列を出力しています。ただし、コードでマトリックスとリストの両方を返すと、次のエラーが発生します: IndexError: string index out of range
変数 temp と higestcount を含むコーディングを削除すると、コードは行列を適切に出力します。マトリックスに同様のコーディングを使用してリストを生成しようとしています。このエラーを回避する方法はありますか? シーケンス AGCTGGTCAG および TACGCTGGTGGCAT に基づくと、最も長い共通シーケンスは GCTGGT になります。
def lcs(x,y):
c = len(x)
d = len(y)
plot = []
temp = ''
highestcount = ''
for i in range(c):
plot.append([])
temp.join('')
for j in range(d):
if x[i] == y[j]:
plot[i].append(plot[i-1][j-1] + 1)
temp.join(temp[i-1][j-1])
else:
plot[i].append(0)
temp = ''
if temp > highestcount:
highestcount = temp
return plot, temp
x = "AGCTGGTCAG"
y = "TACGCTGGTGGCAT"
test = compute_lcs(x,y)
print test