Skip to content

Instantly share code, notes, and snippets.

@Evantm
Last active March 19, 2019 23:58
Show Gist options
  • Save Evantm/6ddba2fab89f101fe9adcdb559f42925 to your computer and use it in GitHub Desktop.
Save Evantm/6ddba2fab89f101fe9adcdb559f42925 to your computer and use it in GitHub Desktop.
Nussinov algorithm for bioinformatics from pseudo code provided in class
grid = [
[0,None,None,None],
[0,0,None,None],
[-1,0,0,None],
[-1,-1,0,0],
]
seq = ['U','G','A','U']
def match(i,j):
return 'A' in (seq[i],seq[j]) and 'U' in (seq[i],seq[j])
return 'C' in (seq[i],seq[j]) and 'G' in (seq[i],seq[j])
return 0
while grid[0][len(grid) - 1] is None:
for row_index, row in enumerate(grid):
for col_index, col in enumerate(row):
if col is None:
bot_right = grid[row_index+1][col_index]
left = grid[row_index][col_index-1]
bot_left = grid[row_index+1][col_index-1] + match(row_index,col_index)
other_one = max(
[grid[row_index][k] + grid[k+1][row_index]
for k in range(row_index,col_index)]
)
grid[row_index][col_index] = max(bot_right,left,bot_left)
break
for row in grid:
print(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment