-
Notifications
You must be signed in to change notification settings - Fork 0
/
countingSNPsbyloci.py
executable file
·57 lines (45 loc) · 1.33 KB
/
countingSNPsbyloci.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
#!/usr/bin/env python
#Sarah Stevens
import sys
def usage():
print("Usage: countingSNPsbyloci.py [SNPs_file.csv] [output.tsv]")
print("This program takes a csv file listing all the SNPs found in coding regions by geneious, and counts how many nonsyn and syn SNPs there are for each loci. It outputs this as a tsv.")
if len(sys.argv) != 3:
usage()
exit()
inputfile = open(sys.argv[1], "rU")
outputfile = open(sys.argv[2], "w")
outputfile.write("loci\tsyn\tnonsyn\n")
inputlines = inputfile.readlines()
table = []
for line in inputlines:
table.append(line.split(","))
table.pop(0)
locitable = []
locitable.append(table[0][21])
locicountingsyn = [0]
locicountingnonsyn = [0]
for snp in table:
try:
index = locitable.index(snp[21])
if snp[25] == 'None':
value = locicountingsyn[index]
locicountingsyn[index] = value + 1
else:
value = locicountingnonsyn[index]
locicountingnonsyn[index] = value + 1
except ValueError:
locitable.append(snp[21])
if snp[25] == 'None':
locicountingsyn.append(1)
locicountingnonsyn.append(0)
else:
locicountingsyn.append(0)
locicountingnonsyn.append(1)
for item in locitable:
outputfile.write(str(item)+"\t")
index = locitable.index(item)
outputfile.write(str(locicountingsyn[index])+"\t")
outputfile.write(str(locicountingnonsyn[index])+"\n")
outputfile.close()