-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathiqtreegui.py
executable file
·1197 lines (1007 loc) · 48.9 KB
/
iqtreegui.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
#written by Philipp Resl
#this is the python3 version of iqtreegui
import sys, os
import subprocess
import multiprocessing
import tempfile
from subprocess import Popen, PIPE
import datetime
import configparser
import xml.etree.ElementTree as ET
from xml.dom import minidom as MD
import unicodedata
from tkinter import *
import tkinter.filedialog, tkinter.messagebox
from tkinter.scrolledtext import ScrolledText
from tkinter.ttk import *
import platform
from os.path import expanduser
from shutil import copy, rmtree
# import iqtreegui modules
import iqtree_gui_support
import iqtgui_modules as iqtg
def resource_path(relative): #needed to load iqtreeGUI icon
if hasattr(sys, '_MEIPASS'):
return sys._MEIPASS + relative
return sys.path[0] + relative
#return os.path.join(os.environ.get("_MEIPASS2",os.path.abspath(".")),relative)
###### main class #######
class iqtree_GUI(Tk):
#class iqtree_GUI(Frame):
nthreads = "AUTO"
nbootstrap = 1000
overwrite=1
simulate_only=1
choice_bs_option = 1
choice_part_option = 1
choice_model_option = 1
partition_model = ""
model_partitions = []
align_partitions = []
alignments = []
part_offset=0
align_offset = 0
nmodels = 1
reduce_model_violation = 0
command = ""
partition_command = ""
is_models_set = False
# initialize advanced settings types
advanced_bs_settings = iqtg.data_types_settings.BootstrapConfig()
treesearch_settings = iqtg.data_types_settings.TreeSearchSettings()
iqtree_settings = iqtg.data_types_settings.IQtreeSettings()
gui_settings = iqtg.data_types_settings.IQtreeGUIConfig()
advanced_model_settings = iqtg.data_types_settings.AutomaticModelSelectionSettings()
anc_settings = iqtg.data_types_settings.AncSeqSettings()
def convert_number(self, s): #function to distinguish between float, int and str when reading from xml file
try:
float(s)
if float(s).is_integer():
return int(s)
else:
return float(s)
except ValueError:
return s
def about_message(self):
tkinter.messagebox.showinfo("About", "iqtreeGUI Version "+self.gui_settings.version+"\nwritten by Philipp Resl")
def not_yet(self):
tkinter.messagebox.showinfo("Info", "This feature is not yet implemented in IQ-tree GUI.")
def save_analysis(self):
f = tkinter.filedialog.asksaveasfile(mode='w', defaultextension=".xml")
if f is None: # asksaveasfile return `None` if dialog closed with "cancel".
return
top = ET.Element('top')
comment = ET.Comment('Generated for iqtreeGUI')
top.append(comment)
#write bootstrap settings
child = ET.SubElement(top, "advancedbootstrap")
for key, value in self.advanced_bs_settings.__dict__.items():
elem = ET.SubElement(child, key)
elem.text = str(value)
elem = ET.SubElement(child, "nbootstrap")
elem.text = self.entry_bs.get()
elem = ET.SubElement(child, "bootstrap_type")
elem.text = str(self.choice_bs_option)
#write tree search settings
child = ET.SubElement(top, "treesearch")
for key, value in self.treesearch_settings.__dict__.items():
elem = ET.SubElement(child, key)
elem.text = str(value)
#write iqtree settings
child = ET.SubElement(top, "iqtreesettings")
for key, value in self.iqtree_settings.__dict__.items():
elem = ET.SubElement(child, key)
elem.text = str(value)
elem = ET.SubElement(child, "redo")
elem.text = str(self.overwrite)
#write advanced model settings
child = ET.SubElement(top, "advancedmodelsettings")
for key, value in self.advanced_model_settings.__dict__.items():
elem = ET.SubElement(child, key)
elem.text = str(value)
#alignment
child = ET.SubElement(top, "alignments")
for alignment in self.alignments:
elem = ET.SubElement(child, "filename")
elem.text = alignment.alignment_path
#for partitioned analysis
part_child = ET.SubElement(top, "partitions")
elem = ET.SubElement(part_child, "part_var")
elem.text = str(self.part_var.get())
if self.part_var.get() == 2: #if there are multiple partitions
#partitions
child = ET.SubElement(part_child, "partitionmodeltype")
child.text = str(self.part_model_var.get())
for i in range(0, len(self.align_partitions)):
name = "partition%d" % i
child = ET.SubElement(part_child, name)
elem = ET.SubElement(child, "start")
elem.text = str(self.align_partitions[i].get_start())
elem = ET.SubElement(child, "end")
elem.text = str(self.align_partitions[i].get_end())
elem = ET.SubElement(child, "which_alignment")
elem.text = str(self.align_partitions[i].get_which_alignment())
else:
child = ET.SubElement(part_child, "partition0")
elem = ET.SubElement(child, "start")
elem.text = str(0)
elem = ET.SubElement(child, "end")
elem.text = str("end")
#models
model_child = ET.SubElement(top, "models")
elem = ET.SubElement(model_child, "model_var")
elem.text = str(self.v_model_option.get())
if self.v_model_option.get() == 2: #if model specification is set to manual
for i in range(0, len(self.model_partitions)):
name = "model%d" % i
child = ET.SubElement(model_child, name)
print(self.model_partitions[i].model.__dict__)
for key, value in self.model_partitions[i].model.__dict__.items():
elem = ET.SubElement(child, key)
print(value)
elem.text = value
else:
child = ET.SubElement(model_child, "model0")
elem = ET.SubElement(child, "model")
elem.text = str(self.v_model_option.get())
child = ET.SubElement(top, "bootstrap")
elem = ET.SubElement(child, "option")
elem.text = str(self.v.get())
elem = ET.SubElement(child, "nbootstrap")
elem.text = self.entry_bs.get()
#make output human readable
output = ET.tostring(top, 'utf-8')
reparsed_output = MD.parseString(output)
f.write(reparsed_output.toprettyxml(indent="\t"))
f.close()
def load_analysis(self):
print("loading analysis...")
self.reset_partitions() # delete old partitions
filename = tkinter.filedialog.askopenfilename()
if filename == "": # return `None` if dialog closed with "cancel".
return
try:
tree = ET.parse(filename)
except:
tkinter.messagebox.showinfo("Error", "Not a valid iqtreeGUI XML file")
return
root = tree.getroot()
for child in root:
if child.tag == "advancedbootstrap":
for subelement in child:
for key, setting in self.advanced_bs_settings.__dict__.items():
if key == subelement.tag:
self.advanced_bs_settings.__dict__[key] = self.convert_number(subelement.text)
if child.tag == "treesearch":
for subelement in child:
for key, setting in self.treesearch_settings.__dict__.items():
if key == subelement.tag:
self.treesearch_settings.__dict__[key] = self.convert_number(subelement.text)
if child.tag == "iqtreesettings":
for subelement in child:
for key, setting in self.iqtree_settings.__dict__.items():
if key == subelement.tag:
self.iqtree_settings.__dict__[key] = self.convert_number(subelement.text)
if child.tag == "advancedmodelsettings":
for subelement in child:
for key, setting in self.advanced_model_settings.__dict__.items():
if key == subelement.tag:
#print key
#print subelement.text
self.advanced_model_settings.__dict__[key] = self.convert_number(subelement.text)
if child.tag == "alignments": #adjust this for multiple alignment files
print("loading alignments")
# first remove old alignments
for i in range(0,len(self.alignments)):
self.alignments[i].grid_forget()
self.alignments = []
# now load new ones
for subelement in child:
self.alignments.append(iqtg.alignment.Alignment(self.alignment_scroll_frame, align_id="Alignment "+str(len(self.alignments)+1)+": ", path = subelement.text, number=len(self.alignments)+1, alignment_list = self.alignments, info_label=self.alignment_info_label))
self.alignments[-1].grid(sticky=W)
self.align_offset += 30
self.alignment_scroll_frame.update()
self.alignment_info_label.config(text="Alignments: %s Alignment(s) loaded" % str(len(self.alignments)))
if child.tag == "partitions":
self.align_partitions = []
self.part_set_frame_container.lift(self.partition_layer)
self.button_create_part.lift(self.partition_layer)
self.button_delete_part.lift(self.partition_layer)
self.which_partition_model.lift(self.partition_layer)
for subelement in child:
if subelement.tag == "part_var":
self.part_var.set(self.convert_number(subelement.text))
self.choice_part_option = self.convert_number(subelement.text)
if subelement.text=="1":
self.part_set_frame_container.lower(self.partition_layer)
self.button_create_part.lower(self.partition_layer)
self.button_delete_part.lower(self.partition_layer)
self.which_partition_model.lower(self.partition_layer)
break
elif subelement.tag == "partitionmodeltype":
self.partition_model = subelement.text
self.part_model_var.set(subelement.text)
else:
self.create_partition()
for pos in subelement:
#print pos.tag
#print pos.text
if pos.tag == "start":
self.align_partitions[-1].start_entry.insert(0,pos.text)
if pos.tag == "end":
self.align_partitions[-1].end_entry.insert(0,pos.text)
if pos.tag == "which_alignment":
self.align_partitions[-1].part_alignment_var.set("Alignment " + pos.text)
self.align_partitions[-1].which_alignment = "Alignment " + pos.text
if child.tag == "models":
for i in range(0,len(self.model_partitions)):
self.model_partitions[i].grid_forget()
self.model_partitions = []
i = 0
for subelement in child:
if subelement.tag == "model_var":
self.v_model_option.set(subelement.text)
self.choice_model_option = self.convert_number(subelement.text)
if subelement.tag == "model%d"%i:
self.model_partitions.append(iqtg.model_select.ModelSelection(self.manual_model_frame, part_id=" Alignment %d" % i))
self.model_partitions[-1].grid(sticky=W)
self.part_offset+=30
for model in subelement:
for key, setting in self.model_partitions[i].model.__dict__.items():
if key == model.tag:
#print key, model.text
self.model_partitions[i].model.__dict__[key] = self.convert_number(model.text)
#print "length %d " % len(self.model_partitions)
i += 1
#self.create_models()
for i in range(0, len(self.model_partitions)):
self.model_partitions[i].load_model()
self.manual_model_frame.update()
#self.manual_model_frame.update()
#self.model_frame_down.grid(row=3, column=1, sticky=N+S+W+E)
self.manual_model_frame.update()
self.auto_model_select.grid_forget()
if child.tag == "bootstrap":
for subelement in child:
if subelement.tag == "option":
self.v.set(self.convert_number(subelement.text))
self.choice_bs_option = self.convert_number(subelement.text)
if subelement.tag == "nbootstrap":
self.nbootstrap = self.convert_number(subelement.text)
self.entry_bs.delete(0,END)
self.entry_bs.insert(END, self.nbootstrap)
"""for subelement in child:
print subelement.tag, subelement.text
"""
def spawn_random_tree_window(self):
random_window=Toplevel()
random = iqtg.special.randomtree.RandomTreeWindow(random_window, self.gui_settings)
self.master.wait_window(random_window)
def spawn_consensus_tree_window(self):
consensus_window=Toplevel()
consensus = iqtg.special.consensustree.ConsensusTreeWindow(consensus_window, self.gui_settings)
self.master.wait_window(consensus_window)
def spawn_robionsonfoulds_window(self):
robinson_window=Toplevel()
robinson = iqtg.special.robinsonfoulds.RobinsonFouldsWindow(robinson_window, self.gui_settings)
self.master.wait_window(robinson_window)
def spawn_ancseqs_window(self):
ancseqs_window=Toplevel()
ancseqs = iqtg.special.ancseq.AncSeqWindow(ancseqs_window, self.gui_settings, self.anc_settings)
self.master.wait_window(ancseqs_window)
def spawn_model_selection_window(self):
settings_window=Toplevel()
settings = iqtg.modelselect_settings.ModelselectionSettingsWindow(settings_window, self.advanced_model_settings)
self.master.wait_window(settings_window)
def spawn_settings_window(self):
print("settings")
settings_window=Toplevel(self.master)
settings = iqtg.settings.SettingsWindow(settings_window, self.gui_settings, self.config_path)
self.master.wait_window(settings_window)
self.read_config_file()
# self.info_label.insert(END, self.get_time()+"New configuration file loaded\n")
# self.info_label.insert(END, self.get_time()+"Path to iqtree is: "+self.gui_settings.iqtree_path+"\n")
def spawn_advanced_bootstrap_window(self):
print("advanced bootstrap settings")
settings_window=Toplevel()
settings = iqtg.bootstrap_settings.AdvancedBSWindow(settings_window, self.advanced_bs_settings)
self.master.wait_window(settings_window)
# self.info_label.insert(END, self.get_time()+"Advanced Bootstrap are: \n")
# self.info_label.insert(END, "bcor=" + str(self.advanced_bs_settings.bcor) + ", beps=" + str(self.advanced_bs_settings.beps)+", nm=" + str(self.advanced_bs_settings.nm)+", nstep=" + str(self.advanced_bs_settings.nstep)+", bnni=" + str(self.advanced_bs_settings.bnni)+", wbt=" + str(self.advanced_bs_settings.wbt)+", wbtl=" + str(self.advanced_bs_settings.wbtl)+"\n")
def spawn_iqtree_settings_window(self):
settings_window=Toplevel()
settings = iqtg.iqtree_settings.IQtreeSettingsWindow(settings_window, self.iqtree_settings)
self.master.wait_window(settings_window)
# self.info_label.insert(END, self.get_time()+"IQTree settings are:\n")
# self.info_label.insert(END, self.get_time()+self.iqtree_settings.get_values())
def spawn_treesearch_settings_window(self):
settings_window=Toplevel()
settings = iqtg.treesearch_settings.TreesearchSettingsWindow(settings_window,self.treesearch_settings)
self.master.wait_window(settings_window)
# self.info_label.insert(END, self.get_time()+"Treesearch parameters are:\n")
# self.info_label.insert(END, self.get_time()+self.treesearch_settings.get_values())
def get_time(self):
return "["+datetime.datetime.now().strftime("%Y-%m-%d %H:%M")+"]\t"
def add_alignment(self):
filename = "no file name"
filename = tkinter.filedialog.askopenfilename(initialdir = self.gui_settings.wd,title = "Select alignment")
print(filename)
print("Number of alignments: %s" % str(len(self.alignments)))
if "Windows" in platform.system():
filename = filename.replace("/","\\")
if filename != "" and filename != "no file name":
self.alignments.append(iqtg.alignment.Alignment(self.alignment_scroll_frame, align_id="Alignment "+str(len(self.alignments)+1)+": ", path = filename, number=len(self.alignments)+1, alignment_list = self.alignments, info_label=self.alignment_info_label))
self.alignments[-1].grid(sticky=W)
self.align_offset += 30
self.alignment_scroll_frame.update()
self.alignment_info_label.config(text="Alignments: %s Alignment(s) loaded" % str(len(self.alignments)))
#self.update()
def create_partition(self):
alignment_names = ["Alignment %s" % element.alignment_no for element in self.alignments]
if len(alignment_names) == 0: # in case there is no alignment loaded, return. probably this needs a message box
print("no alignments loaded")
tkinter.messagebox.showerror("Error", "First specify at least one alignment.")
return
print(alignment_names)
self.align_partitions.append(iqtg.partition.Partition(self.partitions_set_frame, part_id="Partition "+str(len(self.align_partitions)+1)+" ", alignments = alignment_names, number = len(self.align_partitions)+1))
self.align_partitions[-1].grid()
self.partitions_set_frame.update()
self.partition_info_label.config(text="Partitions: %s Partitions specified" % str(len(self.align_partitions)))
print("Partition created")
def reset_partitions(self):
for i in range(0, len(self.align_partitions)): # partitions
self.align_partitions[i].grid_forget()
self.align_partitions[:] = []
self.partitions_set_frame.update()
self.partition_info_label.config(text="Partitions: unpartitioned")
def delete_partition(self):
if len(self.align_partitions) > 0:
self.align_partitions[-1].grid_forget()
self.align_partitions = self.align_partitions[:-1]
self.partition_info_label.config(text="Partitions: %s Partitions specified" % str(len(self.align_partitions)))
self.partitions_set_frame.update()
# self.info_label.insert(END, self.get_time()+"Partition deleted\n")
def create_models(self): # function will create model instances according to the specified alignment and partition options
if len(self.alignments) == 1:
print("create_model: single alignment")
if self.choice_part_option == 1: #no partitioning
print("create_model: no partition")
self.model_partitions.append(iqtg.model_select.ModelSelection(self.manual_model_frame, part_id=" Alignment 1"))
self.model_partitions[-1].grid(sticky=W)
self.part_offset+=30
self.manual_model_frame.update()
elif self.choice_part_option == 2: #partitions
if len(self.align_partitions) == 0:
tkinter.messagebox.showerror("Error", "Specify at least one partition per alignment first.")
return
else:
print("create_model: multiple partitions")
for i in range(0, len(self.align_partitions)):
self.model_partitions.append(iqtg.model_select.ModelSelection(self.manual_model_frame, part_id=" Partition %s" % str(i+1)))
self.model_partitions[-1].grid(sticky=W)
self.part_offset+=30
self.manual_model_frame.update()
elif len(self.alignments) > 1: #multiple alignments
print("create_model: multiple alignments")
if self.choice_part_option == 1: #no partitioning
print("create_model: no partitions")
for i in range(0, len(self.alignments)):
self.model_partitions.append(iqtg.model_select.ModelSelection(self.manual_model_frame, part_id=" Alignment %s" % str(i+1)))
self.model_partitions[-1].grid(sticky=W)
self.part_offset+=30
self.manual_model_frame.update()
elif self.choice_part_option == 2: #partitions
if len(self.align_partitions) == 0 or (len(self.align_partitions) < len(self.alignments)):
tkinter.messagebox.showerror("Error", "Specify at least one partition per alignment first.")
return
else:
print("create_model: multiple partitions")
for i in range(0, len(self.align_partitions)):
self.model_partitions.append(iqtg.model_select.ModelSelection(self.manual_model_frame, part_id=" Partition %s" % str(i+1)))
self.model_partitions[-1].grid(sticky=W)
self.part_offset+=30
self.manual_model_frame.update()
self.model_info_label.config(text="Models: %s Models specified" % str(len(self.model_partitions)))
def reset_models(self):
print("reset_models: Removing " +str(len(self.model_partitions))+" partitions")
for i in range(0, len(self.model_partitions)):
self.model_partitions[i].grid_forget()
self.model_partitions[:] = []
self.part_offset=0
self.manual_model_frame.update()
def get_partitions(self):
return len(self.align_partitions)
def get_additional_settings_for_run(self):
add_cmd = ""
print(self.advanced_model_settings.get_command())
add_cmd += self.iqtree_settings.get_command()
add_cmd += self.advanced_bs_settings.get_command()
add_cmd += self.treesearch_settings.get_command()
return add_cmd
######################################################################################
# #
# #
# Create iqtree command #
# #
# #
######################################################################################
def get_run_command_new(self):
print("creating run command")
print("Alignments: %d " % len(self.alignments))
print("Partitions: %d " % len(self.align_partitions))
print("Models: %d" % len(self.model_partitions))
if "Windows" in platform.system():
separator="\\"
else:
separator="/"
## create output directory and transfer alignment files
analysis_dir = self.gui_settings.wd + separator + self.gui_settings.analysisname
#print(analysis_dir)
if self.overwrite == 1 and os.path.exists(analysis_dir) == True:
rmtree(analysis_dir, ignore_errors=True)
os.makedirs(analysis_dir)
elif self.overwrite == 1 and os.path.exists(analysis_dir) == False:
os.makedirs(analysis_dir)
elif self.overwrite == 0 and os.path.exists(analysis_dir) == False:
os.makedirs(analysis_dir)
else:
tkinter.messagebox.showerror("Error", "Analysis folder already exists.")
return
## create initial run command
command = self.gui_settings.iqtree_path +" "
## add number of threads
command += "-nt %s " % str(self.nthreads)
partition_command=""
## select bootstrap option:
if self.choice_bs_option == 2:
try:
int(self.entry_bs.get())
command += "-b %s " % self.entry_bs.get()
except:
tkinter.messagebox.showerror("Error", "Not a valid number of bootstrap replicates.")
return
if self.choice_bs_option == 3:
try:
int(self.entry_bs.get())
command += "-bb %s " % self.entry_bs.get()
except:
tkinter.messagebox.showerror("Error", "Not a valid number of bootstrap replicates.")
return
if len(self.alignments) == 0:
print("no alignment")
return
### if there is only a single alignment:
elif len(self.alignments) == 1:
print("single alignment")
#copy file to analysis directory
copy(self.alignments[0].alignment_path, analysis_dir)
## add model parameters for single partition:
if self.choice_part_option == 1:
partition_command="#NEXUS\nbegin sets;\n"
partition_command += "charset part1="+os.path.basename(self.alignments[0].alignment_path)+":*;\n"
# check for different model options
if self.choice_model_option == 1: # if automatic model selection is specified
partition_command += "end;\n"
if self.choice_model_option == 2:
if "invalid" in self.model_partitions[0].get_model():
tkinter.messagebox.showerror("Error", "Specified model for Partition 1 " + self.model_partitions[0].get_model())
else:
partition_command += "charpartition mine=" + self.model_partitions[0].get_model() +":part1;"
partition_command += "\nend;\n"
## add model parameters for multiple partition
if self.choice_part_option == 2:
# check for different model options
## if modeltest should be used
if self.choice_model_option == 1:
partition_command="#NEXUS\nbegin sets;\n"
partition_command += "charset part1="+self.alignments[0].alignment_path+";"
partition_command += "\nend;\n"
## add parameters for multiple partition:
## if there are multiple partitions and models
if self.choice_model_option == 2:
print("single alignment, multiple partitions and models")
partition_command="#NEXUS\nbegin sets;\n"
## first get partition boundaries:
partition_command += "charset part1="+self.alignments[0].alignment_path+":"
for part in range(0,len(self.align_partitions)):
partition_command += " " + str(self.align_partitions[part].get_start())+ "-"+str(self.align_partitions[part].get_end())
partition_command += ";\n"
## second add models:
model_string = "charpartition mine = "
print("found partitions: %s" % len(self.model_partitions))
for i in range(0, len(self.model_partitions)):
model = self.model_partitions[i].get_model()
print(model)
if "invalid" in model:
tkinter.messagebox.showerror("Error", "Specified model for Partition " + str(i+1))
break
else:
model_string += model
model_string +=":part%s," % str(i+1)
#print self.model_partitions[i].model.__dict__
model_string = model_string[:-1]
model_string += ";\nend;\n"
partition_command += model_string
print(partition_command)
if self.choice_model_option == 1 and len(self.align_partitions)>1: #if there is automatic model selection
partition_command="#NEXUS\nbegin sets;\n"
partition_command += "charset part1="+self.alignments[0].alignment_path+":"
## first get partition boundaries:
for part in range(0,len(self.align_partitions)):
partition_command += " " + str(self.align_partitions[part].get_start())+ "-"+str(self.align_partitions[part].get_end())
partition_command += "\nend;\n"
### if there are multiple alignments
elif len(self.alignments) > 1:
print("multiple alignments")
#### Baustelle hier!!
### multiple alignments, no partitions, modeltest = models per alignment
if len(self.align_partitions) == 0 and self.choice_model_option == 1:
print("multiple alignments, no partitions, modeltest")
#command += self.advanced_model_settings.get_command() #first add model testing option to run command
partition_command="#NEXUS\nbegin sets;\n"
i = 1
for alignment in self.alignments:
copy(alignment.alignment_path, analysis_dir)
partition_command += "charset part" + str(i) + "= "+os.path.basename(alignment.alignment_path) + ":*;\n"
i += 1
partition_command +="end;\n"
### multiple alignments, multiple partitions, modeltest = models per alignment (modeltest)
elif len(self.align_partitions) >= 1 and self.choice_model_option == 1:
print("muliple alignments, multiple partitions, modeltest")
#command += self.advanced_model_settings.get_command() #first add model testing option to run command
partition_command="#NEXUS\nbegin sets;\n"
i = 1
for partition in self.align_partitions:
alignment = self.alignments[partition.get_which_alignment()-1]
copy(alignment.alignment_path, analysis_dir)
partition_command += "charset part" + str(i) + "="+os.path.basename(alignment.alignment_path) + ":" + " " + str(partition.get_start()) +"-" +str(partition.get_end()) +";\n"
i += 1
for alignment in self.alignments:
if alignment.alignment_path not in partition_command:
partition_command += "charset part" + str(i) + "="+os.path.basename(alignment.alignment_path) + ":" + " *;\n"
i +=1
partition_command +="end;\n"
### multiple alignments, multiple partitions, models per partition
elif len(self.align_partitions) >= 1 and self.choice_model_option == 2:
print("muliple alignments, multiple partitions, models per partition")
#command += self.advanced_model_settings.get_command() #first add model testing option to run command
partition_command="#NEXUS\nbegin sets;\n"
i = 1
for partition in self.align_partitions:
alignment = self.alignments[partition.get_which_alignment()-1]
copy(alignment.alignment_path, analysis_dir)
partition_command += "charset part" + str(i) + "="+os.path.basename(alignment.alignment_path) + ":" + " " + str(partition.get_start()) +"-" +str(partition.get_end()) +";\n"
i += 1
for alignment in self.alignments:
if alignment.alignment_path not in partition_command:
partition_command += "charset part" + str(i) + "="+os.path.basename(alignment.alignment_path) + ":" + " *;\n"
i +=1
## second add models:
model_string = "charpartition mine = "
print("found partitions: %s" % len(self.model_partitions))
for i in range(0, len(self.model_partitions)):
model = self.model_partitions[i].get_model()
print(model)
if "invalid" in model:
tkinter.messagebox.showerror("Error", "Check model for Partition " + str(i+1))
break
else:
model_string += model
model_string +=":part%s," % str(i+1)
partition_command += model_string.strip(",")
partition_command +=";\nend;\n"
#### to here all for multiple partitions
### the stuff from here should be the same regardless of the other options
## check for partition command and adjust
if partition_command != "":
file = open(analysis_dir+separator+"partitions.nex", "w")
file.write(partition_command)
file.close()
if "(-spp)" in self.partition_model:
command += "-spp "+analysis_dir+separator+"partitions.nex "
elif "(-q)" in self.partition_model:
command += "-q "+analysis_dir+separator+"partitions.nex "
elif "(-sp)" in self.partition_model:
command += "-sp "+analysis_dir+separator+"partitions.nex "
else:
command += "-spp "+analysis_dir+separator+"partitions.nex " #standard
## check if ancestral seq reconstruction should be performed
if self.anc_settings.set == 1:
if self.anc_settings.anc != "":
command += self.anc_settings.anc
if self.anc_settings.tree != "":
command += self.anc_settings.tree
if self.anc_settings.ppcut != "":
command += self.anc_settings.ppcut
##get additional settings for automatic model selection:
if self.choice_model_option == 1:
command += self.advanced_model_settings.get_command()
## additional settings
command += self.get_additional_settings_for_run()
#repeat analysis
if self.overwrite == 1:
command += " -redo "
self.partition_command = partition_command
## make sure the command looks good
print(partition_command)
print(command)
# self.info_label.insert(END, self.get_time()+"iqtree command will be: "+command+"\n")
if self.simulate_only == 0:
self.spawn_iqtree_subprocess(command)
else:
#self.command_info_label.config(text="IQ-TREE command will be: \n"+command)
self.command_info_label.grid(row=14, column=0, columnspan=3, sticky=W)
self.command_entry.grid(row=15, column=0, sticky=W+E, columnspan=10)
self.command_entry.delete(0, END)
self.command_entry.insert(END, command)
def spawn_iqtree_subprocess(self, command):
iqtree_out_window=Toplevel(self.master)
iqtree_out = iqtg.iqtree_out.IqtreeWindow(iqtree_out_window, self.gui_settings)
iqtree_out.send_command(command)
iqtree_out.spawn_process()
def update_notebook(self, button):
self.manual_model_frame.update()
def read_config_file(self):
config = configparser.ConfigParser()
print("reading config file")
print(self.config_path)
try:
config.read(self.config_path)
if self.gui_settings.version != config.get("Settings", "version"):
print("Config file seems to be from a different version of iqtreegui. This may cause problems: %s" % self.config_path)
self.gui_settings.iqtree_path = config.get('Settings', 'iqtree')
self.gui_settings.wd = config.get('Settings', 'wd')
self.gui_settings.analysisname = config.get('Settings', 'analysisname')
print("Config file read")
except:
tkinter.messagebox.showerror("Error", "Config file error")
return
def create_new_config_file(self):
config = configparser.ConfigParser()
print("Writing config file to", self.config_path)
configfile = open(self.config_path, "w")
config.add_section('Settings')
config.set('Settings', 'iqtree', self.gui_settings.iqtree_path)
config.set('Settings', 'version', self.gui_settings.version)
config.set('Settings', 'wd', self.gui_settings.wd)
config.set('Settings', 'analysisname', self.gui_settings.analysisname)
config.write(configfile)
configfile.close()
def __init__(self, top):
os.chdir(self.gui_settings.wd) # this is needed for the bundled mac app
#_bgcolor = 'gray85' # X11 color: 'gray85'
#_fgcolor = '#000000' # X11 color: 'black'
#_compcolor = 'gray85' # X11 color: 'gray85'
#_ana1color = 'gray85' # X11 color: 'gray85'
#_ana2color = 'gray85' # X11 color: 'gray85'
self.master = top
top.geometry("1000x593")#+330+201")
top.title("iqtreeGUI Alpha")
#top.configure(background="#F0F0F0")
# this is not needed like it is, it does not help. it needs to be changed:
#plain_style=Style()
#plain_style.configure("plain.TFrame", foreground="black", background="#F0F0F0", bordercolor="red", borderwidth=4)
#top.resizable(width=True, height=True) # set to True to enable the workaround for the disappearing buttons on Mojave
top.grid_rowconfigure(0, weight=1)
top.grid_columnconfigure(0, weight=1)
#top.iconbitmap(resource_path("iqtreegui.ico"))
if "Linux" in platform.system() or "Darwin" in platform.system():
self.config_path=os.path.expanduser("~/.iqtree_config")
if "Windows" in platform.system():
self.config_path=os.path.expanduser("~\iqtree_config.cfg")
#### BASIC NOTEBOOK #######
#stylenb
self.notebook = Notebook(top)
#self.notebook.bind("<ButtonRelease-1>", self.update_notebook)
#print(tkinter.TkVersion)
#print(tkinter.TclVersion)
# this was used due to a bug in tk/tcl
#if root.call('tk', 'windowingsystem') == 'aqua': #change padding of notebook tabs if osx
# s=tStyle()
# s.configure("TNotebook.Tab", padding=(18, 8, 20, 0))
self.notebook.grid(row=0, column=0,columnspan=10, rowspan=1, sticky=N+S+W+E)
## threads selection
self.Label3 = Label(top)
self.Label3.configure(text="Number of threads:")
self.Label3.grid(row=1, column=4, sticky=W)
threads = [str(i) for i in range(1, multiprocessing.cpu_count()+1)]
threads = ["AUTO"] + threads
var_thread = StringVar()
var_thread.set(threads[0])
def cbOption_threads(which):
self.nthreads = which
# self.info_label.insert(END, self.get_time()+"Number of threads is set to "+self.nthreads+"\n")
print("Number of threads set to %s" % self.nthreads)
self.threads_select = OptionMenu(top, var_thread, *threads, command=cbOption_threads)
#self.threads_select.place(relx=0.31, rely=0.93, height=26, width=65)
self.threads_select.grid(row=1, column=5, sticky=W)
self.button_run = Button(top)
#self.button_run.place(relx=0.01, rely=0.93, height=26, width=102)
self.button_run.grid(row=1,column=0, sticky=W)
#self.button_run.configure(activebackground="#d9d9d9")
self.button_run.configure(text="Run Analysis", command=self.get_run_command_new)
cb_overwritevar = IntVar()
cb_overwritevar.set(1)
def cb_overwrite():
self.overwrite = cb_overwritevar.get()
#print self.overwrite
# self.info_label.insert(END, self.get_time()+"Overwrite analysis is set to "+str(self.overwrite)+"\n")
self.overwrite_analysis = Checkbutton(top, text="Overwrite analysis",variable=cb_overwritevar,command=cb_overwrite)
self.overwrite_analysis.grid(row=1, column=1, sticky=W)
cb_simulate_only_var = IntVar()
cb_simulate_only_var.set(1)
def cb_simulate_only():
self.simulate_only = cb_simulate_only_var.get()
# self.info_label.insert(END, self.get_time()+"Simulate only is set to "+str(self.simulate_only)+"\n")
self.simulate_only_check = Checkbutton(top, text="Simulate (only display iqtree command) ",variable=cb_simulate_only_var,command=cb_simulate_only)
self.simulate_only_check.grid(row=1, column=2, sticky=W)
########INFO#########
self.info_frame = Frame(self.notebook)
self.info_frame.columnconfigure(0, minsize=250)
self.info_frame.rowconfigure(0, minsize=50)
#this can be uncommented if the label should be displayed. it has been disabled for testing purposes
self.img=PhotoImage(file=resource_path("/icon/iqtreegui.gif"))
self.logo_cv = Label(self.info_frame, image=self.img)
self.logo_cv.image = self.img
self.logo_cv.grid(row=1, column=1, rowspan=5, sticky=W)
message = "iqtreeGUI - A graphical user interface for IQ-TREE.\n\nhttp://github.com/reslp/iqtreegui\n\nVersion %s \n\n" % self.gui_settings.version
self.label = Label(self.info_frame, text=message)
self.label.configure(font="Helvetica 14 bold")
self.label.config(justify=LEFT)
self.label.grid(row=1, column=2, sticky=NW)
self.info_frame.rowconfigure(6, minsize=20)
self.overview_label = Label(self.info_frame, text = "Overview of current analysis:")
self.overview_label.configure(font="Helvetica 14 bold")
self.overview_label.grid(row=7,column=1, columnspan=3, sticky=W)
self.alignment_info_label = Label(self.info_frame, text="Alignments: no alignment loaded")
self.alignment_info_label.config(justify=LEFT)
self.alignment_info_label.grid(row=9, column=1, columnspan=3, sticky=W)
self.partition_info_label = Label(self.info_frame, text="Partitions: unpartitioned")
self.partition_info_label.config(justify=LEFT)
self.partition_info_label.grid(row=10, column=1, columnspan=3, sticky=W)
self.model_info_label = Label(self.info_frame, text="Models: automated model selection")
self.model_info_label.config(justify=LEFT)
self.model_info_label.grid(row=11, column=1, columnspan=3, sticky=W)
self.bootstrap_info_label = Label(self.info_frame, text="Bootstrap: no bootstraping")
self.bootstrap_info_label.config(justify=LEFT)
self.bootstrap_info_label.grid(row=12, column=1, columnspan=3, sticky=W)
self.info_frame.rowconfigure(13, minsize=140)
self.command_info_label = Label(self.info_frame, text="IQ-TREE command will be:")
self.command_info_label.configure(font="Helvetica 14 bold")
self.command_info_label.config(justify=LEFT)
self.command_info_label.grid(row=14, column=0, columnspan=3, sticky=W)
self.command_info_label.grid_forget()
self.command_entry = Entry(self.info_frame)
self.command_entry.grid(row=15, column=0, sticky=W+E, columnspan=10)
self.command_entry.insert(END, "no command yet")
self.command_entry.grid_forget()
#self.info_label.tag_configure("center", justify='center')
# self.info_label.insert(END, welcome_message)
# load settings file, create if it does not exist
#tkMessageBox.showerror("Error", resource_path('/config.txt'))
print("Looking for config file in:", self.config_path)
if not os.path.isfile(self.config_path): #check if config file exists
print("config file not found, new config file will be created")
self.create_new_config_file()
## self.info_label.insert(END, self.get_time()+"No config file found. I created a new one...\n")
else:
print("Read config file...")
self.read_config_file()
self.notebook.add(self.info_frame, text="Info")
###ALIGNMENT########
## create frame for scrollbars and alignment view
self.alignment_frame = Frame(self.notebook,style="plain.TFrame")
self.alignment_frame.grid(sticky=N+W+S+E)
self.alignment_frame.rowconfigure(0, minsize=30)
self.alignment_frame.columnconfigure(0, minsize=30)
self.alignment_frame.grid_rowconfigure(4,weight=1)
self.alignment_frame.grid_columnconfigure(1,weight=1)
self.description = Label(self.alignment_frame,text="Specify alignment files (FASTA) here: ", justify=LEFT)
self.description.configure(font="Helvetica 14 bold")
self.description.grid(row=1,column=1, sticky=W)
self.load_alignment_button = Button(self.alignment_frame)
self.load_alignment_button.grid(row=2,column=1,sticky=W)
self.load_alignment_button.configure(text="Add alignment", command=self.add_alignment)
#bgcol = self.alignment_frame.cget("bg")
#print(bgcol)
self.alignment_frame_container = Frame(self.alignment_frame, style="plain.TFrame")
self.alignment_frame_container.grid(row=4, column=1, columnspan=10, sticky=N+S+W+E)
self.alignment_scroll_frame = iqtg.ScrollableFrame.ScrollableFrame(self.alignment_frame_container)
self.notebook.add(self.alignment_frame, text="Alignment")
#self.notebook.update_idletasks()
###Partitioning########
## partitioning frame
self.partition_option_frame = Frame(self.notebook) #original frame
self.partition_option_frame.grid(sticky=N+S+W+E)
#self.partition_option_frame.configure(relief=GROOVE)
self.partition_option_frame.columnconfigure(0, minsize=30)
self.partition_option_frame.rowconfigure(0, minsize=30)
self.description_part = Label(self.partition_option_frame,text="Specify partitions: ", justify=LEFT)
self.description_part.configure(font="Helvetica 14 bold")
self.description_part.grid(row=1,column=1, sticky=W)
self.partition_layer = Label(self.partition_option_frame)
self.partition_layer.grid(row=2,column=1,rowspan=20, columnspan=20, sticky=N+S+W+E)
self.part_set_frame_container = Frame(self.partition_option_frame)
self.part_set_frame_container.grid(row=4, column=2, columnspan=5, sticky=N+W+S+E)
self.partitions_set_frame = iqtg.ScrollableFrame.ScrollableFrame(self.part_set_frame_container)
self.button_create_part = Button(self.partition_option_frame)
self.button_create_part.grid(row=3, column=2, sticky=N)
#self.button_create_part.configure(activebackground="#d9d9d9")
self.button_create_part.configure(text="Create partition", command=self.create_partition)
self.button_delete_part = Button(self.partition_option_frame)
self.button_delete_part.grid(row=3,column=3, sticky=N)
#self.button_delete_part.configure(activebackground="#d9d9d9")
self.button_delete_part.configure(text="Delete partition", command=self.delete_partition)
#initial position hidden
self.part_set_frame_container.lower(self.partition_layer)
self.button_create_part.lower(self.partition_layer)
self.button_delete_part.lower(self.partition_layer)
partition_options = [("single partition",1),("multiple partitions",2)]
self.part_var=IntVar()
self.part_var.set(1)
self.small_part_subframe = Frame(self.partition_option_frame)
self.small_part_subframe.grid(row=2,column=1)
def ShowChoice_part():
self.choice_part_option=self.part_var.get()
# self.info_label.insert(END, self.get_time()+"Partitioning changed to: "+partition_options[self.choice_part_option-1][0]+"\n")
if self.part_var.get() == 1:
self.part_set_frame_container.lower(self.partition_layer)
self.button_create_part.lower(self.partition_layer)