-
Notifications
You must be signed in to change notification settings - Fork 1
/
dialogs.py
1012 lines (871 loc) · 44.9 KB
/
dialogs.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
# -*- coding: utf-8 -*-
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtDeclarative
import sys
sys.path.append("tangelo")
from ArborAlgorithmManagerAPI import ArborAlgorithmManager
# test to see if a variable can be expressed as a continous numeric value. This
# test is used when displaying the character names, so the user knows if they are
# continuous or discrete characters
def isContinuous(s):
try:
float(s)
return True
except ValueError:
return False
# define the dialogs designed to exercise the API
class NewProjectDialog(QDialog):
# Define the user interface for a new dialog to be created
def __init__(self, ArborAPI,parent=None):
super(NewProjectDialog, self).__init__(parent)
self.api = ArborAPI
self.titleText = QLabel("Enter the name of a new Arbor Project")
self.projectNameDialog = QLineEdit()
self.cancelButton = QPushButton("Cancel")
self.acceptButton = QPushButton("Accept")
self.layout = QVBoxLayout()
self.layout.addWidget(self.titleText)
self.layout.addWidget(self.projectNameDialog)
self.layout.addWidget(self.acceptButton)
self.layout.addWidget(self.cancelButton)
self.setLayout(self.layout)
self.cancelButton.clicked.connect(self.closeProjectDialog)
self.acceptButton.clicked.connect(self.createNewProject)
def closeProjectDialog(self):
self.hide()
def createNewProject(self):
projectTitleAsQstring = self.projectNameDialog.text()
# need to convert from PyQt4.QtCore.QString to Python string
projectTitle = str(projectTitleAsQstring)
# if a valid name was entered, create the project record
if len(projectTitle)>0:
print "creating project entitled:",projectTitle
self.hide()
# create project record in the database
self.api.newProject(projectTitle)
def initializeAllDialogs(arborAPI,algorithms):
global savedArborAPI
savedArborAPI = arborAPI
global newProjectDialogInstance
newProjectDialogInstance = NewProjectDialog(arborAPI)
global newTreeDialogInstance
newTreeDialogInstance = NewTreeDialog(arborAPI)
global newCharacterDialogInstance
newCharacterDialogInstance = NewCharacterDialog(arborAPI)
global newOccurrenceDialogInstance
newOccurrenceDialogInstance = NewOccurrenceDialog(arborAPI)
global newSequenceDialogInstance
newSequenceDialogInstance = NewSequenceDialog(arborAPI)
global newWorkflowDialogInstance
newWorkflowDialogInstance = NewWorkflowDialog(arborAPI,algorithms)
global newOpenTreeOfLifeDialogInstance
newOpenTreeOfLifeDialogInstance = NewOpenTreeOfLifeDialog(arborAPI)
global newDatabaseInfoDialogInstance
newDatabaseInfoDialogInstance = ChangeDatabaseDialog(arborAPI)
global newAlgorithmControlsDialogInstance
newAlgorithmControlsDialogInstance = NewAlgorithmControlsDialog(arborAPI,algorithms)
global newWorkstepParameterDialogInstance
newWorkstepParameterDialogInstance = NewWorkstepParametersDialog(arborAPI)
if (arborAPI.getCurrentProjectName()):
newAlgorithmControlsDialogInstance.setCurrentProjectName(arborAPI.getCurrentProjectName())
def openNewProjectDialog():
global app
print "open new project"
global newProjectDialogInstance
newProjectDialogInstance.show()
#text, ok = QInputDialog.getText('Create New Project', 'Enter the new project name:')
#if ok:
# print "accept was clicked"
# define the dialogs designed to exercise the API
class ChangeDatabaseDialog(QDialog):
# Define the user interface for a new dialog to be created
def __init__(self, ArborAPI,parent=None):
super(ChangeDatabaseDialog, self).__init__(parent)
self.api = ArborAPI
self.titleText = QLabel("Enter the database to use:")
self.databaseNameDialog = QLineEdit()
self.titleText2 = QLabel("Enter an (optional) prefix string:")
self.titleText3 = QLabel("Enter a separation string (e.g. '.' or '_'):")
self.prefixStringDialog = QLineEdit()
self.separationStringDialog = QLineEdit()
self.cancelButton = QPushButton("Cancel")
self.acceptButton = QPushButton("Accept")
self.layout = QVBoxLayout()
self.layout.addWidget(self.titleText)
self.layout.addWidget(self.databaseNameDialog)
self.layout.addWidget(self.titleText2)
self.layout.addWidget(self.prefixStringDialog)
self.layout.addWidget(self.titleText3)
self.layout.addWidget(self.separationStringDialog)
self.layout.addWidget(self.acceptButton)
self.layout.addWidget(self.cancelButton)
self.setLayout(self.layout)
self.cancelButton.clicked.connect(self.closeDatabaseDialog)
self.acceptButton.clicked.connect(self.setDatabaseInfo)
def closeDatabaseDialog(self):
self.hide()
def setDatabaseInfo(self):
databaseTitleAsQstring = self.databaseNameDialog.text()
prefixAsQstring = self.prefixStringDialog.text()
separatorAsQstring = self.separationStringDialog.text()
# need to convert from PyQt4.QtCore.QString to Python string
databaseTitle = str(databaseTitleAsQstring)
prefixString = str(prefixAsQstring)
separatorString = str(separatorAsQstring)
# if a valid name was entered, create the project record
if len(databaseTitle)>0:
print "changing database to :",databaseTitle
print "changing prefix to :",prefixString
print "changing separator to: ",separatorString
self.api.setMongoDatabase(databaseTitle)
self.api.setPrefixString(prefixString)
self.api.setSeparatorString(separatorString)
self.api.initDatabaseConnection()
self.hide()
def openDatabaseChangeDialog():
global app
print "open database dialog"
global newDatabaseInfoDialogInstance
newDatabaseInfoDialogInstance.show()
# pop up to load a new tree into the selected project
class NewTreeDialog(QDialog):
# Define the user interface for a new dialog to be created
def __init__(self, ArborAPI,parent=None):
super(NewTreeDialog, self).__init__(parent)
self.api = ArborAPI
self.treeType = "newick"
self.titleText = QLabel("Add a new Tree to the current project")
self.titleText2 = QLabel("Enter the name to give the dataset here:")
self.confirmationText = QLabel("")
self.nameDialog = QLineEdit()
self.selectFileName = QPushButton("Select PhyloXML file to import")
self.fileSelector = QFileDialog()
self.fileSelector.setNameFilter("PhyloXML files (*.xml)")
self.selectFileNameNewick = QPushButton("Select Newick file to import")
self.fileSelectorNewick = QFileDialog()
self.fileSelectorNewick.setNameFilter("Newick files (*.*)")
#self.fileSelector.setFileMode(QtGui.QFileDialog.ExistingFile)
self.cancelButton = QPushButton("Cancel")
self.acceptButton = QPushButton("Accept")
self.layout = QVBoxLayout()
self.layout.addWidget(self.titleText)
self.layout.addWidget(self.titleText2)
self.layout.addWidget(self.nameDialog)
self.layout.addWidget(self.selectFileNameNewick)
self.layout.addWidget(self.selectFileName)
self.layout.addWidget(self.confirmationText)
self.layout.addWidget(self.acceptButton)
self.layout.addWidget(self.cancelButton)
self.setLayout(self.layout)
self.cancelButton.clicked.connect(self.closeTreeDialog)
self.selectFileName.clicked.connect(self.openFileDialog)
self.selectFileNameNewick.clicked.connect(self.openFileDialogNewick)
self.acceptButton.clicked.connect(self.createNewTree)
self.fileSelector.fileSelected.connect(self.displayNewTreeStatus)
self.fileSelectorNewick.fileSelected.connect(self.displayNewTreeStatus)
def closeTreeDialog(self):
self.hide()
def openFileDialog(self):
self.fileSelector.show()
self.treeType = "phyloxml"
def openFileDialogNewick(self):
self.fileSelectorNewick.show()
self.treeType = "newick"
def displayNewTreeStatus(self,treefile):
self.savedTreeFilename = str(treefile)
confirmString = str("OK to import file '"+treefile+ "' as '"+str(self.nameDialog.text())+"' ?")
self.confirmationText.setText(confirmString)
# the user selected a treefile and confirmed the selection was OK, so perform
# the import operation
def createNewTree(self):
nameForTree = str(self.nameDialog.text())
print "create new tree from file: ",self.savedTreeFilename
print "name for the tree is: ",nameForTree
print "default project for tree is: ", self.api.getCurrentProjectName()
# need to convert from PyQt4.QtCore.QString to Python string
#projectTitle = str(projectTitleAsQstring)
# if valid names are entered, then create the tree record
if len(self.savedTreeFilename)>0 and len(self.api.getCurrentProjectName())>0:
print "adding a tree entitled: ",self.savedTreeFilename
self.hide()
# # create project record in the database
self.api.newTreeInProject(nameForTree, self.savedTreeFilename, self.api.getCurrentProjectName(),self.treeType)
#
def openNewTreeDialog():
global app
print "open new tree dialog"
global newTreeDialogInstance
newTreeDialogInstance.show()
#------------------------ definition for character matrix -----------------
class NewCharacterDialog(QDialog):
# Define the user interface for a new dialog to be created
def __init__(self, ArborAPI,parent=None):
super(NewCharacterDialog, self).__init__(parent)
self.api = ArborAPI
self.titleText = QLabel("Add a new Character Matrix to the current project")
self.titleText2 = QLabel("Enter the name to give the dataset here:")
self.confirmationText = QLabel("")
self.nameDialog = QLineEdit()
self.selectFileName = QPushButton("Select CSV file to import")
self.fileSelector = QFileDialog()
self.fileSelector.setNameFilter("CSV files (*.csv)")
self.cancelButton = QPushButton("Cancel")
self.acceptButton = QPushButton("Accept")
self.layout = QVBoxLayout()
self.layout.addWidget(self.titleText)
self.layout.addWidget(self.titleText2)
self.layout.addWidget(self.nameDialog)
self.layout.addWidget(self.selectFileName)
self.layout.addWidget(self.confirmationText)
self.layout.addWidget(self.acceptButton)
self.layout.addWidget(self.cancelButton)
self.setLayout(self.layout)
self.cancelButton.clicked.connect(self.closeCharacterDialog)
self.selectFileName.clicked.connect(self.openFileDialog)
self.acceptButton.clicked.connect(self.createNewCharacterMatrix)
self.fileSelector.fileSelected.connect(self.displayNewCharacterStatus)
def closeCharacterDialog(self):
self.hide()
def openFileDialog(self):
self.fileSelector.show()
def displayNewCharacterStatus(self,inputfile):
self.savedFilename = str(inputfile)
confirmString = str("OK to import file '"+inputfile+ "' as '"+str(self.nameDialog.text())+"' ?")
self.confirmationText.setText(confirmString)
# the user selected a CSV file and confirmed the selection was OK, so perform
# the import operation
def createNewCharacterMatrix(self):
nameForInstance = str(self.nameDialog.text())
print "create new character matrix from file: ",self.savedFilename
print "name for the tree is: ",nameForInstance
print "default project for matrix is: ", self.api.getCurrentProjectName()
# if valid names are entered, then create the character record
if len(self.savedFilename)>0 and len(self.api.getCurrentProjectName())>0:
print "adding a tree entitled: ",self.savedFilename
self.hide()
# # create project record in the database
self.api.newCharacterMatrixInProject(nameForInstance, self.savedFilename, self.api.getCurrentProjectName())
#
def openNewCharacterDialog():
global app
print "open new character matrix dialog"
global newCharacterDialogInstance
newCharacterDialogInstance.show()
#------------------------ definition for occurrences -----------------
class NewOccurrenceDialog(QDialog):
# Define the user interface for a new dialog to be created
def __init__(self, ArborAPI,parent=None):
super(NewOccurrenceDialog, self).__init__(parent)
self.api = ArborAPI
self.titleText = QLabel("Add a new set of species occurrences to the current project")
self.titleText2 = QLabel("Enter the name to give the dataset here:")
self.confirmationText = QLabel("")
self.nameDialog = QLineEdit()
self.selectFileName = QPushButton("Select CSV file to import")
self.fileSelector = QFileDialog()
self.fileSelector.setNameFilter("CSV files (*.csv)")
self.cancelButton = QPushButton("Cancel")
self.acceptButton = QPushButton("Accept")
self.layout = QVBoxLayout()
self.layout.addWidget(self.titleText)
self.layout.addWidget(self.titleText2)
self.layout.addWidget(self.nameDialog)
self.layout.addWidget(self.selectFileName)
self.layout.addWidget(self.confirmationText)
self.layout.addWidget(self.acceptButton)
self.layout.addWidget(self.cancelButton)
self.setLayout(self.layout)
self.cancelButton.clicked.connect(self.closeOccurrencesDialog)
self.selectFileName.clicked.connect(self.openFileDialog)
self.acceptButton.clicked.connect(self.createNewOccurrences)
self.fileSelector.fileSelected.connect(self.displayNewOccurrencesStatus)
def closeOccurrencesDialog(self):
self.hide()
def openFileDialog(self):
self.fileSelector.show()
def displayNewOccurrencesStatus(self,inputfile):
self.savedFilename = str(inputfile)
confirmString = str("OK to import file '"+inputfile+ "' as '"+str(self.nameDialog.text())+"' ?")
self.confirmationText.setText(confirmString)
# the user selected a CSV file and confirmed the selection was OK, so perform
# the import operation
def createNewOccurrences(self):
nameForInstance = str(self.nameDialog.text())
print "create new occurrence records from file: ",self.savedFilename
print "name for the occurrence set is: ",nameForInstance
print "default project for occurrence is: ", self.api.getCurrentProjectName()
# if valid names are entered, then create the character record
if len(self.savedFilename)>0 and len(self.api.getCurrentProjectName())>0:
print "adding occurrences entitled: ",self.savedFilename
self.hide()
# # create project record in the database
self.api.newOccurrencesInProject(nameForInstance, self.savedFilename, self.api.getCurrentProjectName())
#
def openNewOccurrencesDialog():
global app
print "open new occurrence dialog"
global newOccurrenceDialogInstance
newOccurrenceDialogInstance.show()
#------------------------ definition for sequences -----------------
class NewSequenceDialog(QDialog):
# Define the user interface for a new dialog to be created
def __init__(self, ArborAPI,parent=None):
super(NewSequenceDialog, self).__init__(parent)
self.api = ArborAPI
self.titleText = QLabel("Add ew sequences to the current project")
self.titleText2 = QLabel("Enter the name to give the sequence set:")
self.confirmationText = QLabel("")
self.nameDialog = QLineEdit()
self.selectFileName = QPushButton("Select sequences file to import")
self.fileSelector = QFileDialog()
self.fileSelector.setNameFilter("FASTA files (*.fasta)")
self.cancelButton = QPushButton("Cancel")
self.acceptButton = QPushButton("Accept")
self.layout = QVBoxLayout()
self.layout.addWidget(self.titleText)
self.layout.addWidget(self.titleText2)
self.layout.addWidget(self.nameDialog)
self.layout.addWidget(self.selectFileName)
self.layout.addWidget(self.confirmationText)
self.layout.addWidget(self.acceptButton)
self.layout.addWidget(self.cancelButton)
self.setLayout(self.layout)
self.cancelButton.clicked.connect(self.closeSequenceDialog)
self.selectFileName.clicked.connect(self.openFileDialog)
self.acceptButton.clicked.connect(self.createNewSequence)
self.fileSelector.fileSelected.connect(self.displayNewSequenceStatus)
def closeSequenceDialog(self):
self.hide()
def openFileDialog(self):
self.fileSelector.show()
def displayNewSequenceStatus(self,inputfile):
self.savedFilename = str(inputfile)
confirmString = str("OK to import file '"+inputfile+ "' as '"+str(self.nameDialog.text())+"' ?")
self.confirmationText.setText(confirmString)
# the user selected a CSV file and confirmed the selection was OK, so perform
# the import operation
def createNewSequence(self):
nameForInstance = str(self.nameDialog.text())
print "create new sequence records from file: ",self.savedFilename
print "name for the sequence set is: ",nameForInstance
print "default project for sequence is: ", self.api.getCurrentProjectName()
# if valid names are entered, then create the character record
if len(self.savedFilename)>0 and len(self.api.getCurrentProjectName())>0:
print "adding sequence entitled: ",self.savedFilename
self.hide()
# # create project record in the database
self.api.newSequencesInProject(nameForInstance, self.savedFilename, self.api.getCurrentProjectName())
#
def openNewSequenceDialog():
global app
print "open new sequence dialog"
global newSequenceDialogInstance
newSequenceDialogInstance.show()
#----------------
# pop up to load a tree from the Open Tree of Life Project
class NewOpenTreeOfLifeDialog(QDialog):
# Define the user interface for a new dialog to be created
def __init__(self, ArborAPI,parent=None):
super(NewOpenTreeOfLifeDialog, self).__init__(parent)
self.api = ArborAPI
self.titleText = QLabel("Import a tree from the Open Tree of Life")
self.titleText2 = QLabel("Enter the name to give the dataset here:")
self.confirmationText = QLabel("")
self.nameDialog = QLineEdit()
self.titleText3 = QLabel("Enter the OTTol ID to query:")
self.ottolidDialog = QLineEdit()
self.cancelButton = QPushButton("Cancel")
self.acceptButton = QPushButton("Accept")
self.layout = QVBoxLayout()
self.layout.addWidget(self.titleText)
self.layout.addWidget(self.titleText2)
self.layout.addWidget(self.nameDialog)
self.layout.addWidget(self.titleText3)
self.layout.addWidget(self.ottolidDialog)
self.layout.addWidget(self.acceptButton)
self.layout.addWidget(self.cancelButton)
self.setLayout(self.layout)
self.cancelButton.clicked.connect(self.closeTreeDialog)
self.acceptButton.clicked.connect(self.createNewTreeFromOpenTreeOfLife)
def closeTreeDialog(self):
self.hide()
# the user has entered an OTToLID from the OTL, so lets retrieve it
def createNewTreeFromOpenTreeOfLife(self):
nameForTree = str(self.nameDialog.text())
print "query OpenTreeOfLife from ottolID: ",self.ottolidDialog.text()
print "name for the tree is: ",nameForTree
print "default project for tree is: ", self.api.getCurrentProjectName()
# need to convert from PyQt4.QtCore.QString to Python string
#projectTitle = str(projectTitleAsQstring)
# if valid names are entered, then create the tree record
if len(self.api.getCurrentProjectName())>0:
self.hide()
# # create project record in the database
self.api.newTreeFromOpenTreeOfLife(nameForTree, self.ottolidDialog.text(), self.api.getCurrentProjectName())
#
def openNewTreeOfLifeDialog():
global app
print "open new tree dialog"
global newOpenTreeOfLifeDialogInstance
newOpenTreeOfLifeDialogInstance.show()
#----------------
# pop up to load a tree from the Open Tree of Life Project
class NewAlgorithmControlsDialog(QDialog):
# Define the user interface for a new dialog to be created
def __init__(self, ArborAPI,ArborAlgorithmsAPI,parent=None):
super(NewAlgorithmControlsDialog, self).__init__(parent)
self.api = ArborAPI
self.algorithms = ArborAlgorithmsAPI
self.currentProjectName = ''
self.titleText = QLabel("Run Analyses")
self.vert_splitter = QSplitter(Qt.Vertical, self)
self.button_splitter = QSplitter(Qt.Vertical,self)
self.vert_splitter2 = QSplitter(Qt.Vertical,self)
# list the tree instances of data in the project
self.treeLabel = QLabel("Select a Tree:")
self.treeLabel.setMaximumHeight(40)
self.treeListWidget = QListWidget(self)
self.treeListWidget.setObjectName("treeListWidget")
# list the character matrix instances of data in the project
self.matrixLabel = QLabel("Select a Character Matrix:")
self.matrixLabel.setMaximumHeight(40)
self.matrixListWidget = QListWidget(self)
self.matrixListWidget.setObjectName("matrixListWidget")
# list the attribute columns in the current character matrix
self.charcterLabel = QLabel("Select a Character:")
self.charcterLabel.setMaximumHeight(40)
self.characterListWidget = QListWidget(self)
self.characterListWidget.setObjectName("characterListWidget")
# list the algorithms available
self.algorithmLabel = QLabel("Algorithm To Run:")
self.algorithmLabel.setMaximumHeight(40)
self.algorithmListWidget = QListWidget(self)
self.algorithmListWidget.setObjectName("algorithmListWidget")
self.confirmationText = QLabel("")
self.nameDialog = QLineEdit()
self.titleText3 = QLabel("Enter the output name to use:")
self.titleText3.setMaximumHeight(40)
self.outputObjectName = QLineEdit()
self.outputObjectName.setMaximumHeight(50)
self.cancelButton = QPushButton("Close Window")
self.runButton = QPushButton("Run Tree/Matrix \n Algorithm")
#put up a logo
pm = QPixmap("Arbor_128px.png")
self.arborLogo = QLabel()
self.arborLogo.setPixmap(pm);
self.arborLogo.setAlignment(Qt.AlignCenter)
# lay out the elements in the dialog panel
self.vert_splitter.addWidget(self.treeLabel)
self.vert_splitter.addWidget(self.treeListWidget)
self.vert_splitter.addWidget(self.matrixLabel)
self.vert_splitter.addWidget(self.matrixListWidget)
self.vert_splitter2.addWidget(self.charcterLabel)
self.vert_splitter2.addWidget(self.characterListWidget)
self.vert_splitter2.addWidget(self.algorithmLabel)
self.vert_splitter2.addWidget(self.algorithmListWidget)
self.button_splitter.addWidget(self.arborLogo)
self.button_splitter.addWidget(self.titleText3)
self.button_splitter.addWidget(self.outputObjectName)
self.button_splitter.addWidget(self.runButton)
self.button_splitter.addWidget(self.cancelButton)
self.layout = QHBoxLayout()
#self.layout.addWidget(self.arborLogo)
self.layout.addWidget(self.vert_splitter)
self.layout.addWidget(self.vert_splitter2)
self.layout.addWidget(self.button_splitter)
self.setLayout(self.layout)
# connect statements to connect behaviors to events
self.cancelButton.clicked.connect(self.closeAlgrorithmControlsDialog)
self.runButton.clicked.connect(self.doStuff)
self.matrixListWidget.currentItemChanged.connect(self.fillCharacterListWidget)
def closeAlgrorithmControlsDialog(self):
self.hide()
def clearAll(self):
self.treeListWidget.clear()
self.matrixListWidget.clear()
self.characterListWidget.clear()
def loadAlgorithms(self):
# get a record from the Arbor datastore and iterate through its headers
self.algorithmListWidget.clear()
charList = self.algorithms.returnListOfLoadedAlgorithms()
for j in range(0,len(charList)):
self.algorithmListWidget.addItem(charList[j])
def setCurrentProjectName(self,prname):
self.characterListWidget.clear()
# fill tree and character matrix lists
treeInstances = self.api.getListOfDatasetsByProjectAndType(prname,'PhyloTree')
self.currentProjectName = prname;
#print "api returned trees: ",treeInstances
self.treeListWidget.clear()
for j in range(0,len(treeInstances)):
self.treeListWidget.addItem(treeInstances[j])
matrixInstances = self.api.getListOfDatasetsByProjectAndType(prname,'CharacterMatrix')
#print "api returned matrices: ",matrixInstances
self.matrixListWidget.clear()
for j in range(0,len(matrixInstances)):
self.matrixListWidget.addItem(matrixInstances[j])
# this method finds whih matrix has been selected and list all the columns
# to be processed in the cha
def fillCharacterListWidget(self):
if (self.matrixListWidget.currentItem()):
matrixname = str(self.matrixListWidget.currentItem().text())
self.characterListWidget.clear()
# get a record from the Arbor datastore and iterate through its headers
charList = self.api.returnCharacterListFromCharacterMatrix(
self.matrixListWidget.currentItem().text(),
self.currentProjectName)
# now fill the display widget with the characters, indicating their continuous or discrete nature
# by listing them one per line with the proper type indicated
for j in range(0,len(charList)):
#if isContinuous(charList[j]):
# charentry = "Continuous: "+charList[j]
#else:
# charentry = "Discrete: "+charList[j]
charentry = charList[j]
self.characterListWidget.addItem(charentry)
# the user has invoked run on a selected algorithm, collected the selected datasets and invoke
# the algorithm
def doStuff(self):
currenttree = currentmatrix = currentcharacter = outputname = ''
if (self.algorithmListWidget.currentItem()):
algorithmToRun = self.algorithmListWidget.currentItem().text()
if (self.treeListWidget.currentItem()):
currenttree=self.treeListWidget.currentItem().text()
if (self.matrixListWidget.currentItem()):
currentmatrix = self.matrixListWidget.currentItem().text()
if (self.characterListWidget.currentItem()):
currentcharacter = self.characterListWidget.currentItem().text()
if (self.outputObjectName.text()):
outputname = self.outputObjectName.text()
# TODO: add checking logic here to make sure appropriate data types are defined for algorithms
# before running them. All algorithms could have a list of data they depend on and it would get checked
self.algorithms.runAlgorithmByName(algorithmToRun,self.api.getMongoDatabase(),self.currentProjectName,currenttree,currentmatrix,currentcharacter,outputname)
pass
#
def openAlgorithmControlsDialog():
global app
print "open algorithm controls "
global newAlgorithmControlsDialogInstance
#newAlgorithmControlsDialogInstance.clearAll()
newAlgorithmControlsDialogInstance.loadAlgorithms()
newAlgorithmControlsDialogInstance.show()
# this is defined at the dialogs package level, it invokes changed toany
# dialogs that needs to know the project has changed
def changeCurrentProject(prname):
newAlgorithmControlsDialogInstance.setCurrentProjectName(prname)
#------------------------ definition for workflows -----------------
# pop up to load a tree from the Open Tree of Life Project
class NewWorkflowDialog(QDialog):
# Define the user interface for a new dialog to be created
def __init__(self, ArborAPI,AlgorithmAPI,parent=None):
super(NewWorkflowDialog, self).__init__(parent)
self.api = ArborAPI
self.algorithms = AlgorithmAPI
self.currentProjectName = ''
self.titleText = QLabel("Add a new workflow to the current project")
# left column (existing wflows and naming the new one
self.vert_splitter = QSplitter(Qt.Vertical, self)
self.vert_splitter2 = QSplitter(Qt.Vertical,self)
self.vert_splitter3 = QSplitter(Qt.Vertical,self)
self.vert_splitter4 = QSplitter(Qt.Vertical,self)
self.button_splitter = QSplitter(Qt.Vertical,self)
self.titleText2 = QLabel("Existing workflows:")
self.workflowListWidget = QListWidget(self)
self.nameWflowText = QLabel("New Workflow Name:")
self.newWfNameDialog = QLineEdit()
self.newWorkflowButton = QPushButton("Create New Workflow")
self.deleteWorkflowButton = QPushButton("Delete Workflow")
self.executeWorkflowButton = QPushButton("Execute Workflow")
# 2nd column; list workstep types and name of new step dialog
self.stepTypeLabel = QLabel("Workstep Types: ")
self.stepTypeLabel.setMaximumHeight(40)
self.workstepListWidget = QListWidget(self)
self.workstepListWidget.setObjectName("workstepListWidget")
self.nameWflowText2 = QLabel("New Workstep Name:")
self.newStepNameDialog = QLineEdit()
self.newWorkstepButton = QPushButton("New Step in the Workflow")
# list the attribute columns in the current character matrix
self.outText1 = QLabel("connect output of:")
self.outText1.setMaximumHeight(40)
self.outputOfListWidget = QListWidget(self)
self.outputOfListWidget.setMaximumHeight(200)
self.outText2 = QLabel("select output:")
self.outputSelectDialog = QLineEdit()
self.setStepParametersButton = QPushButton("Edit Workstep Parameters")
self.inText1 = QLabel("to input of:")
self.inText1.setMaximumHeight(40)
self.inputOfListWidget = QListWidget(self)
self.inputOfListWidget.setMaximumHeight(200)
self.inText2 = QLabel("select output:")
self.inputSelectDialog = QLineEdit()
self.connectButton = QPushButton("Connect Steps")
self.cancelButton = QPushButton("Close Window")
#put up a logo
pm = QPixmap("Arbor_128px.png")
self.arborLogo = QLabel()
self.arborLogo.setPixmap(pm);
self.arborLogo.setAlignment(Qt.AlignCenter)
# lay out the elements in the dialog panel
self.vert_splitter.addWidget(self.titleText)
self.vert_splitter.addWidget(self.workflowListWidget)
self.vert_splitter.addWidget(self.nameWflowText)
self.vert_splitter.addWidget(self.newWfNameDialog)
self.vert_splitter.addWidget(self.newWorkflowButton)
self.vert_splitter.addWidget(self.deleteWorkflowButton)
self.vert_splitter.addWidget(self.executeWorkflowButton)
self.vert_splitter2.addWidget(self.stepTypeLabel)
self.vert_splitter2.addWidget(self.workstepListWidget)
self.vert_splitter2.addWidget(self.nameWflowText2)
self.vert_splitter2.addWidget(self.newStepNameDialog)
self.vert_splitter2.addWidget(self.newWorkstepButton)
self.vert_splitter3.addWidget(self.outText1)
self.vert_splitter3.addWidget(self.outputOfListWidget)
self.vert_splitter3.addWidget(self.setStepParametersButton)
#self.vert_splitter3.addWidget(self.outText2)
#self.vert_splitter3.addWidget(self.outputSelectDialog)
self.vert_splitter4.addWidget(self.inText1)
self.vert_splitter4.addWidget(self.inputOfListWidget)
#self.vert_splitter4.addWidget(self.inText2)
#self.vert_splitter4.addWidget(self.inputSelectDialog)
self.vert_splitter4.addWidget(self.connectButton)
self.button_splitter.addWidget(self.arborLogo)
self.button_splitter.addWidget(self.cancelButton)
self.layout = QHBoxLayout()
#self.layout.addWidget(self.arborLogo)
self.layout.addWidget(self.vert_splitter)
self.layout.addWidget(self.vert_splitter2)
self.layout.addWidget(self.vert_splitter3)
self.layout.addWidget(self.vert_splitter4)
self.layout.addWidget(self.button_splitter)
self.setLayout(self.layout)
# connect statements to connect behaviors to events
self.cancelButton.clicked.connect(self.closeWorkflowDialog)
self.connectButton.clicked.connect(self.connectStuff)
self.newWorkflowButton.clicked.connect(self.createNewWorkflow)
self.deleteWorkflowButton.clicked.connect(self.deleteWorkflow)
self.executeWorkflowButton.clicked.connect(self.executeWorkflow)
self.newWorkstepButton.clicked.connect(self.newWorkstepInWorkflow)
self.workflowListWidget.itemClicked.connect(self.selectWorkflowItem)
def closeWorkflowDialog(self):
self.hide()
def openWorkstepParameterButton(self):
self.openNewWorkstepParametersDialog()
def connectStuff(self):
print "** connect stuff **"
projectTitle = self.api.getCurrentProjectName()
wflowName = str(self.workflowListWidget.currentItem().text())
outstep = str(self.outputOfListWidget.currentItem().text())
instep = str(self.inputOfListWidget.currentItem().text())
self.api.connectStepsInWorkflow(wflowName,outstep,instep,projectTitle)
# the user clicked on a workflow, update the other UI elements to show info from the database
# about this iteam
def selectWorkflowItem(self):
projectTitle = self.api.getCurrentProjectName()
wflowName = str(self.workflowListWidget.currentItem().text())
print "looking up record for wf:",wflowName,"proj:",projectTitle
wflowRecord = self.api.returnWorkflowRecord(wflowName,projectTitle)
print wflowRecord
# fill the "output of" and "input of" list widgets since the user will want to
# connect the steps together
self.inputOfListWidget.clear()
self.outputOfListWidget.clear()
for step in wflowRecord['analyses']:
if step['name']:
self.inputOfListWidget.addItem(step['name'])
self.outputOfListWidget.addItem(step['name'])
# add the record of a new workstep to the currently selected workflow
def newWorkstepInWorkflow(self):
projectTitle = self.api.getCurrentProjectName()
workStepType = str(self.workstepListWidget.currentItem().text())
stepName = str(self.newStepNameDialog.text())
wflowName = str(self.workflowListWidget.currentItem().text())
self.api.newWorkstepInWorkflow(str(wflowName),str(workStepType),str(stepName),projectTitle)
# rerender the input/output lists so the new step shows up
self.selectWorkflowItem()
# add the record of a new workstep to the currently selected workflow
def deleteWorkflow(self):
projectTitle = self.api.getCurrentProjectName()
wflowName = str(self.workflowListWidget.currentItem().text())
self.api.deleteWorkflow(str(wflowName),projectTitle)
self.fillDialogs()
# add the record of a new workstep to the currently selected workflow
def executeWorkflow(self):
print "executing workflow"
projectTitle = self.api.getCurrentProjectName()
wflowName = str(self.workflowListWidget.currentItem().text())
# execute workflow, delete intermediate steps, pass algorithms in for execution
self.api.executeWorkflowInProject(str(wflowName),projectTitle,True,self.algorithms)
self.fillDialogs()
# the user selected a file and confirmed the selection was OK, so perform
# the import operation
def createNewWorkflow(self):
nameForInstance = str(self.newWfNameDialog.text())
currentProject = self.api.getCurrentProjectName()
# if valid names are entered, then create the character record
if len(nameForInstance)>0 and len(currentProject)>0:
print "name for a new workflow is: ",nameForInstance
print "default project for workflow is: ", currentProject
# # create project record in the database
self.api.newWorkflowInProject(nameForInstance, currentProject)
self.fillDialogs()
def fillDialogs(self):
# get a record from the Arbor project and iterate through its workflows
self.workflowListWidget.clear()
project = self.api.getCurrentProjectName()
itemList = self.api.getListOfDatasetsByProjectAndType(project,"Workflow")
for j in range(0,len(itemList)):
self.workflowListWidget.addItem(itemList[j])
# fill the worksteps dialog
self.workstepListWidget.clear()
itemList = self.api.returnListOfLoadedWorksteps()
for j in range(0,len(itemList)):
self.workstepListWidget.addItem(itemList[j])
def openNewWorkflowDialog():
global app
print "open new workflow dialog"
global newWorkflowDialogInstance
newWorkflowDialogInstance.fillDialogs()
newWorkflowDialogInstance.show()
#-----------------------------------------
# workstep parameter options dialog
#-----------------------------------------
# pop up to interact with workflows inside a single project
class NewWorkstepParametersDialog(QDialog):
# Define the user interface for a new dialog to be created
def __init__(self, ArborAPI,parent=None):
super(NewWorkstepParametersDialog, self).__init__(parent)
self.api = ArborAPI
self.currentProjectName = ''
self.titleText = QLabel("Add a new workflow to the current project")
self.vert_splitter = QSplitter(Qt.Vertical, self)
self.vert_splitter2 = QSplitter(Qt.Vertical,self)
self.vert_splitter3 = QSplitter(Qt.Vertical,self)
#self.vert_splitter4 = QSplitter(Qt.Vertical,self)
self.button_splitter = QSplitter(Qt.Vertical,self)
# left column (existing wflows and the worksteps in the flow
self.titleText2 = QLabel("Existing workflows:")
self.workflowListWidget = QListWidget(self)
self.stepTypeLabel = QLabel("Worksteps: ")
self.stepTypeLabel.setMaximumHeight(40)
self.workstepListWidget = QListWidget(self)
self.workstepListWidget.setObjectName("workstepListWidget")
# 2nd column; list parameter name and value
self.parameterNameText = QLabel("Parameter Name:")
self.parameterNameDialog = QLineEdit()
self.numericValueText = QLabel("Numeric Value:")
self.numericValueDialog = QLineEdit()
self.addNumericParameterButton = QPushButton("Add Numeric Parameter")
self.stringValueText = QLabel("String Parameter:")
self.stringValueText.setMaximumHeight(40)
self.stringValueDialog = QLineEdit()
self.addStringParameterButton = QPushButton("Add String Parameter")
# show the already defined parameters
self.outText1 = QLabel("Defined Parameters:")
self.outText1.setMaximumHeight(40)
self.definedParametersListWidget = QListWidget(self)
self.definedParametersListWidget.setMaximumHeight(200)
#put up a logo
pm = QPixmap("Arbor_128px.png")
self.arborLogo = QLabel()
self.arborLogo.setPixmap(pm);
self.arborLogo.setAlignment(Qt.AlignCenter)
self.cancelButton = QPushButton("Close Window")
# lay out the elements in the dialog panel
self.vert_splitter.addWidget(self.titleText2)
self.vert_splitter.addWidget(self.workflowListWidget)
self.vert_splitter.addWidget(self.stepTypeLabel)
self.vert_splitter.addWidget(self.workstepListWidget)
self.vert_splitter2.addWidget(self.parameterNameText)
self.vert_splitter2.addWidget(self.parameterNameDialog)
self.vert_splitter2.addWidget(self.numericValueText)
self.vert_splitter2.addWidget(self.numericValueDialog)
self.vert_splitter2.addWidget(self.addNumericParameterButton)
self.vert_splitter2.addWidget(self.stringValueText)
self.vert_splitter2.addWidget(self.stringValueDialog)
self.vert_splitter2.addWidget(self.addStringParameterButton)
self.vert_splitter3.addWidget(self.outText1)
self.vert_splitter3.addWidget(self.definedParametersListWidget)
self.button_splitter.addWidget(self.arborLogo)
self.button_splitter.addWidget(self.cancelButton)
self.layout = QHBoxLayout()
#self.layout.addWidget(self.arborLogo)
self.layout.addWidget(self.vert_splitter)
self.layout.addWidget(self.vert_splitter2)
self.layout.addWidget(self.vert_splitter3)
self.layout.addWidget(self.button_splitter)
self.setLayout(self.layout)
# connect statements to connect behaviors to events
self.cancelButton.clicked.connect(self.closeWorkstepParameterDialog)
self.addStringParameterButton.clicked.connect(self.addStringParameter)
self.addNumericParameterButton.clicked.connect(self.addNumericParameter)
self.workflowListWidget.itemClicked.connect(self.selectWorkflowItem)
self.workstepListWidget.itemClicked.connect(self.selectWorkstepItem)
def closeWorkstepParameterDialog(self):
self.hide()
# this method adds/updates a string parameter on a workstep inside the selected
# workflow. The current selections for workflow and worksteps are read in order to
# decide which step to change. The strings entered are processed with str() to convert
# them from QStrings to python strings before further proessing, as he API is pure python.
def addStringParameter(self):
print "add string parameter"
projectTitle = self.api.getCurrentProjectName()
wflowName = str(self.workflowListWidget.currentItem().text())
thisStepName = str(self.workstepListWidget.currentItem().text())
parameterName = str(self.parameterNameDialog.text())
parameterValue = str(self.stringValueDialog.text())
self.api.updateWorkstepParameter(wflowName,thisStepName,parameterName,parameterValue,projectTitle)
self.fillWorkstepParametersDialog()
def addNumericParameter(self):
print "add numeric parameter"
projectTitle = self.api.getCurrentProjectName()
wflowName = str(self.workflowListWidget.currentItem().text())
thisStepName = str(self.workstepListWidget.currentItem().text())
parameterName = str(self.parameterNameDialog.text())
parameterValue = float(self.numericValueDialog.text())
self.api.updateWorkstepParameter(wflowName,thisStepName,parameterName,parameterValue,projectTitle)
self.fillWorkstepParametersDialog()
# the user clicked on a workflow, update the other UI elements to show info from the database
# about this iteam
def selectWorkflowItem(self):
projectTitle = self.api.getCurrentProjectName()
wflowName = str(self.workflowListWidget.currentItem().text())
print "looking up record for wf:",wflowName,"proj:",projectTitle
wflowRecord = self.api.returnWorkflowRecord(wflowName,projectTitle)
print wflowRecord
# fill the list of steps in this workflow
self.workstepListWidget.clear()
for step in wflowRecord['analyses']:
if step['name']:
self.workstepListWidget.addItem(step['name'])
# the user clicked on a workstep, update the other UI elements to show info from the database
# about this item
def selectWorkstepItem(self):
self.numericValueDialog.clear()
self.stringValueDialog.clear()
self.parameterNameDialog.clear()
self.fillWorkstepParametersDialog()
def fillDialogs(self):
# get a record from the Arbor project and iterate through its workflows
self.workflowListWidget.clear()
project = self.api.getCurrentProjectName()
itemList = self.api.getListOfDatasetsByProjectAndType(project,"Workflow")
for j in range(0,len(itemList)):
self.workflowListWidget.addItem(itemList[j])
def fillWorkstepParametersDialog(self):
projectTitle = self.api.getCurrentProjectName()
wflowName = str(self.workflowListWidget.currentItem().text())
thisStepName = str(self.workstepListWidget.currentItem().text())
print "retrieving parameters for:",thisStepName
parameters = self.api.returnWorkstepParameters(wflowName,thisStepName,projectTitle)
self.definedParametersListWidget.clear()