-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathshift.py
More file actions
42 lines (32 loc) · 981 Bytes
/
Copy pathshift.py
File metadata and controls
42 lines (32 loc) · 981 Bytes
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
import sys
from timeit import timeit
from typing import List, Tuple
sys.path.insert(0, '../shared')
ENCODE_SNPS = 14
def encode_snps(snps: List[str]) -> Tuple[Tuple[str], List[int]]:
allele_pos = tuple(set(snps))
enc_list = []
for i in range(len(snps) // ENCODE_SNPS):
enc = 0
for j in range(ENCODE_SNPS):
if j > 0:
enc <<= 2
enc += allele_pos.index(snps[i * ENCODE_SNPS + j])
enc_list.append(enc)
return allele_pos, enc_list
def get_chrom(my_chrom: int):
calls = []
with open('my_hapmap.tped') as f:
for l in f:
toks = l.rstrip().split(' ')
chrom = int(toks[0])
if chrom < my_chrom:
continue
if chrom > my_chrom:
break
calls.append(encode_snps(toks[4:])[1])
return calls
calls = get_chrom(1)
print(len(calls[0]))
print(sys.getsizeof(calls[0]))
print(sys.getsizeof(calls[0][0]))