-
Notifications
You must be signed in to change notification settings - Fork 0
/
plink2treemix.py
47 lines (39 loc) · 1007 Bytes
/
plink2treemix.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
#!/usr/bin/python
import sys, os, gzip
if len(sys.argv) < 3:
print "plink2treemix.py [gzipped input file] [gzipped output file]"
print "ERROR: improper command line"
exit(1)
infile = gzip.open(sys.argv[1])
outfile = gzip.open(sys.argv[2], "w")
pop2rs = dict()
rss = list()
rss2 = set()
line = infile.readline()
line = infile.readline()
while line:
line = line.strip().split()
rs = line[1]
pop = line[2]
mc = line[6]
total = line[7]
if rs not in rss2:
rss.append(rs)
rss2.add(rs)
if pop2rs.has_key(pop)==0:
pop2rs[pop] = dict()
if pop2rs[pop].has_key(rs)==0:
pop2rs[pop][rs] = " ".join([mc, total])
line = infile.readline()
pops = pop2rs.keys()
for pop in pops:
print >> outfile, pop,
print >> outfile, ""
for rs in rss:
for pop in pops:
tmp = pop2rs[pop][rs].split()
c1 = int(tmp[0])
c2 = int(tmp[1])
c3 = c2-c1
print >> outfile, ",".join([str(c1), str(c3)]),
print >> outfile, ""