-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowDynamicFunctional.py
More file actions
678 lines (581 loc) · 32.5 KB
/
Copy pathWindowDynamicFunctional.py
File metadata and controls
678 lines (581 loc) · 32.5 KB
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
#import config module for environmental variability
import config
#import my utility class and function
import MyUtility
#import my multi threading function to upload and download file
from MyMultiThreading import *
#tkinter import
import tkinter as tk
from tkinter import *
from tkinter import filedialog
from tkinter.filedialog import askopenfile
from tkinter.messagebox import showinfo
#pandas import
import pandas as pd
#random import
import random
#importo os
import os
# importing the threading module
from threading import Thread
#import loading window
import WindowLoading as wLd
#import next window
import WindowSummaryMetricsPre as wSMpr
class DynamicFunctionalWindow(tk.Toplevel): #tk.Tk):
def __init__(self, wn_root, wn_previous, previousDf):
super().__init__()
#change icon
img = PhotoImage(file=resource_path(config.icon))
self.iconphoto(False, img)
#take the root window
self.wn_root = wn_root
#take the previous window
self.wn_previous = wn_previous
#take the old df
self.df = previousDf;
#check if file is load
self.isFileLoad = False
#preapre df
self.df_annotation = pd.DataFrame()
# configure the root window
self.title('Functional annotation')
### left area ###
#Load/download frame
self.frame_left = tk.Frame(self, borderwidth=2, relief='flat')
self.frame_left.grid(row=0, column=0, padx=2, pady=2, sticky="nsew")
#Load button
self.btn_loadFile = tk.Button(self.frame_left, text='Upload annotation file', bg='yellow', font=config.font_button, width=20, command=self.upload_file)
self.btn_loadFile.grid(row=0, column=0, padx=5, pady=5)
#label template
self.lbl_loadedFile = tk.Label(self.frame_left, text='No file',width=30,font=config.font_up_base)
self.lbl_loadedFile.grid(row=1, column=0, padx=5, pady=5)
#Fill with unassigned
self.var_chc_unassigned = IntVar(value=0)
self.chc_unassigned = tk.Checkbutton(self.frame_left, text='Replace missing values with \'unassigned\'',
width=34, anchor="w", variable=self.var_chc_unassigned, onvalue=1, offvalue=0)
self.chc_unassigned.grid(row=2, column=0, padx=5, pady=10)
self.chc_unassigned.config(font = config.font_checkbox )
#Equate I and L
if( (MyUtility.workDict["mode"] != 'Proteins') and (MyUtility.workDict['functional_match'] == 'peptide')):
self.var_chc_IandL = IntVar(value=0)
self.chc_IandL = tk.Checkbutton(self.frame_left, text='Isoleucines replaced by leucines in peptide sequences',
wraplength=250, width=34, anchor="w", variable=self.var_chc_IandL, onvalue=1, offvalue=0)
self.chc_IandL.grid(row=3, column=0, padx=5, pady=10)
self.chc_IandL.config(font = config.font_checkbox )
#Download button
self.btn_download = tk.Button(self.frame_left, text='Download annotated table', bg='lime', font=config.font_button, width=20,command=self.download)
self.btn_download.grid(row=5, column=0, padx=5, pady=5)
### centre area ###
#title frame
self.frame_centre = tk.Frame(self, borderwidth=2, relief='flat')
self.frame_centre.grid(row=0, column=1, padx=2, pady=2,sticky="nsew")
#title of editing
self.lbl_fileter = tk.Label(self.frame_centre,text='Column selection',width=20,font=config.font_title)
self.lbl_fileter.grid(row=0, column=0, columnspan=2, padx=6, pady=6, sticky='ew')
#riquadro con le colonne da scegliere
self.make_columnsHeaders(p_row=1, p_column=0, p_rowspan=7, p_sticky='n')
#primary key use to join
if(MyUtility.workDict['mode'] == 'Proteins'):
self.make_proteinAccession(p_row=1, p_column=1, p_name='Accession', p_sticky='n')
else:
if(MyUtility.workDict['functional_match'] == 'protein'):
self.make_proteinAccession(p_row=1, p_column=1, p_name='Protein Accessions', p_sticky='n')
else: #peptide
self.make_peptideSequence(p_row=1, p_column=1, p_sticky='n')
#columns for KEGG
self.make_kegg_ko(p_row=2, p_column=1, p_sticky='n')
self.make_kegg_pathway(p_row=3, p_column=1, p_sticky='n')
self.make_kegg_module(p_row=4, p_column=1, p_sticky='n')
self.make_kegg_reaction(p_row=5, p_column=1, p_sticky='n')
#column for COG
self.make_cog(p_row=1, p_column=2, p_sticky='n')
#other columns chose by user
self.make_chosenColumns(p_row=2, p_column=2, p_rowspan=3, p_sticky='n')
self.make_kegg_online(p_row=5, p_column=2, p_sticky='n')
### down area ###
self.frame_down = tk.Frame(self, borderwidth=2, relief='flat')
self.frame_down.grid(row=1, column=0, columnspan=2, padx=2, pady=(2,10), sticky="nsew")
self.frame_down.columnconfigure(0, weight=1)
self.frame_down.columnconfigure(1, weight=1)
self.frame_down.columnconfigure(2, weight=1)
#Previous Step
self.btn_previous_step = tk.Button(self.frame_down, text='← Previous step', font=config.font_button, width=20, command=self.previous_window)
self.btn_previous_step.grid(row=0, column=0, padx=20, pady=5, sticky="w")
#Next Step
self.btn_next_step = tk.Button(self.frame_down, text='Next step →', font=config.font_button, width=20, command=self.next_window)
self.btn_next_step.grid(row=0, column=2, padx=20, pady=5, sticky="e")
#put this window up
self.lift()
#when I close window
self.protocol("WM_DELETE_WINDOW", self.on_closing)
def make_columnsHeaders(self, p_row=0, p_column=0, p_rowspan=1, p_columnspan=1, p_sticky='nsew'):
#Columns Headers frame
self.frame_columnsHeaders = tk.Frame(self.frame_centre, borderwidth=2, relief='flat')
self.frame_columnsHeaders.grid(row=p_row, column=p_column, rowspan=p_rowspan, columnspan=p_columnspan, padx=2, pady=2, sticky=p_sticky)
#title of select column area
self.lbl_columnHeaders = tk.Label(self.frame_columnsHeaders, text='Functional annotations', width=32, font=config.font_subtitle )
self.lbl_columnHeaders.grid(row=0, column=0, padx=6, pady=6)
#Create frame and scrollbar
self.all_columns_frame = Frame(self.frame_columnsHeaders)#, bg='red')
self.all_columns_frame.grid(row=1, column=0, rowspan=1)
#scrollbar
self.all_columns_scrollbar = Scrollbar(self.all_columns_frame, orient=VERTICAL)
#Listbox
#SINGLE, BROWSE, MULTIPLE, EXTENDED
self.all_columns_listbox = Listbox(self.all_columns_frame, yscrollcommand=self.all_columns_scrollbar.set, selectmode=EXTENDED) #background="Blue", fg="white", selectbackground="Red",highlightcolor="Red",
self.all_columns_listbox.grid(row=0, column=0)
self.all_columns_listbox.config(width=40, height=31)
#configure scrollvar
self.all_columns_scrollbar.config(command=self.all_columns_listbox.yview)
self.all_columns_scrollbar.grid(row=0, column=1, sticky="NS")
def make_proteinAccession(self, p_row=0, p_column=0, p_rowspan=1, p_columnspan=1, p_name='', p_sticky='nsew'):
#protein Accession frame
self.frame_proteinAccession = tk.Frame(self.frame_centre, borderwidth=2, relief='flat')
self.frame_proteinAccession.grid(row=p_row, column=p_column, rowspan=p_rowspan, columnspan=p_columnspan, padx=2, pady=2, sticky=p_sticky)
#title of select column area
self.lbl_proteinAccession = tk.Label(self.frame_proteinAccession, text=p_name, width=32, font=config.font_subtitle )
self.lbl_proteinAccession.grid(row=0, column=0, columnspan=2, padx=6, pady=2)
#button select >
self.btn_take_proteinAccession = tk.Button(self.frame_proteinAccession, text='>', font=config.font_button,
width=2, command=lambda: self.take_column(self.proteinAccession_listbox))
self.btn_take_proteinAccession.grid(row=1, column=0, padx=1, pady=1)
#button unselect <
self.btn_restore_proteinAccession = tk.Button(self.frame_proteinAccession, text='<', font=config.font_button,
width=2, command=lambda: self.restore_column(self.proteinAccession_listbox))
self.btn_restore_proteinAccession.grid(row=2, column=0, padx=1, pady=1)
#Create frame and scrollbar
self.all_proteinAccession = Frame(self.frame_proteinAccession)#, bg='red')
self.all_proteinAccession.grid(row=1, column=1, rowspan=2, padx=1, pady=1)
#scrollbar
self.proteinAccession_scrollbar = Scrollbar(self.all_proteinAccession, orient=VERTICAL)
#Listbox
#SINGLE, BROWSE, MULTIPLE, EXTENDED
self.proteinAccession_listbox = Listbox(self.all_proteinAccession, yscrollcommand=self.proteinAccession_scrollbar.set, selectmode=EXTENDED) #background="Blue", fg="white", selectbackground="Red",highlightcolor="Red",
self.proteinAccession_listbox.grid(row=0, column=0)
self.proteinAccession_listbox.config(width=40, height=4)
#configure scrollvar
self.proteinAccession_scrollbar.config(command=self.proteinAccession_listbox.yview)
self.proteinAccession_scrollbar.grid(row=0, column=1, sticky="NS")
def make_peptideSequence(self, p_row=0, p_column=0, p_rowspan=1, p_columnspan=1, p_sticky='nsew'):
#protein Accession frame
self.frame_peptideSequence = tk.Frame(self.frame_centre, borderwidth=2, relief='flat')
self.frame_peptideSequence.grid(row=p_row, column=p_column, rowspan=p_rowspan, columnspan=p_columnspan, padx=2, pady=2, sticky=p_sticky)
#title of select column area
self.lbl_peptideSequence = tk.Label(self.frame_peptideSequence, text='Peptide sequence', width=32, font=config.font_subtitle )
self.lbl_peptideSequence.grid(row=0, column=0, columnspan=2, padx=6, pady=6)
#button select >
self.btn_take_peptideSequence = tk.Button(self.frame_peptideSequence, text='>', font=config.font_button,
width=2, command=lambda: self.take_column(self.peptideSequence_listbox))
self.btn_take_peptideSequence.grid(row=1, column=0, padx=1, pady=1)
#button unselect <
self.btn_restore_peptideSequence = tk.Button(self.frame_peptideSequence, text='<', font=config.font_button,
width=2, command=lambda: self.restore_column(self.peptideSequence_listbox))
self.btn_restore_peptideSequence.grid(row=2, column=0, padx=1, pady=1)
#Create frame and scrollbar
self.all_peptideSequence = Frame(self.frame_peptideSequence)#, bg='red')
self.all_peptideSequence.grid(row=1, column=1, rowspan=2, padx=1, pady=1)
#scrollbar
self.peptideSequence_scrollbar = Scrollbar(self.all_peptideSequence, orient=VERTICAL)
#Listbox
#SINGLE, BROWSE, MULTIPLE, EXTENDED
self.peptideSequence_listbox = Listbox(self.all_peptideSequence, yscrollcommand=self.peptideSequence_scrollbar.set, selectmode=EXTENDED) #background="Blue", fg="white", selectbackground="Red",highlightcolor="Red",
self.peptideSequence_listbox.grid(row=0, column=0)
self.peptideSequence_listbox.config(width=40, height=4)
#configure scrollvar
self.peptideSequence_scrollbar.config(command=self.peptideSequence_listbox.yview)
self.peptideSequence_scrollbar.grid(row=0, column=1, sticky="NS")
def make_kegg_ko(self, p_row=0, p_column=0, p_rowspan=1, p_columnspan=1, p_sticky='nsew'):
#kegg_ko frame
self.frame_kegg_ko = tk.Frame(self.frame_centre, borderwidth=2, relief='flat')
self.frame_kegg_ko.grid(row=p_row, column=p_column, rowspan=p_rowspan, columnspan=p_columnspan, padx=2, pady=2, sticky=p_sticky)
#title of select column area
self.lbl_kegg_ko = tk.Label(self.frame_kegg_ko, text='KEGG KO', width=32, font=config.font_subtitle )
self.lbl_kegg_ko.grid(row=0, column=0, columnspan=2, padx=6, pady=2)
#button select >
self.btn_take_kegg_ko = tk.Button(self.frame_kegg_ko, text='>', font=config.font_button,
width=2, command=lambda: self.take_column(self.kegg_ko_listbox))
self.btn_take_kegg_ko.grid(row=1, column=0, padx=1, pady=1)
#button unselect <
self.btn_restore_kegg_ko = tk.Button(self.frame_kegg_ko, text='<', font=config.font_button,
width=2, command=lambda: self.restore_column(self.kegg_ko_listbox))
self.btn_restore_kegg_ko.grid(row=2, column=0, padx=1, pady=1)
#Create frame and scrollbar
self.all_kegg_ko = Frame(self.frame_kegg_ko)#, bg='red')
self.all_kegg_ko.grid(row=1, column=1, rowspan=2, padx=1, pady=1)
#scrollbar
self.kegg_ko_scrollbar = Scrollbar(self.all_kegg_ko, orient=VERTICAL)
#Listbox
#SINGLE, BROWSE, MULTIPLE, EXTENDED
self.kegg_ko_listbox = Listbox(self.all_kegg_ko, yscrollcommand=self.kegg_ko_scrollbar.set, selectmode=EXTENDED) #background="Blue", fg="white", selectbackground="Red",highlightcolor="Red",
self.kegg_ko_listbox.grid(row=0, column=0)
self.kegg_ko_listbox.config(width=40, height=4)
#configure scrollvar
self.kegg_ko_scrollbar.config(command=self.kegg_ko_listbox.yview)
self.kegg_ko_scrollbar.grid(row=0, column=1, sticky="NS")
def make_kegg_pathway(self, p_row=0, p_column=0, p_rowspan=1, p_columnspan=1, p_sticky='nsew'):
#kegg_pathway frame
self.frame_kegg_pathway = tk.Frame(self.frame_centre, borderwidth=2, relief='flat')
self.frame_kegg_pathway.grid(row=p_row, column=p_column, rowspan=p_rowspan, columnspan=p_columnspan, padx=2, pady=2, sticky=p_sticky)
#title of select column area
self.lbl_kegg_pathway = tk.Label(self.frame_kegg_pathway, text='KEGG pathway', width=32, font=config.font_subtitle )
self.lbl_kegg_pathway.grid(row=0, column=0, columnspan=2, padx=6, pady=2)
#button select >
self.btn_take_kegg_pathway = tk.Button(self.frame_kegg_pathway, text='>', font=config.font_button,
width=2, command=lambda: self.take_column(self.kegg_pathway_listbox))
self.btn_take_kegg_pathway.grid(row=1, column=0, padx=1, pady=1)
#button unselect <
self.btn_restore_kegg_pathway = tk.Button(self.frame_kegg_pathway, text='<', font=config.font_button,
width=2, command=lambda: self.restore_column(self.kegg_pathway_listbox))
self.btn_restore_kegg_pathway.grid(row=2, column=0, padx=1, pady=1)
#Create frame and scrollbar
self.all_kegg_pathway = Frame(self.frame_kegg_pathway)#, bg='red')
self.all_kegg_pathway.grid(row=1, column=1, rowspan=2, padx=1, pady=1)
#scrollbar
self.kegg_pathway_scrollbar = Scrollbar(self.all_kegg_pathway, orient=VERTICAL)
#Listbox
#SINGLE, BROWSE, MULTIPLE, EXTENDED
self.kegg_pathway_listbox = Listbox(self.all_kegg_pathway, yscrollcommand=self.kegg_pathway_scrollbar.set, selectmode=EXTENDED) #background="Blue", fg="white", selectbackground="Red",highlightcolor="Red",
self.kegg_pathway_listbox.grid(row=0, column=0)
self.kegg_pathway_listbox.config(width=40, height=4)
#configure scrollvar
self.kegg_pathway_scrollbar.config(command=self.kegg_pathway_listbox.yview)
self.kegg_pathway_scrollbar.grid(row=0, column=1, sticky="NS")
def make_kegg_module(self, p_row=0, p_column=0, p_rowspan=1, p_columnspan=1, p_sticky='nsew'):
#kegg_module frame
self.frame_kegg_module = tk.Frame(self.frame_centre, borderwidth=2, relief='flat')
self.frame_kegg_module.grid(row=p_row, column=p_column, rowspan=p_rowspan, columnspan=p_columnspan, padx=2, pady=2, sticky=p_sticky)
#title of select column area
self.lbl_kegg_module = tk.Label(self.frame_kegg_module, text='KEGG module', width=32, font=config.font_subtitle )
self.lbl_kegg_module.grid(row=0, column=0, columnspan=2, padx=6, pady=2)
#button select >
self.btn_take_kegg_module = tk.Button(self.frame_kegg_module, text='>', font=config.font_button,
width=2, command=lambda: self.take_column(self.kegg_module_listbox))
self.btn_take_kegg_module.grid(row=1, column=0, padx=1, pady=1)
#button unselect <
self.btn_restore_kegg_module = tk.Button(self.frame_kegg_module, text='<', font=config.font_button,
width=2, command=lambda: self.restore_column(self.kegg_module_listbox))
self.btn_restore_kegg_module.grid(row=2, column=0, padx=1, pady=1)
#Create frame and scrollbar
self.all_kegg_module = Frame(self.frame_kegg_module)#, bg='red')
self.all_kegg_module.grid(row=1, column=1, rowspan=2, padx=1, pady=1)
#scrollbar
self.kegg_module_scrollbar = Scrollbar(self.all_kegg_module, orient=VERTICAL)
#Listbox
#SINGLE, BROWSE, MULTIPLE, EXTENDED
self.kegg_module_listbox = Listbox(self.all_kegg_module, yscrollcommand=self.kegg_module_scrollbar.set, selectmode=EXTENDED) #background="Blue", fg="white", selectbackground="Red",highlightcolor="Red",
self.kegg_module_listbox.grid(row=0, column=0)
self.kegg_module_listbox.config(width=40, height=4)
#configure scrollvar
self.kegg_module_scrollbar.config(command=self.kegg_module_listbox.yview)
self.kegg_module_scrollbar.grid(row=0, column=1, sticky="NS")
def make_kegg_reaction(self, p_row=0, p_column=0, p_rowspan=1, p_columnspan=1, p_sticky='nsew'):
#kegg_reaction frame
self.frame_kegg_reaction = tk.Frame(self.frame_centre, borderwidth=2, relief='flat')
self.frame_kegg_reaction.grid(row=p_row, column=p_column, rowspan=p_rowspan, columnspan=p_columnspan, padx=2, pady=2, sticky=p_sticky)
#title of select column area
self.lbl_kegg_reaction = tk.Label(self.frame_kegg_reaction, text='KEGG reaction', width=32, font=config.font_subtitle )
self.lbl_kegg_reaction.grid(row=0, column=0, columnspan=2, padx=6, pady=2)
#button select >
self.btn_take_kegg_reaction = tk.Button(self.frame_kegg_reaction, text='>', font=config.font_button,
width=2, command=lambda: self.take_column(self.kegg_reaction_listbox))
self.btn_take_kegg_reaction.grid(row=1, column=0, padx=1, pady=1)
#button unselect <
self.btn_restore_kegg_reaction = tk.Button(self.frame_kegg_reaction, text='<', font=config.font_button,
width=2, command=lambda: self.restore_column(self.kegg_reaction_listbox))
self.btn_restore_kegg_reaction.grid(row=2, column=0, padx=1, pady=1)
#Create frame and scrollbar
self.all_kegg_reaction = Frame(self.frame_kegg_reaction)#, bg='red')
self.all_kegg_reaction.grid(row=1, column=1, rowspan=2, padx=1, pady=1)
#scrollbar
self.kegg_reaction_scrollbar = Scrollbar(self.all_kegg_reaction, orient=VERTICAL)
#Listbox
#SINGLE, BROWSE, MULTIPLE, EXTENDED
self.kegg_reaction_listbox = Listbox(self.all_kegg_reaction, yscrollcommand=self.kegg_reaction_scrollbar.set, selectmode=EXTENDED) #background="Blue", fg="white", selectbackground="Red",highlightcolor="Red",
self.kegg_reaction_listbox.grid(row=0, column=0)
self.kegg_reaction_listbox.config(width=40, height=4)
#configure scrollvar
self.kegg_reaction_scrollbar.config(command=self.kegg_reaction_listbox.yview)
self.kegg_reaction_scrollbar.grid(row=0, column=1, sticky="NS")
def make_cog(self, p_row=0, p_column=0, p_rowspan=1, p_columnspan=1, p_sticky='nsew'):
#kegg_reaction frame
self.frame_cog = tk.Frame(self.frame_centre, borderwidth=2, relief='flat')
self.frame_cog.grid(row=p_row, column=p_column, rowspan=p_rowspan, columnspan=p_columnspan, padx=2, pady=2, sticky=p_sticky)
#title of select column area
self.lbl_cog = tk.Label(self.frame_cog, text='COG category', width=32, font=config.font_subtitle )
self.lbl_cog.grid(row=0, column=0, columnspan=2, padx=6, pady=2)
#button select >
self.btn_take_cog = tk.Button(self.frame_cog, text='>', font=config.font_button,
width=2, command=lambda: self.take_column(self.cog_listbox))
self.btn_take_cog.grid(row=1, column=0, padx=1, pady=1)
#button unselect <
self.btn_restore_cog = tk.Button(self.frame_cog, text='<', font=config.font_button,
width=2, command=lambda: self.restore_column(self.cog_listbox))
self.btn_restore_cog.grid(row=2, column=0, padx=1, pady=1)
#Create frame and scrollbar
self.all_cog = Frame(self.frame_cog)#, bg='red')
self.all_cog.grid(row=1, column=1, rowspan=2, padx=1, pady=1)
#scrollbar
self.cog_scrollbar = Scrollbar(self.all_cog, orient=VERTICAL)
#Listbox
#SINGLE, BROWSE, MULTIPLE, EXTENDED
self.cog_listbox = Listbox(self.all_cog, yscrollcommand=self.cog_scrollbar.set, selectmode=EXTENDED) #background="Blue", fg="white", selectbackground="Red",highlightcolor="Red",
self.cog_listbox.grid(row=0, column=0)
self.cog_listbox.config(width=40, height=4)
#configure scrollvar
self.cog_scrollbar.config(command=self.cog_listbox.yview)
self.cog_scrollbar.grid(row=0, column=1, sticky="NS")
def make_chosenColumns(self, p_row=0, p_column=0, p_rowspan=1, p_columnspan=1, p_sticky='nsew'):
#protein Accession frame
self.frame_chosenColumns = tk.Frame(self.frame_centre, borderwidth=2, relief='flat')
self.frame_chosenColumns.grid(row=p_row, column=p_column, rowspan=p_rowspan, columnspan=p_columnspan, padx=2, pady=2, sticky=p_sticky)
#title of select column area
self.lbl_taxonomicColumns = tk.Label(self.frame_chosenColumns, text='Functional columns', width=32, font=config.font_subtitle )
self.lbl_taxonomicColumns.grid(row=0, column=0, columnspan=2, padx=6, pady=6)
#button select >
self.btn_take_columns = tk.Button(self.frame_chosenColumns, text='>', font=config.font_button,
width=2, command=lambda: self.take_column(self.chosenColumns_listbox))
self.btn_take_columns.grid(row=1, column=0, padx=1, pady=1)
#button unselect <
self.btn_restore_columns = tk.Button(self.frame_chosenColumns, text='<', font=config.font_button,
width=2, command=lambda: self.restore_column(self.chosenColumns_listbox))
self.btn_restore_columns.grid(row=2, column=0, padx=1, pady=1)
#Create frame and scrollbar
self.all_chosenColumns = Frame(self.frame_chosenColumns)#, bg='red')
self.all_chosenColumns.grid(row=1, column=1, rowspan=2, padx=1, pady=1)
#scrollbar
self.chosenColumns_scrollbar = Scrollbar(self.all_chosenColumns, orient=VERTICAL)
#Listbox
#SINGLE, BROWSE, MULTIPLE, EXTENDED
self.chosenColumns_listbox = Listbox(self.all_chosenColumns, yscrollcommand=self.chosenColumns_scrollbar.set, selectmode=EXTENDED) #background="Blue", fg="white", selectbackground="Red",highlightcolor="Red",
self.chosenColumns_listbox.grid(row=0, column=0)
self.chosenColumns_listbox.config(width=40, height=18)
#configure scrollvar
self.chosenColumns_scrollbar.config(command=self.chosenColumns_listbox.yview)
self.chosenColumns_scrollbar.grid(row=0, column=1, sticky="NS")
def make_kegg_online(self, p_row=0, p_column=0, p_rowspan=1, p_columnspan=1, p_sticky='nsew'):
#protein kegg online frame
self.frame_keggOnline = tk.Frame(self.frame_centre, borderwidth=2, relief='flat')
self.frame_keggOnline.grid(row=p_row, column=p_column, rowspan=p_rowspan, columnspan=p_columnspan, padx=2, pady=18, sticky=p_sticky)
#Kegg description checkbox
self.var_chc_kegg_description = IntVar(value=0)
self.chc_kegg_description = tk.Checkbutton(self.frame_keggOnline, text='Retrieve KEGG name', width=30, variable=self.var_chc_kegg_description, onvalue=1, offvalue=0)
self.chc_kegg_description.grid(row=0, column=0, padx=5, pady=5, sticky=p_sticky)
self.chc_kegg_description.config( font = config.font_checkbox )
#label description
self.lbl_keggOnline = tk.Label(self.frame_keggOnline, text='(working internet connection needed)', width=30, font=config.font_info)
self.lbl_keggOnline.grid(row=1, column=0, padx=5, pady=(0,10))
def take_column(self, recipient_listbox):
#Prevent it from putting more than one element in the Protein Accession or Peptide Sequence or sampleID
proteinOrPeptide = False
if( hasattr(self, 'proteinAccession_listbox') ):
proteinOrPeptide = (recipient_listbox == self.proteinAccession_listbox)
if( hasattr(self, 'peptideSequence_listbox') ):
proteinOrPeptide = (recipient_listbox == self.peptideSequence_listbox)
if( (proteinOrPeptide) or (recipient_listbox == self.kegg_ko_listbox) or
(recipient_listbox == self.kegg_pathway_listbox) or (recipient_listbox == self.kegg_module_listbox) or
(recipient_listbox == self.kegg_reaction_listbox) or (recipient_listbox == self.cog_listbox) ):
if(len(self.all_columns_listbox.curselection()) > 1):
tk.messagebox.showerror(parent=self, title="Error", message="Select only 1 item for this area")
return
elif(recipient_listbox.size() > 0):
tk.messagebox.showerror(parent=self, title="Error", message="This area can only have 1 associated column")
return
#Move the elements to the various areas and remove them from the main one
#remove the elements from the starting listbox
items_to_move = []
for index in reversed(self.all_columns_listbox.curselection()):
#add elemnts to list for recipient listbox
items_to_move.append(self.all_columns_listbox.get(index))
#remove element to all columns listbox
self.all_columns_listbox.delete(index)
#add elements to recipient listbox
for el in reversed(items_to_move):
recipient_listbox.insert(END, el)
def restore_column(self, sender_listbox):
#Move the elements to the various areas and remove them from the main one
#remove the elements from the starting listbox
items_to_move = []
for index in reversed(sender_listbox.curselection()):
#add elemnts to list for sender listbox
items_to_move.append(sender_listbox.get(index))
#remove element to all columns listbox
sender_listbox.delete(index)
#add elements to recipient listbox
for el in reversed(items_to_move):
self.all_columns_listbox.insert(END, el)
def on_closing(self):
if tk.messagebox.askokcancel("Quit", "Do you want to quit?"):
self.wn_root.destroy()
def monitor_upload(self, thread):
if thread.is_alive():
# check the thread every 100ms
self.after(100, lambda: self.monitor_upload(thread))
else:
#delete load window
self.winLoad.destroy()
#put window in front
self.lift()
if(thread.fileOpen):
#take the df_annotation
self.df_annotation = thread.df
#read it to create some button in the window and mark if the file is load
self.isFileLoad = self.manage_the_upload()
else:
tk.messagebox.showerror(parent=self, title="Error", message="File not uploaded\nIt is probably in use by another program")
def monitor_download(self, thread):
if thread.is_alive():
#check the thread every 100ms
self.after(100, lambda: self.monitor_download(thread))
else:
#delete load window
self.winLoad.destroy()
#put window in front
self.lift()
if(not thread.fileSaved):
tk.messagebox.showerror(parent=self, title="Error", message="File not saved\nIt is probably in use by another program")
def starting_with_map(self, lst):
map_words = [word for word in lst if word.startswith('map')]
return ','.join(map_words) if map_words else ''
def choose_element(self, lst):
if len(lst) == 1:
return lst[0]
else:
return lst[1]
def manage_the_upload(self):
#if need clear previous listbox
if( hasattr(self, 'proteinAccession_listbox') ):
self.proteinAccession_listbox.delete(0, END)
if( hasattr(self, 'peptideSequence_listbox') ):
self.peptideSequence_listbox.delete(0, END)
if( hasattr(self, 'kegg_ko_listbox') ):
self.kegg_ko_listbox.delete(0, END)
if( hasattr(self, 'kegg_pathway_listbox') ):
self.kegg_pathway_listbox.delete(0, END)
if( hasattr(self, 'kegg_module_listbox') ):
self.kegg_module_listbox.delete(0, END)
if( hasattr(self, 'kegg_reaction_listbox') ):
self.kegg_reaction_listbox.delete(0, END)
if( hasattr(self, 'chosenColumns_listbox') ):
self.chosenColumns_listbox.delete(0, END)
if( hasattr(self, 'cog_listbox') ):
self.cog_listbox.delete(0, END)
#if listbox is not empty then clear all
if self.all_columns_listbox.size() > 0:
#rimozione di tutti gli elementi dalla ListBox
self.all_columns_listbox.delete(0, END)
#fill_listbox with all columns
columns = self.df_annotation.columns.tolist()
for column in columns:
self.all_columns_listbox.insert(END, column)
return True
def upload_file(self):
#ask file name
filepath = filedialog.askopenfilename(parent=self, title="Open",filetypes=config.file_types_fragpipe)
#check if a file has been chosen
if filepath:
#load the name of file in label (if name is too long then resize it)
tmp_path = os.path.basename(filepath)
if(len(tmp_path)>25):
tmp_path = tmp_path[:25] + "..."
self.lbl_loadedFile['text'] = tmp_path
#self.lbl_loadedFile['text'] = os.path.basename(filepath)
#show loading windows
self.winLoad = wLd.LoadingWindow("Uploading file...")
#create thread to load file
upload_thread = AsyncUpload_2(filepath)
upload_thread.start()
self.monitor_upload(upload_thread)
else:
tk.messagebox.showwarning(parent=self, title="Warning", message="No file selected")
def monitor_manage_file(self, thread, next_command):
if thread.is_alive():
# check the thread every 100ms
self.after(100, lambda: self.monitor_manage_file(thread, next_command))
else:
#delete load window
self.winLoad.destroy()
#put window in front
self.lift()
if(next_command == "download"):
self.ultimate_download()
elif(next_command == "next_window"):
self.ultimate_next_window()
def final_checks(self):
#cotrols to check if the choose columns are good enough
if( hasattr(self, 'proteinAccession_listbox') ):
if(self.proteinAccession_listbox.size() != 1):
tk.messagebox.showerror(parent=self, title="Error", message="Protein Accession must have 1 attribute")
return False
if( hasattr(self, 'chosenColumns_listbox') ):
tot = self.chosenColumns_listbox.size() + self.kegg_ko_listbox.size()
tot += self.kegg_pathway_listbox.size() + self.kegg_module_listbox.size()
tot += self.kegg_reaction_listbox.size()
if(tot < 1):
tk.messagebox.showerror(parent=self, title="Error", message="Functional annotations or KEGG columns\nmust have at least 1 attribute")
return False
#return true if all is okay
return True
def download(self):
#check if file is loadid
if(self.isFileLoad):
#Check if value are right
if(not self.final_checks()):
return
#ask directory to save file
file_path = filedialog.asksaveasfilename(parent=self, filetypes=config.file_types_generic, defaultextension=".xlsx")
#check if a file has been chosen
if file_path:
#save file temporaneous
self.file_path = file_path
#show loading windows
self.winLoad = wLd.LoadingWindow("Managing file...")
#create thread to manage the file
manage_file_thread = ManageFunctional(self)
manage_file_thread.start()
self.monitor_manage_file(manage_file_thread, "download")
else:
tk.messagebox.showerror(parent=self, title="Error", message="No directory selected")
else:
tk.messagebox.showerror(parent=self, title="Error", message="No files uploaded")
def ultimate_download(self):
#show loading windows
self.winLoad = wLd.LoadingWindow("Downloading file...")
#create thread to download file
download_thread = AsyncDownload(self.df_tmp, self.file_path)
download_thread.start()
self.monitor_download(download_thread)
def previous_window(self):
#hide this window
#self.withdraw()
#Destroy this window
self.destroy()
#show last window
self.wn_previous.deiconify()
self.wn_previous.lift()
def next_window(self):
#check if file is loadid
if(self.isFileLoad):
#Check if value are right
if(not self.final_checks()):
return
#show loading windows
self.winLoad = wLd.LoadingWindow("Managing file...")
#create thread to manage the file
manage_file_thread = ManageFunctional(self)
manage_file_thread.start()
self.monitor_manage_file(manage_file_thread, "next_window")
else:
tk.messagebox.showerror(parent=self, title="Error", message="No files uploaded")
def ultimate_next_window(self):
#Edit the previous dict
MyUtility.workDict["functional"] = True
#hide this window
self.withdraw()
#create new window
self.windowSummaryMetricsPre = wSMpr.SummaryMetricsPreWindow(self.wn_root, self, self.df_tmp)
'''
if __name__ == "__main__":
app = TaxonomicWindow()
app.mainloop()
'''