forked from donovan-h-parks/STAMP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
STAMP.py
1857 lines (1457 loc) · 85.2 KB
/
STAMP.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
#=======================================================================
# Author: Donovan Parks
#
# Copyright 2011 Donovan Parks
#
# This file is part of STAMP.
#
# STAMP is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# STAMP is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with STAMP. If not, see <http://www.gnu.org/licenses/>.
#=======================================================================
__author__ = 'Donovan Parks'
__copyright__ = 'Copyright 2013'
__credits__ = ['Donovan Parks']
__license__ = 'GPL3'
__version__ = '2.0.1'
__maintainer__ = 'Donovan Parks'
__email__ = '[email protected]'
__status__ = 'Development'
import sys, os, platform
import string
import Dependencies
from GUI.plotDlg import PlotDlg # forward reference so py2app recognizes this file is required
from PyQt4 import QtGui, QtCore
from mainUI import Ui_MainWindow
from GUI.selectFeaturesDlg import SelectFeaturesDlg
from GUI.createProfileMgRastDlg import CreateProfileMgRastDlg
from GUI.createProfileRITADlg import CreateProfileRITADlg
from GUI.createProfileCoMetDlg import CreateProfileCoMetDlg
from GUI.createProfileMothurDlg import CreateProfileMothurDlg
from GUI.createProfileBiomDlg import CreateProfileBiomDlg
from GUI.loadDataDlg import LoadDataDlg
from GUI.assignCOGsDlg import AssignCOGsDlg
from GUI.preferencesDlg import PreferencesDlg
from GUI.multCompCorrectionInfoDlg import MultCompCorrectionInfoDlg
from GUI.groupLegendDlg import GroupLegendDlg
from GUI.statsTableDlg import StatsTableDlg
from GUI.metadataTableDlg import MetadataTableDlg
from commandLine import CommandLineParser
from metagenomics.stats.SampleStatsTests import SampleStatsTests
from metagenomics.stats.GroupStatsTests import GroupStatsTests
from metagenomics.stats.MultiGroupStatsTests import MultiGroupStatsTests
from metagenomics.fileIO.StampIO import StampIO
from metagenomics.fileIO.MetadataIO import MetadataIO
from metagenomics.GenericTable import GenericTable
from metagenomics.ProfileTree import ProfileTree
from metagenomics.SampleProfile import SampleProfile
from metagenomics.GroupProfile import GroupProfile
from metagenomics.MultiGroupProfile import MultiGroupProfile
from metagenomics.DirectoryHelper import getMainDir
from plugins.PlotsManager import PlotsManager
from plugins.PluginManager import PluginManager
import matplotlib as mpl
from numpy import seterr
class MainWindow(QtGui.QMainWindow):
def __init__(self, preferences, parent=None):
QtGui.QWidget.__init__(self, parent)
# setup default plot settings
mpl.rcParams['font.size'] = 8
mpl.rcParams['axes.titlesize'] = 8
mpl.rcParams['axes.labelsize'] = 8
mpl.rcParams['xtick.labelsize'] = 8
mpl.rcParams['ytick.labelsize'] = 8
mpl.rcParams['legend.fontsize'] = 8
# setup preferences and settings
self.preferences = preferences
self.settings = QtCore.QSettings("BeikoLab", "STAMP")
self.preferences['Settings'] = self.settings
# icons
self.refreshIcon = QtGui.QIcon()
self.refreshIcon.addPixmap(QtGui.QPixmap("icons/refresh.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
# initialize GUI
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
# setup status bar
self.lblStatusBar = QtGui.QLabel()
self.ui.statusBar.addPermanentWidget(self.lblStatusBar)
self.btnAutoRecalculation = QtGui.QPushButton('Recalculate statistics and plots')
self.btnAutoRecalculation.setCheckable(True)
self.btnAutoRecalculation.setChecked(True)
self.btnAutoRecalculation.setFixedHeight(20)
self.ui.statusBar.addPermanentWidget(self.btnAutoRecalculation)
self.connect(self.btnAutoRecalculation, QtCore.SIGNAL('toggled(bool)'), self.autoRecalculateChanged)
self.bAutoRecalculate = True
# initialize class variables
self.profileTree = ProfileTree()
self.sampleProfile = SampleProfile()
self.groupProfile = GroupProfile()
self.multiGroupProfile = MultiGroupProfile()
# setup view STAMP properties menu item
self.ui.dockProperties.toggleViewAction().setShortcut("Ctrl+P")
self.ui.dockProperties.toggleViewAction().setToolTip("Show\hide properties window")
self.ui.dockProperties.toggleViewAction().setStatusTip("Show\hide properties window")
self.ui.menuView.addAction(self.ui.dockProperties.toggleViewAction())
# setup group legend
self.ui.menuView.addSeparator()
self.groupLegendDlg = GroupLegendDlg(self.preferences, self)
self.groupLegendDlg.setObjectName("groupLegendDlg");
self.groupLegendDlg.setVisible(True)
self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.groupLegendDlg)
self.groupLegendDlg.setFloating(False)
self.groupLegendDlg.toggleViewAction().setShortcut("Ctrl+L")
self.groupLegendDlg.toggleViewAction().setToolTip("Show\hide group legend window")
self.groupLegendDlg.toggleViewAction().setStatusTip("Show\hide group legend window")
self.ui.menuView.addAction(self.groupLegendDlg.toggleViewAction())
self.connect(self.groupLegendDlg, QtCore.SIGNAL('legendItemChanged()'), self.legendItemChanged)
self.connect(self.groupLegendDlg, QtCore.SIGNAL('legendFieldChanged()'), self.legendFieldChanged)
self.connect(self.groupLegendDlg, QtCore.SIGNAL('legendActiveGroupsChanged()'), self.legendActiveGroupsChanged)
# setup metadata window
self.ui.menuView.addSeparator()
self.metadataDlg = MetadataTableDlg(self)
self.metadataDlg.setObjectName("metadataDlg");
self.metadataDlg.setVisible(True)
self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, self.metadataDlg)
self.metadataDlg.setFloating(False)
self.metadataDlg.toggleViewAction().setShortcut("Ctrl+M")
self.metadataDlg.toggleViewAction().setToolTip("Show\hide metadata table")
self.metadataDlg.toggleViewAction().setStatusTip("Show\hide metadata table")
self.ui.menuView.addAction(self.metadataDlg.toggleViewAction())
self.connect(self.metadataDlg, QtCore.SIGNAL('activeSamplesChanged()'), self.activeSamplesChanged)
# connect menu items signals to slots
self.connect(self.ui.mnuFileOpenProfile, QtCore.SIGNAL('triggered()'), self.loadProfile)
self.connect(self.ui.mnuFileMgRast, QtCore.SIGNAL('triggered()'), self.createProfileMgRast)
self.connect(self.ui.mnuFileRITA, QtCore.SIGNAL('triggered()'), self.createProfileRita)
self.connect(self.ui.mnuFileCoMet, QtCore.SIGNAL('triggered()'), self.createProfileComet)
self.connect(self.ui.mnuFileMothur, QtCore.SIGNAL('triggered()'), self.createProfileMothur)
self.connect(self.ui.mnuFileBIOM, QtCore.SIGNAL('triggered()'), self.createProfileBIOM)
self.connect(self.ui.mnuFileAppendCategoryCOG, QtCore.SIGNAL('triggered()'), self.appendCategoriesCOG)
self.connect(self.ui.mnuFileSavePlot, QtCore.SIGNAL('triggered()'), self.saveImageDlg)
self.connect(self.ui.mnuFileExit, QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()'))
self.connect(self.ui.mnuViewSendPlotToWindow, QtCore.SIGNAL('triggered()'), self.sendPlotToWindow)
self.connect(self.ui.mnuSettingsPreferences, QtCore.SIGNAL('triggered()'), self.prefrencesDlg)
self.connect(self.ui.mnuHelpAbout, QtCore.SIGNAL('triggered()'), self.openAboutDlg)
# connect profile level combo box signals to slots
self.connect(self.ui.cboProfileLevel, QtCore.SIGNAL('activated(QString)'), self.profileLevelChanged)
self.connect(self.ui.cboParentalLevel, QtCore.SIGNAL('activated(QString)'), self.parentLevelChanged)
self.connect(self.ui.cboUnclassified, QtCore.SIGNAL('activated(QString)'), self.unclassifiedTreatmentChanged)
self.setupSampleWidgets()
self.setupGroupWidgets()
self.setupMultiGroupWidgets()
# load multiple test correction methods
pluginManager = PluginManager(self.preferences)
self.multCompDict = pluginManager.loadPlugins('plugins/common/multipleComparisonCorrections/')
pluginManager.populateComboBox(self.multCompDict, self.ui.cboSampleMultCompMethod, 'No correction')
pluginManager.populateComboBox(self.multCompDict, self.ui.cboGroupMultCompMethod, 'No correction')
pluginManager.populateComboBox(self.multCompDict, self.ui.cboMultiGroupMultCompMethod, 'No correction')
# connect tab widget signals to slots
self.connect(self.ui.tabWidgetProperties, QtCore.SIGNAL('currentChanged(int)'), self.propertiesTabChanged)
# restore previous window states (size and location of main window and all dock widgets)
windowSettings = QtCore.QSettings("BeikoLab", "STAMP");
self.restoreState(windowSettings.value("MainWindow/State").toByteArray())
bRestoredState = self.restoreGeometry(windowSettings.value("MainWindow/Geometry").toByteArray())
if not bRestoredState:
self.resize(800, 600)
self.showMaximized()
self.metadata = None
#self.loadProfile() # *** For debugging purposes
def propertiesTabChanged(self, currentIndex):
self.ui.stackedWidgetViews.setCurrentIndex(currentIndex)
self.updateStatusBar()
def setupSampleWidgets(self):
self.sampleStatsTest = SampleStatsTests(self.preferences)
# initialize statistical summary tables
self.ui.menuView.addSeparator()
self.sampleTable = StatsTableDlg(self.preferences, self)
self.sampleTable.setWindowTitle('Two sample statistics table')
self.sampleTable.setVisible(False)
self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, self.sampleTable)
self.sampleTable.setFloating(True)
self.sampleTable.toggleViewAction().setShortcut("Ctrl+T")
self.sampleTable.toggleViewAction().setToolTip("Show\hide two sample statistical table")
self.sampleTable.toggleViewAction().setStatusTip("Show\hide two sample statistical table")
self.ui.menuView.addAction(self.sampleTable.toggleViewAction())
# load plot plugins
self.samplePlot = PlotsManager(self.ui.cboSamplePlots, self.ui.plotSampleScrollArea, 'Scatter plot')
self.samplePlot.loadPlots(self.preferences, 'plugins/samples/plots/')
# load statistical technique plugins
pluginManager = PluginManager(self.preferences)
self.sampleStatTestDict = pluginManager.loadPlugins('plugins/samples/statisticalTests/')
pluginManager.populateComboBox(self.sampleStatTestDict, self.ui.cboSampleStatTests, 'G-test (w/ Yates\') + Fisher\'s')
self.sampleConfIntervMethodDict = pluginManager.loadPlugins('plugins/samples/confidenceIntervalMethods/')
pluginManager.populateComboBox(self.sampleConfIntervMethodDict, self.ui.cboSampleConfIntervMethods, 'DP: Asymptotic-CC')
# load effect size filters
self.sampleEffectSizeDict = pluginManager.loadPlugins('plugins/samples/effectSizeFilters/')
pluginManager.populateComboBox(self.sampleEffectSizeDict, self.ui.cboSampleEffectSizeMeasure1, 'Difference between proportions')
pluginManager.populateComboBox(self.sampleEffectSizeDict, self.ui.cboSampleEffectSizeMeasure2, 'Ratio of proportions')
# widget controls in sidebar
self.connect(self.ui.btnSampleProfileTab, QtCore.SIGNAL('clicked()'), self.sampleProfileTabClicked)
self.connect(self.ui.btnSampleProfileArrow, QtCore.SIGNAL('clicked()'), self.sampleProfileTabClicked)
self.connect(self.ui.btnSampleStatisticsTab, QtCore.SIGNAL('clicked()'), self.samplePropTabClicked)
self.connect(self.ui.btnSampleStatisticsArrow, QtCore.SIGNAL('clicked()'), self.samplePropTabClicked)
self.connect(self.ui.btnSampleFilteringTab, QtCore.SIGNAL('clicked()'), self.sampleFilteringTabClicked)
self.connect(self.ui.btnSampleFilteringArrow, QtCore.SIGNAL('clicked()'), self.sampleFilteringTabClicked)
# connect profile widget signals to slots
self.connect(self.ui.cboSample1, QtCore.SIGNAL('activated(QString)'), self.sampleHierarchicalLevelsChanged)
self.connect(self.ui.cboSample2, QtCore.SIGNAL('activated(QString)'), self.sampleHierarchicalLevelsChanged)
self.connect(self.ui.btnSample1Colour, QtCore.SIGNAL('clicked()'), self.sample1ColourDlg)
self.connect(self.ui.btnSample2Colour, QtCore.SIGNAL('clicked()'), self.sample2ColourDlg)
# connect statistical test widget signals to slots
self.connect(self.ui.cboSampleStatTests, QtCore.SIGNAL('activated(QString)'), self.sampleRunTest)
self.connect(self.ui.cboSampleSignTestType, QtCore.SIGNAL('activated(QString)'), self.sampleRunTest)
self.connect(self.ui.cboSampleConfIntervMethods, QtCore.SIGNAL('activated(QString)'), self.sampleRunTest)
self.connect(self.ui.cboSampleNominalCoverage, QtCore.SIGNAL('activated(QString)'), self.sampleRunTest)
self.connect(self.ui.cboSampleMultCompMethod, QtCore.SIGNAL('activated(QString)'), self.sampleMultCompCorrectionChanged)
self.connect(self.ui.btnSampleMultCompCorrectionInfo, QtCore.SIGNAL('clicked()'), self.sampleMultCompCorrectionInfo)
# connect filtering test widget signals to slots
self.connect(self.ui.chkSampleSelectFeatures, QtCore.SIGNAL('toggled(bool)'), self.sampleSelectFeaturesCheckbox)
self.connect(self.ui.btnSampleSelectFeatures, QtCore.SIGNAL('clicked()'), self.sampleSelectFeaturesDlg)
self.connect(self.ui.chkSampleEnableSignLevelFilter, QtCore.SIGNAL('toggled(bool)'), self.sampleFilteringPropChanged)
self.connect(self.ui.spinSampleSignLevelFilter, QtCore.SIGNAL('editingFinished()'), self.sampleFilteringPropChanged)
self.connect(self.ui.cboSampleSeqFilter, QtCore.SIGNAL('activated(QString)'), self.sampleSeqFilterChanged)
self.connect(self.ui.chkSampleEnableSeqFilter, QtCore.SIGNAL('toggled(bool)'), self.sampleFilteringPropChanged)
self.connect(self.ui.spinSampleFilterSample1, QtCore.SIGNAL('editingFinished()'), self.sampleFilteringPropChanged)
self.connect(self.ui.spinSampleFilterSample2, QtCore.SIGNAL('editingFinished()'), self.sampleFilteringPropChanged)
self.connect(self.ui.cboSampleParentSeqFilter, QtCore.SIGNAL('activated(QString)'), self.sampleParentSeqFilterChanged)
self.connect(self.ui.chkSampleEnableParentSeqFilter, QtCore.SIGNAL('toggled(bool)'), self.sampleFilteringPropChanged)
self.connect(self.ui.spinSampleParentFilterSample1, QtCore.SIGNAL('editingFinished()'), self.sampleFilteringPropChanged)
self.connect(self.ui.spinSampleParentFilterSample2, QtCore.SIGNAL('editingFinished()'), self.sampleFilteringPropChanged)
self.connect(self.ui.radioSampleOR, QtCore.SIGNAL('clicked()'), self.sampleFilteringPropChanged)
self.connect(self.ui.radioSampleAND, QtCore.SIGNAL('clicked()'), self.sampleFilteringPropChanged)
self.connect(self.ui.cboSampleEffectSizeMeasure1, QtCore.SIGNAL('activated(QString)'), self.sampleChangeEffectSizeMeasure)
self.connect(self.ui.cboSampleEffectSizeMeasure2, QtCore.SIGNAL('activated(QString)'), self.sampleChangeEffectSizeMeasure)
self.connect(self.ui.spinSampleMinEffectSize1, QtCore.SIGNAL('editingFinished()'), self.sampleFilteringPropChanged)
self.connect(self.ui.spinSampleMinEffectSize2, QtCore.SIGNAL('editingFinished()'), self.sampleFilteringPropChanged)
self.connect(self.ui.chkSampleEnableEffectSizeFilter1, QtCore.SIGNAL('toggled(bool)'), self.sampleFilteringPropChanged)
self.connect(self.ui.chkSampleEnableEffectSizeFilter2, QtCore.SIGNAL('toggled(bool)'), self.sampleFilteringPropChanged)
# connect statistical plot page widget signals to slots
self.connect(self.ui.cboSamplePlots, QtCore.SIGNAL('activated(QString)'), self.samplePlotUpdate)
self.connect(self.ui.btnSampleConfigurePlot, QtCore.SIGNAL('clicked()'), self.samplePlotConfigure)
self.connect(self.ui.cboSampleHighlightHierarchy, QtCore.SIGNAL('activated(QString)'), self.sampleHighlightHierarchyChanged)
self.connect(self.ui.cboSampleHighlightFeature, QtCore.SIGNAL('activated(QString)'), self.sampleHighlightFeatureChanged)
# initialize dynamic GUI elements
self.setSample1Colour(self.preferences['Sample 1 colour'])
self.setSample2Colour(self.preferences['Sample 2 colour'])
def setupGroupWidgets(self):
self.groupStatsTest = GroupStatsTests(self.preferences)
# initialize statistical summary tables
self.groupTable = StatsTableDlg(self.preferences, self)
self.groupTable.setWindowTitle('Two group statistics table')
self.groupTable.setVisible(False)
self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, self.groupTable)
self.groupTable.setFloating(True)
self.groupTable.toggleViewAction().setShortcut("Ctrl+G")
self.groupTable.toggleViewAction().setToolTip("Show\hide two group statistical table")
self.groupTable.toggleViewAction().setStatusTip("Show\hide two group statistical table")
self.ui.menuView.addAction(self.groupTable.toggleViewAction())
# load plot plugins
self.groupPlot = PlotsManager(self.ui.cboGroupPlots, self.ui.plotGroupScrollArea, 'PCA plot')
self.groupPlot.loadPlots(self.preferences, 'plugins/groups/plots/')
# load statistical technique plugins
pluginManager = PluginManager(self.preferences)
self.groupStatTestDict = pluginManager.loadPlugins('plugins/groups/statisticalTests/')
pluginManager.populateComboBox(self.groupStatTestDict, self.ui.cboGroupStatTests, "Welch's t-test")
# load effect size filters
self.groupEffectSizeDict = pluginManager.loadPlugins('plugins/groups/effectSizeFilters/')
pluginManager.populateComboBox(self.groupEffectSizeDict, self.ui.cboGroupEffectSizeMeasure1, 'Difference between proportions')
pluginManager.populateComboBox(self.groupEffectSizeDict, self.ui.cboGroupEffectSizeMeasure2, 'Ratio of proportions')
# widget controls in sidebar
self.connect(self.ui.btnGroupProfileTab, QtCore.SIGNAL('clicked()'), self.groupProfileTabClicked)
self.connect(self.ui.btnGroupProfileArrow, QtCore.SIGNAL('clicked()'), self.groupProfileTabClicked)
self.connect(self.ui.btnGroupStatisticsTab, QtCore.SIGNAL('clicked()'), self.groupPropTabClicked)
self.connect(self.ui.btnGroupStatisticsArrow, QtCore.SIGNAL('clicked()'), self.groupPropTabClicked)
self.connect(self.ui.btnGroupFilteringTab, QtCore.SIGNAL('clicked()'), self.groupFilteringTabClicked)
self.connect(self.ui.btnGroupFilteringArrow, QtCore.SIGNAL('clicked()'), self.groupFilteringTabClicked)
# connect profile widget signals to slots
self.connect(self.ui.cboGroup1, QtCore.SIGNAL('activated(QString)'), self.groupHierarchicalLevelsChanged)
self.connect(self.ui.cboGroup2, QtCore.SIGNAL('activated(QString)'), self.groupHierarchicalLevelsChanged)
self.connect(self.ui.btnGroup1Colour, QtCore.SIGNAL('clicked()'), self.group1ColourDlg)
self.connect(self.ui.btnGroup2Colour, QtCore.SIGNAL('clicked()'), self.group2ColourDlg)
# connect statistical test widget signals to slots
self.connect(self.ui.cboGroupStatTests, QtCore.SIGNAL('activated(QString)'), self.groupRunTest)
self.connect(self.ui.cboGroupSignTestType, QtCore.SIGNAL('activated(QString)'), self.groupRunTest)
self.connect(self.ui.cboGroupConfIntervMethods, QtCore.SIGNAL('activated(QString)'), self.groupRunTest)
self.connect(self.ui.cboGroupNominalCoverage, QtCore.SIGNAL('activated(QString)'), self.groupRunTest)
self.connect(self.ui.cboGroupMultCompMethod, QtCore.SIGNAL('activated(QString)'), self.groupMultCompCorrectionChanged)
self.connect(self.ui.btnGroupMultCompCorrectionInfo, QtCore.SIGNAL('clicked()'), self.groupMultCompCorrectionInfo)
# connect filtering test widget signals to slots
self.connect(self.ui.chkGroupSelectFeatures, QtCore.SIGNAL('toggled(bool)'), self.groupSelectFeaturesCheckbox)
self.connect(self.ui.btnGroupSelectFeatures, QtCore.SIGNAL('clicked()'), self.groupSelectFeaturesDlg)
self.connect(self.ui.chkGroupEnableSignLevelFilter, QtCore.SIGNAL('toggled(bool)'), self.groupFilteringPropChanged)
self.connect(self.ui.spinGroupSignLevelFilter, QtCore.SIGNAL('editingFinished()'), self.groupFilteringPropChanged)
self.connect(self.ui.cboGroupSeqFilter, QtCore.SIGNAL('activated(QString)'), self.groupSeqFilterChanged)
self.connect(self.ui.chkGroupEnableSeqFilter, QtCore.SIGNAL('toggled(bool)'), self.groupFilteringPropChanged)
self.connect(self.ui.spinGroupFilter1, QtCore.SIGNAL('editingFinished()'), self.groupFilteringPropChanged)
self.connect(self.ui.spinGroupFilter2, QtCore.SIGNAL('editingFinished()'), self.groupFilteringPropChanged)
self.connect(self.ui.cboGroupParentSeqFilter, QtCore.SIGNAL('activated(QString)'), self.groupParentSeqFilterChanged)
self.connect(self.ui.chkGroupEnableParentSeqFilter, QtCore.SIGNAL('toggled(bool)'), self.groupFilteringPropChanged)
self.connect(self.ui.spinGroupParentFilter1, QtCore.SIGNAL('editingFinished()'), self.groupFilteringPropChanged)
self.connect(self.ui.spinGroupParentFilter2, QtCore.SIGNAL('editingFinished()'), self.groupFilteringPropChanged)
self.connect(self.ui.radioGroupOR, QtCore.SIGNAL('clicked()'), self.groupFilteringPropChanged)
self.connect(self.ui.radioGroupAND, QtCore.SIGNAL('clicked()'), self.groupFilteringPropChanged)
self.connect(self.ui.cboGroupEffectSizeMeasure1, QtCore.SIGNAL('activated(QString)'), self.groupChangeEffectSizeMeasure)
self.connect(self.ui.cboGroupEffectSizeMeasure2, QtCore.SIGNAL('activated(QString)'), self.groupChangeEffectSizeMeasure)
self.connect(self.ui.spinGroupMinEffectSize1, QtCore.SIGNAL('editingFinished()'), self.groupFilteringPropChanged)
self.connect(self.ui.spinGroupMinEffectSize2, QtCore.SIGNAL('editingFinished()'), self.groupFilteringPropChanged)
self.connect(self.ui.chkGroupEnableEffectSizeFilter1, QtCore.SIGNAL('toggled(bool)'), self.groupFilteringPropChanged)
self.connect(self.ui.chkGroupEnableEffectSizeFilter2, QtCore.SIGNAL('toggled(bool)'), self.groupFilteringPropChanged)
self.connect(self.ui.chkShowActiveFeaturesGroupTable, QtCore.SIGNAL('clicked()'), self.groupFeaturesTableUpdate)
# connect statistical plot page widget signals to slots
self.connect(self.ui.cboGroupPlots, QtCore.SIGNAL('activated(QString)'), self.groupPlotUpdate)
self.connect(self.ui.btnGroupConfigurePlot, QtCore.SIGNAL('clicked()'), self.groupPlotConfigure)
self.connect(self.ui.cboGroupHighlightHierarchy, QtCore.SIGNAL('activated(QString)'), self.groupHighlightHierarchyChanged)
self.connect(self.ui.cboGroupHighlightFeature, QtCore.SIGNAL('activated(QString)'), self.groupHighlightFeatureChanged)
# initialize dynamic GUI elements
self.setGroup1Colour(self.groupLegendDlg.groupColours[0], False)
self.setGroup2Colour(self.groupLegendDlg.groupColours[1], False)
self.groupTestConfIntervMethods()
def setupMultiGroupWidgets(self):
self.multiGroupStatsTest = MultiGroupStatsTests(self.preferences)
# initialize statistical summary tables
self.multiGroupTable = StatsTableDlg(self.preferences, self)
self.multiGroupTable.setWindowTitle('Multiple group statistics table')
self.multiGroupTable.setVisible(False)
self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, self.multiGroupTable)
self.multiGroupTable.setFloating(True)
self.multiGroupTable.toggleViewAction().setShortcut("Ctrl+M")
self.multiGroupTable.toggleViewAction().setToolTip("Show\hide multiple group statistical table")
self.multiGroupTable.toggleViewAction().setStatusTip("Show\hide multiple group statistical table")
self.ui.menuView.addAction(self.multiGroupTable.toggleViewAction())
# load plot plugins
self.multiGroupPlot = PlotsManager(self.ui.cboMultiGroupPlots, self.ui.plotMultiGroupScrollArea, 'PCA plot')
self.multiGroupPlot.loadPlots(self.preferences, 'plugins/multiGroups/plots/')
# load statistical technique plugins
pluginManager = PluginManager(self.preferences)
self.multiGroupStatTestDict = pluginManager.loadPlugins('plugins/multiGroups/statisticalTests/')
pluginManager.populateComboBox(self.multiGroupStatTestDict, self.ui.cboMultiGroupStatTests, 'ANOVA')
self.postHocTestDict = pluginManager.loadPlugins('plugins/multiGroups/postHoc/')
pluginManager.populateComboBox(self.postHocTestDict, self.ui.cboPostHocTest, 'Tukey-Kramer')
# load effect size filters
self.multiGroupEffectSizeDict = pluginManager.loadPlugins('plugins/multiGroups/effectSizeFilters/')
pluginManager.populateComboBox(self.multiGroupEffectSizeDict, self.ui.cboMultiGroupEffectSizeMeasure, 'Eta-squared')
# widget controls in sidebar
self.connect(self.ui.btnMultiGroupStatisticsTab, QtCore.SIGNAL('clicked()'), self.multiGroupPropTabClicked)
self.connect(self.ui.btnMultiGroupStatisticsArrow, QtCore.SIGNAL('clicked()'), self.multiGroupPropTabClicked)
self.connect(self.ui.btnMultiGroupFilteringTab, QtCore.SIGNAL('clicked()'), self.multiGroupFilteringTabClicked)
self.connect(self.ui.btnMultiGroupFilteringArrow, QtCore.SIGNAL('clicked()'), self.multiGroupFilteringTabClicked)
# connect statistical test widget signals to slots
self.connect(self.ui.cboMultiGroupStatTests, QtCore.SIGNAL('activated(QString)'), self.multiGroupRunTest)
self.connect(self.ui.cboMultiGroupMultCompMethod, QtCore.SIGNAL('activated(QString)'), self.multiGroupMultCompCorrectionChanged)
self.connect(self.ui.btnMultiGroupMultCompCorrectionInfo, QtCore.SIGNAL('clicked()'), self.multiGroupMultCompCorrectionInfo)
self.connect(self.ui.cboPostHocTest, QtCore.SIGNAL('activated(QString)'), self.multiGroupPlotUpdate)
self.connect(self.ui.cboMultiGroupNominalCoverage, QtCore.SIGNAL('activated(QString)'), self.multiGroupPlotUpdate)
# connect filtering test widget signals to slots
self.connect(self.ui.chkMultiGroupSelectFeatures, QtCore.SIGNAL('toggled(bool)'), self.multiGroupSelectFeaturesCheckbox)
self.connect(self.ui.btnMultiGroupSelectFeatures, QtCore.SIGNAL('clicked()'), self.multiGroupSelectFeaturesDlg)
self.connect(self.ui.chkMultiGroupEnableSignLevelFilter, QtCore.SIGNAL('toggled(bool)'), self.multiGroupFilteringPropChanged)
self.connect(self.ui.spinMultiGroupSignLevelFilter, QtCore.SIGNAL('editingFinished()'), self.multiGroupFilteringPropChanged)
self.connect(self.ui.spinMultiGroupMinEffectSize, QtCore.SIGNAL('editingFinished()'), self.multiGroupFilteringPropChanged)
self.connect(self.ui.chkMultiGroupEnableEffectSizeFilter, QtCore.SIGNAL('toggled(bool)'), self.multiGroupFilteringPropChanged)
self.connect(self.ui.chkShowActiveFeaturesMultiGroupTable, QtCore.SIGNAL('clicked()'), self.multiGroupFeaturesTableUpdate)
# connect statistical plot page widget signals to slots
self.connect(self.ui.cboMultiGroupPlots, QtCore.SIGNAL('activated(QString)'), self.multiGroupPlotUpdate)
self.connect(self.ui.btnMultiGroupConfigurePlot, QtCore.SIGNAL('clicked()'), self.multiGroupPlotConfigure)
self.connect(self.ui.cboMultiGroupHighlightHierarchy, QtCore.SIGNAL('activated(QString)'), self.multiGroupHighlightHierarchyChanged)
self.connect(self.ui.cboMultiGroupHighlightFeature, QtCore.SIGNAL('activated(QString)'), self.multiGroupHighlightFeatureChanged)
def autoRecalculateChanged(self, checked):
self.bAutoRecalculate = checked
if self.bAutoRecalculate == True:
self.sampleRunTest()
self.groupRunTest()
self.multiGroupRunTest()
def activeSamplesChanged(self):
self.populateSampleComboBoxes()
self.sampleRunTest()
self.groupLegendDlg.initLegend(self.profileTree, self.metadata, self.metadata.activeField)
self.groupRunTest()
self.multiGroupRunTest()
def populateSampleComboBoxes(self):
# cache currently selected samples
sampleName1 = str(self.ui.cboSample1.currentText())
sampleName2 = str(self.ui.cboSample2.currentText())
self.ui.cboSample1.clear()
self.ui.cboSample2.clear()
for name in sorted(self.profileTree.sampleNames):
if self.metadata == None or name in self.metadata.activeSamples:
self.ui.cboSample1.addItem(name)
self.ui.cboSample2.addItem(name)
if self.ui.cboSample1.findText(sampleName1) != -1:
self.ui.cboSample1.setCurrentIndex(self.ui.cboSample1.findText(sampleName1))
else:
self.ui.cboSample1.setCurrentIndex(0)
if self.ui.cboSample2.findText(sampleName2) != -1:
self.ui.cboSample2.setCurrentIndex(self.ui.cboSample2.findText(sampleName2))
else:
self.ui.cboSample2.setCurrentIndex(1)
def legendActiveGroupsChanged(self):
group1 = self.ui.cboGroup1.currentText()
group2 = self.ui.cboGroup2.currentText()
self.ui.cboGroup1.clear()
self.ui.cboGroup2.clear()
for name, bActive in sorted(self.profileTree.groupActive.items()):
if bActive:
self.ui.cboGroup1.addItem(name)
self.ui.cboGroup2.addItem(name)
self.ui.cboGroup2.addItem('<All other samples>')
index = self.ui.cboGroup1.findText(group1)
if index != -1:
self.ui.cboGroup1.setCurrentIndex(index)
else:
self.ui.cboGroup1.setCurrentIndex(0)
index = self.ui.cboGroup2.findText(group2)
if index != -1:
self.ui.cboGroup2.setCurrentIndex(index)
else:
if self.ui.cboGroup2.count() >= 2:
self.ui.cboGroup2.setCurrentIndex(1)
else:
self.ui.cboGroup2.setCurrentIndex(0)
self.multiGroupRunTest()
self.groupRunTest()
def legendFieldChanged(self):
self.multiGroupRunTest()
self.populateGroupComboBoxes()
self.groupRunTest()
def legendItemChanged(self):
self.setGroup1Colour(self.groupLegendDlg.groupColourDict[str(self.ui.cboGroup1.currentText())], False)
if self.ui.cboGroup2.currentText() != '<All other samples>':
self.setGroup2Colour(self.groupLegendDlg.groupColourDict[str(self.ui.cboGroup2.currentText())], False)
else:
self.setGroup2Colour(self.preferences['All other samples colour'])
self.groupPlotUpdate()
self.multiGroupPlotUpdate()
def appendCategoriesCOG(self):
assignCOGsDlg = AssignCOGsDlg(self.preferences, self)
assignCOGsDlg.exec_()
def sampleProfileTabClicked(self):
self.ui.widgetSampleProfile.setVisible(not self.ui.widgetSampleProfile.isVisible())
self.updateSideBarTabIcon(self.ui.widgetSampleProfile, self.ui.btnSampleProfileArrow)
def samplePropTabClicked(self):
self.ui.widgetSampleStatisticalProp.setVisible(not self.ui.widgetSampleStatisticalProp.isVisible())
self.updateSideBarTabIcon(self.ui.widgetSampleStatisticalProp, self.ui.btnSampleStatisticsArrow)
def sampleFilteringTabClicked(self):
self.ui.widgetSampleFilter.setVisible(not self.ui.widgetSampleFilter.isVisible())
self.updateSideBarTabIcon(self.ui.widgetSampleFilter, self.ui.btnSampleFilteringArrow)
def groupProfileTabClicked(self):
self.ui.widgetGroupProfile.setVisible(not self.ui.widgetGroupProfile.isVisible())
self.updateSideBarTabIcon(self.ui.widgetGroupProfile, self.ui.btnGroupProfileArrow)
def groupPropTabClicked(self):
self.ui.widgetGroupStatisticalProp.setVisible(not self.ui.widgetGroupStatisticalProp.isVisible())
self.updateSideBarTabIcon(self.ui.widgetGroupStatisticalProp, self.ui.btnGroupStatisticsArrow)
def groupFilteringTabClicked(self):
self.ui.widgetGroupFilter.setVisible(not self.ui.widgetGroupFilter.isVisible())
self.updateSideBarTabIcon(self.ui.widgetGroupFilter, self.ui.btnGroupFilteringArrow)
def multiGroupPropTabClicked(self):
self.ui.widgetMultiGroupStatisticalProp.setVisible(not self.ui.widgetMultiGroupStatisticalProp.isVisible())
self.updateSideBarTabIcon(self.ui.widgetMultiGroupStatisticalProp, self.ui.btnMultiGroupStatisticsArrow)
def multiGroupFilteringTabClicked(self):
self.ui.widgetMultiGroupFiltering.setVisible(not self.ui.widgetMultiGroupFiltering.isVisible())
self.updateSideBarTabIcon(self.ui.widgetMultiGroupFiltering, self.ui.btnMultiGroupFilteringArrow)
def updateSideBarTabIcon(self, tab, arrowButton):
icon = QtGui.QIcon()
if tab.isVisible():
icon.addPixmap(QtGui.QPixmap("icons/downArrow.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
else:
icon.addPixmap(QtGui.QPixmap("icons/rightArrow.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
arrowButton.setIcon(icon)
def prefrencesDlg(self):
preferencesDlg = PreferencesDlg(self)
preferencesDlg.ui.spinPseudoCount.setValue(self.preferences['Pseudocount'])
preferencesDlg.ui.spinReplicates.setValue(self.preferences['Replicates'])
preferencesDlg.ui.chkTruncateFeatureNames.setChecked(self.preferences['Truncate feature names'])
preferencesDlg.ui.spinFeatureNameLength.setValue(self.preferences['Length of truncated feature names'])
preferencesDlg.setMinimumReportedPValue(self.preferences['Minimum reported p-value exponent'])
preferencesDlg.setAxesButtonColour(self.preferences['Axes colour'])
preferencesDlg.setAllOtherSamplesButtonColour(self.preferences['All other samples colour'])
if preferencesDlg.exec_() == QtGui.QDialog.Accepted:
self.preferences['Pseudocount'] = preferencesDlg.ui.spinPseudoCount.value()
self.preferences['Replicates'] = preferencesDlg.ui.spinReplicates.value()
self.preferences['Truncate feature names'] = preferencesDlg.ui.chkTruncateFeatureNames.isChecked()
self.preferences['Length of truncated feature names'] = preferencesDlg.ui.spinFeatureNameLength.value()
self.preferences['Minimum reported p-value exponent'] = preferencesDlg.getMinimumReportedPValue()
self.preferences['Axes colour'] = preferencesDlg.getAxesColour()
if self.preferences['All other samples colour'] != preferencesDlg.getAllOtherSamplesColour():
self.preferences['All other samples colour'] = preferencesDlg.getAllOtherSamplesColour()
self.setGroup2Colour(self.preferences['All other samples colour'], False)
self.samplePlotUpdate()
self.groupPlotUpdate()
self.multiGroupPlotUpdate()
def samplePlotUpdate(self):
QtGui.QApplication.instance().setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
if self.sampleStatsTest.results.data != []:
self.samplePlot.update(self.sampleProfile, self.sampleStatsTest.results)
else:
self.samplePlot.update(None, None)
QtGui.QApplication.instance().restoreOverrideCursor()
def groupPlotUpdate(self):
QtGui.QApplication.instance().setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
# update plot
if self.groupStatsTest.results.data != []:
self.groupPlot.update(self.groupProfile, self.groupStatsTest.results)
else:
self.groupPlot.update(None, None)
self.ui.cboGroupHighlightHierarchy.setEnabled(self.groupPlot.currentPlot.bSupportsHighlight)
self.ui.cboGroupHighlightFeature.setEnabled(self.groupPlot.currentPlot.bSupportsHighlight)
self.ui.frameGroupTable.setVisible(self.groupPlot.currentPlot.bPlotFeaturesIndividually)
QtGui.QApplication.instance().restoreOverrideCursor()
def multiGroupPlotUpdate(self):
QtGui.QApplication.instance().setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
# update plot
if self.multiGroupStatsTest.results.data != []:
if self.multiGroupPlot.checkFlags().bRunPostHocTest:
coverage = float(self.ui.cboMultiGroupNominalCoverage.currentText())
postHocTest = self.postHocTestDict[unicode(self.ui.cboPostHocTest.currentText(), 'latin-1')]
self.multiGroupStatsTest.runPostHocTest(postHocTest, self.multiGroupProfile, self.preferences['Selected multiple group feature'], coverage)
self.multiGroupPlot.update(self.multiGroupProfile, self.multiGroupStatsTest.results)
else:
self.multiGroupPlot.update(None, None)
self.ui.cboMultiGroupHighlightHierarchy.setEnabled(self.multiGroupPlot.currentPlot.bSupportsHighlight)
self.ui.cboMultiGroupHighlightFeature.setEnabled(self.multiGroupPlot.currentPlot.bSupportsHighlight)
self.ui.frameMultiGroupTable.setVisible(self.multiGroupPlot.currentPlot.bPlotFeaturesIndividually)
QtGui.QApplication.instance().restoreOverrideCursor()
def samplePlotConfigure(self):
self.samplePlot.configure(self.sampleProfile, self.sampleStatsTest.results)
def groupPlotConfigure(self):
self.groupPlot.configure(self.groupProfile, self.groupStatsTest.results)
def multiGroupPlotConfigure(self):
self.multiGroupPlot.configure(self.multiGroupProfile, self.multiGroupStatsTest.results)
def sample1ColourDlg(self):
colour = QtGui.QColorDialog.getColor(self.preferences['Sample 1 colour'], self, 'Colour for sample 1')
if colour.isValid():
self.preferences['Sample 1 colour'] = colour
self.setSample1Colour(colour)
def setSample1Colour(self, colour):
colourStr = str(colour.red()) + ',' + str(colour.green()) + ',' + str(colour.blue())
self.ui.btnSample1Colour.setStyleSheet('* { background-color: rgb(' + colourStr + ') }')
self.samplePlotUpdate()
def sample2ColourDlg(self):
colour = QtGui.QColorDialog.getColor(self.preferences['Sample 2 colour'], self, 'Colour for sample 2')
if colour.isValid():
self.preferences['Sample 2 colour'] = colour
self.setSample2Colour(colour)
def setSample2Colour(self, colour):
colourStr = str(colour.red()) + ',' + str(colour.green()) + ',' + str(colour.blue())
self.ui.btnSample2Colour.setStyleSheet('* { background-color: rgb(' + colourStr + ') }')
self.samplePlotUpdate()
def group1ColourDlg(self):
colour = QtGui.QColorDialog.getColor(self.preferences['Group colours'][self.groupProfile.groupName1], self, 'Colour for group 1')
if colour.isValid():
self.setGroup1Colour(colour)
def setGroup1Colour(self, colour, bUpdatePlot = True):
colourStr = str(colour.red()) + ',' + str(colour.green()) + ',' + str(colour.blue())
self.ui.btnGroup1Colour.setStyleSheet('* { background-color: rgb(' + colourStr + ') }')
self.preferences['Group colours'][self.groupProfile.groupName1] = colour
if bUpdatePlot:
self.groupLegendDlg.updateLegend(self.groupProfile.groupName1, colour)
self.groupPlotUpdate()
def group2ColourDlg(self):
colour = QtGui.QColorDialog.getColor(self.preferences['Group colours'][self.groupProfile.groupName2], self, 'Colour for group 2')
if colour.isValid():
self.setGroup2Colour(colour)
def setGroup2Colour(self, colour, bUpdatePlot = True):
colourStr = str(colour.red()) + ',' + str(colour.green()) + ',' + str(colour.blue())
self.ui.btnGroup2Colour.setStyleSheet('* { background-color: rgb(' + colourStr + ') }')
self.preferences['Group colours'][self.groupProfile.groupName2] = colour
if bUpdatePlot:
if self.groupProfile.groupName2 != '<All other samples>':
self.groupLegendDlg.updateLegend(self.groupProfile.groupName2, colour)
else:
self.preferences['All other samples colour'] = colour
self.groupPlotUpdate()
def createProfileMgRast(self):
createProfileMgRastDlg = CreateProfileMgRastDlg(self.preferences, self)
createProfileMgRastDlg.exec_()
def createProfileRita(self):
createProfileRITADlg = CreateProfileRITADlg(self.preferences, self)
createProfileRITADlg.exec_()
def createProfileComet(self):
createProfileCoMetDlg = CreateProfileCoMetDlg(self.preferences, self)
createProfileCoMetDlg.exec_()
def createProfileMothur(self):
createProfileMothurDlg = CreateProfileMothurDlg(self.preferences, self)
createProfileMothurDlg.exec_()
def createProfileBIOM(self):
createProfileBiomDlg = CreateProfileBiomDlg(self.preferences, self)
createProfileBiomDlg.exec_()
def loadProfile(self):
loadDataDlg = LoadDataDlg(self.preferences, self)
if loadDataDlg.exec_() == QtGui.QDialog.Accepted:
profileFile = loadDataDlg.getProfileFile()
#profileFile = "D:/GitHub/STAMP/examples/heatmap.spf"
if profileFile == '':
return
self.preferences['Last directory'] = profileFile[0:profileFile.lastIndexOf('/')]
metadataFile = loadDataDlg.getMetadataFile()
#metadataFile = "D:/GitHub/STAMP/examples/heatmap.metadata.tsv"
# read profiles from file
try:
stampIO = StampIO(self.preferences)
self.profileTree, errMsg = stampIO.read(profileFile)
if errMsg != None:
QtGui.QMessageBox.information(self, 'Error reading profile file', errMsg, QtGui.QMessageBox.Warning)
return
except:
QtGui.QMessageBox.information(self, 'Error reading profile file','Unknown parsing error.', QtGui.QMessageBox.Warning)
return
self.metadata = None
if metadataFile != '':
try:
metadataIO = MetadataIO(self.preferences)
self.metadata, warningMsg = metadataIO.read(metadataFile, self.profileTree)
if warningMsg != None:
QtGui.QMessageBox.information(self, 'Metadata warnings', warningMsg)
except:
QtGui.QMessageBox.information(self, 'Error reading metadata file', 'Unknown parsing error.', QtGui.QMessageBox.Warning)
return
QtGui.QApplication.instance().setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
# populate sample combo boxes
self.populateSampleComboBoxes()
# populate hierarchy combo boxes
self.ui.cboParentalLevel.clear()
self.ui.cboParentalLevel.addItem('Entire sample')
for header in self.profileTree.hierarchyHeadings[0:-1]:
self.ui.cboParentalLevel.addItem(header)
self.ui.cboParentalLevel.setCurrentIndex(0)
self.ui.cboProfileLevel.clear()
for header in self.profileTree.hierarchyHeadings:
self.ui.cboProfileLevel.addItem(header)
self.ui.cboProfileLevel.setCurrentIndex(0)
# setup group legend
if self.metadata != None:
self.groupLegendDlg.initLegend(self.profileTree, self.metadata, self.metadata.getFeatures()[0])
self.preferences['Group colours'] = self.groupLegendDlg.groupColourDict
# populate group combo box
self.populateGroupComboBoxes()
# indicate the hierarchical level of interest has changed
bGroupLegendVisibility = self.groupLegendDlg.isVisible()
if platform.system() != 'Windows' and bGroupLegendVisibility:
self.groupLegendDlg.setVisible(False) # HACK: OS X crashes if this dialog is open when loading data for the first time!
self.multiGroupHierarchicalLevelsChanged()
self.groupHierarchicalLevelsChanged()
self.sampleHierarchicalLevelsChanged()
if platform.system() != 'Windows' and bGroupLegendVisibility:
self.groupLegendDlg.setVisible(True)
# update tables
self.groupFeaturesTableUpdate()
self.multiGroupFeaturesTableUpdate()
self.metadataDlg.setTable(self.metadata)
QtGui.QApplication.instance().restoreOverrideCursor()
def populateGroupComboBoxes(self):
self.ui.cboGroup1.clear()
self.ui.cboGroup2.clear()
for name, bActive in sorted(self.profileTree.groupActive.items()):
if bActive:
self.ui.cboGroup1.addItem(name)
self.ui.cboGroup2.addItem(name)
self.ui.cboGroup2.addItem('<All other samples>')
self.ui.cboGroup1.setCurrentIndex(0)
self.ui.cboGroup2.setCurrentIndex(1)
def parentLevelChanged(self):
parentDepth = self.profileTree.getHierarchicalLevelDepth(str(self.ui.cboParentalLevel.currentText()))
profileDepth= self.profileTree.getHierarchicalLevelDepth(str(self.ui.cboProfileLevel.currentText()))
if parentDepth >= profileDepth:
QtGui.QMessageBox.information(self, 'Invalid profile', 'The parent level must be higher in the hierarchy than the profile level.', QtGui.QMessageBox.Warning)
self.ui.cboParentalLevel.setCurrentIndex(0)
self.sampleHierarchicalLevelsChanged()
self.groupHierarchicalLevelsChanged()
self.multiGroupHierarchicalLevelsChanged()
def profileLevelChanged(self):
parentDepth = self.profileTree.getHierarchicalLevelDepth(str(self.ui.cboParentalLevel.currentText()))
profileDepth= self.profileTree.getHierarchicalLevelDepth(str(self.ui.cboProfileLevel.currentText()))
if profileDepth <= parentDepth:
QtGui.QMessageBox.information(self, 'Invalid profile', 'The profile level must be deeper in the hierarchy than the parent level.', QtGui.QMessageBox.Warning)
self.ui.cboProfileLevel.setCurrentIndex(len(self.profileTree.hierarchyHeadings)-1)
return
self.sampleHierarchicalLevelsChanged()
self.preferences['Selected group feature'] = ''
self.groupHierarchicalLevelsChanged()
self.preferences['Selected multiple group feature'] = ''
self.multiGroupHierarchicalLevelsChanged()
def unclassifiedTreatmentChanged(self):
self.sampleRunTest()
if self.preferences['Selected group feature'].lower() == 'unclassified':
self.preferences['Selected group feature'] = ''
self.groupRunTest()
if self.preferences['Selected multiple group feature'].lower() == 'unclassified':
self.preferences['Selected multiple group feature'] = ''
self.multiGroupRunTest()
def sampleHierarchicalLevelsChanged(self):
QtGui.QApplication.instance().setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
# populate highlight hierarchy combo box
profileHeading = str(self.ui.cboProfileLevel.currentText())
profileIndex = self.profileTree.hierarchyHeadings.index(profileHeading)
self.ui.cboSampleHighlightHierarchy.clear()
self.ui.cboSampleHighlightHierarchy.addItem('None')
for header in self.profileTree.hierarchyHeadings[0:profileIndex+1]:
self.ui.cboSampleHighlightHierarchy.addItem(header)
self.ui.cboSampleHighlightHierarchy.setCurrentIndex(0)
self.ui.cboSampleHighlightFeature.clear()
# keep selected features
selectedFeatures = self.sampleStatsTest.results.getSelectedFeatures()
self.sampleStatsTest = SampleStatsTests(self.preferences)
self.sampleStatsTest.results.setSelectedFeatures(selectedFeatures)
QtGui.QApplication.instance().restoreOverrideCursor()
# run statistics
self.sampleRunTest()
self.updateStatusBar()
def groupHierarchicalLevelsChanged(self):
if self.metadata == None:
return
QtGui.QApplication.instance().setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
# set group colours
groupName1 = str(self.ui.cboGroup1.currentText())
groupName2 = str(self.ui.cboGroup2.currentText())
if groupName1 == '' or groupName2 == '':
QtGui.QApplication.instance().restoreOverrideCursor()
return
# populate highlight hierarchy combo box
profileHeading = str(self.ui.cboProfileLevel.currentText())
profileIndex = self.profileTree.hierarchyHeadings.index(profileHeading)
self.ui.cboGroupHighlightHierarchy.clear()
self.ui.cboGroupHighlightHierarchy.addItem('None')
for header in self.profileTree.hierarchyHeadings[0:profileIndex+1]:
self.ui.cboGroupHighlightHierarchy.addItem(header)
self.ui.cboGroupHighlightHierarchy.setCurrentIndex(0)
self.ui.cboGroupHighlightFeature.clear()
# keep selected features
selectedFeatures = self.groupStatsTest.results.getSelectedFeatures()
self.groupStatsTest = GroupStatsTests(self.preferences)
self.groupStatsTest.results.setSelectedFeatures(selectedFeatures)
QtGui.QApplication.instance().restoreOverrideCursor()
# run statistics
self.groupRunTest()
self.updateStatusBar()
def multiGroupHierarchicalLevelsChanged(self):
if self.metadata == None:
return
QtGui.QApplication.instance().setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
# populate highlight hierarchy combo box
profileHeading = str(self.ui.cboProfileLevel.currentText())
profileIndex = self.profileTree.hierarchyHeadings.index(profileHeading)
self.ui.cboMultiGroupHighlightHierarchy.clear()
self.ui.cboMultiGroupHighlightHierarchy.addItem('None')
for header in self.profileTree.hierarchyHeadings[0:profileIndex+1]:
self.ui.cboMultiGroupHighlightHierarchy.addItem(header)
self.ui.cboMultiGroupHighlightHierarchy.setCurrentIndex(0)
self.ui.cboMultiGroupHighlightFeature.clear()
# keep selected features
selectedFeatures = self.multiGroupStatsTest.results.getSelectedFeatures()
self.multiGroupStatsTest = MultiGroupStatsTests(self.preferences)
self.multiGroupStatsTest.results.setSelectedFeatures(selectedFeatures)
QtGui.QApplication.instance().restoreOverrideCursor()
# run test
self.multiGroupRunTest()
self.updateStatusBar()
def groupFeaturesTableUpdate(self):
tableData = []
bActiveFeatures = self.ui.chkShowActiveFeaturesGroupTable.isChecked()
features = self.groupStatsTest.results.getColumn('Features', bActiveFeatures)
if len(features) != 0:
effectSizes = self.groupStatsTest.results.getColumnAsFloatStr('EffectSize', bActiveFeatures)
pValues = self.groupStatsTest.results.getColumnAsStr('pValues', bActiveFeatures)
pValuesCorrected = self.groupStatsTest.results.getColumnAsStr('pValuesCorrected', bActiveFeatures)
notes = self.groupStatsTest.results.getColumn('Note', bActiveFeatures)
for i in xrange(0, len(features)):
tableData.append([features[i], effectSizes[i], pValues[i], pValuesCorrected[i], notes[i]])
if preferences['Selected group feature'] not in features:
preferences['Selected group feature'] = ''
self.groupFeatureTable = GenericTable(tableData, ['Feature', 'Diff. between means', 'p-value', 'Corrected p-value', 'Note'], self)
self.groupFeatureTable.sort(0,QtCore.Qt.AscendingOrder) # start with features in alphabetical order
self.ui.tableGroupFeatures.horizontalHeader().setStretchLastSection(True)
self.ui.tableGroupFeatures.setModel(self.groupFeatureTable)
self.ui.tableGroupFeatures.verticalHeader().setVisible(True)
self.ui.tableGroupFeatures.resizeColumnsToContents()
self.tableGroupSelectionModel = QtGui.QItemSelectionModel(self.groupFeatureTable, self.ui.tableGroupFeatures)
self.ui.tableGroupFeatures.setSelectionModel(self.tableGroupSelectionModel)
self.connect(self.tableGroupSelectionModel, QtCore.SIGNAL('selectionChanged(const QItemSelection, const QItemSelection)'), self.groupTableFeatureChanged)
def multiGroupFeaturesTableUpdate(self):
tableData = []
bActiveFeatures = self.ui.chkShowActiveFeaturesMultiGroupTable.isChecked()
features = self.multiGroupStatsTest.results.getColumn('Features', bActiveFeatures)
if len(features) != 0:
effectSizes = self.multiGroupStatsTest.results.getColumnAsFloatStr('EffectSize', bActiveFeatures)
pValues = self.multiGroupStatsTest.results.getColumnAsStr('pValues', bActiveFeatures)