IndexError: list assignment index out of range | Needleman-Wunsch Algorithm - Python
1
0
Entering edit mode
3.6 years ago
Anonymous ▴ 10

I am attempting to implement the Dynamic Programming Table Needleman-Wunsch Algorithm in Python:

My code is inspired by this.

The far left column and top row need to start from 0, decrementing downwards

Note: this works perfectly fine if I limit the 2 sequences to just 100 characters long each. So maybe it's because the data is too big?

m, n = len(seqA), len(seqB)  # let m, n denote the lengths of two sequences

score_matrix = tasks.empty_matrix(m+1, n+1)

for i in range(0, m+1):
    score_matrix[i][0] = i * -1
for j in range(0, n+1):
    score_matrix[0][j] = j * -1

Error:

for j in range(0, n+1):
    score_matrix[0][j] = j * -1
IndexError: list assignment index out of range

Note: my DNA sequences are all ~10,000 characters long. So, 10K * 10K DP table.

Python Needleman-Wunsch Dynamic-Programming • 1.9k views
ADD COMMENT
1
Entering edit mode

the error simply means your matrix has the wrong dimensions, you accessing an index that does not exist

that being said I don't think you can make a 10K x 10K nested list in python,

use a numpy array instead

ADD REPLY
0
Entering edit mode
3.6 years ago
Anonymous ▴ 10

score_matrix had it's x and y value muddled up.

ADD COMMENT
0
Entering edit mode

please do not delete posts that have comments or answers, we can all learn from various errors, people would not contribute to a post if they knew that their contributions will be deleted

ADD REPLY

Login before adding your answer.

Traffic: 2736 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6