-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainGui.py
2648 lines (2322 loc) · 130 KB
/
MainGui.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
from Tkinter import *
import tkColorChooser
import tkFileDialog
import tkMessageBox
from tkFileDialog import askopenfilename
import glob
import os
from numpy import *
from SampleSeparation import *
from normalitycalculation import *
from Exporting_Files import *
from GeneLevelOutDet import *
from PieChartAndVennDia import *
from groupingOutliers import *
from SampleLevelOutlierDetection import *
from GetSingleOutlierGene import *
from helpMenuDataImporting import *
from HelpMenuOutlierMenu import *
from HelpMenuGrouping import *
from ExtractionOutliers import *
class Tool(Frame):
''' Main GUI for outlier detection'''
# Initializing the tool #
def __init__(self,master):
Frame.__init__(self,master)
self.grid()
self.radiobutton()
self.helpmenudatabutton=Button(mGui,text='Help',command=self.helpmenu1)
self.helpmenudatabutton.place(relx=0.42,rely=0.9)
# Help menu for the data selection and p value for distribution #
def helpmenu1(self):
tkMessageBox.showwarning(title='Help',message=hlpmenu.helpscripts())
return
# Creating radio button for data set selection #
def radiobutton(self):
self.radiobuttonLabel=Label(mGui,text='Please select the dataset source',font='Times 18 bold italic')
self.radiobuttonLabel.place(relx=0.25,rely=0.25)
self.favorite=StringVar()
self.TCGARadiobutton=Radiobutton(mGui,text='TCGA',value=1,variable=self.favorite,command=self.TCGARadiobutton)
self.TCGARadiobutton.place(relx=0.3,rely=0.4)
self.GEORadiobutton=Radiobutton(mGui,text='GEO',value=2,variable=self.favorite,command=self.GEORadiobutton)
self.GEORadiobutton.place(relx=0.5,rely=0.4)
self.startRadiobutton=Button(mGui,text='Start',command=self.radiobuttonstart)
self.startRadiobutton.place(relx=0.3,rely=0.6)
self.cancelRadioButton=Button(mGui,text="Quit",command=self.mQuit)
self.cancelRadioButton.place(relx=0.5,rely=0.6)
# assigning TCGA radiobutton for further steps #
def TCGARadiobutton(self):
self.selectedRbutton=1
# assigning GEO radiobutton for further steps #
def GEORadiobutton(self):
self.selectedRbutton=2
# next step after selecting data type #
def radiobuttonstart(self):
try:
if self.selectedRbutton==1 or self.selectedRbutton==2:
# removing buttons #
self.radiobuttonLabel.destroy()
self.TCGARadiobutton.destroy()
self.GEORadiobutton.destroy()
self.startRadiobutton.destroy()
self.cancelRadioButton.destroy()
# TCGA dataset #
if self.selectedRbutton==1:
self.browse()
# GEO data set#
else:
self.GEOselectbutton=Button(mGui,text='Select File',command=self.selectFileGEO)
self.GEOselectbutton.place(relx=0.73,rely=0.25)
self.GEOEntry=Entry(mGui,width=35)
self.GEOEntry.place(relx=0.13,rely=0.25)
# warning when start button first is clicked, before selecting data source
except:
tkMessageBox.showwarning(title='Attention',message='Please select data source first !!!')
# Selecting GEO data set #
def selectFileGEO(self):
self.GEOfilename=askopenfilename(parent=mGui)
self.GEOEntry.delete(0,END)
self.GEOEntry.insert(0,self.GEOfilename)
#Creating buttons #
self.startbuttonGEO=Button(mGui,text='Start',command=self.readdataGEO)
self.startbuttonGEO.place(relx=0.3,rely=0.4)
self.cancelbuttonGEO=Button(mGui,text="Quit",command=self.mQuit)
self.cancelbuttonGEO.place(relx=0.6,rely=0.4)
#Opening and Reading GEO dataset and merging #
def readdataGEO(self):
fileGEO=open(self.GEOEntry.get())
self.data_set=[]
for i,line in enumerate(fileGEO.readlines()):
data=line
data1=data.split("\t")
data2=[i.strip() for i in data1]
self.data_set.append(data2)
#P value for shapiro test #
self.distthresholdlabel=Label(mGui,text='Input Shapiro test treshold')
self.distthresholdlabel.place(relx=0.25,rely=0.55)
self.distthresholdEntry=Entry(mGui,width=6)
self.distthresholdEntry.place(relx=0.61,rely=0.55)
self.flterButton=Button(mGui,text='Filter Data',command=self.filter_data)
self.flterButton.place(relx=0.4,rely=0.7)
# Creating browse button for TCGA data set #
def browse(self):
self.entry=Entry(mGui,width=30)
self.entry.place(relx=0.2,rely=0.2)
self.pathButton=Button(mGui)
self.pathButton.config(text="Browse",font=10,command=self.path)
self.pathButton.place(relx=0.75,rely=0.2)
#Selecting the path where expression files are exist #
def path(self):
mGui.fileName = tkFileDialog.askdirectory(parent=mGui, title='Select Directory')
pathName=mGui.fileName
self.entry.delete(0,END)
self.entry.insert(0,pathName)
self.StartButton=Button(mGui,text="Start",font=10,command=self.combining_genes)
self.StartButton.place(relx=0.3,rely=0.4)
self.CancelButton=Button(mGui,text="Quit",font=10,command=self.mQuit)
self.CancelButton.place(relx=0.6,rely=0.4)
#Opening single text files, reading and merging #
def combining_genes(self):
directory=self.entry.get()
os.chdir(directory)
list_of_files=glob.glob('*.txt')
self.data_set=[]
for i,filename in enumerate(list_of_files):
data_list=open(filename,'r')
if i==0:
for j,line in enumerate(data_list.readlines()):
data=line
data1=data.split("\t")
self.data_set.append(data1)
else:
for j,line in enumerate(data_list.readlines()):
temp_data=[]
data=line
data1=data.split("\t")
for k in self.data_set[j]:
temp_data.append(k)
temp_data.append(data1[1])
self.data_set[j]=temp_data
data_list.close()
##P value for shapiro test #
self.distthresholdlabel=Label(mGui,text='Input Shapiro test treshold')
self.distthresholdlabel.place(relx=0.25,rely=0.55)
self.distthresholdEntry=Entry(mGui,width=6)
self.distthresholdEntry.place(relx=0.61,rely=0.55)
#Creating button for further step #
self.flterButton=Button(mGui,text='Filter Data',command=self.filter_data)
self.flterButton.place(relx=0.4,rely=0.65)
#Filterign data set #
def filter_data(self):
#checking if p value is input #
try:
self.thresholdforPvalue=float(self.distthresholdEntry.get())
except:
tkMessageBox.showwarning(title='Attention',message='Please enter numeric value for threshold')
self.cancerandnormaldatafull=[]
self.incomplete_genes=[]
self.dist=[]
#checking if correct data set is selected #
try:
self.list1=self.data_set[0][1:]
except:
tkMessageBox.showwarning(title='Attention',message='Please select correct directory or check txt files and Restart the program')
self.cancersets=[]
self.full_dataset=[]
self.normalsets=[]
#data set filtering for TCGA #
if self.selectedRbutton==1:
for i in range(0,len(self.data_set)):
if i>=2:
data=[]
temporary=self.data_set[i]
for k in temporary[1:]:
try:
tempfloat=float(k)
data.append(tempfloat)
except:
pass
data=[x for x in data if x]
temp=[]
for j in data:
if type(j)==float:
temp.append(j)
else:
pass
if len(temp)==(len(temporary)-1):
self.full_dataset.append(data)
#separating samples into tumor and normal #
data2=sampleClass.cancersample(self.list1,data)
self.data3=[temporary[0]]+data2 # tumor sample
self.cancersets.append(self.data3)
data4=sampleClass.normalsample(self.list1,data)
self.data5=[temporary[0]]+data4 #normal sample
self.normalsets.append(self.data5)
self.cancerNormal=[temporary[0]]+data2 +data4
self.cancerandnormaldatafull.append(self.cancerNormal)
try:
pval=normality.distribution(self.data3,self.thresholdforPvalue)
except:
tkMessageBox.showwarning(title='Attention',message='Please select correct directory or check txt files and Restart the program')
#normality calculation #
if pval>self.thresholdforPvalue:
self.dist.append(self.data3[0])
else:
pass
#incomplete genes are detected #
else:
line=str(i+1)+str(' ')+str(temporary[0])
self.incomplete_genes.append(line)
#Data set filtering fot GEO #
else:
for i in range(0,len(self.data_set)):
if i>=1:
data=[]
temporary=self.data_set[i]
for k in temporary[1:]:
try:
tempfloat=float(k)
data.append(tempfloat)
except:
pass
data=[x for x in data if x]
#data=[float(a) for a in data[1:]]
temp=[]
for j in data:
if type(j)==float:
temp.append(j)
else:
pass
if len(temp)==(len(temporary)-1):
self.full_dataset.append(data)
#separating samples into tumor and normal #
data2=sampleClass.cancersampleGEO(self.list1,data)
self.data3=[temporary[0]]+data2 # tumor samples
self.cancersets.append(self.data3)
data4=sampleClass.normalsampleGEO(self.list1,data)
self.data5=[temporary[0]]+data4 #normal samples
self.normalsets.append(self.data5)
self.cancerNormal=[temporary[0]]+data2 +data4
self.cancerandnormaldatafull.append(self.cancerNormal)
try:
pval=normality.distribution(self.data3,self.thresholdforPvalue)
except:
tkMessageBox.showwarning(title='Attention',message='Please select correct file and Restart the program')
#normality calculation #
if pval>self.thresholdforPvalue:
self.dist.append(self.data3[0])
#incomplete genes are detected #
else:
line=str(i+1)+str(' ')+str(temporary[0])
self.incomplete_genes.append(line)
#normal samples are added data if number of normal samples are > 50 #
if len(self.normalsets[0])>50:
self.cancersets=self.cancersets + self.normalsets
else:
pass
#Destroying buttons #
self.helpmenudatabutton.destroy()
#if TCGA is selected #
try:
self.distthresholdlabel.destroy()
self.distthresholdEntry.destroy()
self.StartButton.destroy()
self.CancelButton.destroy()
self.pathButton.destroy()
self.entry.destroy()
self.flterButton.destroy()
#if GEO is selected #
except:
self.GEOEntry.destroy()
self.GEOselectbutton.destroy()
self.startbuttonGEO.destroy()
self.cancelbuttonGEO.destroy()
self.distthresholdlabel.destroy()
self.distthresholdEntry.destroy()
self.flterButton.destroy()
#Reporting the characteristic of data set #
self.datahead=Label(mGui,text ='Characteristics of Data Set',font='Times 18 bold italic')
self.datahead.place(relx=0.1,rely=0.2)
self.geneText=Text(mGui,height=1,width=50,wrap=None)
self.geneText.place(relx=0.1,rely=0.3)
gText="Number of Genes : "+str(len(self.data_set))
self.geneText.insert(0.0,gText)
self.sampleText=Text(mGui,height=1,width=50)
self.sampleText.place(relx=0.1,rely=0.35)
sText="Number of Samples: "+ str(len(self.data_set[0][1:]))
self.sampleText.insert(0.0,sText)
self.cancerText=Text(mGui,height=1,width=50)
self.cancerText.place(relx=0.1,rely=0.4)
cText="Number of Cancer Samples : "+ str(len(self.data3[1:]))
self.cancerText.insert(0.0,cText)
self.normalText=Text(mGui,height=1,width=50)
self.normalText.place(relx=0.1,rely=0.45)
nText="Number of Normal Samples: "+ str(len(self.data5[1:]))
self.normalText.insert(0.0,nText)
self.incompleteText=Text(mGui,height=1,width=50)
self.incompleteText.place(relx=0.1,rely=0.5)
iText="Number of incomplete Genes: "+ str(len(self.incomplete_genes))
self.incompleteText.insert(0.0,iText)
self.distText=Text(mGui,height=1,width=50)
self.distText.place(relx=0.1,rely=0.55)
dText="Number of genes follow normal distribution: " +str(len(self.dist))
self.distText.insert(0.0,dText)
#Creating the buttons for next steps #
self.goForAnalysis=Button(mGui,text='Outlier Menu',command=self.goForAnalysis)
self.goForAnalysis.place(relx=0.07,rely=0.7)
self.CancelButton=Button(mGui,text="Quit",command=self.mQuit)
self.CancelButton.place(relx=0.72,rely=0.7)
self.exportincompletegenes=Button(mGui,text='Export Incomplete Genes',command=self.ExportIncmopleteGene)
self.exportincompletegenes.place(relx=0.32,rely=0.7)
#Exporting Incomplete Genes where expression file exists #
def ExportIncmopleteGene(self):
exportincompgenes.ExportIncmopleteGenes(self.incomplete_genes)
tkMessageBox.showinfo(title='Info',message='File were successfully exported')
#Propceeding sample/gene level outlier detection #
def goForAnalysis(self):
#Deleting buttons #
self.datahead.destroy()
self.geneText.destroy()
self.sampleText.destroy()
self.cancerText.destroy()
self.normalText.destroy()
self.incompleteText.destroy()
self.distText.destroy()
self.goForAnalysis.destroy()
self.CancelButton.destroy()
self.exportincompletegenes.destroy()
#Creating buttons#
self.selectLabel=Label(mGui,text='Please select outlier detection level type',font='Times 14 bold italic')
self.selectLabel.place(relx=0.22,rely=0.2)
self.genelLevelButton=Button(mGui,text='Gene Level ',command=self.checkbutgene)
self.genelLevelButton.place(relx=0.22,rely=0.27)
self.sampleLevelButton=Button(mGui,text='Sample Level',command=self.checkbutsample)
self.sampleLevelButton.place(relx=0.52,rely=0.27)
self.helpmenualgorithmsbutton=Button(mGui,text='Help',command=self.helpmenu2)
self.helpmenualgorithmsbutton.place(relx=0.44,rely=0.93)
#Sample level outlier detection menu #
def checkbutsample(self):
# Removing labels and buttons if gene level is selected before #
try:
self.selectalgogeneLabel.destroy()
self.checkbutton_Mzs.destroy()
self.checkbutton_Abp.destroy()
self.checkbutton_Gesd.destroy()
self.applygeneButton.destroy()
self.checkbutton_MedianRule.destroy()
self.selectedgeneLabel.destroy()
self.cancelButgen.destroy()
self.genethresholdEntry.destroy()
self.genethresholdlabel.destroy()
self.helpmenualgorithmsbutton.destroy()
self.backToStatsButton.destroy()
except:
pass
#Creating buttons and labels for sample level outlier detection #
self.selectLabel.destroy()
self.selectedsampleLabel=Label(mGui,text='Detecting Outliers at sample level is selected',font='Times 14 bold italic')
self.selectedsampleLabel.place(relx=0.22,rely=0.2)
self.selectalgogeneLabel=Label(mGui,text='Please select algorithm',font='Times 14 bold ')
self.selectalgogeneLabel.place(relx=0.3,rely=0.4)
#Adding button for sample level #
self.ahc=BooleanVar()
self.checkbutton_ahc=Checkbutton(mGui,text='Average Hierarchical Clustering',variable=self.ahc,command=self.checkbutsamplealgo)
self.checkbutton_ahc.place(relx=0.2,rely=0.5)
self.applysampleButton=Button(mGui,text='Apply',command=self.applycheckbutsamplealgo)
self.applysampleButton.place(relx=0.2,rely=0.7)
self.cancelButsample=Button(mGui,text='Quit',command=self.mQuit)
self.cancelButsample.place(relx=0.7,rely=0.7)
self.goBackStatsButton=Button(mGui, text='Back to Stats',command=self.backtoStatistics)
self.goBackStatsButton.place(relx=0.4, rely=0.7)
#Checking if sample level outlier detection is selected #
def checkbutsamplealgo(self):
if self.ahc.get():
#print 'just mzscore'
pass
#Applying Average hierarchical algorithm and displaying the results#
def applycheckbutsamplealgo(self):
#TCGA dataset#
if self.selectedRbutton==1:
SampleLevelTCGA.hierarchical(self.list1,self.full_dataset)
#GEO dataset#
else:
SampleLevelGEO.hierarchical(self.list1,self.full_dataset)
tkMessageBox.showinfo(title='Attention',message='Image was saved into selected diretory')
#Removing buttons #
self.genelLevelButton.destroy()
self.sampleLevelButton.destroy()
self.selectedsampleLabel.destroy()
self.selectalgogeneLabel.destroy()
self.checkbutton_ahc.destroy()
self.applysampleButton.destroy()
self.cancelButsample.destroy()
self.helpmenualgorithmsbutton.destroy()
self.goBackStatsButton.destroy()
#Results #
self.SilhouetteCofText=Text(mGui,height=1,width=50,wrap=None)
self.SilhouetteCofText.place(relx=0.2,rely=0.22)
if self.selectedRbutton==1:
SilCofText="Silhouette Coefficient : "+str(SampleLevelTCGA.score)
else:
SilCofText="Silhouette Coefficient : "+str(SampleLevelGEO.score)
self.SilhouetteCofText.insert(0.0,SilCofText)
self.sampleLevelOutlierLabel=Label(mGui,text='Please enter the outlier label',font='Times 14 bold ')
self.sampleLevelOutlierLabel.place(relx=0.27,rely=0.32)
self.sampleLevelOutlierEntry=Entry(mGui,width=25)
self.sampleLevelOutlierEntry.place(relx=0.27,rely=0.4)
self.sampleNameLabel=Label(mGui,text='If there is more than one outlier,Please seperate them by comma',font='8')
self.sampleNameLabel.place(relx=0.05,rely=0.5)
#Creating buttons for futher studies #
self.GoGenelevelOutlierButton=Button(mGui,text='Go Gene Level',command=self.GoGeneLevel)
self.GoGenelevelOutlierButton.place(relx=0.15,rely=0.6)
self.removeSampleOutlierButton=Button(mGui,text='Remove Outlier',command=self.deleteOutlierfromSampleLevel)
self.removeSampleOutlierButton.place(relx=0.45,rely=0.6)
self.cancelSampleOutlierButton=Button(mGui,text='Quit',command=self.mQuit)
self.cancelSampleOutlierButton.place(relx=0.75,rely=0.6)
#deleting outliers#
def deleteOutlierfromSampleLevel(self):
self.sampleoutlierstring=self.sampleLevelOutlierEntry.get() # getting outliers from input box
#removing labels and buttons #
self.sampleLevelOutlierLabel.destroy()
self.sampleLevelOutlierEntry.destroy()
self.sampleNameLabel.destroy()
self.GoGenelevelOutlierButton.destroy()
self.removeSampleOutlierButton.destroy()
self.cancelSampleOutlierButton.destroy()
self.SilhouetteCofText.destroy()
#creating labels for the removing outlier section section #
self.dataCharacterwoutOutlierSampleLabel=Label(mGui,text='Characteristics of Pure Data Set ',font='Times 18 bold italic')
self.dataCharacterwoutOutlierSampleLabel.place(relx=0.2,rely=0.2)
#when gene level outlier algorithms are applied too#
try:
seperateSampleOutlier=self.sampleoutlierstring.split(',')
self.sampleindex=[]
# reading sample outliers from text widget and preparing for removal #
for sample in seperateSampleOutlier:
if self.selectedRbutton==1:
if sample in SampleLevelTCGA.newlist:
index=SampleLevelTCGA.newlist.index(sample)
self.sampleindex.append(index)
else:
pass
else:
if sample in SampleLevelGEO.newlist:
index=SampleLevelGEO.newlist.index(sample)
self.sampleindex.append(index)
else:
pass
reverseData=zip(*self.cancerandnormaldatafull)
#deleting sample level outliers #
for sampleindex in sorted(self.sampleindex,reverse=True):
del reverseData[int(sampleindex+1)]
self.backcancerandnormaldatafull=zip(*reverseData)
#deleting gene level outliers #
cleaneddatagenes=GeneLevel.deleting_outliers(self.backcancerandnormaldatafull,self.RealOutlier)
self.cleaneddatagenes=cleaneddatagenes
#results#
self.numberofdeletedSampleText=Text(mGui,height=1,width=60,wrap=None)
self.numberofdeletedSampleText.place(relx=0.1,rely=0.3)
numberofdeletedSample='Number of Deleted Sample: '+str(len(self.sampleindex))
self.numberofdeletedSampleText.insert(0.0,numberofdeletedSample)
self.numberofremainSampleText=Text(mGui,height=1,width=60,wrap=None)
self.numberofremainSampleText.place(relx=0.1,rely=0.35)
numberofremainSample='Number of Sample of Data Set: '+str(len(reverseData)-1)
self.numberofremainSampleText.insert(0.0,numberofremainSample)
self.numberofdeletedgenesText=Text(mGui,height=1,width=60,wrap=None)
self.numberofdeletedgenesText.place(relx=0.1,rely=0.40)
numberofdeletedgenes='Number of Deleted Outlier Genes: '+str(len(self.RealOutlier))
self.numberofdeletedgenesText.insert(0.0,numberofdeletedgenes)
self.numberofcleanedgenesText=Text(mGui,height=1,width=60,wrap=None)
self.numberofcleanedgenesText.place(relx=0.1,rely=0.45)
numberofcleangenes='Number of Genes of Data Set: '+str(len(self.cleaneddatagenes))
self.numberofcleanedgenesText.insert(0.0,numberofcleangenes)
#creating buttons for next steps #
self.extractsampleButton=Button(mGui,text='Extract Files',command=self.browseforsamplelevel)
self.extractsampleButton.place(relx=0.25,rely=0.5)
self.CancelfromSampleButton=Button(mGui,text='Quit',command=self.mQuit)
self.CancelfromSampleButton.place(relx=0.55,rely=0.5)
#when just sample level outlier detection algorithm is applied #
except:
seperateSampleOutlier=self.sampleoutlierstring.split(',')
self.sampleindex=[]
# reading sample outliers from text widget and preparing for removal #
for sample in seperateSampleOutlier:
if self.selectedRbutton==1:
if sample in SampleLevelTCGA.newlist:
index=SampleLevelTCGA.newlist.index(sample)
self.sampleindex.append(index)
else:
pass
else:
if sample in SampleLevelGEO.newlist:
index=SampleLevelGEO.newlist.index(sample)
self.sampleindex.append(index)
else:
pass
reverseData=zip(*self.cancerandnormaldatafull)
#deleting sample level outliers #
for sampleindex in sorted(self.sampleindex,reverse=True):
del reverseData[int(sampleindex+1)]
self.backcancerandnormaldatafull=zip(*reverseData)
self.cleaneddatagenes=self.backcancerandnormaldatafull
#result#
self.numberofdeletedSampleText=Text(mGui,height=1,width=60,wrap=None)
self.numberofdeletedSampleText.place(relx=0.1,rely=0.3)
numberofdeletedSample='Number of Deleted Sample: '+str(len(self.sampleindex))
self.numberofdeletedSampleText.insert(0.0,numberofdeletedSample)
self.numberofremainSampleText=Text(mGui,height=1,width=60,wrap=None)
self.numberofremainSampleText.place(relx=0.1,rely=0.35)
numberofremainSample='Number of Sample of Data Set: '+str(len(reverseData)-1)
self.numberofremainSampleText.insert(0.0,numberofremainSample)
##creating buttons for next steps ##
self.extractsampleButton=Button(mGui,text='Extract Files',command=self.browseforsamplelevel)
self.extractsampleButton.place(relx=0.25,rely=0.5)
self.CancelfromSampleButton=Button(mGui,text='Quit',command=self.mQuit)
self.CancelfromSampleButton.place(relx=0.55,rely=0.5)
#Browsing path button to extract files#
def browseforsamplelevel(self):
self.browseSampleEntry=Entry(mGui,width=26)
self.browseSampleEntry.place(relx=0.2,rely=0.6)
self.browseSampleButton=Button(mGui)
self.browseSampleButton.config(text="Browse",font=10,command=self.getdirectoryforSampleExtract)
self.browseSampleButton.place(relx=0.7,rely=0.6)
#Selecting path using pop-up #
def getdirectoryforSampleExtract(self):
mGui.fileNameSampleExtract = tkFileDialog.askdirectory(parent=mGui, title='Select Directory')
pathname=mGui.fileNameSampleExtract
self.browseSampleEntry.delete(0,END)
self.browseSampleEntry.insert(0,pathname)
#removing buttons #
self.extractsampleButton.destroy()
self.CancelfromSampleButton.destroy()
#creating buttons for next steps#
self.ExtractSampleButton=Button(mGui,text="Extract",font=10,command=self.FinalSampleExtract)
self.ExtractSampleButton.place(relx=0.3,rely=0.68)
self.CancelExtractSampleButton=Button(mGui,text="Quit",font=10,command=self.mQuit)
self.CancelExtractSampleButton.place(relx=0.6,rely=0.68)
#Extracting files#
def FinalSampleExtract(self):
new_directorySample=self.browseSampleEntry.get()
os.chdir(new_directorySample)
for sampleindex in sorted(self.sampleindex,reverse=True):
del self.data_set[0][int(sampleindex+1)]
for sampleindex in sorted(self.sampleindex,reverse=True):
del self.data_set[1][int(sampleindex+1)]
#TCGA dataset#
if self.selectedRbutton==1:
final_data=[self.data_set[0]] + [self.data_set[1]] + self.cleaneddatagenes
extractFile.Extracting_files_TCGA(final_data)
#GEO dataset#
else:
final_data=[self.data_set[0]] + self.cleaneddatagenes
extractFile.Extracting_files_GEO(final_data)
tkMessageBox.showinfo(title='Info',message='Files were successfully extracted')
#Back to gene level #
def GoGeneLevel(self):
self.sampleoutlierstring=self.sampleLevelOutlierEntry.get()
self.sampleLevelOutlierLabel.destroy()
self.sampleLevelOutlierEntry.destroy()
self.sampleNameLabel.destroy()
self.GoGenelevelOutlierButton.destroy()
self.removeSampleOutlierButton.destroy()
self.cancelSampleOutlierButton.destroy()
self.SilhouetteCofText.destroy()
self.selectLabel=Label(mGui,text='Please select outlier detection level type',font='Times 14 bold italic')
self.selectLabel.place(relx=0.22,rely=0.2)
self.genelLevelButton=Button(mGui,text='Gene Level ',command=self.checkbutgene)
self.genelLevelButton.place(relx=0.22,rely=0.27)
self.sampleLevelButton=Button(mGui,text='Sample Level',command=self.checkbutsample)
self.sampleLevelButton.place(relx=0.52,rely=0.27)
#Gene level outlier detection menu #
def checkbutgene(self):
#destroying buttons and labels if sample is selected before #
try:
self.applysampleButton.destroy()
self.checkbutton_ahc.destroy()
self.applysampleButton.destroy()
self.checkbutton_ahc.destroy()
self.selectedsampleLabel.destroy()
self.cancelButsample.destroy()
self.selectalgogeneLabel.destroy()
self.goBackStatsButton.destroy()
except:
pass
self.selectLabel.destroy()
self.selectedgeneLabel=Label(mGui,text='Detecting Outliers at gene level is selected',font='Times 14 bold italic')
self.selectedgeneLabel.place(relx=0.22,rely=0.2)
self.selectalgogeneLabel=Label(mGui,text='Please select algorithms that you would like to apply',font='Times 14 bold ')
self.selectalgogeneLabel.place(relx=0.1,rely=0.4)
#Creating buttons for gene level algorithms #
self.mzscore=BooleanVar()
self.checkbutton_Mzs=Checkbutton(mGui,text='Modified Z-Score (MAD)',variable=self.mzscore,command=self.checkbutgenealgo)
self.checkbutton_Mzs.place(relx=0.2,rely=0.5)
self.abplot=BooleanVar()
self.checkbutton_Abp=Checkbutton(mGui,text='Adjusted Box Plot',variable=self.abplot,command=self.checkbutgenealgo)
self.checkbutton_Abp.place(relx=0.2,rely=0.55)
self.gesd=BooleanVar()
self.checkbutton_Gesd=Checkbutton(mGui,text='Generalized Extreme Studentized Deviate ',variable=self.gesd,command=self.checkbutgenealgo)
self.checkbutton_Gesd.place(relx=0.2,rely=0.6)
self.medianRule=BooleanVar()
self.checkbutton_MedianRule=Checkbutton(mGui,text='Median Rule ',variable=self.medianRule,command=self.checkbutgenealgo)
self.checkbutton_MedianRule.place(relx=0.2,rely=0.65)
# Threshold for gene level outlier detection
self.genethresholdlabel=Label(mGui,text='Outlier observation threshold')
self.genethresholdlabel.place(relx=0.2,rely=0.75)
self.genethresholdEntry=Entry(mGui,width=4)
self.genethresholdEntry.place(relx=0.61,rely=0.75)
#Buttons for further steps #
self.applygeneButton=Button(mGui,text='Apply',command=self.applycheckbutgenealgo)
self.applygeneButton.place(relx=0.2,rely=0.85)
self.cancelButgen=Button(mGui,text='Quit',command=self.mQuit)
self.cancelButgen.place(relx=0.7,rely=0.85)
self.backToStatsButton=Button(mGui,text='Back to Stats',command=self.backtoStatistics)
self.backToStatsButton.place(relx=0.4, rely=0.85)
#Back to stats #
def backtoStatistics(self):
try:
#deleting buttons and labels if sample level is selected #
self.applysampleButton.destroy()
self.checkbutton_ahc.destroy()
self.applysampleButton.destroy()
self.checkbutton_ahc.destroy()
self.selectedsampleLabel.destroy()
self.cancelButsample.destroy()
self.selectalgogeneLabel.destroy()
self.goBackStatsButton.destroy()
except:
#deleting buttons and labels if gene level is selected #
self.selectalgogeneLabel.destroy()
self.checkbutton_Mzs.destroy()
self.checkbutton_Abp.destroy()
self.checkbutton_Gesd.destroy()
self.applygeneButton.destroy()
self.checkbutton_MedianRule.destroy()
self.selectedgeneLabel.destroy()
self.cancelButgen.destroy()
self.genethresholdEntry.destroy()
self.genethresholdlabel.destroy()
self.helpmenualgorithmsbutton.destroy()
self.backToStatsButton.destroy()
self.genelLevelButton.destroy()
self.sampleLevelButton.destroy()
#Reporting the characteristic of data set #
self.datahead=Label(mGui,text ='Characteristics of Data Set',font='Times 18 bold italic')
self.datahead.place(relx=0.1,rely=0.2)
self.geneText=Text(mGui,height=1,width=50,wrap=None)
self.geneText.place(relx=0.1,rely=0.3)
gText="Number of Genes : "+str(len(self.data_set))
self.geneText.insert(0.0,gText)
self.sampleText=Text(mGui,height=1,width=50)
self.sampleText.place(relx=0.1,rely=0.35)
sText="Number of Samples: "+ str(len(self.data_set[0][1:]))
self.sampleText.insert(0.0,sText)
self.cancerText=Text(mGui,height=1,width=50)
self.cancerText.place(relx=0.1,rely=0.4)
cText="Number of Cancer Samples : "+ str(len(self.data3[1:]))
self.cancerText.insert(0.0,cText)
self.normalText=Text(mGui,height=1,width=50)
self.normalText.place(relx=0.1,rely=0.45)
nText="Number of Normal Samples: "+ str(len(self.data5[1:]))
self.normalText.insert(0.0,nText)
self.incompleteText=Text(mGui,height=1,width=50)
self.incompleteText.place(relx=0.1,rely=0.5)
iText="Number of incomplete Genes: "+ str(len(self.incomplete_genes))
self.incompleteText.insert(0.0,iText)
self.distText=Text(mGui,height=1,width=50)
self.distText.place(relx=0.1,rely=0.55)
dText="Number of genes follow normal distribution: " +str(len(self.dist))
self.distText.insert(0.0,dText)
#Creating the buttons for next steps #
self.goForAnalysis=Button(mGui,text='Outlier Menu',command=self.GoOutlierMenu)
self.goForAnalysis.place(relx=0.07,rely=0.7)
self.CancelButton=Button(mGui,text="Quit",command=self.mQuit)
self.CancelButton.place(relx=0.72,rely=0.7)
self.exportincompletegenes=Button(mGui,text='Export Incomplete Genes',command=self.ExportIncmopleteGene)
self.exportincompletegenes.place(relx=0.32,rely=0.7)
#Go outlier menu after clicking back to stats#
def GoOutlierMenu(self):
#Deleting buttons #
self.datahead.destroy()
self.geneText.destroy()
self.sampleText.destroy()
self.cancerText.destroy()
self.normalText.destroy()
self.incompleteText.destroy()
self.distText.destroy()
self.goForAnalysis.destroy()
self.CancelButton.destroy()
self.exportincompletegenes.destroy()
#Creating buttons#
self.selectLabel=Label(mGui,text='Please select outlier detection level type',font='Times 14 bold italic')
self.selectLabel.place(relx=0.22,rely=0.2)
self.genelLevelButton=Button(mGui,text='Gene Level ',command=self.checkbutgene)
self.genelLevelButton.place(relx=0.22,rely=0.27)
self.sampleLevelButton=Button(mGui,text='Sample Level',command=self.checkbutsample)
self.sampleLevelButton.place(relx=0.52,rely=0.27)
self.helpmenualgorithmsbutton=Button(mGui,text='Help',command=self.helpmenu2)
self.helpmenualgorithmsbutton.place(relx=0.42,rely=0.93)
#checking which algorithms is selected #
def checkbutgenealgo(self):
if self.medianRule.get():
pass
if self.mzscore.get():
pass
if self.abplot.get():
pass
if self.gesd.get():
pass
if self.mzscore.get() and self.medianRule.get():
pass
if self.medianRule.get() and self.abplot.get():
pass
if self.mzscore.get() and self.abplot.get():
pass
if self.gesd.get() and self.medianRule.get():
pass
if self.gesd.get() and self.abplot.get():
pass
if self.gesd.get() and self.mzscore.get():
pass
if self.gesd.get() and self.mzscore.get() and self.medianRule.get():
pass
if self.medianRule.get() and self.mzscore.get() and self.abplot.get():
pass
if self.gesd.get() and self.mzscore.get() and self.abplot.get():
pass
if self.gesd.get() and self.medianRule.get() and self.abplot.get():
pass
if self.gesd.get() and self.medianRule.get() and self.abplot.get() and self.medianRule.get():
pass
#Applying algortihms for gene level outlier detection #
def applycheckbutgenealgo(self):
#Empty list to extract outliers #
self.extractOut=[]
#Generalized ESD, Adjusted box plot, Modified Z-Score Algorithms and Median Rule #
if self.gesd.get() and self.mzscore.get() and self.abplot.get() and self.medianRule.get():
self.abplot_outlier_list=[]
self.gesd_outlier_list=[]
self.medianRule_outlier_list=[]
self.mzs_outlier_list=[]
self.total_outlier=[]
for i in range(0,len(self.cancersets)):
#Normality Calculation#
pval=normality.distribution(self.cancersets[i],self.thresholdforPvalue)
if pval>self.thresholdforPvalue:
#Modified Z-Score and Generalized ESD for normal distribution gene #
self.out_mz=GeneLevel.outlier_detection_modified_z_score(self.cancersets[i],thresholdGeneLevel=self.genethresholdEntry.get())
self.out_gesd=GeneLevel.main_gesd(self.cancersets[i],thresholdGeneLevel=self.genethresholdEntry.get())
if self.out_mz==None:
pass
else:
self.mzs_outlier_list.append(self.out_mz)
temp=['Modified Z-score',self.out_mz[0],i] # temprorary list to add main extraction list for outliers
self.extractOut.append(temp)
if self.out_gesd==None:
pass
else:
self.gesd_outlier_list.append(self.out_gesd)
temp=['GESD',self.out_gesd[0],i] # temprorary list to add main extraction list for outliers
self.extractOut.append(temp)
#Adjusted box plot and Median Rule for non-normal distribution gene #
else:
self.out_medianrule=GeneLevel.median_rule_outlier_det(self.cancersets[i],thresholdGeneLevel=self.genethresholdEntry.get())
self.out_abp=GeneLevel.outlier_detection_adjusted_box_plot(self.cancersets[i],thresholdGeneLevel=self.genethresholdEntry.get())
if self.out_abp==None:
pass
else:
self.abplot_outlier_list.append(self.out_abp)
temp=['Adjusted BP',self.out_abp[0],i] # temprorary list to add main extraction list for outliers
self.extractOut.append(temp)
if self.out_medianrule==None:
pass
else:
self.medianRule_outlier_list.append(self.out_medianrule)
temp=['Median R.',self.out_medianrule[0],i] # temprorary list to add main extraction list for outliers
self.extractOut.append(temp)
#common outliers for median rule and adjusted box plot#
self.commonAbp_Median=GeneLevel.common_outlier(self.medianRule_outlier_list,self.abplot_outlier_list,self.cancersets[0])
#common outliers for Generalized ESD and Modified Z-score #
self.common=GeneLevel.common_outlier(self.mzs_outlier_list,self.gesd_outlier_list,self.cancersets[0])
#merging outliers for Generalized ESD and Modified Z-score #
self.single=GeneLevel.singleListforMzsGesd(self.mzs_outlier_list,self.gesd_outlier_list)
#total outlier#
self.total_outlier_list=self.single + self.commonAbp_Median
#Removing labels and buttons #
self.RemoveButtonandLabel()
#Displaying results#
self.resultgenelevelLabel=Label(mGui,text='Detected outliers at Gene Level',font='Times 18 bold')
self.resultgenelevelLabel.place(relx=0.1,rely=0.2)
self.appliedalgoLabel=Label(mGui,text='Applied Algorithm',font='bold')
self.appliedalgoLabel.place(relx=0.1,rely=0.3)
self.numberofoutlierLabel=Label(mGui,text='Number of Outliers',font='bold')
self.numberofoutlierLabel.place(relx=0.45,rely=0.3)
self.numberofMzsText=Text(mGui,height=1,width=60,wrap=None)
self.numberofMzsText.place(relx=0.1,rely=0.4)
numberoutliemMzs="Modified Z-Score "+str(len(self.mzs_outlier_list))
self.numberofMzsText.insert(0.0,numberoutliemMzs)
self.numberofabplotText=Text(mGui,height=1,width=60,wrap=None)
self.numberofabplotText.place(relx=0.1,rely=0.55)
numberoutliemabplot="Adjusted Box Plot "+str(len(self.abplot_outlier_list))
self.numberofabplotText.insert(0.0,numberoutliemabplot)
self.numberofcommonText=Text(mGui,height=1,width=60,wrap=None)
self.numberofcommonText.place(relx=0.1,rely=0.5)
numberoutliemcommon="Common (GESD & M.Z-score) "+str(len(self.common))
self.numberofcommonText.insert(0.0,numberoutliemcommon)
self.numberofcommonAbp_MedianText=Text(mGui,height=1,width=60,wrap=None)
self.numberofcommonAbp_MedianText.place(relx=0.1,rely=0.65)
numberoutliemcommonAbp_Median="Common (A.BoxPlot & M.Rule) "+str(len(self.commonAbp_Median))
self.numberofcommonAbp_MedianText.insert(0.0,numberoutliemcommonAbp_Median)
self.numberofGesdText=Text(mGui,height=1,width=60,wrap=None)
self.numberofGesdText.place(relx=0.1,rely=0.45)
numberoutliemGesd="Generalized ESD "+str(len(self.gesd_outlier_list))
self.numberofGesdText.insert(0.0,numberoutliemGesd)
self.numberofMedianText=Text(mGui,height=1,width=60,wrap=None)
self.numberofMedianText.place(relx=0.1,rely=0.6)
numberoutlierMedian="Median Rule "+str(len(self.medianRule_outlier_list))
self.numberofMedianText.insert(0.0,numberoutlierMedian)
#Creating buttons for next steps#
self.CreateButtonandLabel()
self.venndiagramButton=Button(mGui,text='Venn Diagram',command=self.Venn_Diagram)
self.venndiagramButton.place(relx=0.1,rely=0.8)
return
#Generalized ESD, Adjusted box plot and Modified Z-Score Algorithms #
if self.gesd.get() and self.mzscore.get() and self.abplot.get():
self.abplot_outlier_list=[]
self.gesd_outlier_list=[]
self.mzs_outlier_list=[]
self.total_outlier=[]
for i in range(0,len(self.cancersets)):
#Normality Calculation#
pval=normality.distribution(self.cancersets[i],self.thresholdforPvalue)
if pval>self.thresholdforPvalue:
#Modified Z-Score and Generalized ESD for normal distribution gene #
self.out_mz=GeneLevel.outlier_detection_modified_z_score(self.cancersets[i],thresholdGeneLevel=self.genethresholdEntry.get())
self.out_gesd=GeneLevel.main_gesd(self.cancersets[i],thresholdGeneLevel=self.genethresholdEntry.get())
if self.out_mz==None:
pass
else:
self.mzs_outlier_list.append(self.out_mz)
temp=['Modified Z-score',self.out_mz[0],i] # temprorary list to add main extraction list for outliers
self.extractOut.append(temp)
if self.out_gesd==None:
pass
else:
self.gesd_outlier_list.append(self.out_gesd)
temp=['GESD',self.out_gesd[0],i] # temprorary list to add main extraction list for outliers
self.extractOut.append(temp)
#Adjusted box plot for non-normal distribution gene #
else:
self.out_abp=GeneLevel.outlier_detection_adjusted_box_plot(self.cancersets[i],thresholdGeneLevel=self.genethresholdEntry.get())
if self.out_abp==None:
pass
else:
self.abplot_outlier_list.append(self.out_abp)
temp=['Adjusted BP',self.out_abp[0],i] # temprorary list to add main extraction list for outliers
self.extractOut.append(temp)
#common outliers for Generalized ESD and Modified Z-score #
self.common=GeneLevel.common_outlier(self.mzs_outlier_list,self.gesd_outlier_list,self.cancersets[0])
#merging outliers for Generalized ESD and Modified Z-score #
self.single=GeneLevel.singleListforMzsGesd(self.mzs_outlier_list,self.gesd_outlier_list)
#total outlier#
self.total_outlier_list=self.single + self.abplot_outlier_list
#Removing labels and buttons #
self.RemoveButtonandLabel()
#Displaying results#
self.resultgenelevelLabel=Label(mGui,text='Detected outliers at Gene Level',font='Times 18 bold')
self.resultgenelevelLabel.place(relx=0.1,rely=0.2)
self.appliedalgoLabel=Label(mGui,text='Applied Algorithm',font='bold')
self.appliedalgoLabel.place(relx=0.1,rely=0.3)
self.numberofoutlierLabel=Label(mGui,text='Number of Outliers',font='bold')
self.numberofoutlierLabel.place(relx=0.45,rely=0.3)
self.numberofMzsText=Text(mGui,height=1,width=60,wrap=None)
self.numberofMzsText.place(relx=0.1,rely=0.4)
numberoutliemMzs="Modified Z-Score "+str(len(self.mzs_outlier_list))
self.numberofMzsText.insert(0.0,numberoutliemMzs)
self.numberofabplotText=Text(mGui,height=1,width=60,wrap=None)
self.numberofabplotText.place(relx=0.1,rely=0.45)
numberoutliemabplot="Adjusted Box Plot "+str(len(self.abplot_outlier_list))
self.numberofabplotText.insert(0.0,numberoutliemabplot)
self.numberofcommonText=Text(mGui,height=1,width=60,wrap=None)
self.numberofcommonText.place(relx=0.1,rely=0.5)
numberoutliemcommon="Common (GESD & M. Z-score) "+str(len(self.common))
self.numberofcommonText.insert(0.0,numberoutliemcommon)
self.numberofGesdText=Text(mGui,height=1,width=60,wrap=None)
self.numberofGesdText.place(relx=0.1,rely=0.55)
numberoutliemGesd="Generalized ESD "+str(len(self.gesd_outlier_list))
self.numberofGesdText.insert(0.0,numberoutliemGesd)
#Creating buttons for next steps#
self.CreateButtonandLabel()
self.venndiagramButton=Button(mGui,text='Venn Diagram',command=self.Venn_Diagram)
self.venndiagramButton.place(relx=0.1,rely=0.8)
return
#Median Rule, Adjusted box plot and Modified Z-Score Algorithms #
if self.medianRule.get() and self.mzscore.get() and self.abplot.get():
self.abplot_outlier_list=[]