-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu_mod.py
311 lines (210 loc) · 9.47 KB
/
menu_mod.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#Menu Interfacer in that Menu.py file
#-------------------------------------------------------------------------------------------------------------------------------------------
def options(menu):
import gffloader
import fastaloader
qq=0
tt=0
#Load fasta files:
#-------------------------------------------------------------------------------------------------------------------------------------------
if menu == "1" or menu == "F":
import fastaloader
f = input("Enter the fasta file name to be entered, character for character : ")
fastaloader.fasta_loader(f)
qq=0
for seq in fastaloader.slist:
qq = qq + 1
while f != '':
f = input("Enter another fasta file name to be entered, character for character, or press [Enter] to go back to the Menu: ")
if f == "":
return f
break
else:
fastaloader.fasta_loader(f)
for seq in fastaloader.slist:
qq = qq + 1
#Load gff files #--------------------------------------------------------------------------------------------------------------------------------------------
elif menu == "2" or menu == "G":
import gffloader
g = input("Enter the gff file to be entered, character for character : ")
gffloader.gff_loader(g)
while g != '':
g = input("Enter another gff file to be entered, or press [Enter] to go back to the Menu: ")
if g == "":
return g
break
else:
gffloader.gff_loader(g)
#Annotation explorer: #---------------------------------------------------------------------------------------------------------------------------------------------
elif menu == "3" or menu == "A":
seq1 = input("Which sequence's annotations would you like to view? \n")
seq2 = []
for anno in gffloader.alist:
seq2.append(anno.SEQREF)
noanno = 0
noanno = seq2.count(seq1)
if noanno == 0:
print("Sequence %s has no annotations. \n\n" %(seq1))
return ""
else:
print("The sequence %s has %i annotations:\n" %(seq1, noanno))
tempdiction = {}
for seq in fastaloader.slist:
tempdiction[seq.IDY] = seq.SEQ
tempsublist = []
templist = []
for anno in gffloader.alist:
tempsublist = []
tempsublist.append(anno.SEQREF)
tempsublist.append(anno.SRC)
tempsublist.append(anno.FEAT)
tempsublist.append(int(anno.START))
tempsublist.append(int(anno.STOP))
tempsublist.append(anno.SCORE)
tempsublist.append(anno.STRAND)
tempsublist.append(anno.FSE)
tempsublist.append(anno.GRP)
if seq1 == tempsublist[0]:
templist.append(tempsublist)
for p in range(len(templist)):
smin10 = 0
smax10 = 0
left = ''
right = ''
middle = ''
if seq1.lower() not in tempdiction: #warning for no seq loaded
input("Annotation %s. %s(%s)\n------------------------------------------------------------\nWARNING: No sequence loaded for sequence id %s!!!\nSTART: %i\nSTOP: %i\nSCORE: %s \nSTRAND: %s\nPHASE: %s\nGROUP: %s\n\nPress [enter] for the next annotation, else [M] to return to Menu: \n" %((p+1), templist[p][2], templist[p][1], seq1, int(templist[p][3]), int(templist[p][4]), templist[p][5], templist[p][6], templist[p][7], templist[p][8]))
else:
if (int(templist[p][3])-1) > 10:
smin10 = int(templist[p][3])-11
else:
smin10 = 1
if (int(templist[p][4])+1) < len(tempdiction[str(templist[p][0]).lower()])-11:
smax10 = int(templist[p][4])+11
else:
smax10 = len(tempdiction[str(templist[p][0]).lower()])
left = tempdiction[str(templist[p][0]).lower()][smin10:int(templist[p][3])-1].lower()
middle = tempdiction[str(templist[p][0]).lower()][int(templist[p][3]):int(templist[p][4])]
right = tempdiction[str(templist[p][0]).lower()][int(templist[p][4])+1:smax10].lower() #formatting seq portions
input("Annotation %s. %s(%s)\n------------------------------------------------------------\n...(%i)\n%s%s%s\n(%i)...\nSCORE: %s\nSTRAND: %s\nPHASE: %s\nGROUP: %s\n\nPress [enter] for the next annotation, else [M] to return to Menu: \n" %((p+1), templist[p][2], templist[p][1], smin10, left, middle, right, smax10, templist[p][5], templist[p][6], templist[p][7], templist[p][8]))
return ""
#Annotation Creator #------------------------------------------------------------------------------------------------------------------------------------------------
elif menu == "4" or menu == "C":
ant = input("For which sequence would you like to create annotations? ") #first annotation entry
s = input("Source : ")
fe = input("Feature : ")
sta = input("Start : ")
sto = input("Stop : ")
sco = input("Score : ")
st = input("Strand : ")
ph = input("Phase : ")
gr = input("Group : ")
anno = gffloader.Annotate(ant, s, fe, sta, sto, sco, st, ph, gr)
gffloader.alist.append(anno)
temp2diction = {}
for seq in fastaloader.slist:
temp2diction[seq.IDY] = seq.SEQ
smin10 = 0
smax10 = 0
left = ''
right = ''
middle = ''
annan = 'y'
if ant.lower() not in temp2diction:
annan = input("New Annotation : %s(%s)\n------------------------------------------------------------\nWARNING: No sequence loaded for sequence id %s!!!\nSTART: %i\nSTOP: %i\nSCORE: %s \nSTRAND: %s\nPHASE: %s\nGROUP: %s\nWould you like to create another annotation for this sequence ID? [y/n] \n" %(fe, s, ant, int(sta), int(sto), sco, st, ph, gr))
else:
if (int(sta)-1) > 10:
smin10 = int(sta)-11
else:
smin10 = 1
if (int(sto)+1) < len(temp2diction[ant.lower()])-11:
smax10 = int(sto)+11
else:
smax10 = len(temp2diction[ant.lower()])
left = temp2diction[ant.lower()][smin10:int(sta)-1].lower()
middle = temp2diction[ant.lower()][int(sta):int(sto)]
right = temp2diction[ant.lower()][int(sto)+1:smax10].lower()
annan = input("New Annotation : %s(%s)\n------------------------------------------------------------\n...(%i)\n%s%s%s\n(%i)...\nSCORE: %s\nSTRAND: %s\nPHASE: %s\nGROUP: %s\nWould you like to create another annotation for this sequence ID? [y/n] \n\n" %(fe, s, smin10, left, middle, right, smax10, sco, st, ph, gr))
while annan == "y": #subsequent annotation entries
ant = input("For which sequence would you like to create annotations? ")
s = input("Source : ")
fe = input("Feature : ")
sta = input("Start : ")
sto = input("Stop : ")
sco = input("Score : ")
st = input("Strand : ")
ph = input("Phase : ")
gr = input("Group : ")
anno = gffloader.Annotate(ant, s, fe, sta, sto, sco, st, ph, gr)
gffloader.alist.append(anno)
temp2diction = {}
for seq in fastaloader.slist:
temp2diction[seq.IDY] = seq.SEQ
smin10 = 0
smax10 = 0
left = ''
right = ''
middle = ''
if ant.lower() not in temp2diction:
annan = input("New Annotation : %s(%s)\n------------------------------------------------------------\nWARNING: No sequence loaded for sequence id %s!!!\nSTART: %i\nSTOP: %i\nSCORE: %s \nSTRAND: %s\nPHASE: %s\nGROUP: %s\n\nWould you like to create another annotation for this sequence ID? [y/n] \n" %(fe, s, ant, int(sta), int(sto), sco, st, ph, gr))
else:
if (int(sta)-1) > 10:
smin10 = int(sta)-11
else:
smin10 = 1
if (int(sto)+1) < len(temp2diction[ant.lower()])-11:
smax10 = int(sto)+11
else:
smax10 = len(temp2diction[ant.lower()])
left = temp2diction[ant.lower()][smin10:int(sta)-1].lower()
middle = temp2diction[ant.lower()][int(sta):int(sto)]
right = temp2diction[ant.lower()][int(sto)+1:smax10].lower()
annan = input("New Annotation : %s(%s)\n------------------------------------------------------------\n...(%i)\n%s%s%s\n(%i)...\nSCORE: %s\nSTRAND: %s\nPHASE: %s\nGROUP: %s\n\nWould you like to create another annotation for this sequence ID? [y/n] \n" %(fe, s, smin10, left, middle, right, smax10, sco, st, ph, gr))
return ""
#Export to File: #---------------------------------------------------------------------------------------------------------------------------------------------
elif menu == "5" or menu == "X":
ex = input("Filter by sequence ID or [all]? ")
name = input("File path : ")
mkgff = open(str(name), "w")
temp3diction = {}
for seq in fastaloader.slist:
temp3diction[seq.IDY] = seq.SEQ
if ex == "all":
tempsublist = []
for anno in gffloader.alist:
tempsublist = []
tempsublist.append(anno.SEQREF)
tempsublist.append(anno.SRC)
tempsublist.append(anno.FEAT)
tempsublist.append(anno.START)
tempsublist.append(anno.STOP)
tempsublist.append(anno.SCORE)
tempsublist.append(anno.STRAND)
tempsublist.append(anno.FSE)
tempsublist.append(anno.GRP)
mkgff.write("\t".join(tempsublist)+"\n")
else:
tempsublist = []
for anno in gffloader.alist:
tempsublist = []
tempsublist.append(anno.SEQREF)
tempsublist.append(anno.SRC)
tempsublist.append(anno.FEAT)
tempsublist.append(anno.START)
tempsublist.append(anno.STOP)
tempsublist.append(anno.SCORE)
tempsublist.append(anno.STRAND)
tempsublist.append(anno.FSE)
tempsublist.append(anno.GRP)
if ex == tempsublist[0]:
mkgff.write("\t".join(tempsublist)+"\n")
mkgff.close()
return input("FILE SAVED.\nPress [Enter] to go back to the Menu.")
#Quit:
#-------------------------------------------------------------------------------------------------------------------------------------------
elif menu == "6" or menu == "Q":
last = input("Do you want to exit [Enter] or do you want go back to the menu? (M)")
if last == "":
return "exit"
if last == "M":
return ""