Repository navigation
Expand file tree
/
Copy pathExclude_related.py
More file actions
110 lines (85 loc) · 2.55 KB
/
Copy pathExclude_related.py
File metadata and controls
110 lines (85 loc) · 2.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""
Extract related individuals
"""
import os, sys, gzip, datetime
def main(chrom):
#infile = "/gpfs/group/stsi/data/projects/wellderly/GenomeComb/vcf_allFilters_36kmer_snpsOnly_AF0.01/vcf_nokmer_snps_AF0.01." + chrom + ".vcf.gz"
#outfile = "/gpfs/group/stsi/data/projects/wellderly/GenomeComb/vcf_allFilters_36kmer_snpsOnly_AF0.01/vcf_nokmer_snps_AF0.01.noRelated." + chrom + ".vcf.gz"
#For the riskogram
infile = "/gpfs/group/stsi/data/projects/wellderly/GenomeComb/vcf_snps_of_interest/filtered_snps.withHead.txt"
outfile = "/gpfs/group/stsi/data/projects/wellderly/GenomeComb/vcf_snps_of_interest/filtered_snps.noRelated.withHead.txt"
relatedfile = "/gpfs/group/stsi/data/projects/wellderly/GenomeComb/vcf_allFilters_36kmer_snpsOnly_AF0.01/eliminate_individuals.txt"
w = open(relatedfile)
header = []
#index the whites
ln = w.readline()
ln = ln.strip()
#Create dictionary here instead
whites_id = ln.split("\t")
#i = gzip.open(infile)
#o = gzip.open(outfile, 'w')
i = open(infile)
o = open(outfile, 'w')
counter_white = 0
counter = 0
buffe = ""
for line in i:
if line[:2] == "##":
print "header"
o.write(line)
#Extract only the white individuals ID
elif line[0] == "#":
#o.write(line)
line = line.strip()
header = line.split("\t")
final_header = "\t".join(header[:9])
for index, gen in enumerate(header[9:]):
index = index +9
#Extract whites only
if gen in whites_id:
continue
else:
final_header = final_header + "\t" + gen
counter_white += 1
final_header = final_header + "\n"
o.write(final_header)
print "# of whites " + str(counter_white)
else:
counter += 1
line = line.strip()
tp_line = line.split("\t")
white_line = "\t".join(tp_line[:9])
#count_id = 0
for index, gen in enumerate(tp_line[9:]):
index = index +9
indiv_name = header[index]
if indiv_name in whites_id:
continue
else:
#count_id += 1
white_line = white_line + "\t" + gen
buffe = buffe + white_line + "\n"
if counter%100 == 0:
o.write(buffe)
buffe = ""
o.flush()
if counter%10000 ==0:
print "Total lines"
print str(counter)
sys.stdout.flush()
o.write(buffe)
i.close()
o.close()
#clus.close()
print "Total lines"
print str(counter)
print "End"
if __name__ == '__main__':
print "Python Version: " + sys.version
#args = parse_args()
#import time
#start = time.time()
main(sys.argv[1])
#main(sys.argv[1], sys.argv[2], sys.argv[3])
#end = time.time()
#print 'This took {0} seconds'.format(end - start)