-
Notifications
You must be signed in to change notification settings - Fork 3
/
REDigestGUI.py
1486 lines (1302 loc) · 54.8 KB
/
REDigestGUI.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
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
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# Name: REDigestGUI.py
# Sign: Abhi
# Modified: Sat Jan 20 18:50:01 CET 2024
# Version: 3.0
##########
__author__ = "Abhijeet Singh"
__copyright__ = "MIT License*"
__email__ = "abhijeet.singh@slu.se, abhijeetsingh.aau@gmail.com"
########### libraries
# import
import sys
import datetime
import os
import platform
from textwrap import dedent
import pandas as pd
import numpy as np
import matplotlib as mpl
if os.environ.get('DISPLAY','') == '':
os.environ.__setitem__('DISPLAY', ':0.0')
mpl.use('Agg')
from matplotlib.ticker import MaxNLocator
from matplotlib import pyplot
import matplotlib.pyplot as plt
#######################
# import from tkinter
import tkinter as tk
from tkinter import *
from tkinter import ttk
from tkinter import filedialog as fd
from tkinter import messagebox as msg
from tkinter import Menu
#######################
# import from Biopython
from Bio import SeqIO
from Bio.Seq import Seq
from Bio import Restriction
from Bio.Restriction import RestrictionBatch
from Bio.SeqRecord import SeqRecord
#from Bio.Alphabet import IUPAC
from Bio.SeqFeature import SeqFeature, FeatureLocation
################################################## main window
win = tk.Tk()
win.title("REDigest")
win.option_add('*Dialog.msg.font', 'Arial 10')
win.resizable(False, False)
################################################## error check and quit
# error message
def msgBox():
msg.showerror("REDigest Error!", "Please provide required fields")
# Helpbox1
def _helpBox1():
msg.showinfo("REDigest Help!", dedent("""
Tab1\tRestriction & Visualization
----------------------------------------------
# Input/output
---------------
1) Input file = multifasta gene or genome file
2) Infile format = fasta or genbank; def: fasta
3) Output file = output file; def: redigest.<DATE>.out
4) Outputfile format = output file format, fasta or genbank; default = fasta
---------------
# Restriction Enzyme
---------------
1) Enzyme name = Restriction enzyme (case sensitive)
---------------
# Primer Sequences
---------------
* Please ignore this section while processing genome sequence *
1) Labelled primer = fluorescence labelled primer for T-RFLP analysis; def: forward
2) Forward primer = sequence of forward primer to be added to the input sequences
3) Reverse primer = sequence of reverse primer to be added to the input sequences
---------------
# Input Sequence type
---------------
Multifasta gene or single genome file; def: multifasta gene
---------------
# Visualization
---------------
Plot title = title to on plot; def: restriction enzyme"""))
# Helpbox2
def _helpBox2():
msg.showinfo("REDigest Help!", dedent("""
Tab2\tVisualization
----------------------------------------------
# Input/Output
---------------
1) Input file = .csv file generated by REDigest
2) Output plot = name of output plot file; def: redigest.<DATE>.png
3) Plot size = plot size in dpi; def: 300
4) Plot format = output file format; def: .png
---------------
# Plot labels
---------------
1) Plot title = plot title; def: Cluster plot
2) X-axis label = x-axis label; def: Fragment frequency (counts)
3) Y-axis label = y-axis label; def: Fragment size (bp)
---------------
# Plot colour
---------------
Plot Colour = colour palette; def: tab20b_r"""))
def _aboutBox():
msg.showinfo("REDigest About!", dedent("""
REDigest version 3.0
MIT License*
Copyright (c) 2024 Abhijeet Singh
Anaerobic Microbiology and Biotechnology group (AMB)
Department of Molecular Sciences
Swedish University of Agricultural Sciences (SLU)
Uppsala, Sweden
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The software is provided \"AS IS\", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
*small changes made in standard licence
For more information, please check the README file or visit https://github.com/abhijeetsingh1704/REDigest"""))
def _cite():
msg.showinfo("REDigest Citation!", dedent("""SINGH, Abhijeet. REDigest: a Python GUI for In-Silico restriction digestion analysis of genes or complete genome sequences. bioRxiv 2021.11.09.467873; doi: https://doi.org/10.1101/2021.11.09.467873"""))
# quit
def _quit():
win.quit()
win.destroy()
exit()
# help menu
def _help1():
_helpBox1()
def _help2():
_helpBox2()
################################################## Menu
# bar
menuBar = Menu(win)
win.config(menu=menuBar)
# menu
# if on MacOS, put menu items in a dropdown as empty menu items are not allowed
menuDropdown = Menu(menuBar)
if platform.system() == 'Darwin':
targetmenu = menuDropdown
else:
targetmenu = menuBar
targetmenu.add_command(label="Exit", command=_quit)
targetmenu.add_command(label="Help_Tab1", command=_help1)
targetmenu.add_command(label="Help_Tab2", command=_help2)
targetmenu.add_command(label="About", command=_aboutBox)
targetmenu.add_command(label="Citation", command=_cite)
if platform.system() == 'Darwin':
menuBar.add_cascade(label="REDigest", menu=menuDropdown)
################################################## Tabs
# tab control
tabcontrol = ttk.Notebook(win)
tab1 = ttk.Frame(tabcontrol)
tabcontrol.add(tab1, text="Restriction & Visualization")
tab2 = ttk.Frame(tabcontrol)
tabcontrol.add(tab2, text="Visualization")
tabcontrol.pack(fill="both")
########################################################### Frame 1
# frame1 element
frame1 = ttk.Style()
frame1.configure("frame1.Label", font=("TkDefaultFont", 10, "bold"))
frame1.configure("frame1.Label", foreground ='blue')
frame1_label1 = ttk.Label(text="Input / Output files", style="frame1.Label")
file_frame = ttk.Labelframe(tab1, labelwidget=frame1_label1)
file_frame.grid(column=0, row=0, sticky=tk.W, padx = 4, pady=0)
#
# label1 = input file
label1 = ttk.Label(file_frame, text="Input file: * \t")
label1.grid(column=0, row=0, sticky=tk.W, padx = 0, pady=2)
label1.configure(foreground="red")
# entry1 box = input file name
entry1 = tk.StringVar()
entry1_input = ttk.Entry(file_frame, width=30, textvariable=entry1)
entry1_input.grid(column=1, row=0, sticky=tk.W, padx = 0, pady=2)
entry1_input.focus()
# browse input_file
def Browse_file():
filename = fd.askopenfilename(filetypes=[("fasta files","*.f*a*"),("text files","*.txt"),("All files","*.*")] if platform.system() != 'Darwin' else (),
initialdir = ".",
title = "Select file")
entry1_input.insert(tk.END, filename)
if filename:
Browse_btn1.configure(text="Ok")
label1.configure(foreground="green")
label1.configure(text="Input filename:\t")
ifile=entry1_input.get()
print("Input file:\t", ifile)
else:
filename = fd.askopenfilename(filetypes=[("All files","*.*")] if platform.system() != 'Darwin' else (),
initialdir = ".",
title = "Select file")
entry1_input.insert(tk.END, filename)
if entry1_input.get() == "":
msgBox()
# click browse button for input
Browse_btn1 = ttk.Button(file_frame, text="Browse", command=Browse_file)
Browse_btn1.grid(column=2, row=0, sticky=tk.W, padx = 0, pady=2)
# mandatory label for input
# Mandatory1 = ttk.Label(file_frame, text="Required\t\t", foreground="red")
# Mandatory1.grid(column=5, row=0, sticky=tk.W, padx = 4, pady=4)
################################################# Label 2
# label2
label2 = ttk.Label(file_frame, text="Output file:\t")
label2.grid(column=0, row=2, sticky=tk.W, padx = 0, pady=2)
# entry2 box
entry2 = tk.StringVar()
entry2_input = ttk.Entry(file_frame, width=30, textvariable=entry2)
entry2_input.grid(column=1, row=2, sticky=tk.W, padx = 0, pady=2)
entry2_input.focus()
# button
def click_button_entry2():
entry2btn.configure(text="Ok")
label2.configure(foreground="green")
label2.configure(text="Output filename:\t")
ioutput = entry2_input.get()
print("Output file:\t", ioutput)
# click_button entry2
entry2btn = ttk.Button(file_frame, text="Click", command=click_button_entry2)
entry2btn.grid(column=2, row=2, sticky=tk.W, padx = 0, pady=2)
########################################################### Frame 2
#frame2 element
frame2 = ttk.Style()
frame2.configure("frame2.Label", font=("TkDefaultFont", 10, "bold"))
frame2.configure("frame2.Label", foreground ='blue')
frame2_label1 = ttk.Label(text="Restriction Enzyme", style="frame2.Label")
enzyme_frame = ttk.Labelframe(tab1, labelwidget=frame2_label1)
enzyme_frame.grid(column=0, row=1, sticky=tk.W, padx = 4, pady=0)
################################################# Label 3
Restriction_enzymes_var = dir(Restriction)
built_in=['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
Restriction_enzymes = [x for x in Restriction_enzymes_var if (x not in built_in)]
label3 = ttk.Label(enzyme_frame, text="Enzyme: * \t")
label3.grid(column=0, row=0, sticky=tk.W, padx = 0, pady=2)
label3.configure(foreground="red")
# entry2 box
entry3 = tk.StringVar()
entry3_input = ttk.Combobox(enzyme_frame, width=30, textvariable=entry3)
entry3_input['values'] = Restriction_enzymes
entry3_input.grid(column=1, row=0, sticky=tk.W, padx = 0, pady=2)
entry3_input.current(0)
entry3_input.focus()
ienzyme = entry3_input.get()
# button
def click_button_entry3():
if entry3_input.get() == "":
msgBox()
else:
entry3btn.configure(text="Ok")
label3.configure(foreground="green")
label3.configure(text="Enzyme:\t")
ienzyme = entry3_input.get()
print("Input Enzyme:\t", ienzyme)
# click_button entry2
entry3btn = ttk.Button(enzyme_frame, text="Click",
command=click_button_entry3)
entry3btn.grid(column=2, row=0, sticky=tk.W, padx = 0, pady=2)
# mandatory label3
# Mandatory3 = ttk.Label(enzyme_frame, text="Required\t\t", foreground="red")
# Mandatory3.grid(column=5, row=0, sticky=tk.W, padx = 4, pady=4)
# Mandatory3info = ttk.Label(enzyme_frame, text="# case sensitive!\n# Ex: Hpy188III", foreground="red")
# Mandatory3info.grid(column=0, row=1, sticky=tk.W, padx = 4, pady=0)
########################################################### Frame 3
#frame3 element
frame3 = ttk.Style()
frame3.configure("frame3.Label", font=("TkDefaultFont", 10, "bold"))
frame3.configure("frame3.Label", foreground ='blue')
frame3_label1 = ttk.Label(text="Primer Sequences (ignore section for genome)", style="frame3.Label")
primer_frame = ttk.Labelframe(tab1, labelwidget=frame3_label1)
primer_frame.grid(column=0, row=2, sticky=tk.W, padx = 4, pady=0)
################################################# Label 4
# label4
label4 = ttk.Label(primer_frame, text="Labelled primer:\t")
label4.grid(column=0, row=0, sticky=tk.W, padx = 0, pady=2)
# entry4 box
entry4 = tk.StringVar()
entry4_input = ttk.Combobox(primer_frame, width=27, textvariable=entry4)
entry4_input['values'] = ("Forward" , "Reverse")
entry4_input.grid(column=1, row=0, sticky=tk.E, padx = 0, pady=2)
entry4_input.current(0)
# button
def click_button_entry4():
entry4btn.configure(text="Ok")
label4.configure(foreground="green")
label4.configure(text="Tagged primer\t")
if entry4_input.get() == "Forward":
itag = str("Forward")
elif entry4_input.get() == "Reverse":
itag = str("Reverse")
print("Tagged primer:\t", itag)
# click_button entry4
entry4btn = ttk.Button(primer_frame, text="Click",
command=click_button_entry4)
entry4btn.grid(column=2, row=0, sticky=tk.W, padx = 0, pady=2)
# mandatory label3
# Mandatory4 = ttk.Label(primer_frame, text="*Forward\t\t", foreground="black")
# Mandatory4.grid(column=5, row=0, sticky=tk.W, padx = 4, pady=4)
################################################# Label 5
# label5
label5 = ttk.Label(primer_frame, text="Forward primer:\t")
label5.grid(column=0, row=1, sticky=tk.W, padx = 0, pady=2)
# entry5 box
entry5 = tk.StringVar()
entry5_input = ttk.Entry(primer_frame, width=30, textvariable=entry5)
entry5_input.grid(column=1, row=1, sticky=tk.E, padx = 0, pady=2)
entry5_input.focus()
# button
def click_button_entry5():
entry5btn.configure(text="Ok")
label5.configure(foreground="green")
label5.configure(text="Forward Seq\t")
i_fprimer = entry5_input.get()
print("Forward primer:\t5'-"+i_fprimer+"-3'")
#
# # click_button entry5
entry5btn = ttk.Button(primer_frame, text="Click",
command=click_button_entry5)
entry5btn.grid(column=2, row=1, sticky=tk.W, padx = 0, pady=2)
################################################# Label 6
# label6
label6 = ttk.Label(primer_frame, text="Reverse primer:\t")
label6.grid(column=0, row=2, sticky=tk.W, padx = 0, pady=2)
# entry6 box
entry6 = tk.StringVar()
entry6_input = ttk.Entry(primer_frame, width=30, textvariable=entry6)
entry6_input.grid(column=1, row=2, sticky=tk.E, padx = 0, pady=2)
entry6_input.focus()
# button
def click_button_entry6():
entry6btn.configure(text="Ok")
label6.configure(foreground="green")
label6.configure(text="Reverse Seq\t")
i_rprimer = entry6_input.get()
print("Reverse primer:\t5'-" + i_rprimer + "-3'")
#
# # click_button entry6
entry6btn = ttk.Button(primer_frame, text="Click",
command=click_button_entry6)
entry6btn.grid(column=2, row=2, sticky=tk.W, padx = 0, pady=2)
########################################################### Frame 4
#frame4 element
frame4 = ttk.Style()
frame4.configure("frame4.Label", font=("TkDefaultFont", 10, "bold"))
frame4.configure("frame4.Label", foreground ='blue')
frame4_label1 = ttk.Label(text="Input Sequences type", style="frame4.Label")
type_frame = ttk.Labelframe(tab1, labelwidget=frame4_label1)
type_frame.grid(column=0, row=3, sticky=tk.W, padx = 4, pady=0)
################################################ Label 7
# label7
label7 = ttk.Label(type_frame, text="Input type:\t")
label7.grid(column=0, row=0, sticky=tk.W, padx = 0, pady=2)
# entry7 box
entry7 = tk.StringVar()
entry7_input = ttk.Combobox(type_frame, width=27, textvariable=entry7)
entry7_input['values'] = ("Multifasta gene file" , "Single genome sequence")
entry7_input.grid(column=1, row=0, sticky=tk.W, padx = 0, pady=2)
entry7_input.current(0)
itype = entry7_input.get()
# button
def click_button_entry7():
entry7btn.configure(text="Ok")
label7.configure(foreground="green")
label7.configure(text="File type:\t\t")
itype = entry7_input.get()
print("Input type:\t" + itype)
# click_button entry7
entry7btn = ttk.Button(type_frame, text="Click",
command=click_button_entry7)
entry7btn.grid(column=2, row=0, sticky=tk.W, padx = 0, pady=2)
# legend for input type
# Mandatory7 = ttk.Label(type_frame, text="*gene file\t", foreground="black")
# Mandatory7.grid(column=5, row=0, sticky=tk.W, padx = 4, pady=4)
################################################ Label 8
# label8
label8 = ttk.Label(file_frame, text="Infile format:\t")
label8.grid(column=0, row=1, sticky=tk.W, padx = 0, pady=2)
# entry8 box
entry8 = tk.StringVar()
entry8_input = ttk.Combobox(file_frame, width=27, textvariable=entry8)
entry8_input['values'] = ("Fasta" , "Genbank")
entry8_input.grid(column=1, row=1, sticky=tk.W, padx = 0, pady=2)
entry8_input.current(0)
# button
def click_button_entry8():
entry8btn.configure(text="Ok")
label8.configure(foreground="green")
label8.configure(text="Input format:\t")
iformat = entry8_input.get()
print("Input file format:\t", iformat)
# click_button entry8
entry8btn = ttk.Button(file_frame, text="Click", command=click_button_entry8)
entry8btn.grid(column=2, row=1, sticky=tk.W, padx = 0, pady=2)
# legend for input format
# Mandatory8 = ttk.Label(file_frame, text="*fasta\t\t", foreground="black")
# Mandatory8.grid(column=5, row=1, sticky=tk.W, padx = 4, pady=4)
################################################ Label 9
# label9
label9 = ttk.Label(file_frame, text="Outfile format:\t")
label9.grid(column=0, row=3, sticky=tk.W, padx = 0, pady=2)
# entry9 box
entry9 = tk.StringVar()
entry9_input = ttk.Combobox(file_frame, width=27, textvariable=entry9)
entry9_input['values'] = ("Fasta" , "Genbank")
entry9_input.grid(column=1, row=3, sticky=tk.W, padx = 0, pady=2)
entry9_input.current(0)
# button
def click_button_entry9():
entry9btn.configure(text="Ok")
label9.configure(foreground="green")
label9.configure(text="Output format:\t")
oformat = entry9_input.get()
print("Output file format:\t", oformat)
# click_button entry8
entry9btn = ttk.Button(file_frame, text="Click", command=click_button_entry9)
entry9btn.grid(column=2, row=3, sticky=tk.W, padx = 0, pady=2)
#
# legend for output format
# Mandatory9 = ttk.Label(file_frame, text="*fasta\t\t", foreground="black")
# Mandatory9.grid(column=5, row=3, sticky=tk.W)
########################################################### Frame 5
#frame5 element
frame5 = ttk.Style()
frame5.configure("frame5.Label", font=("TkDefaultFont", 10, "bold"))
frame5.configure("frame5.Label", foreground ='blue')
frame5_label1 = ttk.Label(text="Visualization", style="frame5.Label")
visu_frame = ttk.Labelframe(tab1, labelwidget=frame5_label1)
visu_frame.grid(column=0, row=4, sticky=tk.W, padx = 4, pady=0)
################################################ Label 8
# label10
label10 = ttk.Label(visu_frame, text="Plot title:\t\t")
label10.grid(column=0, row=0, sticky=tk.W, padx = 0, pady=2)
# entry 10
entry10 = tk.StringVar()
entry10_input = ttk.Entry(visu_frame, width=30, textvariable=entry10)
entry10_input.grid(column=1, row=0, sticky=tk.W, padx = 0, pady=2)
entry10_input.focus()
# button
def click_button_entry10():
entry10btn.configure(text="Ok")
label10.configure(foreground="green")
label10.configure(text="Title:\t\t")
iplot = entry10_input.get()
print("Plot title:\t", iplot)
# click_button entry10
entry10btn = ttk.Button(visu_frame, text="Click", command=click_button_entry10)
entry10btn.grid(column=2, row=0, sticky=tk.W, padx = 0, pady=2)
# mandatory entry 10
# Mandatory10 = ttk.Label(visu_frame, text="\t\t ").grid(column=5, row=0, sticky=tk.W, padx = 4, pady=4)
##########################################################
########################################################## # Legend
# Legend1
# Legend1 = ttk.Label(win, text="* = default\t", foreground="black")
# Legend1.grid(column=0, row=15, sticky=tk.E, padx = 4, pady=4)
########################################################### Tab 2
# tab2frame1
# frame1T2 element
frame1T2 = ttk.Style()
frame1T2.configure("frame1T2.Label", font=("TkDefaultFont", 10, "bold"))
frame1T2.configure("frame1T2.Label", foreground ='blue')
frame1T2_label1T2 = ttk.Label(text="Input / Output", style="frame1T2.Label")
file_frameT2 = ttk.Labelframe(tab2, labelwidget=frame1T2_label1T2)
file_frameT2.grid(column=0, row=0, sticky=tk.W, padx = 4, pady=0)
#
# label1T2 = input file
label1T2 = ttk.Label(file_frameT2, text="Input file: * \t")
label1T2.grid(column=0, row=0, sticky=tk.W, padx = 0, pady=2)
label1T2.configure(foreground="red")
# entry1T2 box = input file name
entry1T2 = tk.StringVar()
entry1T2_input = ttk.Entry(file_frameT2, width=30, textvariable=entry1T2)
entry1T2_input.grid(column=1, row=0, sticky=tk.W, padx = 0, pady=2)
entry1T2_input.focus()
# browse input_file
def Browse_fileT2():
filenameT2 = fd.askopenfilename(filetypes=[("csv files", "*.csv"), ("All files", "*.*")] if platform.system() != 'Darwin' else (),
initialdir = ".",
title = "Select file")
entry1T2_input.insert(tk.END, filenameT2)
if filenameT2 :
Browse_btn1.configure(text="Ok")
label1T2.configure(foreground="green")
label1T2.configure(text="Input filename:\t")
ifileT2=entry1T2_input.get()
print("Input file:\t", ifileT2)
else:
filenameT2 = fd.askopenfilename(filetypes=[("All files", "*.*")] if platform.system() != 'Darwin' else (),
initialdir = ".",
title = "Select file")
entry1T2_input.insert(tk.END, filenameT2)
if entry1T2_input.get() == "":
msgBox()
# click browse button for input
Browse_btn1T2 = ttk.Button(file_frameT2, text="Browse", command=Browse_fileT2)
Browse_btn1T2.grid(column=2, row=0, sticky=tk.W, padx = 0, pady=2)
# mandatory label for input
# Mandatory1T2 = ttk.Label(file_frameT2, text="\t", foreground="red")
# Mandatory1T2.grid(column=5, row=0, sticky=tk.E, padx = 4, pady=4)
################################################# Label 2T2
# label2T2
label2T2 = ttk.Label(file_frameT2, text="Output plot:\t")
label2T2.grid(column=0, row=2, sticky=tk.W, padx = 0, pady=2)
# entry2T2 box
entry2T2 = tk.StringVar()
entry2T2_input = ttk.Entry(file_frameT2, width=30, textvariable=entry2T2)
entry2T2_input.grid(column=1, row=2, sticky=tk.W, padx = 0, pady=2)
entry2T2_input.focus()
# button
def click_button_entry2T2():
entry2T2btn.configure(text="Ok")
label2T2.configure(foreground="green")
label2T2.configure(text="Outplot name:\t")
ioutputT2 = entry2T2_input.get()
print("Output file:\t", ioutputT2)
# click_button entry2T2
entry2T2btn = ttk.Button(file_frameT2, text="Click", command=click_button_entry2T2)
entry2T2btn.grid(column=2, row=2, sticky=tk.W, padx = 0, pady=2)
################################################# Label 3T2
# label3T2
label3T2 = ttk.Label(file_frameT2, text="Plot size:\t")
label3T2.grid(column=0, row=3, sticky=tk.W, padx = 0, pady=2)
# entry3T2 box
entry3T2 = tk.StringVar()
entry3T2_input = ttk.Combobox(file_frameT2, width=27, textvariable=entry3T2)
entry3T2_input["values"] = ("100", "200", "300", "400", "500", "600", "700", "800", "900", "1000")
entry3T2_input.grid(column=1, row=3, sticky=tk.W, padx = 0, pady=2)
entry3T2_input.current(2)
# button
def click_button_entry3T2():
entry3T2btn.configure(text="Ok")
label3T2.configure(foreground="green")
label3T2.configure(text="Outplot size:\t")
ioutplotT2 = entry3T2_input.get()
print("Outplot size:\t", ioutplotT2)
# click_button entry2T2
entry3T2btn = ttk.Button(file_frameT2, text="Click", command=click_button_entry3T2)
entry3T2btn.grid(column=2, row=3, sticky=tk.W, padx = 0, pady=2)
#info
# info1T2 = ttk.Label(file_frameT2, text="\t", foreground="black")
# info1T2.grid(column=5, row=3, sticky=tk.W, padx = 4, pady=4)
# info2T2 = ttk.Label(file_frameT2, text="# dpi, Ex: 300\t", foreground="red")
# info2T2.grid(column=0, row=4, sticky=tk.W, padx = 4)
################################################# Label 8T2
# label8T2
label8T2 = ttk.Label(file_frameT2, text="Plot format:\t")
label8T2.grid(column=0, row=4, sticky=tk.W, padx = 0, pady=2)
# entry8T2 box
entry8T2 = tk.StringVar()
entry8T2_input = ttk.Combobox(file_frameT2, width=27, textvariable=entry8T2)
entry8T2_input["values"] = ("eps", "jpg", "pdf", "pgf", "png", "ps", "raw", "svg", "tif")
entry8T2_input.grid(column=1, row=4, sticky=tk.W, padx = 0, pady=2)
entry8T2_input.current(4)
# button
def click_button_entry8T2():
entry8T2btn.configure(text="Ok")
label8T2.configure(foreground="green")
label8T2.configure(text="Outplot format:\t")
ioutfmtT2 = entry8T2_input.get()
print("Outplot format:\t", ioutfmtT2)
# click_button entry8T2
entry8T2btn = ttk.Button(file_frameT2, text="Click", command=click_button_entry8T2)
entry8T2btn.grid(column=2, row=4, sticky=tk.W, padx = 0, pady=2)
#################################################frame2T2
# frame2T2 element
frame2T2 = ttk.Style()
frame2T2.configure("frame2T2.Label", font=("TkDefaultFont", 10, "bold"))
frame2T2.configure("frame2T2.Label", foreground ='blue')
frame2T2_label1T2 = ttk.Label(text="Plot labels", style="frame2T2.Label")
plot_frameT2 = ttk.Labelframe(tab2, labelwidget=frame2T2_label1T2)
plot_frameT2.grid(column=0, row=1, sticky=tk.W, padx = 4, pady=0)
#
# label4T2F2
label4T2F2 = ttk.Label(plot_frameT2, text="Plot title:\t")
label4T2F2.grid(column=0, row=0, sticky=tk.W, padx = 0, pady=2)
# entry1T2F2 box = input file name
entry4T2F2 = tk.StringVar()
entry4T2F2_input = ttk.Entry(plot_frameT2, width=30, textvariable=entry4T2F2)
entry4T2F2_input.grid(column=1, row=0, sticky=tk.W, padx = 0, pady=2)
entry4T2F2_input.focus()
# button
def click_button_entry4T2F2():
entry4T2F2btn.configure(text="Ok")
label4T2F2.configure(foreground="green")
label4T2F2.configure(text="Output plot title:\t")
ioutplottitleT2 = entry4T2F2_input.get()
print("Out plot title:\t", ioutplottitleT2)
# click_button entry2T2
entry4T2F2btn = ttk.Button(plot_frameT2, text="Click", command=click_button_entry4T2F2)
entry4T2F2btn.grid(column=2, row=0, sticky=tk.W, padx = 0, pady=2)
# entry4T2F2tab = ttk.Label(plot_frameT2, text="\t").grid(column=5, row=0, sticky=tk.W, padx = 4, pady=4)
####################################################
# label5T2F2
label5T2F2 = ttk.Label(plot_frameT2, text="X-axis label:\t")
label5T2F2.grid(column=0, row=1, sticky=tk.W, padx = 0, pady=2)
# entry5T2F2 box = input file name
entry5T2F2 = tk.StringVar()
entry5T2F2_input = ttk.Entry(plot_frameT2, width=30, textvariable=entry5T2F2)
entry5T2F2_input.grid(column=1, row=1, sticky=tk.W, padx = 0, pady=2)
entry5T2F2_input.focus()
# button
def click_button_entry5T2F2():
entry5T2F2btn.configure(text="Ok")
label5T2F2.configure(foreground="green")
label5T2F2.configure(text="X-axis label:\t")
iXlabT2 = entry5T2F2_input.get()
print("X-axis label:\t", iXlabT2)
# click_button entry5T2F2
entry5T2F2btn = ttk.Button(plot_frameT2, text="Click", command=click_button_entry5T2F2)
entry5T2F2btn.grid(column=2, row=1, sticky=tk.W, padx = 0, pady=2)
# entry5T2F2tab = ttk.Label(plot_frameT2, text="\t").grid(column=5, row=0, sticky=tk.W, padx = 4, pady=4)
####################################################
# label6T2F2
label6T2F2 = ttk.Label(plot_frameT2, text="Y-axis label:\t")
label6T2F2.grid(column=0, row=2, sticky=tk.W, padx = 0, pady=2)
# entry6T2F2 box = input file name
entry6T2F2 = tk.StringVar()
entry6T2F2_input = ttk.Entry(plot_frameT2, width=30, textvariable=entry6T2F2)
entry6T2F2_input.grid(column=1, row=2, sticky=tk.W, padx = 0, pady=2)
entry6T2F2_input.focus()
# button
def click_button_entry6T2F2():
entry6T2F2btn.configure(text="Ok")
label6T2F2.configure(foreground="green")
label6T2F2.configure(text="Y-axis label:\t")
iYlabT2 = entry6T2F2_input.get()
print("Y-axis label:\t", iYlabT2)
# click_button entry6T2F2
entry6T2F2btn = ttk.Button(plot_frameT2, text="Click", command=click_button_entry6T2F2)
entry6T2F2btn.grid(column=2, row=2, sticky=tk.W, padx = 0, pady=2)
# entry6T2F2tab = ttk.Label(plot_frameT2, text="\t").grid(column=5, row=0, sticky=tk.W, padx = 4, pady=4)
#################################################frame3T2
# frame3T2 element
frame3T2 = ttk.Style()
frame3T2.configure("frame3T2.Label", font=("TkDefaultFont", 10, "bold"))
frame3T2.configure("frame3T2.Label", foreground ='blue')
frame3T2_label1T2 = ttk.Label(text="Plot colour", style="frame3T2.Label")
colr_frameT2 = ttk.Labelframe(tab2, labelwidget=frame3T2_label1T2)
colr_frameT2.grid(column=0, row=2, sticky=tk.W, padx = 4, pady=0)
#
# label7T2F2
label7T2F2 = ttk.Label(colr_frameT2, text="Plot Colour:\t")
label7T2F2.grid(column=0, row=0, sticky=tk.W, padx = 0, pady=2)
# entry7T2F2 box = input file name
entry7T2F2 = tk.StringVar()
entry7T2F2_input = ttk.Combobox(colr_frameT2, width=27, textvariable=entry7T2F2)
entry7T2F2_input['values'] = pyplot.colormaps()
entry7T2F2_input.grid(column=1, row=0, sticky=tk.W, padx = 0, pady=2)
entry7T2F2_input.current(57)
entry7T2F2_input.focus()
# button
def click_button_entry7T2F2():
entry7T2F2btn.configure(text="Ok")
label7T2F2.configure(foreground="green")
label7T2F2.configure(text="Outplot colour:\t")
icolrplotT2 = entry7T2F2_input.get()
print("Outplot colour:\t", icolrplotT2)
# click_button entry2T2
entry7T2F2btn = ttk.Button(colr_frameT2, text="Click", command=click_button_entry7T2F2)
entry7T2F2btn.grid(column=2, row=0, sticky=tk.W, padx = 0, pady=2)
# entry7T2F2tab = ttk.Label(colr_frameT2, text="\t\t ").grid(column=5, row=0, sticky=tk.W, padx = 4, pady=4)
##########################################################
##########################################################
# MAIN CODE CHECK
# catch start-time
date = datetime.datetime.now()
FULL_DATE = date.strftime("%Y-%m-%d %H:%M:%S")
TIME = date.strftime("%y%m%d%H%M%S")
BAD_chr = "|'!\"#$%&\'()*+,-/:;<=?@[\\]^_`}{~'"
#
def argscheck():
if entry1_input.get() == "":
msgBox()
if entry3_input.get() == "":
msgBox()
def redigest_code():
argscheck()
### making outfile
# output file
if entry2_input.get() == "":
outfile = 'redigest.'+ TIME + '.out'
else:
outfile=entry2_input.get()
out_file = open(outfile, 'wt+')
### processing gene sequences
if entry7_input.get() == "Multifasta gene file":
genomeSeq = "N"
elif entry7_input.get() == "Single genome sequence":
genomeSeq = "Y"
if genomeSeq == 'N':
### making report file
verbosity = 'Y'
report_file = outfile + '.csv'
# open report file
RF = open(report_file, 'wt+')
# reverse complement the reverse primer
if entry6_input.get() == "":
reverse = ""
else:
reverse = entry6_input.get()
reverse=str(Seq(reverse).reverse_complement())
# counter for the NAME
count=1
### iterating sequences
input_file = entry1_input.get()
infile= open(input_file, 'r')
# input file format
if entry8_input.get() == "Fasta":
informat = "fasta"
elif entry8_input.get() == "Genbank":
informat = "genbank"
for record in SeqIO.parse(infile, informat):
header=record.description.replace(" ", "_")
#
for characters in BAD_chr:
header=header.replace(characters, "_")
#
array=str(record.seq)
NAME=str('RED' + TIME + str(count))
#
if informat == 'genbank':
desc=str(', '.join(list(record.annotations["taxonomy"])))
else:
desc = ''
## adding primer sequence if provided
if entry5_input.get() == "":
forward = ""
else:
forward = entry5_input.get()
if forward is not None:
Farray=''.join(forward + array)
else:
Farray=array
### adding primer sequence if provided
if entry6_input.get() == "":
reverse = ""
else:
reverse = entry6_input.get()
if reverse is not None:
FarrayR=''.join(Farray.strip('\n') + reverse)
else:
FarrayR=Farray
### orientation based on tagged
if entry4_input.get() == "Forward":
tagg = str("F")
elif entry4_input.get() == "Reverse":
tagg = str("R")
tagged=tagg.upper()
if tagged == 'R':
FarrayRseqFR=str(Seq(FarrayR).reverse_complement())
SubFeat="TRF_RevComp"
else:
FarrayRseqFR=str(FarrayR)
SubFeat="TRF"
### Restriction Enzyme check from list
enzyme = entry3_input.get()
enzyme_RE = RestrictionBatch([enzyme])
### search the restriction sites position in sequence
FarrayRseqFR_RE=enzyme_RE.search(Seq(FarrayRseqFR))
### convert the dict to the list and indexing
index=list(FarrayRseqFR_RE.values())[0]
### checking if restriction site is present or sequence will be uncut
if not index:
fragment=len(FarrayRseqFR)
else:
fragment=index[0]
### adding size to header and trimming sequence to terminal fragment length
if not index:
### non-cut fragment header
FastaHeader=NAME + "|" + str(len(FarrayRseqFR)) + "_bp" + "|" + header
### non-cut fragment sequence
FastaSeq=FarrayRseqFR[:len(FarrayRseqFR)]
# Feat=SeqFeature(FeatureLocation(start=0, end=len(FarrayRseqFR)), type="REDigest", ref=SubFeat)
Feat=SeqFeature(FeatureLocation(start=0, end=len(FarrayRseqFR)), type="REDigest")
else:
### cut fragment header
FastaHeader=NAME + "|" + str(fragment) + "_bp" + "|" + header
### cut fragment sequence and slicing to the fragment length
FastaSeq=FarrayRseqFR[:fragment]
# Feat=SeqFeature(FeatureLocation(start=0, end=fragment), type="REDigest", ref=SubFeat)
Feat=SeqFeature(FeatureLocation(start=0, end=fragment), type="REDigest")
### terminal-screen output, info about sequence header and all the fragments
### based of verbosity
if verbosity == 'Y':
print(" ", FastaHeader, '\t', FarrayRseqFR_RE)
### counter for the locus name
count +=1
### seq object
# FastaSequence = SeqRecord(Seq(FastaSeq, IUPAC.IUPACAmbiguousDNA()), FastaHeader, description=desc, name=NAME)
FastaSequence = SeqRecord(Seq(FastaSeq), FastaHeader, description=desc, name=NAME, annotations={"molecule_type": "DNA"})
### append features to seqobject
FastaSequence.features.append(Feat)
### seq object
if entry9_input.get() == "Fasta":
outformat = "fasta"
elif entry9_input.get() == "Genbank":
outformat = "genbank"
if outformat == 'genbank':
SeqIO.write(FastaSequence, out_file, outformat)
else:
SeqIO.write(FastaSequence, out_file, "fasta-2line")
### writing progress to file too
print(FastaHeader, '\t', FarrayRseqFR_RE, file=RF)
#####################
############################################################### Genome
else:
### parsing genome sequence
### making report file
if entry9_input.get() == "Fasta":
outformat = "fasta"
elif entry9_input.get() == "Genbank":
outformat = "genbank"
if entry2_input.get() == "":
outfile = 'redigest.'+ TIME + '.out'
else:
outfile=entry2_input.get()
report_file = outfile + '_RF.csv'
# open report file
RF = open(report_file, 'wt+')
print("Individual restriction fragments", file=RF)
print("[WRITING:] Individual restriction fragments to file:", report_file)
input_file = entry1_input.get()
infile= open(input_file, 'r')
# input file format
if entry8_input.get() == "Fasta":
informat = "fasta"
elif entry8_input.get() == "Genbank":
informat = "genbank"
for record in SeqIO.parse(infile, informat):
Gen_header=record.id.replace(" ", "_")
for characters in BAD_chr:
Gen_header = Gen_header.replace(characters, "_")
Gen_array=str(record.seq)
#
if informat == 'genbank':
desc=str(', '.join(list(record.annotations["taxonomy"])))
else:
desc = ''
### Restriction Enzyme check from list
enzyme = entry3_input.get()
enzyme_RE = RestrictionBatch([enzyme])
### search the restriction sites position in sequence
Gen_array_RE=enzyme_RE.search(Seq(Gen_array))
Gen_array_RE_V = list(Gen_array_RE.values())[0]
print(Gen_array_RE)
#
ID0 = 0
#
if len(Gen_array_RE_V)==0:
ID_min=0
else:
ID_min = min(Gen_array_RE_V)
#
if len(Gen_array_RE_V)==0:
ID_max=0
else:
ID_max = max(Gen_array_RE_V)
#
ID1 = 0
ID2 = 1
# first fragment from first nt to first cut
GenFastaSeq=Gen_array[0:ID_min]
GenFastaSeqLen = len(GenFastaSeq)
GenFastaHeader=Gen_header + "|" + str(GenFastaSeqLen) + "_bp|" + Gen_header
GenFastaHeader=GenFastaHeader.replace(" ","_")
# verbosity
verbosity = "Y"
if verbosity == 'Y':
print(" ", GenFastaHeader)