-
Notifications
You must be signed in to change notification settings - Fork 1
/
ancestral_Haplo.py
executable file
·64 lines (32 loc) · 1015 Bytes
/
ancestral_Haplo.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
import sys
#give the input file and the column of the ancestral individual
anc_col = int(sys.argv[2])
with open(sys.argv[1]) as file:
for line in file:
line = line.rstrip("\n")
split_line = line.split("\t")
if line.startswith("chr"):
spl1 = [split_line[1]]
new = spl1 + split_line[3:]
print "\t".join(new)
else:
split_line = split_line[0:len(split_line)-1]
ancestral = split_line[(anc_col)-1]
sampled = split_line[3:]
sampled_alleles = set(sampled)
sampled_alleles.remove(ancestral)
if "N" in sampled_alleles:
sampled_alleles.remove("N")
new_line = split_line[1] + "\t"
for ind in sampled:
sampled_alleles_list=list(sampled_alleles)
if (ind == ancestral):
new_line = new_line + "0\t"
elif (ind == "N"):
new_line = new_line + "NA\t"
elif (ind == sampled_alleles_list[0]):
new_line = new_line + "1\t"
else:
new_line = new_line + "2\t"
if not ("2" in new_line.split("\t")[1:]):
print new_line