-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_dist.py
56 lines (46 loc) · 1.61 KB
/
read_dist.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
47
48
49
50
51
52
53
54
55
import os
import pickle
import pysam
import numpy as np
def bam_dist(in_path, out_path, max_rows):
dist = {}
with pysam.AlignmentFile(in_path, "rb") as in_file:
for ind, line in enumerate(in_file):
if ind >= max_rows:
break
try:
wasp_pass = line.get_tag("vW")
if wasp_pass != 1:
continue
except KeyError:
continue
try:
intersects = line.get_tag("vG")
# print(var) ####
for var in intersects:
dist.setdefault(var, 0)
dist[var] += 1
except KeyError:
continue
# if line.startswith("@"):
# continue
# cols = line.split()
# wasp_pass = False
# var = None
# for col in cols:
# if col.startswith("vW"):
# if col.split(":")[-1] == "1":
# wasp_pass = True
# if col.startswith("vG"):
# var = col
# if (var is not None) and wasp_pass:
# dist.setdefault(var, 0)
# dist[var] += 1
# break
with open(out_path, "wb") as out_file:
pickle.dump(dist, out_file)
if __name__ == '__main__':
data_dir = "/agusevlab/awang/sc_le/"
in_path = os.path.join(data_dir, "processed", "YE_7-19-1", "YE_7-19-1Aligned.sortedByCoord.out.bam")
out_path = os.path.join(data_dir, "variant_dist.pickle")
bam_dist(in_path, out_path, np.inf)