-
Notifications
You must be signed in to change notification settings - Fork 30
/
AltAnalyzeViewer.py
2312 lines (2091 loc) · 276 KB
/
AltAnalyzeViewer.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
import os.path, sys, shutil
import os
import string, re
import subprocess
import numpy as np
import unique
import traceback
import wx
import wx.lib.scrolledpanel
import wx.grid as gridlib
try:
import warnings
with warnings.catch_warnings():
warnings.filterwarnings("ignore",category=UserWarning) ### hides import warnings
import matplotlib
#try: matplotlib.use('TkAgg')
#except Exception: pass
#import matplotlib.pyplot as plt ### Backend conflict issue when called prior to the actual Wx window appearing
#matplotlib.use('WXAgg')
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure
from numpy import arange, sin, pi
except Exception: pass
if os.name == 'nt': bheight=20
else: bheight=10
rootDirectory = unique.filepath(str(os.getcwd()))
currentDirectory = unique.filepath(str(os.getcwd())) + "/" + "Config/" ### NS-91615 alternative to __file__
currentDirectory = string.replace(currentDirectory,'AltAnalyzeViewer.app/Contents/Resources','')
os.chdir(currentDirectory)
parentDirectory = str(os.getcwd()) ### NS-91615 gives the parent AltAnalyze directory
sys.path.insert(1,parentDirectory) ### NS-91615 adds the AltAnalyze modules to the system path to from visualization_scripts import clustering and others
import UI
#These classes set up the "tab" feature in the program, allowing you to switch the viewer to different modes.
class PageTwo(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.SetBackgroundColour("white")
myGrid = ""
class PageThree(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.SetBackgroundColour("white")
class PageFour(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
class PageFive(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
class Main(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self, parent, id,'AltAnalyze Results Viewer', size=(900,610))
self.Show()
self.Maximize(True) #### This allows the frame to resize to the host machine's max size
self.heatmap_translation = {}
self.heatmap_run = {}
self.species = 'Hs'
self.platform = 'RNASeq'
self.geneset_type = 'WikiPathways'
self.supported_genesets = []
self.runPCA = False
self.SetBackgroundColour((230, 230, 230))
self.species=''
#PANELS & WIDGETS
#self.panel is one of the TOP PANELS. These are used for title display, the open project button, and sort & filter buttons.
self.panel = wx.Panel(self, id=2, pos=(200,0), size=(600,45), style=wx.RAISED_BORDER)
self.panel.SetBackgroundColour((110, 150, 250))
#Panel 2 is the main view panel.
self.panel2 = wx.Panel(self, id=3, pos=(200,50), size=(1400,605), style=wx.RAISED_BORDER)
self.panel2.SetBackgroundColour((218, 218, 218))
#Panel 3 contains the pseudo-directory tree.
self.panel3 = wx.Panel(self, id=4, pos=(0,50), size=(200,625), style=wx.RAISED_BORDER)
self.panel3.SetBackgroundColour("white")
self.panel4 = wx.Panel(self, id=5, pos=(200,650), size=(1400,150), style=wx.RAISED_BORDER)
self.panel4.SetBackgroundColour("black")
#These are the other top panels.
self.panel_left = wx.Panel(self, id=12, pos=(0,0), size=(200,45), style=wx.RAISED_BORDER)
self.panel_left.SetBackgroundColour((218, 218, 218))
self.panel_right = wx.Panel(self, id=11, pos=(1100,0), size=(200,45), style=wx.RAISED_BORDER)
self.panel_right.SetBackgroundColour((218, 218, 218))
self.panel_right2 = wx.Panel(self, id=13, pos=(1300,0), size=(300,45), style=wx.RAISED_BORDER)
self.panel_right2.SetBackgroundColour((218, 218, 218))
self.panel_right2.SetMaxSize([300, 45])
#Lines 81-93 set up the user input box for the "sort" function (used on the table).
self.sortbox = wx.TextCtrl(self.panel_right2, id=7, pos=(55,10), size=(40,25))
wx.Button(self.panel_right2, id=8, label="Sort", pos=(5, 12), size=(40, bheight))
self.Bind(wx.EVT_BUTTON, self.SortTablefromButton, id=8)
self.AscendingRadio = wx.RadioButton(self.panel_right2, id=17, label="Sort", pos=(100, 3), size=(12, 12))
self.DescendingRadio = wx.RadioButton(self.panel_right2, id=18, label="Sort", pos=(100, 23), size=(12, 12))
font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
self.AscendingOpt = wx.StaticText(self.panel_right2, label="Ascending", pos=(115, 1))
self.AscendingOpt.SetFont(font)
self.DescendingOpt = wx.StaticText(self.panel_right2, label="Descending", pos=(115, 21))
self.DescendingOpt.SetFont(font)
#Lines 96-98 set up the user input box for the "filter" function (used on the table).
self.filterbox = wx.TextCtrl(self.panel_right, id=9, pos=(60,10), size=(125,25))
wx.Button(self.panel_right, id=10, label="Filter", pos=(0, 12), size=(50, bheight))
self.Bind(wx.EVT_BUTTON, self.FilterTablefromButton, id=10)
#Lines 101-103 set up the in-program log.
self.control = wx.TextCtrl(self.panel4, id=6, pos=(1,1), size=(1400,150), style=wx.TE_MULTILINE)
self.control.write("Welcome to AltAnalyze Results Viewer!" + "\n")
self.Show(True)
self.main_results_directory = ""
#self.browser is the "directory tree" where groups of files are instantiated in self.browser2.
self.browser = wx.TreeCtrl(self.panel3, id=2000, pos=(0,0), size=(200,325))
#self.browser2 is the "file group" where groups of files are accessed, respective to the directory selected in self.browser.
self.browser2 = wx.TreeCtrl(self.panel3, id=2001, pos=(0,325), size=(200,325))
self.tree = self.browser
#self.sortdict groups the table headers to integers---this works with sort function.
self.sortdict = {"A" : 0, "B" : 1, "C" : 2, "D" : 3, "E" : 4, "F" : 5, "G" : 6, "H" : 7, "I" : 8, "J" : 9, "K" : 10, "L" : 11, "M" : 12, "N" : 13, "O" : 14, "P" : 15, "Q" : 16, "R" : 17, "S" : 18, "T" : 19, "U" : 20, "V" : 21, "W" : 22, "X" : 23, "Y" : 24, "Z" : 25, "AA" : 26, "AB" : 27, "AC" : 28, "AD" : 29, "AE" : 30, "AF" : 31, "AG" : 32, "AH" : 33, "AI" : 34, "AJ" : 35, "AK" : 36, "AL" : 37, "AM" : 38, "AN" : 39, "AO" : 40, "AP" : 41, "AQ" : 42, "AR" : 43, "AS" : 44, "AT" : 45, "AU" : 46, "AV" : 47, "AW" : 48, "AX" : 49, "AY" : 50, "AZ" : 51}
#SIZER--main sizer for the program.
ver = wx.BoxSizer(wx.VERTICAL)
verpan2 = wx.BoxSizer(wx.VERTICAL)
hpan1 = wx.BoxSizer(wx.HORIZONTAL)
hpan2 = wx.BoxSizer(wx.HORIZONTAL)
hpan3 = wx.BoxSizer(wx.HORIZONTAL)
verpan2.Add(self.panel2, 8, wx.ALL|wx.EXPAND, 2)
hpan1.Add(self.panel_left, 5, wx.ALL|wx.EXPAND, 2)
hpan1.Add(self.panel, 24, wx.ALL|wx.EXPAND, 2)
hpan1.Add(self.panel_right, 3, wx.ALL|wx.EXPAND, 2)
hpan1.Add(self.panel_right2, 3, wx.ALL|wx.EXPAND, 2)
hpan2.Add(self.panel3, 1, wx.ALL|wx.EXPAND, 2)
hpan2.Add(verpan2, 7, wx.ALL|wx.EXPAND, 2)
hpan3.Add(self.panel4, 1, wx.ALL|wx.EXPAND, 2)
ver.Add(hpan1, 1, wx.EXPAND)
ver.Add(hpan2, 18, wx.EXPAND)
ver.Add(hpan3, 4, wx.EXPAND)
self.browser.SetSize(self.panel3.GetSize())
self.SetSizer(ver)
#TABS: lines 137-159 instantiate the tabs for the main viewing panel.
self.nb = wx.Notebook(self.panel2, id=7829, style = wx.NB_BOTTOM)
self.page1 = wx.ScrolledWindow(self.nb, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL|wx.VSCROLL )
self.page1.SetScrollRate( 5, 5 )
self.page2 = PageTwo(self.nb)
self.page3 = PageThree(self.nb)
self.page4 = PageFour(self.nb)
self.nb.AddPage(self.page2, "Table")
self.nb.AddPage(self.page1, "PNG")
self.nb.AddPage(self.page3, "Interactive")
self.page3.SetBackgroundColour((218, 218, 218))
sizer = wx.BoxSizer()
sizer.Add(self.nb, 1, wx.EXPAND)
self.panel2.SetSizer(sizer)
self.page1.SetBackgroundColour("white")
self.myGrid = gridlib.Grid(self.page2, id=1002)
#self.myGrid.CreateGrid(100, self.dataset_file_length) ### Sets this at 400 columns rather than 100 - Excel like
self.Bind(gridlib.EVT_GRID_CELL_RIGHT_CLICK, self.GridRightClick, id=1002)
self.Bind(gridlib.EVT_GRID_CELL_LEFT_DCLICK, self.GridRowColor, id=1002)
self.HighlightedCells = []
gridsizer = wx.BoxSizer(wx.VERTICAL)
gridsizer.Add(self.myGrid)
self.page2.SetSizer(gridsizer)
self.page2.Layout()
#In the event that the interactive tab is chosen, a function must immediately run.
self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.InteractiveTabChoose, id=7829)
#INTERACTIVE PANEL LAYOUT: lines 167-212
#Pca Setup
self.RunButton1 = wx.Button(self.page3, id=43, label="Run", pos=(275, 150), size=(120, bheight))
self.Bind(wx.EVT_BUTTON, self.InteractiveRun, id=43)
self.Divider1 = self.ln = wx.StaticLine(self.page3, pos=(5,100))
self.ln.SetSize((415,10))
IntTitleFont = wx.Font(15, wx.SWISS, wx.NORMAL, wx.BOLD)
self.InteractiveTitle = wx.StaticText(self.page3, label="Main Dataset Parameters", pos=(10, 15))
self.InteractiveDefaultMessage = wx.StaticText(self.page3, label="No interactive options available.", pos=(10, 45))
self.InteractiveTitle.SetFont(IntTitleFont)
self.IntFileTxt = wx.TextCtrl(self.page3, id=43, pos=(105,45), size=(375,20))
self.InteractiveFileLabel = wx.StaticText(self.page3, label="Selected File:", pos=(10, 45))
self.Yes1Label = wx.StaticText(self.page3, label="Yes", pos=(305, 80))
self.No1Label = wx.StaticText(self.page3, label="No", pos=(375, 80))
self.D_3DLabel = wx.StaticText(self.page3, label="3D", pos=(305, 120))
self.D_2DLabel = wx.StaticText(self.page3, label="2D", pos=(375, 120))
self.IncludeLabelsRadio = wx.RadioButton(self.page3, id=40, pos=(285, 83), size=(12, 12), style=wx.RB_GROUP)
self.No1Radio = wx.RadioButton(self.page3, id=41, pos=(355, 83), size=(12, 12))
self.IncludeLabelsRadio.SetValue(True)
#self.EnterPCAGenes = wx.TextCtrl(self.page3, id=48, pos=(105,45), size=(375,20))
self.D_3DRadio = wx.RadioButton(self.page3, id=46, pos=(285, 123), size=(12, 12), style=wx.RB_GROUP)
self.D_2DRadio = wx.RadioButton(self.page3, id=47, pos=(355, 123), size=(12, 12))
self.D_3DRadio.SetValue(True)
self.Opt1Desc = wx.StaticText(self.page3, label="Display sample labels next to each object", pos=(10, 80))
self.Opt2Desc = wx.StaticText(self.page3, label="Dimensions to display", pos=(10, 120))
self.IntFileTxt.Hide()
self.InteractiveFileLabel.Hide()
self.Yes1Label.Hide()
self.No1Label.Hide()
self.D_3DLabel.Hide()
self.D_2DLabel.Hide()
self.IncludeLabelsRadio.Hide()
self.No1Radio.Hide()
self.D_3DRadio.Hide()
self.D_2DRadio.Hide()
self.Opt1Desc.Hide()
self.Opt2Desc.Hide()
self.RunButton1.Hide()
self.Divider1.Hide()
#TERMINAL SETUP
TxtBox = wx.BoxSizer(wx.VERTICAL)
TxtBox.Add(self.control, 1, wx.EXPAND)
self.panel4.SetSizer(TxtBox)
self.panel4.Layout()
#SELECTION LIST
self.TopSelectList = []
self.SearchArray = []
self.SearchArrayFiltered = []
self.TopID = ""
self.ColoredCellList = []
#LOGO
self.png = wx.Image("logo.gif", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.LOGO = wx.StaticBitmap(self.page1, -1, self.png, (0,0), (self.png.GetWidth(), self.png.GetHeight()), style=wx.ALIGN_CENTER)
imgsizer_v = wx.BoxSizer(wx.VERTICAL)
imgsizer_v.Add(self.LOGO, proportion=0, flag=wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL)
self.page1.SetSizer(imgsizer_v)
self.page1.Layout()
self.nb.SetSelection(1)
browspan = wx.BoxSizer(wx.VERTICAL)
browspan.Add(self.browser, 1, wx.EXPAND)
browspan.Add(self.browser2, 1, wx.EXPAND)
self.panel3.SetSizer(browspan)
self.PanelTitle = wx.StaticText(self.panel, label="", pos=(210, 15))
#Open Button
ButtonMan = wx.Button(self.panel_left, id=1001, label="Open Project", pos=(0,0), size=(100,100))
self.Bind(wx.EVT_BUTTON, self.OnOpen, id=1001)
OpenSizer = wx.BoxSizer(wx.HORIZONTAL)
OpenSizer.Add(ButtonMan, 1, wx.EXPAND)
self.panel_left.SetSizer(OpenSizer)
#STATUS BAR CREATE --- not all of these are currently functional. The "edit" menu still needs to be implemented.
status = self.CreateStatusBar()
menubar = wx.MenuBar()
file = wx.Menu()
edit = wx.Menu()
view = wx.Menu()
search = wx.Menu()
filter_table = wx.Menu()
help_menu = wx.Menu()
open_menu = wx.Menu()
open_menu.Append(120, 'Project')
open_menu.Append(121, 'File')
file.AppendMenu(101, '&Open\tCtrl+O', open_menu)
file.Append(102, '&Save\tCtrl+S', 'Save the document')
file.AppendSeparator()
file.Append(103, 'Options', '')
file.AppendSeparator()
quit = wx.MenuItem(file, 105, '&Quit\tCtrl+Q', 'Quit the Application')
file.AppendItem(quit)
edit.Append(109, 'Undo', '')
edit.Append(110, 'Redo', '')
edit.AppendSeparator()
edit.Append(106, '&Cut\tCtrl+X', '')
edit.Append(107, '&Copy\tCtrl+C', '')
edit.Append(108, '&Paste\tCtrl+V', '')
edit.AppendSeparator()
edit.Append(111, '&Select All\tCtrl+A', '')
view.Append(112, '&Clear Panel\tCtrl+.', '')
search.Append(113, 'Tree', '')
search.Append(114, 'Table', '')
filter_table.Append(116, 'Filter', '')
filter_table.Append(117, 'Sort', '')
help_menu.AppendSeparator()
help_menu.Append(139, 'Help', '')
help_menu.Append(140, 'About', '')
menubar.Append(file, "File")
menubar.Append(edit, "Edit")
menubar.Append(view, "View")
menubar.Append(search, "Search")
menubar.Append(filter_table, "Table")
menubar.Append(help_menu, "Help")
self.SetMenuBar(menubar)
#STATUS BAR BINDINGS
self.Bind(wx.EVT_MENU, self.OnOpen, id=120)
self.Bind(wx.EVT_MENU, self.OnOpenSingleFile, id=121)
self.Bind(wx.EVT_MENU, self.OnQuit, id=105)
self.Bind(wx.EVT_MENU, self.ClearVisualPanel, id=112)
self.Bind(wx.EVT_MENU, self.TreeSearch, id=113)
self.Bind(wx.EVT_MENU, self.GridSearch, id=114)
self.Bind(wx.EVT_MENU, self.FilterTable, id=116)
self.Bind(wx.EVT_MENU, self.SortTable, id=117)
self.Bind(wx.EVT_MENU, self.OnAbout, id=140)
self.Bind(wx.EVT_MENU, self.OnHelp, id=139)
self.Layout()
def OnQuit(self, event):
popup = wx.MessageDialog(None, "Are you sure you want to quit?", "Warning", wx.YES_NO)
popup_answer = popup.ShowModal()
#print popup_answer
if(popup_answer == 5103):
self.Close()
else:
return
def GridRowColor(self, event):
#This colors any row that has been selected and resets it accordingly: may be removed in future versions.
if len(self.HighlightedCells) > 0:
for i in self.HighlightedCells:
self.myGrid.SetCellBackgroundColour(i[0], i[1], (255, 255, 255))
self.HighlightedCells = []
self.GridRowEvent = event.GetRow()
for i in range(50):
self.myGrid.SetCellBackgroundColour(self.GridRowEvent, i, (235, 255, 255))
self.HighlightedCells.append((self.GridRowEvent, i))
def GridRightClick(self, event):
#Pop-up menu instantiation for a right click on the table.
self.GridRowEvent = event.GetRow()
# only do this part the first time so the events are only bound once
if not hasattr(self, "popupID3"):
self.popupID1 = wx.NewId()
self.popupID2 = wx.NewId()
if self.analyzeSplicing:
self.popupID3 = wx.NewId()
self.popupID4 = wx.NewId()
self.popupID5 = wx.NewId()
self.Bind(wx.EVT_MENU, self.GeneExpressionSummaryPlot, id=self.popupID1)
self.Bind(wx.EVT_MENU, self.PrintGraphVariables, id=self.popupID2)
if self.analyzeSplicing:
self.Bind(wx.EVT_MENU, self.AltExonViewInitiate, id=self.popupID3)
self.Bind(wx.EVT_MENU, self.IsoformViewInitiate, id=self.popupID4)
self.Bind(wx.EVT_MENU, self.SashimiPlotInitiate, id=self.popupID5)
# build the menu
menu = wx.Menu()
itemOne = menu.Append(self.popupID1, "Gene Plot")
#itemTwo = menu.Append(self.popupID2, "Print Variables")
if self.analyzeSplicing:
itemThree = menu.Append(self.popupID3, "Exon Plot")
itemFour = menu.Append(self.popupID4, "Isoform Plot")
itemFive = menu.Append(self.popupID5, "SashimiPlot")
# show the popup menu
self.PopupMenu(menu)
menu.Destroy()
def AltExonViewInitiate(self, event):
### Temporary option for exon visualization until the main tool is complete and database can be bundled with the program
i=0; values=[]
while i<1000:
try:
val = str(self.myGrid.GetCellValue(self.GridRowEvent, i))
values.append(val)
if ('G000' in val) and '->' not in val:
geneID_temp = string.split(val,":")[0]
if ('G000' in geneID_temp) and '->' not in geneID_temp:
geneID = geneID_temp
if ' ' in geneID:
geneID = string.split(geneID,' ')[0]
else:
geneID_temp = string.split(val,":")[1]
if ('G000' in geneID_temp):
geneID = geneID_temp
if ' ' in geneID:
geneID = string.split(geneID,' ')[0]
i+=1
except Exception: break
datasetDir = self.main_results_directory
#print datasetDir
self.control.write("Plotting... " + geneID + "\n")
data_type = 'raw expression'
show_introns = 'no'
analysisType = 'graph-plot'
exp_dir = unique.filepath(datasetDir+'/ExpressionInput')
#print exp_dir
exp_file = UI.getValidExpFile(exp_dir)
#print print exp_file
UI.altExonViewer(self.species,self.platform,exp_file,geneID,show_introns,analysisType,'')
def IsoformViewInitiate(self, event):
#print os.getcwd()
#This function is a part of the pop-up menu for the table: it plots a gene and protein level view.
os.chdir(parentDirectory)
t = os.getcwd()
#self.control.write(str(os.listdir(t)) + "\n")
gene = self.myGrid.GetCellValue(self.GridRowEvent, 0)
i=0; values=[]; spliced_junctions=[]
while i<1000:
try:
val = str(self.myGrid.GetCellValue(self.GridRowEvent, i))
values.append(val)
if ('G000' in val) and 'ENSP' not in val and 'ENST' not in val and '->' not in val:
geneID_temp = string.split(val,":")[0]
if ('G000' in geneID_temp) and '->' not in geneID_temp:
geneID = geneID_temp
if ' ' in geneID:
geneID = string.split(geneID,' ')[0]
elif '->' in geneID_temp: pass
else:
geneID_temp = string.split(val,":")[1]
if ('G000' in geneID_temp):
geneID = geneID_temp
if ' ' in geneID:
geneID = string.split(geneID,' ')[0]
i+=1
except Exception: break
#print [geneID]
self.control.write("Plotting... " + geneID + "\n")
from visualization_scripts import ExPlot
reload(ExPlot)
ExPlot.remoteGene(geneID,self.species,self.main_results_directory,self.CurrentFile)
#Q = subprocess.Popen(['python', 'ExPlot13.py', str(R)])
#os.chdir(currentDirectory)
def SashimiPlotInitiate(self, event):
#This function is a part of the pop-up menu for the table: it plots a SashimiPlot
datasetDir = str(self.main_results_directory)
geneID = None
#self.control.write(str(os.listdir(t)) + "\n")
i=0; values=[]; spliced_junctions=[]
while i<1000:
try:
val = str(self.myGrid.GetCellValue(self.GridRowEvent, i))
values.append(val)
if ('G000' in val) and ':E' in val:
#if 'ASPIRE' in self.DirFileTxt:
if ':ENS' in val:
val = 'ENS'+string.split(val,':ENS')[1]
val = string.replace(val,'|', ' ')
#Can also refer to MarkerFinder files
if ' ' in val:
if '.' not in string.split(val,' ')[1]:
val = string.split(val,' ')[0] ### get the gene
if 'Combined-junction' in self.DirFileTxt:
if '-' in val and '|' in val:
junctions = string.split(val,'|')[0]
val = 'ENS'+string.split(junctions,'-ENS')[-1]
spliced_junctions.append(val) ### exclusion junction
if 'index' in self.DirFileTxt: ### Splicing-index analysis
spliced_junctions.append(val)
elif '-' in val:
spliced_junctions.append(val) ### junction-level
if ('G000' in val) and geneID == None and '->' not in val:
geneID = string.split(val,":")[0]
if ' ' in geneID:
geneID = string.split(geneID,' ')[0]
i+=1
except Exception: break
if len(spliced_junctions)>0:
spliced_junctions = [spliced_junctions[-1]] ### Select the exclusion junction
else:
spliced_junctions = [geneID]
if 'DATASET' in self.DirFileTxt:
spliced_junctions = [geneID]
from visualization_scripts import SashimiPlot
reload(SashimiPlot)
self.control.write("Attempting to build SashimiPlots for " + str(spliced_junctions[0]) + "\n")
SashimiPlot.remoteSashimiPlot(self.species,datasetDir,datasetDir,None,events=spliced_junctions,show=True) ### assuming the bam files are in the root-dir
def GeneExpressionSummaryPlot(self, event):
#This function is a part of the pop-up menu for the table: it plots expression levels.
Wikipathway_Flag = 0
Protein_Flag = 0
VarGridSet = []
try:
for i in range(3000):
try:
p = self.myGrid.GetCellValue(0, i)
VarGridSet.append(p)
except Exception:
pass
for i in VarGridSet:
y = re.findall("WikiPathways", i)
if len(y) > 0:
Wikipathway_Flag = 1
break
if Wikipathway_Flag == 0:
for i in VarGridSet:
y = re.findall("Select Protein Classes", i)
if len(y) > 0:
Protein_Flag = 1
break
if Protein_Flag == 1:
VariableBox = []
for i in range(len(VarGridSet)):
y = re.findall("avg", VarGridSet[i])
if(len(y) > 0):
VariableBox.append(i)
if Wikipathway_Flag == 1:
VariableBox = []
for i in range(len(VarGridSet)):
y = re.findall("avg", VarGridSet[i])
if(len(y) > 0):
VariableBox.append(i)
q_barrel = []
for i in VariableBox:
q_box = []
q = i
for p in range(500):
if(q < 0):
break
q = q - 1
#Regular expression is needed to find the appropriate columns to match from.
FLAG_log_fold = re.findall("log_fold",VarGridSet[q])
FLAG_adjp = re.findall("adjp",VarGridSet[q])
FLAG_rawp = re.findall("rawp",VarGridSet[q])
FLAG_wiki = re.findall("Wiki",VarGridSet[q])
FLAG_pc = re.findall("Protein Classes",VarGridSet[q])
FLAG_avg = re.findall("avg",VarGridSet[q])
if(len(FLAG_log_fold) > 0 or len(FLAG_adjp) > 0 or len(FLAG_rawp) > 0 or len(FLAG_wiki) > 0 or len(FLAG_pc) > 0 or len(FLAG_avg) > 0):
break
q_box.append(q)
q_barrel.append((q_box))
Values_List = []
HeaderList = []
TitleList = self.myGrid.GetCellValue(self.GridRowEvent, 0)
for i in VariableBox:
HeaderList.append(self.myGrid.GetCellValue(0, i))
for box in q_barrel:
output_box = []
for value in box:
output_var = self.myGrid.GetCellValue(self.GridRowEvent, value)
output_box.append(float(output_var))
Values_List.append((output_box))
self.control.write("Plotting values from: " + str(self.myGrid.GetCellValue(self.GridRowEvent, 0)) + "\n")
Output_Values_List = []
Output_std_err = []
for box in Values_List:
T = 0
for item in box:
T = T + item
output_item = T / float(len(box))
Output_Values_List.append(output_item)
for box in Values_List:
box_std = np.std(box)
box_power = np.power((len(box)), 0.5)
std_err = box_std / float(box_power)
Output_std_err.append(std_err)
n_groups = len(Output_Values_List)
#PLOTTING STARTS --
means_men = Output_Values_List
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = 0.35
pos = bar_width / float(2)
opacity = 0.4
error_config = {'ecolor': '0.3'}
with warnings.catch_warnings():
rects1 = plt.bar((index + pos), Output_Values_List, bar_width,
alpha=opacity,
color='b',
yerr=Output_std_err,
label="")
#plt.title(self.myGrid.GetCellValue(self.GridRowEvent, 2))
plt.title(TitleList)
plt.xticks(index + bar_width, HeaderList)
plt.legend()
plt.tight_layout()
plt.show()
#-- PLOTTING STOPS
except Exception:
self.control.write("Plot failed to output... only applicalbe for the file with prefix DATASET")
def PrintGraphVariables(self, event):
#This function is a part of the pop-up menu for the table: it prints the variables for the expression levels. Used for testing mainly.
Wikipathway_Flag = 0
Protein_Flag = 0
VarGridSet = []
for i in range(100):
p = self.myGrid.GetCellValue(0, i)
VarGridSet.append(p)
for i in VarGridSet:
y = re.findall("WikiPathways", i)
if len(y) > 0:
Wikipathway_Flag = 1
break
if Wikipathway_Flag == 0:
for i in VarGridSet:
y = re.findall("Select Protein Classes", i)
if len(y) > 0:
Protein_Flag = 1
break
if Protein_Flag == 1:
VariableBox = []
for i in range(len(VarGridSet)):
y = re.findall("avg", VarGridSet[i])
if(len(y) > 0):
VariableBox.append(i)
if Wikipathway_Flag == 1:
VariableBox = []
for i in range(len(VarGridSet)):
y = re.findall("avg", VarGridSet[i])
if(len(y) > 0):
VariableBox.append(i)
q_barrel = []
for i in VariableBox:
q_box = []
q = i
for p in range(500):
if(q < 0):
break
q = q - 1
FLAG_log_fold = re.findall("log_fold",VarGridSet[q])
FLAG_adjp = re.findall("adjp",VarGridSet[q])
FLAG_rawp = re.findall("rawp",VarGridSet[q])
FLAG_wiki = re.findall("Wiki",VarGridSet[q])
FLAG_pc = re.findall("Protein Classes",VarGridSet[q])
FLAG_avg = re.findall("avg",VarGridSet[q])
if(len(FLAG_log_fold) > 0 or len(FLAG_adjp) > 0 or len(FLAG_rawp) > 0 or len(FLAG_wiki) > 0 or len(FLAG_pc) > 0 or len(FLAG_avg) > 0):
break
q_box.append(q)
q_barrel.append((q_box))
self.control.write("Selected Row: " + str(self.myGrid.GetCellValue(self.GridRowEvent, 0)) + "\n")
self.control.write("Selected Columns: " + str(q_barrel) + "\n")
Values_List = []
HeaderList = []
for i in VariableBox:
HeaderList.append(self.myGrid.GetCellValue(0, i))
for box in q_barrel:
output_box = []
for value in box:
output_var = self.myGrid.GetCellValue(self.GridRowEvent, value)
output_box.append(float(output_var))
Values_List.append((output_box))
self.control.write("Selected Values: " + str(Values_List) + "\n")
def InteractiveTabChoose(self, event):
#If the interactive tab is chosen, a plot will immediately appear with the default variables.
try:
#The PCA and Heatmap flags are set; a different UI will appear for each of them.
PCA_RegEx = re.findall("PCA", self.DirFile)
Heatmap_RegEx = re.findall("hierarchical", self.DirFile)
if(self.nb.GetSelection() == 2):
if(len(PCA_RegEx) > 0 or len(Heatmap_RegEx) > 0):
self.InteractiveRun(event)
except:
pass
def getDatasetVariables(self):
for file in os.listdir(self.main_results_directory):
if 'AltAnalyze_report' in file and '.log' in file:
log_file = unique.filepath(self.main_results_directory+'/'+file)
log_contents = open(log_file, "rU")
species = ' species: '
platform = ' method: '
for line in log_contents:
line = line.rstrip()
if species in line:
self.species = string.split(line,species)[1]
if platform in line:
self.platform = string.split(line,platform)[1]
try:
self.supported_genesets = UI.listAllGeneSetCategories(self.species,'WikiPathways','gene-mapp')
self.geneset_type = 'WikiPathways'
except Exception:
try:
self.supported_genesets = UI.listAllGeneSetCategories(self.species,'GeneOntology','gene-mapp')
self.geneset_type = 'GeneOntology'
except Exception:
self.supported_genesets = []
self.geneset_type = 'None Selected'
#print 'Using',self.geneset_type, len(self.supported_genesets),'pathways'
break
try:
for file in os.listdir(self.main_results_directory+'/ExpressionOutput'):
if 'DATASET' in file:
dataset_file = unique.filepath(self.main_results_directory+'/ExpressionOutput/'+file)
for line in open(dataset_file,'rU').xreadlines():
self.dataset_file_length = len(string.split(line,'\t'))
break
except Exception:
pass
try:
if self.dataset_file_length<50:
self.dataset_file_length=50
except Exception:
self.dataset_file_length=50
self.myGrid.CreateGrid(100, self.dataset_file_length) ### Re-set the grid width based on the DATASET- file width
def OnOpen(self, event):
#Bound to the open tab from the menu and the "Open Project" button.
openFileDialog = wx.DirDialog(None, "Choose project", "", wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return
#self.input stream is the path of our project's main directory.
self.main_results_directory = openFileDialog.GetPath()
if (len(self.main_results_directory) > 0):
if self.species == '':
self.getDatasetVariables()
self.SearchArray = []
self.SearchArrayFiltered = []
self.control.write("Working..." + "\n")
#FLAG COLLECT
root = 'Data'
for (dirpath, dirnames, filenames) in os.walk(root):
for dirname in dirnames:
#fullpath = os.path.join(dirpath, dirname)
fullpath = currentDirectory+'/'+dirpath+'/'+dirname
for filename in sorted(filenames):
if filename == "location.txt":
#file_fullpath = unique.filepath(os.path.join(dirpath, filename))
file_fullpath = currentDirectory+'/'+dirpath+'/'+filename
file_location = open(file_fullpath, "r")
fl_array = []
for line in file_location:
line = line.rstrip(); line = string.replace(line,'"','')
line = line.split("\r")
if len(line) > 1:
fl_array.append(line[0])
fl_array.append(line[1])
else:
fl_array.append(line[0])
file_location.close()
#if dirname == 'ExonGraph': print fl_array
if(len(fl_array) == 3):
fl_array.append(dirpath)
self.SearchArray.append(fl_array)
self.control.write("Opening project at: " + self.main_results_directory + "\n")
self.browser2.DeleteAllItems()
#SEARCH USING FLAGS
count = 0
for FLAG in self.SearchArray:
if((FLAG[0][-1] != "/") and (FLAG[0][-1] != "\\")):
SearchingFlag = FLAG[0] + "/"
SearchingFlag = FLAG[0]
SearchingFlagPath = self.main_results_directory + "/" + SearchingFlag
try:
SFP_Contents = os.listdir(SearchingFlagPath)
for filename in SFP_Contents:
Search_base = FLAG[1]
Search_base = Search_base.split(":")
Search_base = Search_base[1]
Split_Extension = str(FLAG[2])
Split_Extension = Split_Extension.split(":")
S_E = str(Split_Extension[1]).split(",")
GOOD_FLAG = 0
if(Search_base != "*"):
for i in S_E:
if(filename[-4:] == i):
GOOD_FLAG = 1
if(Search_base != "*"):
candidate = re.findall(Search_base, filename)
if(Search_base == "*"):
candidate = "True"
GOOD_FLAG = 1
if (len(Search_base) == 0 or GOOD_FLAG == 0):
continue
if len(candidate) > 0:
self.SearchArrayFiltered.append(FLAG)
except:
continue
count = count + 1
#AVAILABLE DATA SET
try:
shutil.rmtree("AvailableData")
except:
pass
for i in self.SearchArrayFiltered:
AvailablePath = "Available" + i[3]
if '\\' in AvailablePath: ### Windows
AvailablePath = string.replace(AvailablePath,'/','\\')
if '/' in AvailablePath:
Path_List = AvailablePath.split("/")
else:
Path_List = AvailablePath.split("\\")
Created_Directory = ""
for directorynum in range(len(Path_List)):
if directorynum == 0:
Created_Directory = Created_Directory + Path_List[directorynum]
try:
os.mkdir(Created_Directory)
except:
continue
else:
Created_Directory = Created_Directory + "/" + Path_List[directorynum]
try:
os.mkdir(Created_Directory)
except:
continue
#TOP BROWSER SET
root = 'AvailableData'
color_root = [253, 253, 253]
self.tree.DeleteAllItems()
self.ids = {root : self.tree.AddRoot(root)}
self.analyzeSplicing=False
for (dirpath, dirnames, filenames) in os.walk(root):
#print 'x',[dirpath, dirnames, filenames]#;sys.exit()
for dirname in dirnames:
#print dirpath, dirname
if 'Splicing' in dirpath: self.analyzeSplicing=True
fullpath = os.path.join(dirpath, dirname)
#print currentDirectory+'/'+dirpath
self.ids[fullpath] = self.tree.AppendItem(self.ids[dirpath], dirname)
DisplayColor = [255, 255, 255]
DisplayColor[0] = color_root[0] - len(dirpath)
DisplayColor[1] = color_root[1] - len(dirpath)
DisplayColor[2] = color_root[2] - len(dirpath)
self.tree.SetItemBackgroundColour(self.ids[fullpath], DisplayColor)
for i in self.SearchArrayFiltered:
SearchRoot = "Available" + i[3]
if(SearchRoot == fullpath):
SearchSplit = i[1].split(":")
SearchSplit = SearchSplit[1]
SearchSplit = SearchSplit + ";" + i[0]
SearchSplit = SearchSplit + ";" + i[2]
DisplayColor = [130, 170, 250]
self.tree.SetItemData(self.ids[fullpath],SearchSplit)
self.tree.SetItemBackgroundColour(self.ids[fullpath], DisplayColor)
self.tree.SetItemBackgroundColour(self.ids[root], [100, 140, 240])
self.tree.Expand(self.ids[root])
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.SelectedTopTreeID, self.tree)
#OPENING DISPLAY
try:
self.LOGO.Destroy()
except:
pass
self.png = wx.Image(rootDirectory+"/Config/no-image-available.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.LOGO = wx.StaticBitmap(self.page1, -1, self.png, (0,0), (self.png.GetWidth(), self.png.GetHeight()), style=wx.ALIGN_CENTER)
imgsizer_v = wx.BoxSizer(wx.VERTICAL)
imgsizer_v.Add(self.LOGO, proportion=0, flag=wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL)
self.page1.SetSizer(imgsizer_v)
self.page1.Layout()
self.control.write("Resetting grid..." + "\n")
self.control.write("Currently displaying: " + "SUMMARY" + "\n")
self.myGrid.ClearGrid()
if 'ExpressionInput' in self.main_results_directory:
self.main_results_directory = string.split(self.main_results_directory,'ExpressionInput')[0]
if 'AltResults' in self.main_results_directory:
self.main_results_directory = string.split(self.main_results_directory,'AltResults')[0]
if 'ExpressionOutput' in self.main_results_directory:
self.main_results_directory = string.split(self.main_results_directory,'ExpressionOutput')[0]
if 'GO-Elite' in self.main_results_directory:
self.main_results_directory = string.split(self.main_results_directory,'GO-Elite')[0]
if 'ICGS' in self.main_results_directory:
self.main_results_directory = string.split(self.main_results_directory,'ICGS')[0]
if 'DataPlots' in self.main_results_directory:
self.main_results_directory = string.split(self.main_results_directory,'DataPlots')[0]
if 'AltExpression' in self.main_results_directory:
self.main_results_directory = string.split(self.main_results_directory,'AltExpression')[0]
if 'AltDatabase' in self.main_results_directory:
self.main_results_directory = string.split(self.main_results_directory,'AltDatabase')[0]
if 'ExonPlots' in self.main_results_directory:
self.main_results_directory = string.split(self.main_results_directory,'ExonPlots')[0]
if 'SashimiPlots' in self.main_results_directory:
self.main_results_directory = string.split(self.main_results_directory,'SashimiPlots')[0]
opening_display_folder = self.main_results_directory + "/ExpressionOutput"
try:
list_contents = os.listdir(opening_display_folder)
target_file = ""
for file in list_contents:
candidate = re.findall("SUMMARY", file)
if len(candidate) > 0:
target_file = file
break
except Exception:
opening_display_folder = self.main_results_directory
list_contents = os.listdir(opening_display_folder)
for file in list_contents:
candidate = re.findall(".log", file)
if len(candidate) > 0:
target_file = file ### get the last log file
target_file = unique.filepath(opening_display_folder + "/" + target_file)
opened_target_file = open(target_file, "r")
opened_target_file_contents = []
for line in opened_target_file:
line = line.rstrip(); line = string.replace(line,'"','')
line = line.split("\t")
if len(line)==1: line += ['']*5
opened_target_file_contents.append((line))
self.table_length = len(opened_target_file_contents)
for cell in self.ColoredCellList:
try: self.myGrid.SetCellBackgroundColour(cell[0], cell[1], wx.WHITE)
except Exception: pass
self.ColoredCellList = []
x_count = 0
for item_list in opened_target_file_contents:
y_count = 0
for item in item_list:
try:
self.myGrid.SetCellValue(x_count, y_count, item)
except Exception:
pass ### if the length of the row is 0
if(x_count == 0):
self.myGrid.SetCellFont(x_count, y_count, wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
y_count = y_count + 1
x_count = x_count + 1
self.myGrid.AutoSize()
for i in range(50):
colsize = self.myGrid.GetColSize(i)
if(colsize > 200):
self.myGrid.SetColSize(i, 200)
self.page2.Layout()
#This line always sets the opening display to the "Table" tab.
self.nb.SetSelection(0)
def OnOpenSingleFile(self, event):
#Opens only one file as opposed to the whole project; possibly unstable and needs further testing.
openFileDialog = wx.FileDialog(self, "", "", "", "", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return