diff --git a/limestone/editdistance.py b/limestone/editdistance.py index dc84a46..7c11843 100644 --- a/limestone/editdistance.py +++ b/limestone/editdistance.py @@ -1,4 +1,5 @@ from __future__ import annotations +from re import sub try: # external dependency import numpy @@ -8,14 +9,10 @@ numpy = None def main(): - qqs = "AFTG" - sss = "ACTG" + qqs = "AT" + sss = "AAGT" - print(needlemanWunsch.matrix(qqs,sss)) - print(needlemanWunsch.align(qqs,sss)) - print(watermanSmithBeyer.matrix(qqs,sss)) - print(watermanSmithBeyer.align(qqs,sss)) - print(hirschbergDist.align(qqs,sss)) + print(watermanSmithBeyer.matrix(qqs, sss)) class _GLOBALBASE(): def matrix(self, querySequence: str, subjectSequence: str)->list[list[float]]: @@ -124,7 +121,7 @@ def align(self, querySequence: str, subjectSequence: str)->str: return f"{queryAlign}\n{subjectAlign}" -class hamming(_GLOBALBASE): +class Hamming(_GLOBALBASE): def align(self, querySequence: str, subjectSequence: str)->str: return f"{querySequence}\n{subjectSequence}" @@ -134,13 +131,17 @@ def matrix(self, qs: str, ss: str) -> None: def __call__(self, querySequence: str, subjectSequence: str)->tuple[int,list[int]]: if not numpy: raise ImportError('Please pip install numpy!') - + qs,ss = map(lambda x: x.upper(), [querySequence,subjectSequence]) - qs = [x for x in qs] - ss = [x for x in ss] - long = max(ss,qs) - short = min(ss,qs) + if len(qs) == 1 and len(ss) == 1: + dist = 1 if qs != ss else 0 + dist_array = [dist] + return dist, dist_array + + shortlen = min(map(len, [ss,qs])) + short = qs if len(qs) == shortlen else ss + long = ss if len(qs) == shortlen else qs dist = 0 dist_array = [] @@ -173,7 +174,7 @@ def binary_similarity_array(self, querySequence: str, subjectSequence: str)->lis simarray = [1 if num == 0 else 0 for num in distarray] return simarray -class needleman_wunsch(_GLOBALBASE): +class Needleman_Wunsch(_GLOBALBASE): def __init__(self, match_score:int = 0, mismatch_penalty:int = 1, gap_penalty:int = 2)->None: self.match_score = match_score self.mismatch_penalty = mismatch_penalty @@ -194,14 +195,14 @@ def __call__(self, querySequence: str, subjectSequence: str)->tuple[NDArray[floa self.pointer = numpy.zeros((len(qs), len(ss))) self.pointer[:,0] = 3 self.pointer[0,:] = 4 - #keeps first row and column consistent throughout all calculations + #initialisation of starter values for first column and first row self.alignment_score[:,0] = [n*self.gap_penalty for n in range(len(qs))] self.alignment_score[0,:] = [n*self.gap_penalty for n in range(len(ss))] for i, query_char in enumerate(qs): for j, subject_char in enumerate(ss): if i == 0 or j == 0: - #doesn't override initialization + #keeps first row and column consistent throughout all calculations continue if query_char == subject_char: match = self.alignment_score[i-1][j-1] - self.match_score @@ -223,13 +224,13 @@ def __call__(self, querySequence: str, subjectSequence: str)->tuple[NDArray[floa return self.alignment_score, self.pointer -class levenshtein(needleman_wunsch): +class Levenshtein(Needleman_Wunsch): def __init__(self): self.match_score = 0 self.mismatch_penalty = 1 self.gap_penalty = 1 -class smith_waterman(_LOCALBASE): +class Smith_Waterman(_LOCALBASE): def __init__(self, match_score:int = 1, mismatch_penalty:int = 1, gap_penalty:int = 2)->None: self.match_score = match_score self.mismatch_penalty = mismatch_penalty @@ -268,7 +269,7 @@ def __call__(self, subjectSequence: str, querySequence: str)-> NDArray[float64]: self.alignment_score[i][j] = tmax return self.alignment_score -class waterman_smith_beyer(_GLOBALBASE): +class Waterman_Smith_Beyer(_GLOBALBASE): def __init__(self, match_score:int = 0, mismatch_penalty:int = 1, new_gap_penalty:int = 3, continue_gap_penalty:int = 1)->None: self.match_score = match_score self.mismatch_penalty = mismatch_penalty @@ -290,6 +291,7 @@ def __call__(self, querySequence: str, subjectSequence: str)->tuple[NDArray[floa self.pointer = numpy.zeros((len(qs), len(ss))) self.pointer[:,0] = 3 self.pointer[0,:] = 4 + #initialisation of starter values for first column and first row self.alignment_score[:,0] = [self.new_gap_penalty + n * self.continue_gap_penalty for n in range(len(qs))] self.alignment_score[0,:] = [self.new_gap_penalty + n * self.continue_gap_penalty for n in range(len(ss))] self.alignment_score[0][0] = 0 @@ -325,7 +327,7 @@ def __call__(self, querySequence: str, subjectSequence: str)->tuple[NDArray[floa return self.alignment_score, self.pointer -class hirschberg(): +class Hirschberg(): def __init__(self, match_score: int = 1, mismatch_penalty: int = -1, gap_penalty: int = -2)->None: self.match_score = match_score self.mismatch_penalty = mismatch_penalty @@ -387,7 +389,6 @@ def _align(self, qs, ss): for i in range(1, m + 1): for j in range(1, n + 1): - if qs[i-1] == ss[j-1]: match = score[i-1][j-1] + self.match_score else: @@ -395,7 +396,6 @@ def _align(self, qs, ss): delete = score[i - 1][j] + self.gap_penalty insert = score[i][j - 1] + self.gap_penalty score[i][j] = max(match, delete, insert) - if score[i][j] == match: pointer[i][j] = 3 elif score[i][j] == delete: @@ -434,18 +434,18 @@ def frontWhiteSpace(qs: list[str], ss: list[str])->tuple[list[str],list[str]]: return qs, ss def ljustlist(sequence: list[str], n: int, fillvalue='')->list[str]: - return sequence + [fillvalue] * (n - len(sequence)) + return sequence + [fillvalue] * (n - len(sequence)) def rjustlist(sequence: list[str], fillvalue='')->list[str]: - return [fillvalue] + sequence + return [fillvalue] + sequence -needlemanWunsch = needleman_wunsch() -watermanSmithBeyer = waterman_smith_beyer() -smithWaterman = smith_waterman() -levenshteinDist = levenshtein() -hirschbergDist = hirschberg() -hammingDist = hamming() +needleman_wunsch = Needleman_Wunsch() +waterman_smith_beyer = Waterman_Smith_Beyer() +smith_waterman = Smith_Waterman() +levenshtein = Levenshtein() +hirschberg = Hirschberg() +hamming = Hamming() if __name__ == "__main__": main() diff --git a/tests/test_Hamming.py b/tests/test_Hamming.py index 5a1cca6..139134a 100644 --- a/tests/test_Hamming.py +++ b/tests/test_Hamming.py @@ -1,89 +1,89 @@ from __future__ import annotations import unittest -from limestone.editdistance import hammingDist +from limestone.editdistance import hamming class TestHamming(unittest.TestCase): def test_distance_diff(self): - dist = hammingDist.distance("ACTG","FHYU") + dist = hamming.distance("ACTG","FHYU") self.assertEqual(dist, 4.0) def test_similarity_diff(self): - sim = hammingDist.similarity("ACTG","FHYU") + sim = hamming.similarity("ACTG","FHYU") self.assertEqual(sim, 0.0) def test_norm_distance_diff(self): - dist = hammingDist.normalized_distance("ACTG","FHYU") + dist = hamming.normalized_distance("ACTG","FHYU") self.assertEqual(dist, 1.0) def test_norm_similarity_diff(self): - sim = hammingDist.normalized_similarity("ACTG","FHYU") + sim = hamming.normalized_similarity("ACTG","FHYU") self.assertEqual(sim, 0.0) def test_distance_sim(self): - dist = hammingDist.distance("ACTG","ACTG") + dist = hamming.distance("ACTG","ACTG") self.assertEqual(dist, 0.0) def test_similarity_sim(self): - sim = hammingDist.similarity("ACTG","ACTG") + sim = hamming.similarity("ACTG","ACTG") self.assertEqual(sim, 4.0) def test_norm_distance_sim(self): - dist = hammingDist.normalized_distance("ACTG","ACTG") + dist = hamming.normalized_distance("ACTG","ACTG") self.assertEqual(dist, 0.0) def test_norm_similarity_sim(self): - sim = hammingDist.normalized_similarity("ACTG","ACTG") + sim = hamming.normalized_similarity("ACTG","ACTG") self.assertEqual(sim, 1.0) def test_norm_distance1(self): - dist = hammingDist.normalized_distance("ACTG","AATG") + dist = hamming.normalized_distance("ACTG","AATG") self.assertEqual(dist, 0.25) def test_norm_distance2(self): - dist = hammingDist.normalized_distance("ACTG","AAAG") + dist = hamming.normalized_distance("ACTG","AAAG") self.assertEqual(dist, 0.5) def test_norm_distance3(self): - dist = hammingDist.normalized_distance("ACTG","AAAA") + dist = hamming.normalized_distance("ACTG","AAAA") self.assertEqual(dist, 0.75) def test_norm_similarity1(self): - dist = hammingDist.normalized_similarity("ACTG","AATG") + dist = hamming.normalized_similarity("ACTG","AATG") self.assertEqual(dist, 0.75) def test_norm_similarity2(self): - dist = hammingDist.normalized_similarity("ACTG","AAAG") + dist = hamming.normalized_similarity("ACTG","AAAG") self.assertEqual(dist, 0.5) def test_norm_similarity3(self): - dist = hammingDist.normalized_similarity("ACTG","AAAA") + dist = hamming.normalized_similarity("ACTG","AAAA") self.assertEqual(dist, 0.25) def test_diff_len(self): - dist = hammingDist.distance("ACTG","AATGA") + dist = hamming.distance("ACTG","AATGA") self.assertEqual(dist,2.0) def test_diff_len2(self): - dist = hammingDist.distance("AATGA","ACTG") + dist = hamming.distance("AATGA","ACTG") self.assertEqual(dist,2.0) def test_binary_diff(self): - dist = hammingDist.binary_distance_array("ACTG","AATG") + dist = hamming.binary_distance_array("ACTG","AATG") ans = [1,0,1,1] self.assertEqual(dist, ans) def test_binary_sim(self): - dist = hammingDist.binary_similarity_array("ACTG","AATG") + dist = hamming.binary_similarity_array("ACTG","AATG") ans = [0,1,0,0] self.assertEqual(dist, ans) def test_align1(self): - dist = hammingDist.align("ACTG","ATGA") + dist = hamming.align("ACTG","ATGA") ans = f"ACTG\nATGA" self.assertEqual(dist,ans) def test_align2(self): - dist = hammingDist.align("ACTGAA","ATGA") + dist = hamming.align("ACTGAA","ATGA") ans = f"ACTGAA\nATGA" self.assertEqual(dist,ans) diff --git a/tests/test_Hirschberg.py b/tests/test_Hirschberg.py index c432ca0..dd6a9ee 100644 --- a/tests/test_Hirschberg.py +++ b/tests/test_Hirschberg.py @@ -1,38 +1,38 @@ from __future__ import annotations import unittest -from limestone.editdistance import needlemanWunsch -from limestone.editdistance import hirschbergDist +from limestone.editdistance import needleman_wunsch +from limestone.editdistance import hirschberg class TestHirschberg(unittest.TestCase): def test_align1(self): - nwalignment = needlemanWunsch.align("BA", "ABA") - hsalignment = hirschbergDist.align("BA","ABA") + nwalignment = needleman_wunsch.align("BA", "ABA") + hsalignment = hirschberg.align("BA","ABA") self.assertEqual(nwalignment, hsalignment) def test_align2(self): - nwalignment = needlemanWunsch.align("ATCG","ATCG") - hsalignment = hirschbergDist.align("ATCG","ATCG") + nwalignment = needleman_wunsch.align("ATCG","ATCG") + hsalignment = hirschberg.align("ATCG","ATCG") self.assertEqual(nwalignment, hsalignment) def test_align3(self): - nwalignment = needlemanWunsch.align("ACTG","FHYU") - hsalignment = hirschbergDist.align("ACTG","FHYU") + nwalignment = needleman_wunsch.align("ACTG","FHYU") + hsalignment = hirschberg.align("ACTG","FHYU") self.assertEqual(nwalignment, hsalignment) def test_align4(self): - nwalignment = needlemanWunsch.align("AGTACGCA","TATGC") - hsalignment = hirschbergDist.align("AGTACGCA","TATGC") + nwalignment = needleman_wunsch.align("AGTACGCA","TATGC") + hsalignment = hirschberg.align("AGTACGCA","TATGC") self.assertEqual(nwalignment, hsalignment) def test_align5(self): - nwalignment = needlemanWunsch.align("TACOBELL","TABELL") - hsalignment = hirschbergDist.align("TACOBELL","TABELL") + nwalignment = needleman_wunsch.align("TACOBELL","TABELL") + hsalignment = hirschberg.align("TACOBELL","TABELL") self.assertEqual(nwalignment, hsalignment) def test_align6(self): - nwalignment = needlemanWunsch.align("FASTFOAODKING","FASTAKING") - hsalignment = hirschbergDist.align("FASTFOAODKING","FASTAKING") + nwalignment = needleman_wunsch.align("FASTFOAODKING","FASTAKING") + hsalignment = hirschberg.align("FASTFOAODKING","FASTAKING") self.assertEqual(nwalignment, hsalignment) diff --git a/tests/test_SmithWaterman.py b/tests/test_SmithWaterman.py index 3f5bb7a..5620861 100644 --- a/tests/test_SmithWaterman.py +++ b/tests/test_SmithWaterman.py @@ -1,71 +1,71 @@ from __future__ import annotations import unittest -from limestone.editdistance import smithWaterman +from limestone.editdistance import smith_waterman class TestWatermanSmithBayer(unittest.TestCase): def test_distance_diff(self): - dist = smithWaterman.distance("ACTG","FHYU") + dist = smith_waterman.distance("ACTG","FHYU") self.assertEqual(dist, 4.0) def test_similarity_diff(self): - sim = smithWaterman.similarity("ACTG","FHYU") + sim = smith_waterman.similarity("ACTG","FHYU") self.assertEqual(sim, 0.0) def test_norm_distance_diff(self): - dist = smithWaterman.normalized_distance("ACTG","FHYU") + dist = smith_waterman.normalized_distance("ACTG","FHYU") self.assertEqual(dist, 1.0) def test_norm_similarity_diff(self): - sim = smithWaterman.normalized_similarity("ACTG","FHYU") + sim = smith_waterman.normalized_similarity("ACTG","FHYU") self.assertEqual(sim, 0.0) def test_distance_sim(self): - dist = smithWaterman.distance("ACTG","ACTG") + dist = smith_waterman.distance("ACTG","ACTG") self.assertEqual(dist, 0.0) def test_similarity_sim(self): - sim = smithWaterman.similarity("ACTG","ACTG") + sim = smith_waterman.similarity("ACTG","ACTG") self.assertEqual(sim, 4.0) def test_norm_distance_sim(self): - dist = smithWaterman.normalized_distance("ACTG","ACTG") + dist = smith_waterman.normalized_distance("ACTG","ACTG") self.assertEqual(dist, 0.0) def test_norm_distance1(self): - dist = smithWaterman.normalized_distance("ACTG","ACTF") + dist = smith_waterman.normalized_distance("ACTG","ACTF") self.assertEqual(dist, 0.25) def test_norm_distance2(self): - dist = smithWaterman.normalized_distance("ACTG","ACFF") + dist = smith_waterman.normalized_distance("ACTG","ACFF") self.assertEqual(dist, 0.5) def test_norm_distance3(self): - dist = smithWaterman.normalized_distance("ACTG","AFFF") + dist = smith_waterman.normalized_distance("ACTG","AFFF") self.assertEqual(dist, 0.75) def test_norm_similarity_sim(self): - sim = smithWaterman.normalized_similarity("ACTG","ACTG") + sim = smith_waterman.normalized_similarity("ACTG","ACTG") self.assertEqual(sim, 1.0) def test_norm_similarity1(self): - dist = smithWaterman.normalized_similarity("ACTG","ACTF") + dist = smith_waterman.normalized_similarity("ACTG","ACTF") self.assertEqual(dist, 0.75) def test_norm_similarity2(self): - dist = smithWaterman.normalized_similarity("ACTG","ACFF") + dist = smith_waterman.normalized_similarity("ACTG","ACFF") self.assertEqual(dist, 0.5) def test_norm_similarity3(self): - dist = smithWaterman.normalized_similarity("ACTG","AFFF") + dist = smith_waterman.normalized_similarity("ACTG","AFFF") self.assertEqual(dist, 0.25) def test_align(self): - alignment = smithWaterman.align("BA", "ABA") + alignment = smith_waterman.align("BA", "ABA") self.assertEqual(alignment, "BA\nBA") def test_align2(self): - alignment = smithWaterman.align("AGTACGCA","TATGC") + alignment = smith_waterman.align("AGTACGCA","TATGC") self.assertEqual(alignment, "TACGC\nTATGC") if __name__ == '__main__': diff --git a/tests/test_WatermanSmithBeyer.py b/tests/test_WatermanSmithBeyer.py index 1615f6e..66be909 100644 --- a/tests/test_WatermanSmithBeyer.py +++ b/tests/test_WatermanSmithBeyer.py @@ -1,67 +1,67 @@ from __future__ import annotations import unittest -from limestone.editdistance import watermanSmithBeyer +from limestone.editdistance import waterman_smith_beyer class TestWatermanSmithBayer(unittest.TestCase): def test_distance_diff(self): - dist = watermanSmithBeyer.distance("ACTG","FHYU") + dist = waterman_smith_beyer.distance("ACTG","FHYU") self.assertEqual(dist, 4.0) def test_similarity_diff(self): - sim = watermanSmithBeyer.similarity("ACTG","FHYU") + sim = waterman_smith_beyer.similarity("ACTG","FHYU") self.assertEqual(sim, 0.0) def test_norm_distance_diff(self): - dist = watermanSmithBeyer.normalized_distance("ACTG","FHYU") + dist = waterman_smith_beyer.normalized_distance("ACTG","FHYU") self.assertEqual(dist, 1.0) def test_norm_similarity_diff(self): - sim = watermanSmithBeyer.normalized_similarity("ACTG","FHYU") + sim = waterman_smith_beyer.normalized_similarity("ACTG","FHYU") self.assertEqual(sim, 0.0) def test_distance_sim(self): - dist = watermanSmithBeyer.distance("ACTG","ACTG") + dist = waterman_smith_beyer.distance("ACTG","ACTG") self.assertEqual(dist, 0.0) def test_similarity_sim(self): - sim = watermanSmithBeyer.similarity("ACTG","ACTG") + sim = waterman_smith_beyer.similarity("ACTG","ACTG") self.assertEqual(sim, 4.0) def test_norm_distance_sim(self): - dist = watermanSmithBeyer.normalized_distance("ACTG","ACTG") + dist = waterman_smith_beyer.normalized_distance("ACTG","ACTG") self.assertEqual(dist, 0.0) def test_norm_similarity_sim(self): - sim = watermanSmithBeyer.normalized_similarity("ACTG","ACTG") + sim = waterman_smith_beyer.normalized_similarity("ACTG","ACTG") self.assertEqual(sim, 1.0) def test_norm_distance1(self): - dist = watermanSmithBeyer.normalized_distance("ACTG","AATG") + dist = waterman_smith_beyer.normalized_distance("ACTG","AATG") self.assertEqual(dist, 0.25) def test_norm_distance2(self): - dist = watermanSmithBeyer.normalized_distance("ACTG","AAAG") + dist = waterman_smith_beyer.normalized_distance("ACTG","AAAG") self.assertEqual(dist, 0.5) def test_norm_distance3(self): - dist = watermanSmithBeyer.normalized_distance("ACTG","AAAA") + dist = waterman_smith_beyer.normalized_distance("ACTG","AAAA") self.assertEqual(dist, 0.75) def test_norm_similarity1(self): - dist = watermanSmithBeyer.normalized_similarity("ACTG","AATG") + dist = waterman_smith_beyer.normalized_similarity("ACTG","AATG") self.assertEqual(dist, 0.75) def test_norm_similarity2(self): - dist = watermanSmithBeyer.normalized_similarity("ACTG","AAAG") + dist = waterman_smith_beyer.normalized_similarity("ACTG","AAAG") self.assertEqual(dist, 0.5) def test_norm_similarity3(self): - dist = watermanSmithBeyer.normalized_similarity("ACTG","AAAA") + dist = waterman_smith_beyer.normalized_similarity("ACTG","AAAA") self.assertEqual(dist, 0.25) def test_align(self): - alignment = watermanSmithBeyer.align("BA", "ABA") + alignment = waterman_smith_beyer.align("BA", "ABA") self.assertEqual(alignment, "-BA\nABA") if __name__ == '__main__': diff --git a/tests/test_levenshtein.py b/tests/test_levenshtein.py index 6cf83f5..0eefeef 100644 --- a/tests/test_levenshtein.py +++ b/tests/test_levenshtein.py @@ -1,67 +1,67 @@ from __future__ import annotations import unittest -from limestone.editdistance import levenshteinDist +from limestone.editdistance import levenshtein class TestLevenshtein(unittest.TestCase): def test_distance_diff(self): - dist = levenshteinDist.distance("ACTG","FHYU") + dist = levenshtein.distance("ACTG","FHYU") self.assertEqual(dist, 4.0) def test_similarity_diff(self): - sim = levenshteinDist.similarity("ACTG","FHYU") + sim = levenshtein.similarity("ACTG","FHYU") self.assertEqual(sim, 0.0) def test_norm_distance_diff(self): - dist = levenshteinDist.normalized_distance("ACTG","FHYU") + dist = levenshtein.normalized_distance("ACTG","FHYU") self.assertEqual(dist, 1.0) def test_norm_similarity_diff(self): - sim = levenshteinDist.normalized_similarity("ACTG","FHYU") + sim = levenshtein.normalized_similarity("ACTG","FHYU") self.assertEqual(sim, 0.0) def test_distance_sim(self): - dist = levenshteinDist.distance("ACTG","ACTG") + dist = levenshtein.distance("ACTG","ACTG") self.assertEqual(dist, 0.0) def test_similarity_sim(self): - sim = levenshteinDist.similarity("ACTG","ACTG") + sim = levenshtein.similarity("ACTG","ACTG") self.assertEqual(sim, 4.0) def test_norm_distance_sim(self): - dist = levenshteinDist.normalized_distance("ACTG","ACTG") + dist = levenshtein.normalized_distance("ACTG","ACTG") self.assertEqual(dist, 0.0) def test_norm_similarity_sim(self): - sim = levenshteinDist.normalized_similarity("ACTG","ACTG") + sim = levenshtein.normalized_similarity("ACTG","ACTG") self.assertEqual(sim, 1.0) def test_norm_distance1(self): - dist = levenshteinDist.normalized_distance("ACTG","AATG") + dist = levenshtein.normalized_distance("ACTG","AATG") self.assertEqual(dist, 0.25) def test_norm_distance2(self): - dist = levenshteinDist.normalized_distance("ACTG","AAAG") + dist = levenshtein.normalized_distance("ACTG","AAAG") self.assertEqual(dist, 0.5) def test_norm_distance3(self): - dist = levenshteinDist.normalized_distance("ACTG","AAAA") + dist = levenshtein.normalized_distance("ACTG","AAAA") self.assertEqual(dist, 0.75) def test_norm_similarity1(self): - dist = levenshteinDist.normalized_similarity("ACTG","AATG") + dist = levenshtein.normalized_similarity("ACTG","AATG") self.assertEqual(dist, 0.75) def test_norm_similarity2(self): - dist = levenshteinDist.normalized_similarity("ACTG","AAAG") + dist = levenshtein.normalized_similarity("ACTG","AAAG") self.assertEqual(dist, 0.5) def test_norm_similarity3(self): - dist = levenshteinDist.normalized_similarity("ACTG","AAAA") + dist = levenshtein.normalized_similarity("ACTG","AAAA") self.assertEqual(dist, 0.25) def test_align(self): - alignment = levenshteinDist.align("BA", "ABA") + alignment = levenshtein.align("BA", "ABA") self.assertEqual(alignment, "-BA\nABA") if __name__ == '__main__': diff --git a/tests/test_needlemanwunsch.py b/tests/test_needlemanwunsch.py index 3f20013..fbd0cda 100644 --- a/tests/test_needlemanwunsch.py +++ b/tests/test_needlemanwunsch.py @@ -1,67 +1,67 @@ from __future__ import annotations import unittest -from limestone.editdistance import needlemanWunsch +from limestone.editdistance import needleman_wunsch class TestNeedlemanWunsch(unittest.TestCase): def test_distance_diff(self): - dist = needlemanWunsch.distance("ACTG","FHYU") + dist = needleman_wunsch.distance("ACTG","FHYU") self.assertEqual(dist, 4.0) def test_similarity_diff(self): - sim = needlemanWunsch.similarity("ACTG","FHYU") + sim = needleman_wunsch.similarity("ACTG","FHYU") self.assertEqual(sim, 0.0) def test_norm_distance_diff(self): - dist = needlemanWunsch.normalized_distance("ACTG","FHYU") + dist = needleman_wunsch.normalized_distance("ACTG","FHYU") self.assertEqual(dist, 1.0) def test_norm_similarity_diff(self): - sim = needlemanWunsch.normalized_similarity("ACTG","FHYU") + sim = needleman_wunsch.normalized_similarity("ACTG","FHYU") self.assertEqual(sim, 0.0) def test_distance_sim(self): - dist = needlemanWunsch.distance("ACTG","ACTG") + dist = needleman_wunsch.distance("ACTG","ACTG") self.assertEqual(dist, 0.0) def test_similarity_sim(self): - sim = needlemanWunsch.similarity("ACTG","ACTG") + sim = needleman_wunsch.similarity("ACTG","ACTG") self.assertEqual(sim, 4.0) def test_norm_distance_sim(self): - dist = needlemanWunsch.normalized_distance("ACTG","ACTG") + dist = needleman_wunsch.normalized_distance("ACTG","ACTG") self.assertEqual(dist, 0.0) def test_norm_similarity_sim(self): - sim = needlemanWunsch.normalized_similarity("ACTG","ACTG") + sim = needleman_wunsch.normalized_similarity("ACTG","ACTG") self.assertEqual(sim, 1.0) def test_norm_distance1(self): - dist = needlemanWunsch.normalized_distance("ACTG","AATG") + dist = needleman_wunsch.normalized_distance("ACTG","AATG") self.assertEqual(dist, 0.25) def test_norm_distance2(self): - dist = needlemanWunsch.normalized_distance("ACTG","AAAG") + dist = needleman_wunsch.normalized_distance("ACTG","AAAG") self.assertEqual(dist, 0.5) def test_norm_distance3(self): - dist = needlemanWunsch.normalized_distance("ACTG","AAAA") + dist = needleman_wunsch.normalized_distance("ACTG","AAAA") self.assertEqual(dist, 0.75) def test_norm_similarity1(self): - dist = needlemanWunsch.normalized_similarity("ACTG","AATG") + dist = needleman_wunsch.normalized_similarity("ACTG","AATG") self.assertEqual(dist, 0.75) def test_norm_similarity2(self): - dist = needlemanWunsch.normalized_similarity("ACTG","AAAG") + dist = needleman_wunsch.normalized_similarity("ACTG","AAAG") self.assertEqual(dist, 0.5) def test_norm_similarity3(self): - dist = needlemanWunsch.normalized_similarity("ACTG","AAAA") + dist = needleman_wunsch.normalized_similarity("ACTG","AAAA") self.assertEqual(dist, 0.25) def test_align(self): - alignment = needlemanWunsch.align("BA", "ABA") + alignment = needleman_wunsch.align("BA", "ABA") self.assertEqual(alignment, "-BA\nABA") if __name__ == '__main__':