-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.py
41 lines (34 loc) · 1.33 KB
/
dev.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
seqs = [
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"AAAAAAAAAAAAABAAAAAAAABAAAAAAAAAAAAAAAAABAAAAAAA",
"AAAAACAAAAAAABAAAAAABABAAAAAAABABABAAAAAAAAAAAAA",
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"AAAAAAAAAAAAABAAAAAAAABAAAAAAAAAAAAAAAAABAAAAAAA",
"AAAAACAAAAAAABAAAAAABABAAAAAAABABABAAAAAAAAAAAAA",
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
]
def org(sequences) -> int:
"""
Counts the number of segregating sites.
Input:
sequences: list of str, list of sequences.
Returns:
seg_sites: int, number of segregating sites.
"""
seg_sites = 0
# For each position in sequence
for i in range(0, len(sequences[0])):
s = sequences[0][i] # Take the char of first sequence as reference
for seq in sequences: # For each other sequence
if not seq[i] == s:
seg_sites += 1 # Add 1 if not equal
break # And stop comparing this position
return seg_sites
def wany(sequences):
return sum([any([seq[i] != sequences[0][i] for seq in sequences]) for i in range(0, len(sequences[0]))])
# 8
#t_org = timeit.timeit(lambda:org(seqs), number=10000)
#t_wany = timeit.timeit(lambda:wany(seqs), number=10000)
#print(f"{t_org=}")
#print(f"{t_wany=}")