-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNeuroVar_app.py
More file actions
1021 lines (921 loc) · 54.1 KB
/
NeuroVar_app.py
File metadata and controls
1021 lines (921 loc) · 54.1 KB
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 wx
import wx.grid
import pandas as pd
import matplotlib
matplotlib.use('WXAgg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
import numpy as np
import io
import os
import glob
import csv
# Load data
annotation1 = pd.read_csv("annotation.txt",sep=",", low_memory=False)
annotation1 = annotation1.rename(columns={annotation1.columns[8]: "gene"})
full_list = pd.read_csv("full_list.csv",low_memory=False)
diseases = full_list['disease'].unique()
disease_type = full_list['disease_type'].unique()
gene = full_list['gene'].unique()
################ Tab 1: Biomarker ####################
######################################################
######################################################
class TabOne(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
# Create panels
side_panel = wx.Panel(self)
side_panel.SetBackgroundColour('#ebebeb')
main_panel = wx.Panel(self)
about_gene_panel = wx.Panel(main_panel)
about_gene_panel.SetBackgroundColour('#FFFFFF')
transcript_panel = wx.Panel(main_panel)
transcript_panel.SetBackgroundColour("#FFFFFF")
side_sizer = wx.BoxSizer(wx.VERTICAL)
about_gene_sizer = wx.BoxSizer(wx.VERTICAL)
transcript_sizer = wx.BoxSizer(wx.VERTICAL)
# Disease selection
disease_sizer = wx.BoxSizer(wx.VERTICAL)
disease_label = wx.StaticText(side_panel, label='Select the disease of interest:')
self.disease_combo = wx.ComboBox(side_panel, choices=list(diseases), style=wx.CB_READONLY)
self.disease_combo.Bind(wx.EVT_COMBOBOX, self.OnDiseaseSelected)
disease_sizer.Add(disease_label, 0, wx.ALL | wx.RIGHT, 5)
disease_sizer.Add(self.disease_combo, 0, wx.ALL, 5)
side_sizer.Add(disease_sizer, 0, wx.EXPAND)
# Disease type selection
self.disease_type_sizer = wx.BoxSizer(wx.VERTICAL)
disease_type_label = wx.StaticText(side_panel, label='Select the disease type:')
self.disease_type_combo = wx.ComboBox(side_panel, choices=list(disease_type), style=wx.CB_READONLY|wx.TE_MULTILINE)
self.disease_type_combo.SetMinSize((250, -1))
self.disease_type_combo.Bind(wx.EVT_COMBOBOX, self.OnDiseaseTypeSelected)
self.disease_type_sizer.Add(disease_type_label, 0, wx.ALL | wx.RIGHT, 5)
self.disease_type_sizer.Add(self.disease_type_combo, 0, wx.ALL, 5)
side_sizer.Add(self.disease_type_sizer, 0, wx.EXPAND)
# gene selection
self.gene_sizer = wx.BoxSizer(wx.VERTICAL)
gene_label = wx.StaticText(side_panel, label='Gene of Interest:')
self.gene_combo = wx.ComboBox(side_panel, choices=list(gene), style=wx.CB_READONLY)
self.gene_combo.Bind(wx.EVT_COMBOBOX, self.process_data)
self.gene_sizer.Add(gene_label, 0, wx.ALL | wx.RIGHT, 5)
self.gene_sizer.Add(self.gene_combo, 0, wx.ALL, 5)
side_sizer.Add(self.gene_sizer, 0, wx.EXPAND | wx.ALL, 10)
side_panel.SetSizerAndFit(side_sizer)
# create table gene info
about_gene_label = wx.StaticText(about_gene_panel, label="About the gene")
gene_label_font = about_gene_label.GetFont()
gene_label_font.SetPointSize(16)
about_gene_label.SetFont(gene_label_font)
self.gene_info_table = wx.grid.Grid(about_gene_panel)
self.gene_info_table.CreateGrid(numRows=1, numCols=6)
self.gene_info_table.SetColLabelValue(0, "Gene")
self.gene_info_table.SetColLabelValue(1, "MOI")
self.gene_info_table.SetColLabelValue(2, "SOP")
self.gene_info_table.SetColLabelValue(3, "Classification")
self.gene_info_table.SetColLabelValue(4, "Online report")
self.gene_info_table.SetColLabelValue(5, "Classification date")
self.gene_info_table.SetRowSize(0, 35)
about_gene_sizer.Add(about_gene_label, 0, wx.ALL | wx.RIGHT, 5)
about_gene_sizer.Add(self.gene_info_table, 1, wx.ALL | wx.RIGHT, 5)
about_gene_panel.SetSizerAndFit(about_gene_sizer)
self.gene_info_table.AutoSizeColumns()
# create table gene transcripts
gene_trans_label = wx.StaticText(transcript_panel, label="Gene's transcript")
trans_label_font = gene_trans_label.GetFont()
trans_label_font.SetPointSize(16)
gene_trans_label.SetFont(trans_label_font)
self.gene_trans_table = wx.grid.Grid(transcript_panel)
self.gene_trans_table.CreateGrid(numRows= 0, numCols=5)
self.gene_trans_table.SetColLabelValue(0, "Gene")
self.gene_trans_table.SetColLabelValue(1, "Transcript name")
self.gene_trans_table.SetColLabelValue(2, "Transcript type")
self.gene_trans_table.SetColLabelValue(3, "Transcription start site (TSS)")
self.gene_trans_table.SetColLabelValue(4, "Transcript end (bp)")
self.gene_trans_table.SetColLabelValue(5, "Transcript start (bp)")
transcript_sizer.Add(gene_trans_label, 0, wx.ALL | wx.RIGHT, 5)
transcript_sizer.Add(self.gene_trans_table, 4, wx.ALL | wx.RIGHT, 5)
self.gene_trans_table.AutoSizeColumns()
transcript_panel.SetSizerAndFit(transcript_sizer)
# Main sizer to hold all panels
main_sizer = wx.BoxSizer(wx.VERTICAL)
main_sizer.Add(about_gene_panel, 0, wx.EXPAND)
main_sizer.Add(transcript_panel, 1, wx.EXPAND)
main_panel.SetSizerAndFit(main_sizer)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(side_panel, 1, wx.EXPAND)
sizer.Add(main_panel, 4, wx.EXPAND)
self.SetSizer(sizer)
def OnDiseaseSelected(self, event):
# Update disease type
selected_disease = self.disease_combo.GetValue()
disease_types = full_list.loc[full_list['disease'] == selected_disease, 'disease_type'].unique()
self.disease_type_combo.SetItems(list(disease_types))
self.disease_type_sizer.ShowItems(show=True)
def OnDiseaseTypeSelected(self, event):
# Update gene list
selected_disease_type = self.disease_type_combo.GetValue()
gene_list = full_list.loc[full_list['disease_type'] == selected_disease_type, 'gene'].unique()
self.gene_combo.SetItems(list(gene_list))
self.gene_sizer.ShowItems(show=True)
self.Layout()
def process_data(self, event):
# filter
disease_n = self.disease_combo.GetValue()
disease_t = self.disease_type_combo.GetValue()
target_gene = self.gene_combo.GetValue()
gene_info = full_list.loc[(full_list['disease'] == disease_n) & (full_list['disease_type'] == disease_t) &
(full_list['gene'] == target_gene)]
gene_info = gene_info.drop(columns=["GENE ID (HGNC)","disease_type","DISEASE ID (MONDO)","disease"])
# Update the table with filtered data
self.gene_info_table.ClearGrid()
# Get the number of rows and columns
num_rows, num_cols = gene_info.shape
# Populate the table
for row in range(num_rows):
for col in range(num_cols):
value = str(gene_info.iloc[row, col])
self.gene_info_table.SetCellValue(row, col, value)
# Refresh the table
self.gene_info_table.Refresh()
self.gene_info_table.AutoSizeColumns()
# annotate genes
gene_trans = annotation1[annotation1["gene"] == target_gene]
gene_trans = gene_trans.iloc[:, [8, 9, 12, 13, 14, 15]]
gene_trans = gene_trans.drop_duplicates()
# Clear existing data
self.gene_trans_table.ClearGrid()
num_rows, num_cols = gene_trans.shape
# Get the current number of rows in the table
current_num_rows = self.gene_trans_table.GetNumberRows()
current_num_cols = self.gene_trans_table.GetNumberCols()
# Delete excess rows and columns
if current_num_rows > num_rows:
self.gene_trans_table.DeleteRows(numRows=current_num_rows - num_rows)
if current_num_cols > num_cols:
self.gene_trans_table.DeleteCols(numCols=current_num_cols - num_cols)
# Append additional rows and columns
if current_num_rows < num_rows:
self.gene_trans_table.AppendRows(numRows=num_rows - current_num_rows)
if current_num_cols < num_cols:
self.gene_trans_table.AppendCols(numCols=num_cols - current_num_cols)
# Populate the table
for row in range(num_rows):
for col in range(num_cols):
value = str(gene_trans.iloc[row, col])
self.gene_trans_table.SetCellValue(row, col, value)
# Refresh the table
self.gene_trans_table.Refresh()
self.gene_trans_table.AutoSizeColumns()
self.Layout()
#####################################################################
######Tab 2: Expression##############################################
#####################################################################
class TabTwo(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
# Create panels
side_panel = wx.Panel(self)
side_panel.SetBackgroundColour('#ebebeb')
main_panel = wx.Panel(self)
side_sizer = wx.BoxSizer(wx.VERTICAL)
main_sizer = wx.BoxSizer(wx.HORIZONTAL)
#filter by biomarker by disease
diseases = full_list['disease'].unique()
disease_input_label = wx.StaticText(side_panel, label='Select the disease of interest:')
self.disease_combo = wx.ComboBox(side_panel, choices=list(diseases), style=wx.CB_READONLY)
# File input
file_label = wx.StaticText(side_panel, label="Choose file to upload")
self.file_input = wx.FilePickerCtrl(side_panel, style=wx.FLP_DEFAULT_STYLE | wx.FLP_USE_TEXTCTRL)
# Separator radio buttons
separator_label = wx.StaticText(side_panel, label="Separator:")
self.separator_choices = [",", ";", ":"]
self.separator_radio = wx.RadioBox(side_panel, choices=self.separator_choices, majorDimension=1, style=wx.RA_SPECIFY_COLS)
# Column selection
col1_label = wx.StaticText(side_panel, label="Select Gene Column")
self.col1_input = wx.ComboBox(side_panel, choices=[], style=wx.CB_READONLY)
col2_label = wx.StaticText(side_panel, label="Select P-value Column")
self.col2_input = wx.ComboBox(side_panel, choices=[], style=wx.CB_READONLY)
col3_label = wx.StaticText(side_panel, label="Select LogFC Column")
self.col3_input = wx.ComboBox(side_panel, choices=[], style=wx.CB_READONLY)
# P-value and LogFC sliders
pval_logfc_label = wx.StaticText(side_panel, label="Define the p-value and LogFC value to identify DEGs")
pval_label = wx.StaticText(side_panel, label="P-value:")
self.pval_slider = wx.Slider(side_panel, value=1, minValue=0, maxValue=100, style=wx.SL_HORIZONTAL)
log_label = wx.StaticText(side_panel, label="LogFC:")
self.log_slider = wx.Slider(side_panel, value=1, minValue=0, maxValue=5)
# Create Static text to display slider value
self.slider_value_text = wx.StaticText(side_panel, label='0.01', style=wx.ALIGN_CENTER)
side_panel.SetSizerAndFit(side_sizer)
self.log_slider_value_text = wx.StaticText(side_panel, label='1', style=wx.ALIGN_CENTER)
side_panel.SetSizerAndFit(side_sizer)
# Set default value to 0.01 and 1
self.pval_slider.SetValue(1)
self.log_slider.SetValue(1)
self.slider_pval_value = float(self.slider_value_text.GetLabel())
self.slider_logfc_value = float(self.log_slider_value_text.GetLabel())
# Expression table
self.expression_table = wx.grid.Grid(main_panel)
self.expression_table.CreateGrid(0, 4)
self.expression_table.SetColLabelValue(0, "Gene")
self.expression_table.SetColLabelValue(1, "P-value")
self.expression_table.SetColLabelValue(2, "LogFC")
self.expression_table.SetColLabelValue(3, "Expression Profile")
self.expression_table.AutoSizeColumns()
# Create a save button
self.save_csv_button = wx.Button(side_panel, label="Save table as CSV")
# Volcano plot
self.volcano_plot = wx.Panel(main_panel)
# Create a save button
self.save_png_button = wx.Button(side_panel, label="Save plot as PNG")
# Clear data button
self.clear_data_button = wx.Button(side_panel, label="Clear Data")
self.clear_data_button.SetBackgroundColour("#CD5C5C")
self.clear_data_button.SetForegroundColour(wx.WHITE)
# Bind event
self.file_input.Bind(wx.EVT_FILEPICKER_CHANGED, self.on_upload_button_clicked)
self.expression_table.Bind(wx.EVT_FILEPICKER_CHANGED, self.update_expression_table)
self.separator_radio.Bind(wx.EVT_RADIOBOX, self.on_separator_radio_changed)
self.col1_input.Bind(wx.EVT_COMBOBOX, self.on_col_selected1)
self.col2_input.Bind(wx.EVT_COMBOBOX, self.on_col_selected2)
self.col3_input.Bind(wx.EVT_COMBOBOX, self.on_col_selected3)
self.pval_slider.Bind(wx.EVT_SCROLL, self.on_pval_slider_scroll)
self.log_slider.Bind(wx.EVT_SCROLL, self.on_logfc_slider_scroll)
self.disease_combo.Bind(wx.EVT_TEXT, self.on_gene_selection)
self.save_csv_button.Bind(wx.EVT_BUTTON, self.on_save_csv_button_clicked)
self.save_png_button.Bind(wx.EVT_BUTTON, self.on_save_png_button_clicked)
self.clear_data_button.Bind(wx.EVT_BUTTON, self.on_clear_data_button_clicked)
# Set sizers
side_panel.SetSizerAndFit(side_sizer)
main_panel.SetSizerAndFit(main_sizer)
# Arrange the panels side by side
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(side_panel, 1, wx.EXPAND)
sizer.Add(main_panel, 5, wx.EXPAND)
self.SetSizer(sizer)
side_sizer.Add(disease_input_label, 0, wx.ALL | wx.RIGHT, 5)
side_sizer.Add(self.disease_combo, 0, wx.ALL, 5)
side_sizer.Add(file_label, 0, wx.ALL, 5)
side_sizer.Add(self.file_input, 0, wx.EXPAND | wx.ALL, 5)
side_sizer.Add(separator_label, 0, wx.ALL, 5)
side_sizer.Add(self.separator_radio, 0, wx.EXPAND | wx.ALL, 5)
side_sizer.Add(col1_label, 0, wx.ALL, 5)
side_sizer.Add(self.col1_input, 0, wx.EXPAND | wx.ALL, 5)
side_sizer.Add(col2_label, 0, wx.ALL, 5)
side_sizer.Add(self.col2_input, 0, wx.EXPAND | wx.ALL, 5)
side_sizer.Add(col3_label, 0, wx.ALL, 5)
side_sizer.Add(self.col3_input, 0, wx.EXPAND | wx.ALL, 5)
side_sizer.Add(pval_logfc_label, 0, wx.ALL, 5)
side_sizer.Add(pval_label, 0, wx.ALL, 5)
side_sizer.Add(self.pval_slider, 0, wx.EXPAND | wx.ALL, 5)
side_sizer.Add(self.slider_value_text, 0, wx.ALIGN_CENTER)
side_sizer.Add(log_label, 0, wx.ALL, 5)
side_sizer.Add(self.log_slider, 0, wx.EXPAND | wx.ALL, 5)
side_sizer.Add(self.log_slider_value_text, 0, wx.ALIGN_CENTER)
side_sizer.Add(self.save_csv_button, 0, wx.ALIGN_CENTER)
side_sizer.Add(self.save_png_button, 0, wx.ALIGN_CENTER)
side_sizer.Add(self.clear_data_button, 0, wx.ALIGN_CENTER)
main_sizer.Add(self.expression_table, 1, wx.EXPAND | wx.ALL)
main_sizer.Add(self.volcano_plot, 2, wx.EXPAND | wx.ALL)
def on_gene_selection(self):
self.biom_list = full_list.loc[full_list['disease'] == self.disease_combo.GetValue(), 'gene']
def on_col_selected1(self,event):
self.selected_column1 = self.col1_input.GetValue()
num_rows = self.df.shape[0]
# Update the column label
self.expression_table.SetColLabelValue(0, self.selected_column1)
# Clear the existing data in column 0 before updating
for i in range(num_rows):
self.expression_table.SetCellValue(i, 0, "")
# Update the values in column 0 based on the selected column
for i in range(num_rows):
self.expression_table.SetCellValue(i, 0, str(self.df.iloc[i][self.selected_column1]))
self.expression_table.AutoSizeColumns()
self.update_expression_profile()
def on_col_selected2(self,event):
self.selected_column2 = self.col2_input.GetValue()
num_rows = self.df.shape[0]
# Update the column label
self.expression_table.SetColLabelValue(1, self.selected_column2)
# Clear the existing data in column 1 before updating
for i in range(num_rows):
self.expression_table.SetCellValue(i, 1, "")
# Update the values in column 1 based on the selected column
for i in range(num_rows):
self.expression_table.SetCellValue(i, 1, str(self.df.iloc[i][self.selected_column2]))
self.expression_table.AutoSizeColumns()
self.update_expression_profile()
def on_col_selected3(self,event):
self.selected_column3 = self.col3_input.GetValue()
num_rows = self.df.shape[0]
# Update the column label
self.expression_table.SetColLabelValue(2, self.selected_column3)
# Clear the existing data in column 2 before updating
for i in range(num_rows):
self.expression_table.SetCellValue(i, 2, "")
# Update the values in column 2 based on the selected column
for i in range(num_rows):
self.expression_table.SetCellValue(i, 2, str(self.df.iloc[i][self.selected_column3]))
self.expression_table.AutoSizeColumns()
self.update_expression_profile()
def upload_file(self, file_path):
# Read data from expression file with the selected separator
self.df = pd.read_csv(file_path, sep=",", low_memory=False) ##### the separator is ,
# Filter genes based on the biomarker list
self.df = self.df[self.df['gene'].isin(self.biom_list)]
self.df = self.df.drop_duplicates()
self.df_display = self.df[["gene", "pvalue", "log2FoldChange"]]
# Update combo boxes
self.col1_input.Set(self.df.columns)
self.col2_input.Set(self.df.columns)
self.col3_input.Set(self.df.columns)
# Clear existing data
self.expression_table.ClearGrid()
# Update expression table
num_rows, num_cols = self.df_display.shape
self.expression_table.ClearGrid()
self.expression_table.AppendRows(num_rows)
for row in range(num_rows):
for col in range(num_cols):
# Get the cell value
cell_value = self.df_display.iloc[row, col]
# Set the cell value to the corresponding cell in the table
self.expression_table.SetCellValue(row, col, str(cell_value))
# Update table layout and create the volcano plot
self.expression_table.Refresh()
self.expression_table.AutoSizeColumns()
self.update_expression_profile()
self.create_volcano_plot(self.expression_profile_data)
def on_upload_button_clicked(self, event):
self.on_gene_selection()
file_path = self.file_input.GetPath()
self.upload_file(file_path)
def update_expression_table(self,event):
num_rows, num_cols = self.expression_table.shape
self.expression_table.ClearGrid()
separator = self.separator_radio.GetStringSelection()
# Append new rows to the table
if num_rows < self.df_display.shape[0]:
self.expression_table.AppendRows(numRows=self.df_display.shape[0] - num_rows)
for row in range(num_rows):
for col in range(num_cols):
# Get the cell value
cell_value = self.df_display.iloc[row, col]
# Split the cell value using the selected separator
cell_value_parts = cell_value.split(separator)
# Set the cell value parts to the corresponding cells in the table
# Separate variable for table column index
table_col = col
for i, part in enumerate(cell_value_parts):
self.expression_table.SetCellValue(row -num_rows, table_col + i, part)
# Update expression profile
self.update_expression_profile()
self.on_gene_selection()
# Update table layout and volcano plot
self.expression_table.Refresh()
self.expression_table.AutoSizeColumns()
self.create_volcano_plot()
def on_separator_radio_changed(self, event):
separator = self.separator_choices[self.separator_radio.GetSelection()]
num_rows = self.expression_table.GetNumberRows()
num_cols = self.expression_table.GetNumberCols()
data = []
for row in range(num_rows):
row_data = []
for col in range(num_cols):
row_data.append(self.expression_table.GetCellValue(row, col))
data.append(row_data)
# Update expression table with new separator
df = pd.DataFrame(data, columns=["Gene", "P-value", "LogFC", "Expression Profile"])
self.update_expression_table()
def on_pval_slider_scroll(self, event):
slider = event.GetEventObject()
self.slider_pval_value = slider.GetValue() / 100 # Convert back to float by dividing by 100
self.slider_value_text.SetLabel(f'{self.slider_pval_value:.2f}')
self.update_expression_profile()
def on_logfc_slider_scroll(self, event):
slider = event.GetEventObject()
self.slider_logfc_value = slider.GetValue()
self.log_slider_value_text.SetLabel(f'{self.slider_logfc_value:.2f}')
self.update_expression_profile()
def update_expression_profile(self):
num_rows = self.expression_table.GetNumberRows()
pval_col_label = self.expression_table.GetColLabelValue(1)
for row in range(num_rows):
logfc = self.expression_table.GetCellValue(row, 2)
pval = self.expression_table.GetCellValue(row, 1)
expression_profile = ""
if pval_col_label == "padj":
padj = float(pval)
if float(logfc) > self.slider_logfc_value and padj < self.slider_pval_value :
expression_profile = "Upregulated genes"
elif float(logfc) < -(self.slider_logfc_value) and padj < self.slider_pval_value :
expression_profile = "Downregulated genes"
else:
expression_profile = "Not Significant"
else:
if float(logfc) > self.slider_logfc_value and float(pval) < self.slider_pval_value :
expression_profile = "Upregulated genes"
elif float(logfc) < -(self.slider_logfc_value) and float(pval) < self.slider_pval_value :
expression_profile = "Downregulated genes"
else:
expression_profile = "Not Significant"
self.expression_table.SetCellValue(row, 3, expression_profile)
self.expression_profile_data = [self.expression_table.GetCellValue(row, 3) for row in range(num_rows)]
self.create_volcano_plot(self.expression_profile_data)
def on_save_csv_button_clicked(self, event):
save_dialog = wx.FileDialog(self, "Save as CSV", wildcard="CSV files (*.csv)|*.csv", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
if save_dialog.ShowModal() == wx.ID_CANCEL:
return
file_path = save_dialog.GetPath()
# Save the table as a CSV file
with open(file_path, 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(['Gene', 'P-value', 'LogFC', 'Expression Profile'])
for row in range(self.expression_table.GetNumberRows()):
writer.writerow([
self.expression_table.GetCellValue(row, 0),
self.expression_table.GetCellValue(row, 1),
self.expression_table.GetCellValue(row, 2),
self.expression_table.GetCellValue(row, 3),])
def create_volcano_plot(self, expression_profile_data):
self.volcano_plot.ClearBackground()
# Retrieve data
num_rows = self.expression_table.GetNumberRows()
pval_data = []
logfc_data = []
expression_profile_data = []
for row in range(num_rows):
pval = float(self.expression_table.GetCellValue(row, 1))
logfc = float(self.expression_table.GetCellValue(row, 2))
expression_profile = self.expression_table.GetCellValue(row, 3)
pval_data.append(pval)
logfc_data.append(logfc)
expression_profile_data.append(expression_profile)
# Create volcano plot
fig = Figure(figsize=(10, 8), dpi=80)
canvas = FigureCanvas(self.volcano_plot, -1, fig)
ax = fig.add_subplot(111)
color_map = {'Upregulated genes': 'blue', 'Downregulated genes': 'red', 'Not Significant': 'green'}
colors = np.array([color_map.get(profile, 'black') for profile in expression_profile_data])
# Plot the data points with colors
ax.scatter(logfc_data, -np.log10(pval_data), c=colors, edgecolors='none', alpha=1)
# Add legend
legend_elements = [plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=color_map[profile], markersize=8) for profile in color_map]
ax.legend(legend_elements, color_map.keys(), title='Expression Profile')
ax.set_xlabel('LogFC')
ax.set_ylabel('-log10(P-value)')
ax.set_title('Volcano Plot')
# Update the plot
self.canvas = FigureCanvas(self.volcano_plot, -1, fig)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(canvas, 1, wx.EXPAND)
self.volcano_plot.SetSizer(self.sizer)
self.volcano_plot.Layout()
return fig
def on_save_png_button_clicked(self, event):
save_dialog = wx.FileDialog(self, "Save as PNG", wildcard="PNG files (*.png)|*.png", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
if save_dialog.ShowModal() == wx.ID_CANCEL:
return
filepath = save_dialog.GetPath()
save_dialog.Destroy()
# Create a new figure for saving as PNG
fig = self.create_volcano_plot(self.expression_profile_data)
fig.savefig(filepath, format='png', dpi=300)
def on_clear_data_button_clicked(self, event):
# Clear data in expression table
num_rows = self.expression_table.GetNumberRows()
self.expression_table.ClearGrid()
self.expression_table.DeleteRows(0, num_rows)
self.expression_table.AutoSizeColumns()
# Clear file input
self.file_input.SetPath("")
# Delete the plot
if self.canvas is not None:
self.canvas.Destroy()
self.canvas = None
self.volcano_plot.DestroyChildren()
self.volcano_plot.Layout()
self.Layout()
#######################################################################################
###################Tab3: Variants######################################################
#######################################################################################
class TabThree(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
# Create panels
side_panel = wx.Panel(self)
side_panel.SetBackgroundColour('#ebebeb')
main_panel = wx.Panel(self)
side_sizer = wx.BoxSizer(wx.VERTICAL)
main_sizer = wx.BoxSizer(wx.VERTICAL)
#filter by biomarker by disease
diseases = full_list['disease'].unique()
disease_input_label = wx.StaticText(side_panel, label='Select the disease of interest:')
self.disease_combo = wx.ComboBox(side_panel, choices=list(diseases), style=wx.CB_READONLY)
# File Folder
folder_path_label = wx.StaticText(side_panel, label="Enter folder path:")
self.folder_path_input = wx.TextCtrl(side_panel)
folder_path_note = wx.StaticText(side_panel, label="Note: Make sure the path contains two folders named 'control' and 'patient'")
self.variant_type_radio = wx.RadioBox(side_panel, choices=["SNP", "Indels"], majorDimension=1, style=wx.RA_SPECIFY_COLS)
self.submit_button = wx.Button(side_panel, label="Submit")
self.save_csv_button = wx.Button(side_panel, label="Save table as CSV")
# Clear data button
self.clear_data_button = wx.Button(side_panel, label="Clear Data")
self.clear_data_button.SetBackgroundColour("#CD5C5C")
self.clear_data_button.SetForegroundColour(wx.WHITE)
# Sizers
side_sizer.Add(disease_input_label, 0, wx.EXPAND | wx.ALL, 5)
side_sizer.Add(self.disease_combo, 0, wx.EXPAND | wx.ALL, 5)
side_sizer.Add(folder_path_label, 0, wx.ALL, 5)
side_sizer.Add(self.folder_path_input, 0, wx.EXPAND | wx.ALL, 5)
side_sizer.Add(folder_path_note, 0, wx.ALL, 5)
side_sizer.Add(self.variant_type_radio, 0, wx.ALL, 5)
side_sizer.Add(self.submit_button, 0, wx.ALIGN_CENTER)
side_panel.SetSizerAndFit(side_sizer)
side_sizer.Add(self.save_csv_button, 0, wx.ALIGN_CENTER)
side_sizer.Add(self.clear_data_button, 0, wx.ALIGN_CENTER)
# Variant table :SNP
self.snp_table = wx.grid.Grid(main_panel)
self.snp_table.CreateGrid(0, 8)
self.snp_table.SetColLabelValue(0, "Chrom")
self.snp_table.SetColLabelValue(1, "Gene")
self.snp_table.SetColLabelValue(2, "SNP position")
self.snp_table.SetColLabelValue(3, "SNP ID")
self.snp_table.SetColLabelValue(4, "Reference Genome Allele")
self.snp_table.SetColLabelValue(5, "Control's Allele")
self.snp_table.SetColLabelValue(6, "Patient's Allele")
self.snp_table.SetColLabelValue(7, "Compare")
self.snp_table.AutoSizeColumns()
main_sizer.Add(self.snp_table, 1, wx.EXPAND | wx.ALL, 5)
main_panel.SetSizerAndFit(main_sizer)
# Variant table :Indel
self.indel_table = wx.grid.Grid(main_panel)
self.indel_table.CreateGrid(0, 9)
self.indel_table.SetColLabelValue(0, "Chrom")
self.indel_table.SetColLabelValue(1, "Gene 1")
self.indel_table.SetColLabelValue(2, "Gene 2")
self.indel_table.SetColLabelValue(3, "SNP position")
self.indel_table.SetColLabelValue(4, "ALT Patient")
self.indel_table.SetColLabelValue(5, "REF Control")
self.indel_table.SetColLabelValue(6, "ALT Control")
self.indel_table.SetColLabelValue(7, "REF Patient")
self.indel_table.SetColLabelValue(8, "Compare")
self.indel_table.AutoSizeColumns()
main_sizer.Add(self.indel_table, 1, wx.EXPAND | wx.ALL, 5)
main_panel.SetSizerAndFit(main_sizer)
# Bind event
self.disease_combo.Bind(wx.EVT_TEXT, self.on_gene_selection)
self.submit_button.Bind(wx.EVT_BUTTON, self.on_submit_button_click)
self.variant_type_radio.Bind(wx.EVT_RADIOBUTTON, self.on_submit_button_click)
self.save_csv_button.Bind(wx.EVT_BUTTON, self.on_save_csv_button_clicked)
self.variant_type_radio.Bind(wx.EVT_RADIOBOX, self.on_variant_type_selection)
self.clear_data_button.Bind(wx.EVT_BUTTON, self.on_clear_data_button_clicked)
# Set up sizer
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(side_panel, 0, wx.EXPAND)
sizer.Add(main_panel, 1, wx.EXPAND)
self.SetSizerAndFit(sizer)
# Hide the Indel table by default
self.indel_table.Hide()
# Set the initial table display based on the selected radio button
self.on_variant_type_selection(None)
def on_gene_selection(self):
self.biom_list = full_list.loc[full_list['disease'] == self.disease_combo.GetValue(), 'gene']
def on_variant_type_selection(self, event):
# Determine which table to show based on the selected radio button
if self.variant_type_radio.GetStringSelection() == "SNP":
table_to_show = self.snp_table
table_to_hide = self.indel_table
else:
table_to_show = self.indel_table
table_to_hide = self.snp_table
# Hide the table that's not selected
table_to_hide.Hide()
# Show the table that's selected
table_to_show.Show()
# Refresh the layout to reflect the changes
self.Layout()
def read_vcf(self, path):
with open(path, 'r') as f:
lines = [l for l in f if not l.startswith('##')]
return pd.read_csv(
io.StringIO(''.join(lines)),
dtype={'#CHROM': str, 'POS': int, 'ID': str, 'REF': str, 'ALT': str, 'QUAL': str, 'FILTER': str, 'INFO': str},
sep='\t').rename(columns={'#CHROM': 'CHROM'})
def read_combined_vcf_files(self,folder_path):
# Define transition (Ti) and transveersion (Tv)
ti = ["A>G","G>A","C>T","T>C"]
tv = ["A>T","A>C","G>T","G>C","C>A","C>G","T>A","T>G"]
# Read data from control
folder_name1 = "control"
folder_path1 = os.path.join(folder_path, folder_name1)
file_paths_control = glob.glob(os.path.join(folder_path1, '*.vcf'))
# Read and combine files
file_contents_control = []
for path in file_paths_control:
vcf_reader_control = self.read_vcf(path)
file_contents_control.append(vcf_reader_control)
# Concatenate all tables
self.combined_control = file_contents_control[0]
for df in file_contents_control[1:]:
#self.combined_control = self.combined_control.append(df, ignore_index=True)
self.combined_control = pd.concat(file_contents_control, ignore_index=True)
# Create a new column "nuSub" by concatenating REF and ALT columns
self.combined_control['nuSub'] = self.combined_control['REF'] + '>' + self.combined_control['ALT']
# Set values in "TiTv" column based on "nuSub" values
self.combined_control.loc[self.combined_control['nuSub'].isin(ti), 'TiTv'] = 'Ti'
self.combined_control.loc[self.combined_control['nuSub'].isin(tv), 'TiTv'] = 'Tv'
# Rename columns "nuSub" and "TiTv" to "snp_controls" and "TiTv_controls"
self.combined_control = self.combined_control.rename(columns={'nuSub': 'snp_controls', 'TiTv': 'TiTv_controls'})
# Read data from patient
folder_name2 = "patient"
folder_path2 = os.path.join(folder_path, folder_name2)
file_paths_patient = glob.glob(os.path.join(folder_path2, '*.vcf'))
# Read and combine files
file_contents_patient = []
for path in file_paths_patient:
vcf_reader_patient = self.read_vcf(path)
file_contents_patient.append(vcf_reader_patient)
# Concatenate all tables
self.combined_patient = file_contents_patient[0]
for df in file_contents_patient[1:]:
#self.combined_patient = self.combined_patient.append(df, ignore_index=True)
self.combined_patient = pd.concat(file_contents_control, ignore_index=True)
# Create a new column "nuSub" by concatenating REF and ALT columns
self.combined_patient['nuSub'] = self.combined_patient['REF'] + '>' + self.combined_patient['ALT']
# Set values in "TiTv" column based on "nuSub" values
self.combined_patient.loc[self.combined_patient['nuSub'].isin(ti), 'TiTv'] = 'Ti'
self.combined_patient.loc[self.combined_patient['nuSub'].isin(tv), 'TiTv'] = 'Tv'
# Rename columns "nuSub" and "TiTv" to "snp_controls" and "TiTv_controls"
self.combined_patient = self.combined_patient.rename(columns={'nuSub': 'snp_patients', 'TiTv': 'TiTv_patients'})
def read_compared_group_final(self,combined_patient,combined_control):
# Merge patient and control tables based on "CHROM" and "POS" columns
self.compare_group = pd.merge(combined_patient, combined_control, on=["CHROM", "POS"], how="outer", suffixes=('_patient', '_control'))
# Replace NaN values with "no"
self.compare_group = self.compare_group.fillna("no")
# Set values in "compare" column based on conditions
self.compare_group.loc[(self.compare_group['snp_controls'] != "no") & (self.compare_group['snp_patients'] == "no"), 'compare'] = "deletion"
self.compare_group.loc[(self.compare_group['snp_controls'] == "no") & (self.compare_group['snp_patients'] != "no"), 'compare'] = "addition"
self.compare_group.loc[(self.compare_group['snp_controls'] == self.compare_group['snp_patients']), 'compare'] = "population specific"
self.compare_group.loc[(self.compare_group['snp_controls'] != self.compare_group['snp_patients']) & (self.compare_group['snp_controls'] != "no") & (self.compare_group['snp_patients'] != "no"), 'compare'] = "different"
def read_combined_indels(self,folder_path): #### fix appen error
# Read data from control
folder_name1 = "control"
folder_path1 = os.path.join(folder_path, folder_name1)
file_paths_control = glob.glob(os.path.join(folder_path1, '*.vcf'))
# Read and combine files
file_contents_control = []
for path in file_paths_control:
vcf_reader_control = self.read_vcf(path)
file_contents_control.append(vcf_reader_control)
# Concatenate all
self.combined_control = file_contents_control[0]
for df in file_contents_control[1:]:
#self.combined_control = self.combined_control.append(df, ignore_index=True)
self.combined_control = pd.concat(file_contents_control, ignore_index=True)
self.combined_control = self.combined_control.iloc[:, :5]
self.combined_control = self.combined_control.rename(columns={"#CHROM":"chrom","POS":"POS_snp_control","ID":"id_control","REF":"REF_control","ALT":"ALT_control"})
# Read data from patient
folder_name2 = "patient"
folder_path2 = os.path.join(folder_path, folder_name2)
file_paths_patient = glob.glob(os.path.join(folder_path2, '*.vcf'))
# Read and combine files
file_contents_patient = []
for path in file_paths_patient:
vcf_reader_patient = self.read_vcf(path)
file_contents_patient.append(vcf_reader_patient)
# Concatenate all tables
self.combined_patient = file_contents_patient[0]
for df in file_contents_patient[1:]:
#self.combined_patient = self.combined_patient.append(df, ignore_index=True)
self.combined_patient = pd.concat(file_contents_patient, ignore_index=True)
self.combined_patient = self.combined_patient.iloc[:, :5]
self.combined_patient = self.combined_patient.rename(columns={"#CHROM":"chrom","POS":"POS_snp_patient","ID":"id_patient","REF":"REF_patient","ALT":"ALT_patient"})
def on_save_csv_button_clicked(self, event):
# Ask the user which table to save and save
table_choice = wx.SingleChoiceDialog(self, "Which data do you want to save?", "Choose table", ["Indels", "SNPs"])
if table_choice.ShowModal() == wx.ID_CANCEL:
return
table_name = table_choice.GetStringSelection()
save_dialog = wx.FileDialog(self, "Save as CSV", wildcard="CSV files (*.csv)|*.csv", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
if save_dialog.ShowModal() == wx.ID_CANCEL:
return
file_path = save_dialog.GetPath()
# Define the column names for both tables
indel_cols = ['Chrom', 'Gene1', 'Gene2', ' SNP position', 'ALT Patient',"REF Control","ALT Control","REF Patient" 'Compare']
snp_cols = ['Chrom', 'Gene', 'SNP position', 'SNP ID', 'Reference Genome Allele', 'Control\'s Allele', 'Patient\'s Allele', 'Compare']
# Save the selected table data as a CSV file
with open(file_path, 'w', newline='') as f:
writer = csv.writer(f)
if table_name == "Indels":
writer.writerow(indel_cols)
table = self.indel_table
else:
writer.writerow(snp_cols)
table = self.snp_table
for row in range(table.GetNumberRows()):
writer.writerow([
table.GetCellValue(row, 0),
table.GetCellValue(row, 1),
table.GetCellValue(row, 2),
table.GetCellValue(row, 3),
table.GetCellValue(row, 4),
table.GetCellValue(row, 5),
table.GetCellValue(row, 6),
table.GetCellValue(row, 7)])
def on_submit_button_click(self, event):
# display a message
msg = wx.BusyInfo("Processing data, please wait...")
# Get input values
folder_path = self.folder_path_input.GetValue()
vtype = self.variant_type_radio.GetSelection()
if vtype == 0 :
# Read VCF as df
self.read_combined_vcf_files(folder_path)
msg = wx.BusyInfo("20% ...")
self.read_compared_group_final(self.combined_patient,self.combined_control)
msg = wx.BusyInfo("40% ...")
# Get data from compare_group
# Specify the column names you want to include
selected_columns = ['CHROM','POS', 'ID_patient','ID_patient', 'REF_patient', 'ALT_patient', 'QUAL_patient', 'FILTER_patient', 'INFO_patient', 'FORMAT_patient', 'ID_control', 'REF_control', 'ALT_control', 'QUAL_control', 'FILTER_control', 'INFO_control', 'FORMAT_control', 'snp_controls', 'TiTv_controls', 'compare']
# Use iloc with column names
self.compare_group_final = self.compare_group[selected_columns]
self.compare_group_final.columns = ["Chrom"] + self.compare_group_final.columns.tolist()[1:]
self.compare_group_final = self.compare_group_final.replace(to_replace="chr", value="", regex=True)
# Extract columns Chrom and POS from compare_group_final
chrom_snppos = self.compare_group_final.iloc[:, [0, 1]]
chrom_snppos.columns = ["chrom", "snp_position"]
chrom_snppos = chrom_snppos.replace(to_replace="chr", value="", regex=True)
# Extract gene positions
gene_pos = annotation1.iloc[:, [4, 5, 6, 8]].drop_duplicates()
gene_pos.columns = ["chrom", "start", "end", "gene name"]
gene_pos['start'] = gene_pos['start'].astype('int32')
gene_pos['end'] = gene_pos['end'].astype('int32')
msg = wx.BusyInfo("60% ...")
## start change
# Specify the chunk size (adjust as needed based on your available memory)
chunk_size = 10000
# Calculate the number of chunks needed
num_chunks = len(gene_pos) // chunk_size + 1
# Create an empty DataFrame to store the merged result
ann_snps = pd.DataFrame()
# Loop through chunks and merge
for i in range(num_chunks):
start_idx = i * chunk_size
end_idx = (i + 1) * chunk_size
# Slice the DataFrames into chunks
gene_pos_chunk = gene_pos.iloc[start_idx:end_idx]
chrom_snppos_chunk = chrom_snppos.iloc[start_idx:end_idx]
# Merge the chunks
merged_chunk = pd.merge(gene_pos_chunk, chrom_snppos_chunk, on="chrom")
# Filter and process the merged chunk
merged_chunk = merged_chunk[(merged_chunk["snp_position"] < merged_chunk["end"]) & (merged_chunk["snp_position"] > merged_chunk["start"])].reset_index(drop=True)
merged_chunk = merged_chunk.drop(columns=["end"])
# Concatenate the merged chunk to the final result
ann_snps = pd.concat([ann_snps, merged_chunk], ignore_index=True)
# Clean up: delete the original DataFrames
del gene_pos
del chrom_snppos
msg = wx.BusyInfo("80% ...")
## end change
# Merge ann_snps and compare_group_final
ann_snps2 = pd.merge(ann_snps, self.compare_group_final, left_on=["chrom", "snp_position"], right_on=["Chrom", "POS"])
del ann_snps
del self.compare_group_final
ann_snps3 = ann_snps2.iloc[:, [0, 2, 3, 6, 7, 11, 8, 14]]
ann_snps3.columns = ["Chrom", "Gene", "SNP position", "SNP ID", "Reference Genome Allele", "Control's Allele", "Patient's Allele", "Compare"]
ann_snps3 = ann_snps3.replace(to_replace="no", value=".", regex=True)
ann_snps3 =ann_snps3.drop_duplicates()
self.on_gene_selection()
final_table = ann_snps3[ann_snps3['Gene'].isin(self.biom_list)]
msg = wx.BusyInfo("90% ...")
# Update SNP table with ann_snps3 table data
self.snp_table.ClearGrid()
num_rows, num_cols = final_table.shape
self.snp_table.AppendRows(num_rows)
for row in range(num_rows):
for col in range(num_cols):
# Get the cell value
cell_value = final_table.iloc[row, col]
# Set the cell value to the corresponding cell in the table
self.snp_table.SetCellValue(row, col, str(cell_value))
# Update table layout
self.snp_table.Refresh()
self.snp_table.AutoSizeColumns()
elif vtype == 1:
# Read VCF as df
self.read_combined_indels(folder_path) ######################## the error is here
msg = wx.BusyInfo("20% ...")
# Extract columns chrom and snp position
chrom_snppos = self.combined_control.iloc[:, [0, 1]]
chrom_snppos.columns = ["chrom", "snp_position"]
chrom_snppos = chrom_snppos.replace(to_replace="chr", value="", regex=True)
# Extract gene positions
gene_pos = annotation1.iloc[:, [4, 5, 6, 8]].drop_duplicates()
gene_pos.columns = ["chrom", "start", "end","gene name"]
# Merge gene_pos and chrom_snppos
annotated_indel = pd.merge(gene_pos, chrom_snppos, on="chrom")
msg = wx.BusyInfo("40%...")
del gene_pos
del chrom_snppos
annotated_indel = annotated_indel[(annotated_indel["snp_position"] < annotated_indel["end"]) & (annotated_indel["snp_position"] > annotated_indel["start"])].reset_index(drop=True)
annotated_indel = annotated_indel.drop(columns=["end"])
# Remove 'chr' from chromosome column in combined_control/patient tables
self.combined_control = self.combined_control.replace(to_replace="chr", value="", regex=True)
self.combined_patient = self.combined_patient.replace(to_replace="chr", value="", regex=True)
# Merge annotated_indel with combined_control on matching chrom and snp_position
annotated_indel2 = pd.merge(annotated_indel, self.combined_control, left_on=['chrom', 'snp_position'], right_on=['CHROM', 'POS_snp_control'])
annotated_indel2 = annotated_indel2.drop(columns=["CHROM" , "POS_snp_control"])
# Extract chrom and snp_position columns from combined_patients_indel and remove 'chr' from chrom values
self.combined_patient.rename(columns={"CHROM": "chrom"}, inplace=True)
chrom_snppos = self.combined_patient[['chrom', 'POS_snp_patient']]
chrom_snppos = chrom_snppos.replace(to_replace="chr", value="", regex=True)
msg = wx.BusyInfo("60%...") #
# Extract chrom, start, end, and gene columns from annotation1 and rename columns
gene_pos = annotation1.iloc[:, [4, 5, 6, 8]].drop_duplicates()
gene_pos.columns = ["chrom", "start", "end", "gene name"]
# Merge gene_pos with chrom_snppos on matching chrom and snp_position with snp_position between gene_start and gene_end
annotated_indel3 = pd.merge(gene_pos, chrom_snppos, on="chrom")
annotated_indel3 = annotated_indel3[(annotated_indel3['POS_snp_patient'] > annotated_indel3['start']) & (annotated_indel3['POS_snp_patient'] < annotated_indel3['end'])]
annotated_indel3 = annotated_indel3.drop('POS_snp_patient', axis=1)
# Merge annotated_indel with combined_patients_indel on matching chrom and snp_position
annotated_indel4 = pd.merge(annotated_indel, self.combined_patient, left_on=['chrom', 'snp_position'], right_on=['chrom', 'POS_snp_patient'])
annotated_indel4 = annotated_indel4.drop(['POS_snp_patient'], axis=1)
annotated_indel4 = annotated_indel4.rename(columns={'gene name': 'gene1'})
# Rename columns in annotated_indel2
annotated_indel2 = annotated_indel2.rename(columns={'gene name': 'gene2'})
# Compare groups and assign 'compare' values
compare_group_i = pd.merge(annotated_indel4, annotated_indel2, how='outer', on=['chrom', 'snp_position'])
msg = wx.BusyInfo("80%...") #
msg = wx.BusyInfo("merge error")
compare_group_i['compare'] = ''
compare_group_i.loc[(compare_group_i['ALT_control'].notna()) & (compare_group_i['ALT_patient'].isna()), 'compare'] = 'deletion'
compare_group_i.loc[(compare_group_i['ALT_control'].isna()) & (compare_group_i['ALT_patient'].notna()), 'compare'] = 'addition'
compare_group_i.loc[(compare_group_i['ALT_control'] == compare_group_i['ALT_patient']) & (compare_group_i['ALT_control'].notna()) & (compare_group_i['ALT_patient'].notna()), 'compare'] = 'population specific'
compare_group_i.loc[(compare_group_i["ALT_control"] != compare_group_i['ALT_patient']) & (compare_group_i['ALT_control'] !="no") & (compare_group_i['ALT_patient'] !="no"), 'compare'] = "different"
compare_group_i = compare_group_i[["chrom", "gene1", "gene2", "snp_position", "ALT_patient", "REF_control", "ALT_control", "REF_patient","compare"]]
compare_group_i.fillna(".", inplace=True)
compare_group_i =compare_group_i.drop_duplicates()
self.on_gene_selection()
final_table = pd.merge(self.biom_list, compare_group_i, how='inner', left_on='gene', right_on='gene1')
final_table = pd.concat([final_table, pd.merge(self.biom_list, compare_group_i, how='inner', left_on='gene', right_on='gene2')])
final_table = final_table.drop(['gene'], axis=1)
# Update Indel table with ann_snps3 table data
self.indel_table.ClearGrid()
num_rows, num_cols = final_table.shape
self.indel_table.AppendRows(num_rows)
msg = wx.BusyInfo("90%...") #
for row in range(num_rows):
for col in range(num_cols):
# Get the cell value
cell_value = final_table.iloc[row, col]
# Set the cell value to the corresponding cell in the table
self.indel_table.SetCellValue(row, col, str(cell_value))
# Update table layout
self.indel_table.Refresh()
self.indel_table.AutoSizeColumns()
def on_clear_data_button_clicked(self, event):
# Clear data in expression table
vtype = self.variant_type_radio.GetSelection()
if vtype == 0 :
num_rows = self.snp_table.GetNumberRows()
self.snp_table.ClearGrid()
self.snp_table.DeleteRows(0, num_rows)
self.snp_table.AutoSizeColumns()
elif vtype == 1 :
num_rows = self.indel_table.GetNumberRows()
self.indel_table.ClearGrid()
self.indel_table.DeleteRows(0, num_rows)
self.indel_table.AutoSizeColumns()
# Clear file input
self.folder_path_input.SetValue("")
self.Layout()
class NeuroVar(wx.Frame):
def __init__(self):
super().__init__(parent=None, title='NeuroVar')
# Create a panel and notebook (tabs holder)
p = wx.Panel(self)
nb = wx.Notebook(p)
# Create the tab windows
Biomarker = TabOne(nb)
Expression = TabTwo(nb)
Variants = TabThree(nb)