-
Notifications
You must be signed in to change notification settings - Fork 3
/
GUI.py
340 lines (291 loc) · 12.4 KB
/
GUI.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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
import threading
from tkinter import *
import tkinter as tk
from tkinter import messagebox, filedialog
import os
import sys #.path import append as append_system_path
import webbrowser
#global variables
DEFULT_ENTRY_CSV_MSG = "Enter .csv file"
Fasta_File_name = ""
csv_file_name = ""
restriction_file_name = ""
ouput_file_location = ""
# 3rd option not shown.
is_3_shown = False
protein_fasta_filename = ""
fasta_file_name = ""
codon_usage_tables_filnames_list = []
MOOLTI_2018 = "MOOLTi 2018"
def open_hebrew_u_website():
"""
prints the official iGEM website for Hebrew U
:return:
"""
webbrowser.open("http://2018.igem.org/Team:HebrewU")
#-------------------------------HebrewU 1 window------------------------------------------
def create_Hebrew_U_window():
"""
creates and runs the main loop for the first screen of the MOOLTI tool.
:return:
"""
root2 = Tk()
root2.configure(background='#00B2B2')
root2.geometry("700x422")
root2.resizable(width=False, height=False)
root2.title("MOOLTi 2018 HebrewU ")
#rectangles wiht colours
canvas = Canvas(root2, width = 700, height = 422)
canvas.pack()
myrectangle1 = canvas.create_rectangle(0, 0, 700, 65, fill='black')
canvas.itemconfig(myrectangle1, fill='#00B2B2')
#gui name
gui_MulT = Label(root2, text="MOOLTi",font=("Calibri", 23),bg="#00B2B2",fg="white")
gui_descriptio_MulT = Label(root2, text=" Multiple Organism Optimization Lab Tool for iGEM ",font=("Calibri", 12),bg="#00B2B2",fg="white")
#create labels
fasta_label = Label(root2, text="Upload protein fasta file :", bg="#F0F0F0",font=("calibri",11))
restriction_label = Label(root2, text="Upload restriction sites file (optional) :", bg="#F0F0F0",font=("calibri",11))
destination_label = Label(root2, text="Enter destination file:", bg="#F0F0F0",font=("calibri",11))
def second_menu():
"""
validates input, continues to second menu
:return:
"""
global restriction_file_name
global ouput_file_location
global protein_fasta_filename
global fasta_file_name
restriction_file_name = restriction_entry.get()
protein_fasta_filename = fasta_entry.get()
ouput_file_location = output_entry.get()
if protein_fasta_filename == "" or protein_fasta_filename.split(".")[-1]!= "fasta":
messagebox.showinfo('MOOLTi 2018',
'Please select a FASTA file')
return
if not os.path.exists(protein_fasta_filename) :
messagebox.showinfo(MOOLTI_2018,
'Invalid or unexisting FASTA file, please select another')
return
if not os.path.exists(protein_fasta_filename) and protein_fasta_filename != "" :
messagebox.showinfo(MOOLTI_2018,"Non- existing restriction file. ")
return
root2.destroy()
create_second_hebrew_U_window()
#next button
Screen1_next2 = tk.Button(root2,text="Next",font=("Calibri", 15 ), command =second_menu )
#creates entrys
output_entry = Entry(root2)
fasta_entry = Entry(root2)
restriction_entry = Entry(root2)
global ouput_file_location
global protein_fasta_filename
global restriction_file_name
#makes sure the value isn't lost between screens
fasta_entry.insert(0, protein_fasta_filename)
restriction_entry.insert(0, restriction_file_name)
output_entry.insert(0, ouput_file_location)
# select file with sequences
def input_file2():
"""
inserts the input into the fasta variable
:return:
"""
# open the file with the sequences
global protein_fasta_filename
if protein_fasta_filename != "":
fasta_entry.delete(0, END)
protein_fasta_filename = filedialog.askopenfilename()
fasta_entry.insert(0, protein_fasta_filename)
def input_file3():
# open the file with the sequences
global restriction_file_name
if restriction_file_name != "":
restriction_entry.delete(0, END)
messagebox.showinfo('MOOTI 2018',
'Please enter a text file containing restriction enzymes names, sperated by a comma.'
' for example:\n EcoRI,HindIII,BamHI \n It\'s case sensitive !')
restriction_file_name = filedialog.askopenfilename()
with open(restriction_file_name, 'r') as content_file:
content = content_file.read()
restriction_entry.insert(0, content)
def output_file():
"""
saves the ouput file location
:return:
"""
# open the file with the sequences
global ouput_file_location
if ouput_file_location != "":
output_entry.delete(0, END)
ouput_file_location = filedialog.askopenfilename()
#show in entry
output_entry.insert(0, ouput_file_location)
#create buttons
fasta_search_button = Button(root2, text="Search file", fg="black", bg="white", command=input_file2, relief=RAISED,
borderwidth=3)
search_restriction_button = Button(root2, text="Search file", fg="black", bg="white", command=input_file3, relief=RAISED,
borderwidth=3)
output_search_button = Button(root2, text="Select folder", fg="black", bg="white", command=output_file, relief=RAISED,
borderwidth=3)
# place buttons in window by coordinates
fasta_search_button.place(x=380, y=163)
output_search_button.place(x=380, y=223)
search_restriction_button.place(x = 380, y = 280)
Screen1_next2.place(x=600,y=325)
#place entrys
fasta_entry.place(x = 480, y = 167)
output_entry.place(x = 480, y = 225)
restriction_entry.place(x = 480, y = 280)
#place labels
fasta_label.place(x=100,y=167)
destination_label.place(x=100,y=227)
restriction_label.place(x=100, y=277)
ouput_file_location = output_entry.get()
global restriction_file_name
restriction_file_name = restriction_entry.get()
gui_MulT.place(x=320,y=4)
gui_descriptio_MulT.place(x=210,y=40)
root2.mainloop()
#-------------------------------HebrewU 2 window------------------------------------------
def create_second_hebrew_U_window():
"""
creates and runs the main loop for the first screen of the MOOLTI tool.
:return:
"""
root3 = Tk()
root3.configure(background='#00B2B2')
root3.geometry("700x422")
root3.resizable(width=False, height=False)
root3.title("MOOLTi 2018 HebrewU")
global codon_usage_tables_filnames_list
def get_back_to_second_window():
"""
closes the current screen and proceedes to the second menu
:return:
"""
root3.destroy()
create_Hebrew_U_window()
#rectangles wiht colours
canvas = Canvas(root3, width = 700, height = 422)
canvas.pack()
myrectangle1 = canvas.create_rectangle(0, 0, 700, 65, fill='black')
canvas.itemconfig(myrectangle1, fill='#00B2B2')
#gui name
gui_MulT4 = Label(root3, text="MOOLTi", font=("Calibri", 23), bg="#00B2B2", fg="white")
gui_descriptio_MulT4 = Label(root3, text=" Multiple Organism Optimization Lab Tool for iGEM", font=("Calibri", 12),bg="#00B2B2",fg="white")
# select file with sequences
def input_file(v):
"""
a generalized input function
:param v: the entry variable to fill
:return:
"""
# open the file with the sequences
v.delete(0,END)
v.insert(0, filedialog.askopenfilename())
# Buttons and labels for more and optimizze buttons
def addmore():
"""
shows one or two more buttons
:return:
"""
global is_3_shown
if is_3_shown == False:
label_3.place(x=100, y=244)
v3.place(x=430, y=244)
third_organism_button.place(x=340, y=244)
is_3_shown = True
else:
label_4.place(x=100, y=296)
v4.place(x=430, y=296)
fourth_organism_button.place(x=340, y=296)
#Buttons and labels for more and optimizze buttons
button_more = Button(root3, text="Add more organisms", bg="#F0F0F0", font=("calibri", 15), command=addmore)
button_back = Button(root3, text="Back", bg="#F0F0F0", font=("calibri", 15), command=get_back_to_second_window)
first_organism_button = Button(root3, text="Search file", fg="black", bg="white", command=lambda: input_file(v1), relief=RAISED,
borderwidth=3)
second_organism_button = Button(root3, text="Search file", fg="black", bg="white", command=lambda: input_file(v2),
relief=RAISED,
borderwidth=3)
third_organism_button = Button(root3, text="Search file", fg="black", bg="white", command=lambda: input_file(v3),
relief=RAISED,
borderwidth=3)
fourth_organism_button = Button(root3, text="Search file", fg="black", bg="white", command=lambda: input_file(v4),
relief=RAISED,
borderwidth=3)
#create labels
label_compatible = Label(root3, text="Compatible organisms :", bg="#F0F0F0", font=("calibri", 15))
label_1 = Label(root3, text="Add organism codon usage table file:", bg="#F0F0F0", font=("calibri", 11))
label_2 = Label(root3, text="Add organism codon usage table file:", bg="#F0F0F0", font=("calibri", 11))
label_3 = Label(root3, text="Add organism codon usage table file:", bg="#F0F0F0", font=("calibri", 11))
label_4 = Label(root3, text="Add organism codon usage table file:", bg="#F0F0F0", font=("calibri", 11))
#placements
button_back.place(x = 100, y = 350)
button_more.place(x=230, y=350)
first_organism_button.place(x=340, y=140)
second_organism_button.place(x=340, y=192)
label_compatible.place(x=100, y=100)
label_1.place(x=100, y=140)
label_2.place(x=100, y=192)
#first organizm
v1 = Entry(root3)
v1.insert(0,DEFULT_ENTRY_CSV_MSG) # default value
v1.place(x=430, y=140)
#second organizm
v2 = Entry(root3)
v2.insert(0, DEFULT_ENTRY_CSV_MSG) # default value
v2.place(x=430, y=192)
# 3rd organizm
v3 = Entry(root3)
v3.insert(0, DEFULT_ENTRY_CSV_MSG)
# 4th organizm
v4 = Entry(root3)
v4.insert(0, DEFULT_ENTRY_CSV_MSG)
boolvar = IntVar()
boolvar.set(3)
def run_optimization():
"""
uses user input to run the MOOLTI Codon Optimization
:return:
"""
sys.path.append(os.path.join(sys.path[0], "CodonOptimization"))
import Main
global protein_fasta_filename
name1 = v1.get()
name2 = v1.get()
name3 = v1.get()
name4 = v1.get()
codon_usage_tables_filnames_list = []
if name1 != DEFULT_ENTRY_CSV_MSG:
codon_usage_tables_filnames_list.append(name1)
if name2 != DEFULT_ENTRY_CSV_MSG:
codon_usage_tables_filnames_list.append(name2)
if name3 != DEFULT_ENTRY_CSV_MSG:
codon_usage_tables_filnames_list.append(name3)
if name4 != DEFULT_ENTRY_CSV_MSG:
codon_usage_tables_filnames_list.append(name4)
protein_fasta_filename = protein_fasta_filename
global ouput_file_location
global restriction_file_name
opened_files = [open(filename, "r") for filename in codon_usage_tables_filnames_list]
opened_files = [(open_file.name, open_file ) for open_file in opened_files]
with open(protein_fasta_filename, mode = "r") as opened_fasta_file, open(ouput_file_location, 'w') as opened_output_file:
return Main.main(protein_fasta_open_file=opened_fasta_file,
list_codon_usage_open_files=opened_files,
output_destination=opened_output_file,restriction_enzymes = restriction_file_name , run_from_server = False)
def handle_click():
"""
handles the button click, and the sucsess or failure of the Codon optimization function
:return:
"""
Message = run_optimization()
messagebox.showinfo(MOOLTI_2018, Message)
root3.destroy()
create_Hebrew_U_window()
Screen3_Optimize = Button(root3, text="Optimize", font=("Calibri", 15), command=handle_click)
Screen3_Optimize.place(x=500, y=350)
gui_MulT4.place(x=320,y=4)
gui_descriptio_MulT4.place(x=210,y=40)
root3.mainloop()
if __name__ == '__main__':
create_Hebrew_U_window()