-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchrome.py
More file actions
executable file
·50 lines (48 loc) · 1.55 KB
/
Copy pathchrome.py
File metadata and controls
executable file
·50 lines (48 loc) · 1.55 KB
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
#!/usr/bin/env python3
import sys
import pickle
chromes = {}
for i in range(1, 23):
chromes['chr' + str(i) + '+'] = [1000000000, 0]
chromes['chr' + str(i) + '-'] = [1000000000, 0]
chromes['chrX+'] = [1000000000, 0]
chromes['chrX-'] = [1000000000, 0]
chromes['chrY+'] = [1000000000, 0]
chromes['chrY-'] = [1000000000, 0]
chromes['chrM+'] = [1000000000, 0]
chromes['chrM-'] = [1000000000, 0]
#print(chromes)
lookup = {}
with open('meta/gencode.v19.annotation.gtf', 'r') as f:
for l in f:
if l[:3] == 'chr':
fs = l.strip().split('\t')
chrome = fs[0]
start = int(fs[3])
end = int(fs[4])
strand = fs[6]
if start > end:
print(chrome, start, end, strand)
be = chromes[chrome + strand]
if start < be[0]:
be[0] = start
if end > be[1]:
be[1] = end
name_off = l.find('gene_name')
if name_off < 0:
continue
name_off = l.find('"', name_off)
if name_off < 0:
continue
name_off += 1
name_end = l.find('"', name_off)
if name_end < 0:
continue
name = l[name_off:name_end]
#print(chrome, start, end, strand, name)
lookup.setdefault(name, []).append([chrome, start, end, strand])
pass
#with open('data/chromsome.pkl', 'wb') as f:
# pickle.dump(lookup, f)
with open('data/chrome.pkl', 'wb') as f:
pickle.dump((chromes, lookup), f)