-
Notifications
You must be signed in to change notification settings - Fork 1
/
hmmer_txt_parser.py
executable file
·107 lines (95 loc) · 2.59 KB
/
hmmer_txt_parser.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
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
__author__ = "Bruno Fosso"
__version__ = "1.0"
import os
from string import strip
if os.path.exists("hmm_match_data/align_18S_data.txt"):
print "18S alignment data exist"
else:
print "No 18S alignment data"
exit()
if os.path.exists("hmm_match_data/align_5_8S_data.txt"):
print "5.8S alignment data exist"
else:
print "No 5.8S alignment data"
exit()
print "5.8S ALIGNEMENT EXTRACTION"
os.mkdir("hmm_match_data/5_8S_alignment_file")
f = open("hmm_match_data/align_5_8S_data.txt")
lines = f.readlines()
f.close()
count = 0
stop_file = len(lines) - 15
line2acc = {}
line_num = []
while count <= stop_file:
if lines[count][0:2] == ">>":
s = map(strip, lines[count].split(" "))
acc = s[1]
print acc
line2acc[count] = acc
line_num.append(count)
count += 1
else:
count += 1
line_num.sort()
index = 0
stop = len(line_num)
while index < stop:
if index != stop - 1:
inizio = line_num[index]
fine = line_num[index + 1]
acc = line2acc[inizio]
#print inizio,fine
tmp = open("hmm_match_data/5_8S_alignment_file/" + acc + ".align", "w")
tmp.write("".join(lines[inizio:fine]))
tmp.close()
index += 1
else:
inizio = line_num[index]
fine = stop_file
acc = line2acc[inizio]
tmp = open("hmm_match_data/5_8S_alignment_file/" + acc + ".align", "w")
tmp.write("".join(lines[inizio:fine]))
tmp.close()
index += 1
print "18S ALIGNEMENT EXTRACTION"
os.mkdir("hmm_match_data/18S_alignment_file")
f = open("hmm_match_data/align_18S_data.txt")
lines = f.readlines()
f.close()
count = 0
stop_file = len(lines) - 15
line2acc = {}
line_num = []
while count <= stop_file:
if lines[count][0:2] == ">>":
s = map(strip, lines[count].split(" "))
acc = s[1]
#print acc
line2acc[count] = acc
line_num.append(count)
count += 1
else:
count += 1
line_num.sort()
index = 0
stop = len(line_num)
while index < stop:
if index != stop - 1:
inizio = line_num[index]
fine = line_num[index + 1]
acc = line2acc[inizio]
#print inizio,fine
tmp = open("hmm_match_data/18S_alignment_file/" + acc + ".align", "w")
tmp.write("".join(lines[inizio:fine]))
tmp.close()
index += 1
else:
inizio = line_num[index]
fine = stop_file
acc = line2acc[inizio]
tmp = open("hmm_match_data/18S_alignment_file/" + acc + ".align", "w")
tmp.write("".join(lines[inizio:fine]))
tmp.close()
index += 1
print "FINISH"