forked from sc-zhang/bioscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_QTL_info.py
executable file
·65 lines (59 loc) · 1.54 KB
/
convert_QTL_info.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
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
import sys
def get_tig_pos_of_chr(in_file):
pos_db = {}
with open(in_file, 'r') as f_in:
for line in f_in:
if line.strip() == '':
continue
data = line.strip().split()
if data[4] == 'U':
continue
chrn = data[0]
spos = int(data[1])
epos = int(data[2])
tig = data[5]
direct = data[-1]
pos_db[tig] = [chrn, spos, epos, direct]
return pos_db
def convert_QTL_info(in_QTL, in_agp, out_QTL):
tig_on_chr = get_tig_pos_of_chr(in_agp)
with open(in_QTL, 'r') as fin:
with open(out_QTL, 'w') as fout:
for line in fin:
data = line.strip().split()
if data[0] == 'Pop':
data.extend(['ActChr', 'Left_Pos', 'Right_Pos', 'Direct'])
else:
ltig, lpos = data[4].split('_')
rtig, rpos = data[5].split('_')
lpos = int(lpos)
rpos = int(rpos)
lchr, lsp, lep, ld = tig_on_chr[ltig]
rchr, rsp, rep, rd = tig_on_chr[rtig]
if lchr != rchr:
print(data[1]+"\t"+lchr+"\t"+rchr)
continue
if ld == '-':
lpos = lep-lpos+1
else:
lpos = lsp+lpos-1
if rd == '-':
rpos = rep-rpos+1
else:
rpos = rsp+rpos-1
if lpos > rpos:
tmp = lpos
lpos = rpos
rpos = tmp
direct = "-"
else:
direct = "+"
data.extend([lchr, str(lpos), str(rpos), direct])
fout.write("%s\n"%'\t'.join(data))
if __name__ == "__main__":
if len(sys.argv) < 4:
print("Usage: python "+sys.argv[0]+" <in_QTL> <in_agp> <out_QTL>")
else:
in_QTL, in_agp, out_QTL = sys.argv[1:]
convert_QTL_info(in_QTL, in_agp, out_QTL)