limit fstBC to 30bp in Python3 ver.
[GalaxyCodeBases.git] / python / etc / nID / s2d.py
blobb57348b6c5b135d428e84818a4979291c241dab5
1 #!/usr/bin/env python3
3 import os
4 import csv
6 infile = 'sites.txt'
7 bases = ['A','C','G','T']
8 header = ['rsID','Chr','Pos']
9 headerstr = '\t'.join(header+bases+['sum','dbg'])
10 print(headerstr)
12 with open( infile, 'r' ) as theFile:
13 reader = csv.DictReader(theFile,dialect=csv.excel_tab)
14 for line in reader:
15 # line is { 'workers': 'w0', 'constant': 7.334, 'age': -1.406, ... }
16 # e.g. print( line[ 'workers' ] ) yields 'w0'
17 # print(line)
18 freqs = dict.fromkeys(bases, 0)
19 freqs[line['Alt1']] = line['Freq1']
20 freqs[line['Alt2']] = line['Freq2']
21 freqs[line['Alt3']] = line['Freq3']
22 dbgstr = ','.join([line['Alt1'],line['Freq1'],line['Alt2'],line['Freq2'],line['Alt3'],line['Freq3']])
23 outlist = [line['rsID'],line['Chr'],line['Pos']]
24 sumfreq = 0.0
25 for e in bases:
26 sumfreq += float(freqs[e])
27 outlist.append(str(freqs[e]))
28 outlist.append(str(sumfreq))
29 outlist.append(dbgstr)
30 outstr = '\t'.join(outlist)
31 if sumfreq > 0.1:
32 print(outstr)