-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathClassifyRepeats.py
executable file
·42 lines (31 loc) · 1.17 KB
/
ClassifyRepeats.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
#!/usr/bin/env python
import argparse
ap = argparse.ArgumentParser(description="count masked repeats.")
ap.add_argument("table", help="Repeat table.")
ap.add_argument("--fraction", help="Calls must be at least this fraction to be made.", type=float, default=0.51)
args = ap.parse_args()
table = open(args.table, 'r')
table.readline()
table.readline()
table.readline()
indels = dict([("insertion", {}), ("deletion", {})])
for line in table:
vals = line.split()
title = vals[4]
titleVals = title.split('/')
region = titleVals[0]
inordel = titleVals[1]
if (region not in indels[inordel]):
indels[inordel][region] = {}
if (vals[9] not in indels[inordel][region]):
indels[inordel][region][vals[9]] = 0
indels[inordel][region][vals[9]] += 1
for k in ("insertion", "deletion"):
for region in indels[k].keys():
total = 0.0;
for op in indels[k][region].keys():
total += indels[k][region][op]
for op in indels[k][region].keys():
frac = indels[k][region][op] / total
if ( frac >= args.fraction):
print k + "\t" + region + "\t" + op + "\t" + str(frac)