Skip to content

Instantly share code, notes, and snippets.

View smanurung's full-sized avatar
👋

Sonny Theo Tumbur Manurung smanurung

👋
View GitHub Profile
@smanurung
smanurung / smith_waterman.py
Created September 9, 2019 04:22 — forked from nornagon/smith_waterman.py
Smith-Waterman Python implementation
import numpy as np
def smith_waterman(a: str, b: str, alignment_score: float = 1, gap_cost: float = 1) -> float:
"""
Compute the Smith-Waterman alignment score for two strings.
See https://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm#Algorithm
This implementation has a fixed gap cost (i.e. extending a gap is considered
free). In the terminology of the Wikipedia description, W_k = {c, c, c, ...}.
This implementation also has a fixed alignment score, awarded if the relevant