-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathrepeat_landscape_decimal_050.py
executable file
·80 lines (62 loc) · 1.66 KB
/
repeat_landscape_decimal_050.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/python
import sys
import numpy as np
print "Usage: repeat_landscape_decimal.py AlignFile"
try:
file = sys.argv[1]
except:
file = raw_input("Introduce Align File from RepeatMasker: ")
align = open(file).readlines()
check_name = 0
length = 0
annotation = ""
divs_zero_list = []
for i in np.arange(0,70.1,0.5):
i = round(i,1)
i = str(i)
divs_zero_list.append(i)
#print divs_zero_list
data = {}
for line in align:
info = line.split(" ")
try:
check_name = int(info[0])
except:
check_name = 0
if check_name > 0:
info_5 = int(info[5])
info_6 = int(info[6])
length = 1+info_6-info_5
info_8 = info[8]
info_9 = info[9]
if info_8 != "C":
annotation = info_8
annotation = annotation.split("#")
annotation = annotation[1]
else:
annotation = info_9
annotation = annotation.split("#")
annotation = annotation[1]
if annotation not in data:
data[annotation] = {}
for i in np.arange(0,70.1,0.5):
i = round(i,1)
i = str(i)
data[annotation][i] = 0
if info[0] == "Kimura":
div = info[-1]
div = div[0:-2]
div = float(div)
div = div-(div%0.5)
div = str(div)
data[annotation][div] += length
out = open(file + ".decimal", "w")
header = "Div\t" + "\t".join(divs_zero_list) + "\n"
out.write(header)
for el in data:
collect = [el]
data_el = data[el]
for i in divs_zero_list:
collect.append(str(data_el[i]))
out.write("\t".join(collect)+"\n")
out.close()