forked from mtarbit/Rosalind-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e005-hamm.py
executable file
·47 lines (35 loc) · 881 Bytes
/
e005-hamm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
# Counting Point Mutations
# ========================
#
# Given two strings s and t of equal length, the Hamming distance between s and
# t, denoted dH(s,t), is the number of corresponding symbols that differ in s
# and t. See Figure 2.
#
# Given: Two DNA strings s and t of equal length (not exceeding 1 kbp).
#
# Return: The Hamming distance dH(s,t).
#
# Sample Dataset
# --------------
# GAGCCTACTAACGGGAT
# CATCGTAATGACGGCCT
#
# Sample Output
# -------------
# 7
def hamming_distance(s, t):
dh = 0
for i, c in enumerate(s):
if c != t[i]:
dh += 1
return dh
if __name__ == "__main__":
small_dataset = """
GAGCCTACTAACGGGAT
CATCGTAATGACGGCCT
"""
large_dataset = open('datasets/rosalind_hamm.txt').read()
s, t = large_dataset.split()
dist = hamming_distance(s, t)
print dist