-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
1439 lines (1106 loc) · 58.6 KB
/
main.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 sys, os
import time
import json
import numpy as np
import pandas as pd
import math
import webbrowser
from PyQt6.QtWidgets import *
import PyQt6.QtWidgets as QtWidgets
from PyQt6.QtGui import QIcon, QAction, QPalette, QColor
import PyQt6.QtGui as QtGui
from PyQt6.QtCore import Qt, QFile, QTextStream
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
from matplotlib.patches import Rectangle
import matplotlib.pyplot as plt
# import spectrum_utils.plot as sups
import draw_functions.spectrum_plot as sup # spectrum_util을 내 로컬로 가져온 것
import spectrum_utils.spectrum as sus
# custom modules
import help_functions.process_data as process_data
import help_functions.terminal as terminal
import help_functions.lib_parser as lib_parser
import help_functions.process_sequence as process_sequence
import help_functions.filtering_list as filtering_list
import control_exception
import help_functions.control_table as control_table
import draw_functions.mass_error as mass_error
from draw_functions import draw_terminal_line
from dlgs import (input_dialog, filtering_dialog, run_config_dialog)
from custom_class.filter import FilterInfo
import help_functions.lib_scanner as lib_scanner
sys.path.append(os.getcwd())
cur_path = os.path.dirname(os.path.realpath(__file__))
class GraphWrapperWidget(QWidget):
def __init__(self):
super().__init__()
# _mirror plot custom widget_ start
class MirrorFigureCanvas(FigureCanvas):
lock = None
def __init__(self, figure=None, app=None):
self.myapp = app
figure.canvas.mpl_connect("button_press_event", self.click)
figure.canvas.mpl_connect("button_release_event", self.release)
figure.canvas.mpl_connect("motion_notify_event", self.moved)
self.start, self.end = 0, 0
super().__init__(figure = figure)
def mouseDoubleClickEvent(self, event):
plt.xlim([0, self.myapp.max_peptide_mz])
self.myapp.graph_x_start, self.myapp.graph_x_end = -1, -1
self.myapp.canvas.draw()
return super().mouseDoubleClickEvent(event)
def click(self, event):
self.start = event.xdata
def release(self, event):
self.end = event.xdata
if self.end == None or self.start == None:
return
if self.end < self.start:
tmp = self.start
self.start = self.end
self.end = tmp
if self.end - self.start <= 5:
return
plt.xlim([self.start, self.end])
self.myapp.graph_x_start, self.myapp.graph_x_end = self.start, self.end
self.myapp.canvas.draw()
def moved(self, event):
x, y = event.xdata, event.ydata
if not (x and y):
self.myapp.loc_label.setText("")
return
self.myapp.loc_label.setText("m/z = "+str(round(x, 2))+", intensity = "+str(abs(round(y, 2))))
# _mirror plot custom widget_ end
class MyApp(QMainWindow):
def __init__(self):
super().__init__()
self.current_seq, self.top_seq='A', 'A'
self.frag_tol, self.peptide_tol = 0.02, 10
self.filtering_threshold = 0
self.cur_idx, self.cur_row = -1, 0
self.all_qscore, self.filenames, self.results = [], [], []
self.spectrum_query, self.spectrum_answer = None, None
self.is_list_visible = True
self.target_lib_files, self.decoy_lib_files = None, None
self.data,self.qidx_to_ridx = dict(), dict() # filename : 파싱된 결과(dict) 리스트
self.loc_label = QLabel("") #그래프 내에 현재 마우스 위치 정보 label
self.max_peptide_mz = 100 # 초기값 100
self.filter_info = FilterInfo(self) # filtering 정보 (싱클톤 인스턴스)
self.graph_x_start, self.graph_y_start = -1, -1 ## 그래프의 확대, (x axis 값, -1 -1 이면 기본크기)
self.c13_isotope_tol_min, self.c13_isotope_tol_max = 0, 0
self.target_lib, self.decoy_lib = dict(), dict()
self.project_file_name = None
self.top_graph_label, self.bottom_graph_label = QLabel("top: "), QLabel("Bottom: ")
self.match_info_layout = QHBoxLayout()
self.column_headers_origin = ['FileName', 'Index', 'ScanNo', 'Title', 'PMZ', 'Charge', 'Peptide', 'CalcMass', 'SA', 'QScore', '#Ions', '#Sig', 'ppmError', 'C13', 'ExpRatio', 'ProtSites', 'LibrarySource']
# table 오름차순 여부 초기화
self.is_ascending = []
for i in range(len(self.column_headers_origin)):
self.is_ascending.append(True)
spectrum_query = sus.MsmsSpectrum('', 0, 0, [], [])
spectrum_query.annotate_proforma('A', self.frag_tol, "Da", ion_types="by")
spectrum_answer = sus.MsmsSpectrum('', 0, 0, [], [])
spectrum_answer.annotate_proforma('A', self.frag_tol, "Da", ion_types="by")
self.fig,self.ax = plt.subplots(figsize=(15, 9))
sup.mirror(spectrum_answer, spectrum_answer, ax=self.ax)
self.sa_target, self.sa_decoy = [0 for i in range(50)], [0 for i in range(50)]
self.main_widget = QWidget() # Make main window
self.setCentralWidget(self.main_widget) # Main Window set center
self.resize(1200, 800) # Main Window Size
self.n_btn = QPushButton('N', self)
self.c_btn = QPushButton('C', self)
self.mass_error_btn = QCheckBox('mass error', self)
self.n_btn.setCheckable(False)
self.c_btn.setCheckable(False)
self.mass_error_btn.setCheckable(False)
self.peptide_change_text_box = QLineEdit()
self.peptide_change_text_box.setMinimumWidth(280)
self.peptide_change_btn = QPushButton('apply', self)
self.peptide_reset_btn = QPushButton('reset', self)
self.peptide_change_btn.clicked.connect(self.peptide_change_clicked)
self.peptide_reset_btn.clicked.connect(self.peptide_reset_clicked)
self.peptide_change_btn.setCheckable(False)
self.peptide_change_btn.setCheckable(False)
self.switch_btn = QCheckBox('switch mirror', self)
self.switch_btn.setCheckable(False)
self.switch_status = QLabel('top: query / bottom: library')
self.n_btn.toggled.connect(self.n_button)
self.c_btn.toggled.connect(self.c_button)
self.mass_error_btn.toggled.connect(self.mass_error_btn_clicked)
self.switch_btn.toggled.connect(self.switch_clicked)
# filtering reset btn
self.filter_reset_button = QPushButton('filter reset', self)
self.filter_reset_button.clicked.connect(self.filter_reset)
# tolerance
self.frag_tol_input = QLineEdit()
self.frag_tol_input.setText('0.02')
self.frag_tol_input.setFixedWidth(50)
self.frag_tol_btn = QPushButton('submit', self)
self.frag_tol_btn.clicked.connect(self.change_tol)
self.frag_tol_label = QLabel('tolerance(Da): ')
self.tab1 = self.ui1()
self.tab2 = self.ui2()
# # menubar
exitAction = QAction(QIcon(cur_path +'ui\\image\\exit.png'), 'Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(app.quit)
newProjectAction = QAction(QIcon(cur_path), 'New Project', self)
newProjectAction.triggered.connect(self.open_input_dlg)
openProjectAction = QAction(QIcon(cur_path), 'Open Project', self)
openProjectAction.triggered.connect(self.open_project_dlg)
configAction = QAction(QIcon(cur_path), 'View Config', self)
configAction.triggered.connect(self.open_config_dlg)
docAction = QAction(QIcon(cur_path), 'Document', self)
docAction.triggered.connect(lambda: webbrowser.open('https://github.com/clean2001/MS_GUI_PROJECT#devi-gui'))
# 리스트 단축키
listAction = QAction(QIcon(cur_path +'ui\\image\\exit.png'), 'Hide/Show List', self)
listAction.setShortcut('Ctrl+J')
listAction.triggered.connect(self.toggle_spectrum_list)
##
# _list filtering_
filteringAction = QAction(QIcon(cur_path +'ui\\image\\exit.png'), 'Filter', self)
filteringAction.triggered.connect(self.filtering_action)
# _list filtering_ end
self.statusBar()
self.menubar = self.menuBar()
self.menubar.setNativeMenuBar(False)
filemenu = self.menubar.addMenu('&File')
viewmenu = self.menubar.addMenu('&View')
docmenu = self.menubar.addMenu('&Document')
filemenu.addAction(newProjectAction)
filemenu.addAction(openProjectAction)
filemenu.addAction(configAction)
filemenu.addAction(exitAction)
viewmenu.addAction(filteringAction)
viewmenu.addAction(listAction)
docmenu.addAction(docAction)
##
self.initUI()
self.apply_style()
def apply_style(self):
self.n_btn.setObjectName('n_btn')
self.c_btn.setObjectName('c_btn')
try:
with open('./qstyle/style.qss', 'r') as f:
style = f.read()
app.setStyleSheet(style)
except:
print("err")
def Warning_event(self, warning_msg) :
QMessageBox.warning(self,'Erorr!',warning_msg)
def initUI(self):
left_layout = QHBoxLayout()
left_widget = QWidget()
left_widget.setLayout(left_layout)
self.right_widget = QTabWidget()
self.right_widget.tabBar().setObjectName("mainTab")
self.right_widget.addTab(self.tab1, 'View Spectra')
self.right_widget.addTab(self.tab2, 'Summary')
self.right_widget.setCurrentIndex(0)
left_outer = QVBoxLayout()
left_outer.addWidget(left_widget) # menubar
left_outer.setStretch(0, 0)
left_outer.addWidget(self.right_widget)
left_outer.setStretch(1, 0)
main_layout = QHBoxLayout()
sidebar = QVBoxLayout()
main_layout.addLayout(sidebar)
main_layout.addLayout(left_outer)
main_widget = QWidget()
main_widget.setLayout(main_layout)
self.setCentralWidget(main_widget)
self.n_btn.setMaximumWidth(50)
self.c_btn.setMaximumWidth(50)
# 색 적용 중
# qp = QPalette()
# qp.setColor(QPalette.ColorRole.Light, Qt.GlobalColor.white)
def button1(self):
self.right_widget.setCurrentIndex(0)
def button2(self):
self.right_widget.setCurrentIndex(1)
def mass_error_btn_clicked(self):
# mass_error 그래프 나타내는 함수
if self.mass_error_btn.isChecked():
plt.close()
for i in reversed(range(self.graph_main_layout.count())):
obj = self.graph_main_layout.itemAt(i).widget()
if obj is not None:
obj.deleteLater()
self.fig, self.ax = plt.subplots(figsize=(15, 9))
if self.switch_btn.isChecked():
self.fig = mass_error.mass_error_plot(self.spectrum_answer, self.spectrum_query)
else:
self.fig = mass_error.mass_error_plot(self.spectrum_query, self.spectrum_answer)
self.canvas = MirrorFigureCanvas(self.fig, self) # mirror plot
self.toolbar = NavigationToolbar(self.canvas, self) # tool bar
self.graph_main_layout.addWidget(self.canvas)
self.canvas.draw()
else:
query_filename = self.spectrum_list.item(self.cur_row, 0).text()
self.make_graph(query_filename, self.cur_idx)
s, e, n, c = 0, 1, 1.0, 1.1
if self.mass_error_btn.isChecked():
s, e, n, c = 4, 5, -0.8, -0.9
if self.n_btn.isChecked(): # 방금 체크 됨
self.n_btn.setStyleSheet("background-color: #191970")
n_terms = terminal.make_nterm_list(self.current_seq)
draw_terminal_line.draw_nterm_line(n_terms, self.top_seq, s, e, n)
if self.c_btn.isChecked():
c_terms = terminal.make_cterm_list(self.current_seq)
draw_terminal_line.draw_cterm_line(c_terms, self.top_seq, s, e, c)
self.canvas.draw()
def switch_clicked(self):
query_filename = self.spectrum_list.item(self.cur_row, 0).text()
if self.switch_btn.isChecked(): # 라이브러리가 위로
self.switch_status.setText('top: library / bottom: query')
else:
self.switch_status.setText('top: query / bottom: library')
self.make_graph(query_filename, self.cur_idx)
s, e, n, c = 0, 1, 1.0, 1.1
if self.mass_error_btn.isChecked():
s, e, n, c = 4, 5, -0.8, -0.9
if self.n_btn.isChecked(): # 방금 체크 됨
self.n_btn.setStyleSheet("background-color: #191970")
n_terms = terminal.make_nterm_list(self.current_seq)
draw_terminal_line.draw_nterm_line(n_terms, self.top_seq, s, e, n)
if self.c_btn.isChecked():
c_terms = terminal.make_cterm_list(self.current_seq)
draw_terminal_line.draw_cterm_line(c_terms, self.top_seq, s, e, c)
self.canvas.draw() # refresh plot
def n_button(self):
s, e, n, c = 0, 1, 1.0, 1.1
if self.mass_error_btn.isChecked():
s, e, n , c = 4, 5, -0.8, -0.9
if self.n_btn.isChecked(): # 방금 체크 됨
self.n_btn.setStyleSheet("background-color: #191970")
n_terms = terminal.make_nterm_list(self.current_seq)
draw_terminal_line.draw_nterm_line(n_terms, self.top_seq, s, e, n)
self.canvas.draw() # refresh plot
else:
self.n_btn.setStyleSheet("background-color: #1E90FF")
plt.close()
query_filename = self.spectrum_list.item(self.cur_row, 0).text()
self.make_graph(query_filename, self.cur_idx)
if self.c_btn.isChecked():
c_terms = terminal.make_cterm_list(self.current_seq)
draw_terminal_line.draw_cterm_line(c_terms, self.top_seq, s, e, c)
if self.graph_x_start != -1 and self.graph_x_end != -1:
plt.xlim(self.graph_x_start, self.graph_x_end)
def c_button(self):
s, e, n, c = 0, 1, 1.0, 1.1
if self.mass_error_btn.isChecked():
s, e, n , c = 4, 5, -0.8, -0.9
if self.c_btn.isChecked():
self.c_btn.setStyleSheet("background-color: #800000")#CD5C5C
c_terms = terminal.make_cterm_list(self.current_seq)
draw_terminal_line.draw_cterm_line(c_terms, self.top_seq, s, e, c)
self.canvas.draw() # refresh plot
else:
self.c_btn.setStyleSheet("background-color: #CD5C5C")
query_filename = self.spectrum_list.item(self.cur_row, 0).text()
self.make_graph(query_filename, self.cur_idx)
if self.n_btn.isChecked():
n_terms = terminal.make_nterm_list(self.current_seq)
draw_terminal_line.draw_nterm_line(n_terms, self.top_seq, s, e, n)
if self.graph_x_start != -1 and self.graph_x_end != -1:
plt.xlim([self.graph_x_start, self.graph_x_end])
self.canvas.draw() # refresh plot
def make_graph(self, filename:str, qidx:int):
ridx = int(self.qidx_to_ridx[filename + '_' + str(qidx)])
dict = self.data[filename][qidx]
rdict = self.result_data[self.results[0]][ridx]
# 라이브러리
lib, lib_file = None, None # lib is {num_peaks, offset}
charge = dict['charge']
seq = dict['seq']
seq = process_sequence.brace_modifications(seq) # 0723
seq = process_sequence.remove_modifications(seq)
lib_file_name = rdict['LibrarySource']
if "TARGET" in rdict['ProtSites']:
lib = self.target_lib[lib_file_name][str(seq)+'_'+str(charge)]
else:
lib = self.decoy_lib[lib_file_name][str(seq)+'_'+str(charge)]
seq = self.top_seq
seq = process_sequence.brace_modifications(self.top_seq)
self.current_seq = seq #terminal btn을 눌렀을 때 다시 그리기 위해 저장해놓는 것
query_filename = self.spectrum_list.item(self.cur_row, 0).text()
query_mz, query_intensity = lib_parser.parse_spectrum(query_filename, int(dict['offset']))
self.spectrum_query = sus.MsmsSpectrum(
dict['title'],
float(dict['pepmass']),
int(dict['charge']),
np.array(list(map(float, query_mz))),
np.array(list(map(float, query_intensity)))
)
self.spectrum_query.annotate_proforma(seq, self.frag_tol, "Da", ion_types="by")
# 이부분에서 offset으로 라이브러리를 열어서 mz, intensity를 파싱해서 리턴
lib_mz, lib_intensity = lib_parser.parse_lib(lib_file_name, lib['num_peaks'], lib['offset'])
self.spectrum_answer = sus.MsmsSpectrum(
dict['title'],
float(dict['pepmass']),
int(dict['charge']),
np.array(list(map(float, lib_mz))),
np.array(list(map(float, lib_intensity)))
)
self.spectrum_answer.annotate_proforma(seq, self.frag_tol, "Da", ion_types="by")
plt.close()
## mass error를 그리는 부분
if self.mass_error_btn.isChecked():
plt.close()
for i in reversed(range(self.graph_main_layout.count())):
obj = self.graph_main_layout.itemAt(i).widget()
if obj is not None:
obj.deleteLater()
self.fig, self.ax = plt.subplots(figsize=(15, 9))
if self.switch_btn.isChecked():
self.fig = mass_error.mass_error_plot(self.spectrum_answer, self.spectrum_query)
else:
self.fig = mass_error.mass_error_plot(self.spectrum_query, self.spectrum_answer)
self.canvas = MirrorFigureCanvas(self.fig, self) # mirror plot
self.graph_main_layout.addWidget(self.canvas)
self.canvas.draw()
return
##
self.fig, self.ax = plt.subplots(figsize=(15, 9))
if self.switch_btn.isChecked():
sup.mirror(self.spectrum_answer, self.spectrum_query, ax=self.ax)
else:
sup.mirror(self.spectrum_query, self.spectrum_answer, ax=self.ax)
for i in reversed(range(self.graph_main_layout.count())):
obj = self.graph_main_layout.itemAt(i).widget()
if obj is not None:
obj.deleteLater()
self.canvas = MirrorFigureCanvas(self.fig, self) # mirror plot
self.graph_main_layout.addWidget(self.canvas)
if self.graph_x_start != -1 and self.graph_x_end != -1:
plt.xlim([self.graph_x_start, self.graph_x_end])
self.canvas.draw()
def peptide_change_clicked(self):
peptide_seq, query_filename = '', ''
try:
peptide_seq = self.peptide_change_text_box.text()
query_filename = self.spectrum_list.item(self.cur_row, 0).text()
self.make_graph(query_filename, self.cur_idx)
s, e, n, c = 0, 1, 1.0, 1.1
if self.mass_error_btn.isChecked():
s, e, n, c = 4, 5, -0.8, -0.9
n_terms = terminal.make_nterm_list(peptide_seq)
if self.n_btn.isChecked(): # n terminal 표시
draw_terminal_line.draw_nterm_line(n_terms, peptide_seq, s, e, n)
if self.c_btn.isChecked(): # c terminal 표시
c_terms = terminal.make_cterm_list(peptide_seq)
draw_terminal_line.draw_cterm_line(c_terms, peptide_seq, s, e, c)
except:
print("line 521")
self.peptide_change_text_box.setText(self.top_seq)
s, e, n, c = 0, 1, 1.0, 1.1
if self.mass_error_btn.isChecked():
s, e, n, c = 4, 5, -0.8, -0.9
n_terms = terminal.make_nterm_list(self.top_seq)
if self.n_btn.isChecked(): # n terminal 표시
draw_terminal_line.draw_nterm_line(n_terms, self.top_seq, s, e, n)
if self.c_btn.isChecked(): # c terminal 표시
c_terms = terminal.make_cterm_list(self.top_seq)
draw_terminal_line.draw_cterm_line(c_terms, self.top_seq, s, e, c)
return
def peptide_change_clicked(self):
peptide_seq, query_filename = '', ''
try:
peptide_seq = self.peptide_change_text_box.text()
query_filename = self.spectrum_list.item(self.cur_row, 0).text()
self.current_seq, self.top_seq = peptide_seq, peptide_seq # make_graph 내부를 고치면서 수정한 부분
self.make_graph(query_filename, self.cur_idx)
s, e, n, c = 0, 1, 1.0, 1.1
if self.mass_error_btn.isChecked():
s, e, n, c = 4, 5, -0.8, -0.9
n_terms = terminal.make_nterm_list(peptide_seq)
if self.n_btn.isChecked(): # n terminal 표시
draw_terminal_line.draw_nterm_line(n_terms, peptide_seq, s, e, n)
if self.c_btn.isChecked(): # c terminal 표시
c_terms = terminal.make_cterm_list(peptide_seq)
draw_terminal_line.draw_cterm_line(c_terms, peptide_seq, s, e, c)
except:
print("line 562")
# 유효하지 않은 펩타이드
self.top_seq = self.spectrum_list.item(self.cur_row, 6).text() # make_graph 내부를 고치면서 수정한 부분
self.peptide_change_text_box.setText(self.top_seq)
self.make_graph(query_filename, self.cur_idx)
s, e, n, c = 0, 1, 1.0, 1.1
if self.mass_error_btn.isChecked():
s, e, n, c = 4, 5, -0.8, -0.9
n_terms = terminal.make_nterm_list(self.top_seq)
if self.n_btn.isChecked(): # n terminal 표시
draw_terminal_line.draw_nterm_line(n_terms, self.top_seq, s, e, n)
if self.c_btn.isChecked(): # c terminal 표시
c_terms = terminal.make_cterm_list(self.top_seq)
draw_terminal_line.draw_cterm_line(c_terms, self.top_seq, s, e, c)
plt.xlim(0, n_terms[-1])
# QMessageBox.warning(self,'Error','Invalid Peptide Sequence😵💫')
return
def peptide_reset_clicked(self):
peptide_seq, query_filename = '', ''
try:
peptide_seq = self.spectrum_list.item(self.cur_row, 6).text()
query_filename = self.spectrum_list.item(self.cur_row, 0).text()
except:
return
self.top_seq = self.spectrum_list.item(self.cur_row, 6).text() # make_graph 내부를 고치면서 수정한 부분
self.make_graph(query_filename, self.cur_idx)
s, e, n, c = 0, 1, 1.0, 1.1
if self.mass_error_btn.isChecked():
s, e, n, c = 4, 5, -0.8, -0.9
n_terms = terminal.make_nterm_list(peptide_seq)
if self.n_btn.isChecked(): # n terminal 표시
draw_terminal_line.draw_nterm_line(n_terms, peptide_seq, s, e, n)
if self.c_btn.isChecked(): # c terminal 표시
c_terms = terminal.make_cterm_list(peptide_seq)
draw_terminal_line.draw_cterm_line(c_terms, peptide_seq, s, e, c)
self.top_seq, self.current_seq = peptide_seq, peptide_seq
self.peptide_change_text_box.setText(self.top_seq)
def change_tol(self):
if control_exception.check_tolerence(self.frag_tol_input.text()):
tolerance = float(self.frag_tol_input.text())
else:
self.frag_tol_input.setText(str(self.frag_tol))
self.Warning_event('Invalid Value!😵💫')
return
if self.frag_tol == tolerance:
return
self.frag_tol = tolerance
query_filename = self.spectrum_list.item(self.cur_row, 0).text()
self.make_graph(query_filename, self.cur_idx)
s, e, n, c = 0, 1, 1.0, 1.1
if self.mass_error_btn.isChecked():
s, e, n, c = 4, 5, -0.8, -0.9
n_terms = terminal.make_nterm_list(self.current_seq)
if self.n_btn.isChecked(): # n terminal 표시
draw_terminal_line.draw_nterm_line(n_terms, self.top_seq, s, e, n)
if self.c_btn.isChecked(): # c terminal 표시
c_terms = terminal.make_cterm_list(self.current_seq)
draw_terminal_line.draw_cterm_line(c_terms, self.top_seq, s, e, c)
def ui1(self):
self.graph_outer_layout = QVBoxLayout()
self.graph_main_layout = QVBoxLayout() # 캔버스와 툴바가 들어가는 부분, 바뀌는 부분
self.spectrum_list_layout = QVBoxLayout() # 파일을 열었을 때 바뀌는 부분
self.terminal_btn_layout = QHBoxLayout()
filter_hbox = QHBoxLayout()
top_sp = QVBoxLayout()
bottom_sp = QVBoxLayout()
self.splitter = QSplitter()
self.top_label = QLabel('0 spectra')
filter_hbox.addWidget(self.top_label)
filter_hbox.addStretch(40)
filter_hbox.addWidget(self.filter_reset_button)
top_sp.addLayout(filter_hbox)
self.graph_outer_layout.addStretch(5)
self.spectrum_list = QTableWidget() # spectrum list
self.spectrum_list.setRowCount(0)
self.spectrum_list.setColumnCount(17)
self.spectrum_list.itemClicked.connect(self.chkItemChanged)
self.spectrum_list.currentItemChanged.connect(self.chkItemChanged)
# headers
self.column_headers_with_direction = control_table.add_direction_to_table(self.column_headers_origin, self.is_ascending)
self.spectrum_list.setHorizontalHeaderLabels(self.column_headers_with_direction)
self.spectrum_list_layout.addWidget(self.spectrum_list)
top_sp.addLayout(self.spectrum_list_layout)
self.terminal_btn_layout.addWidget(self.n_btn)
self.terminal_btn_layout.addWidget(self.c_btn)
self.terminal_btn_layout.addStretch(5)
self.terminal_btn_layout.addWidget(self.peptide_change_text_box)
self.terminal_btn_layout.addWidget(self.peptide_change_btn)
self.terminal_btn_layout.addWidget(self.peptide_reset_btn)
self.terminal_btn_layout.addStretch(5)
self.terminal_btn_layout.addWidget(self.switch_btn)
self.terminal_btn_layout.addWidget(self.switch_status)
self.terminal_btn_layout.addStretch(4)
self.terminal_btn_layout.addWidget(self.mass_error_btn)
self.terminal_btn_layout.addStretch(1)
self.terminal_btn_layout.addWidget(self.frag_tol_label)
self.terminal_btn_layout.addWidget(self.frag_tol_input)
self.terminal_btn_layout.addWidget(self.frag_tol_btn)
bottom_sp.addLayout(self.terminal_btn_layout)
# 매치에 대한 정보를 표시
self.match_info_query_file_name, self.match_info_scan_no, self.match_info_pmz, self.match_info_charge, self.match_info_sa_score, self.match_info_qscore = QLabel(''), QLabel(''), QLabel(''), QLabel(''), QLabel(''), QLabel('')
self.match_info_layout.addWidget(self.match_info_query_file_name)
self.match_info_layout.addStretch(1)
self.match_info_layout.addWidget(self.match_info_scan_no)
self.match_info_layout.addStretch(1)
self.match_info_layout.addWidget(self.match_info_pmz)
self.match_info_layout.addStretch(1)
self.match_info_layout.addWidget(self.match_info_charge)
self.match_info_layout.addStretch(1)
self.match_info_layout.addWidget(self.match_info_sa_score)
self.match_info_layout.addStretch(1)
self.match_info_layout.addWidget(self.match_info_qscore)
self.match_info_layout.addStretch(1)
bottom_sp.addLayout(self.match_info_layout)
self.canvas = MirrorFigureCanvas(self.fig, self) # mirror plot
self.canvas.setMinimumHeight(200) # 잠시 없앰
self.graph_main_layout.addWidget(self.canvas)
bottom_sp.addLayout(self.graph_main_layout)
main = QWidget()
## self.splitter를 위한 wrapper
wrapper_widget1 = QWidget()
self.wrapper_widget2 = GraphWrapperWidget()
wrapper_widget1.setLayout(top_sp)
self.wrapper_widget2.setLayout(bottom_sp)
self.inner_sp = QSplitter()
self.inner_sp.addWidget(self.wrapper_widget2)
self.splitter.addWidget(wrapper_widget1)
self.splitter.addWidget(self.inner_sp)
self.splitter.setOrientation(Qt.Orientation.Vertical)
self.graph_outer_layout.addWidget(self.splitter)
self.splitter.setSizes([218, 445])
self.graph_outer_layout.addWidget(self.loc_label)
# 더블클릭하면 home으로 돌아감
main.setLayout(self.graph_outer_layout)
return main
def graph_event(self) :
QDialog.exec(self)
def chkItemChanged(self): # index를 반환 받아서 그걸로 그래프 새로 그리기
self.graph_x_start, self.graph_x_end = -1, -1
# 해제된 항목의 색을 돌려놓기
if self.spectrum_list.item(self.cur_row, 0):
for i in range(0, 16):
item = self.spectrum_list.item(self.cur_row, i)
item.setBackground(QColor(0, 0, 0, 0)) # alpha = 0
self.cur_row = self.spectrum_list.currentRow()
if self.spectrum_list.item(self.cur_row, 1):
qidx = int(self.spectrum_list.item(self.cur_row, 1).text())
if self.cur_row >= 0:
cur_query_file = self.spectrum_list.item(self.cur_row, 0).text()
self.n_btn.setCheckable(True)
self.c_btn.setCheckable(True)
self.mass_error_btn.setCheckable(True)
self.switch_btn.setCheckable(True)
else:
return
query_filename = self.spectrum_list.item(self.cur_row, 0).text()
result_filename = query_filename.split('.')[0] + '_deephos.tsv'
self.currenst_seq = process_sequence.brace_modifications(self.result_data[result_filename][int(self.qidx_to_ridx[query_filename + '_' + str(qidx)])]['Peptide'])
self.current_seq = process_sequence.remove_modifications(self.current_seq)
self.cur_idx = qidx
if self.spectrum_list.item(self.spectrum_list.currentRow(), 0):
# row의 색깔을 바꾸기
for i in range(0, 16):
item = self.spectrum_list.item(int(self.spectrum_list.currentRow()), i)
item.setBackground(QColor(72, 123, 225, 70))
self.top_seq = self.spectrum_list.item(self.cur_row, 6).text()
self.make_graph(cur_query_file, self.cur_idx)
s, e, n, c = 0, 1, 1.0, 1.1
if self.mass_error_btn.isChecked():
s, e, n, c = 4, 5, -0.8, -0.9
n_terms = terminal.make_nterm_list(self.current_seq)
if self.n_btn.isChecked(): # n terminal 표시
draw_terminal_line.draw_nterm_line(n_terms, self.top_seq, s, e, n)
if self.c_btn.isChecked(): # c terminal 표시
c_terms = terminal.make_cterm_list(self.current_seq)
draw_terminal_line.draw_cterm_line(c_terms, self.top_seq, s, e, c)
self.ax.set_xlim(0, n_terms[-1])
self.max_peptide_mz = n_terms[-1]
self.peptide_change_text_box.setText(self.top_seq)
# 매치 정보를 표시
self.set_match_info()
def onHeaderClicked(self, logicalIndex):
table_header_label = ['File', 'Index', 'ScanNo', 'Title', 'PMZ', 'Charge', 'Peptide', 'CalcMass', 'SA', 'QScore', '#Ions', '#Sig', 'ppmError', 'C13', 'ExpRatio', 'ProtSites', 'LibrarySource']
if self.is_ascending[logicalIndex]: # ascending order
self.result_data_list.sort(key=lambda x: x[table_header_label[logicalIndex]])
else:
self.result_data_list.sort(key=lambda x: x[table_header_label[logicalIndex]], reverse=True)
self.is_ascending[logicalIndex] = not self.is_ascending[logicalIndex] # 반전
self.column_headers_with_direction = control_table.add_direction_to_table(self.column_headers_origin, self.is_ascending)
self.spectrum_list.setHorizontalHeaderLabels(self.column_headers_with_direction)
self.refilter_spectrums()
def ui2(self):
self.summary_layout = QGridLayout()
main_layout = QVBoxLayout()
main_layout.addWidget(QLabel('tab 2 Summary'))
main_layout.addStretch(5)
main = QWidget()
# SA
self.sa_canvas = FigureCanvas(Figure(figsize=(4, 3)))
self.sa_ax = self.sa_canvas.figure.subplots()
self.sa_ax.hist([])
# QScore
self.qs_canvas = FigureCanvas(Figure(figsize=(4, 3)))
self.qs_ax = self.qs_canvas.figure.subplots()
self.qs_ax.hist([])
# ppm error
self.ppm_canvas = FigureCanvas(Figure(figsize=(4, 3)))
self.ppm_ax = self.ppm_canvas.figure.subplots()
self.ppm_ax.boxplot([])
# number of charge
self.charge_canvas = FigureCanvas(Figure(figsize=(4, 3)))
self.charge_ax = self.charge_canvas.figure.subplots()
self.charge_ax.hist([])
self.charge_ax.set_ylabel('# of charge')
# peptide length
self.plength_canvas = FigureCanvas(Figure(figsize=(4, 3)))
self.plength_ax = self.plength_canvas.figure.subplots()
self.plength_ax.hist([])
self.plength_ax.set_ylabel('# of spectra')
self.summary_layout.addWidget(self.sa_canvas, 0, 0)
self.summary_layout.addWidget(self.qs_canvas, 0, 1)
self.summary_layout.addWidget(self.ppm_canvas, 0, 2)
self.summary_layout.addWidget(self.charge_canvas, 1, 0)
self.summary_layout.addWidget(self.plength_canvas, 1, 1)
main.setLayout(self.summary_layout)
return main
def check_spectrum_item(self, cur):
fi = self.filter_info
# 1. 파일 이름을 필터링 -> str
if fi.filename:
if not fi.filename in cur['File']:
return False
# 2. 인덱스 필터링 -> int
if fi.index:
if int(fi.index[0]) > 0 and int(cur['Index']) < int(fi.index[0]):
return False
if int(fi.index[1]) > 0 and int(cur['Index']) > int(fi.index[1]):
return False
# 3. ScanNo 필터링 -> int
if fi.scanno:
if int(fi.scanno[0]) > 0 and int(cur['ScanNo']) < int(fi.scanno[0]):
return False
if int(fi.scanno[1]) > 0 and int(cur['ScanNo']) > int(fi.scanno[1]):
return False
# 4. Title 필터링 -> str
if fi.title:
if not fi.title in cur['Title']:
return False
# 5. PMZ 필터링 -> float
if fi.pmz:
if float(fi.pmz[0]) > 0 and float(cur['PMZ']) < float(fi.pmz[0]):
return False
if float(fi.pmz[1]) > 0 and float(cur['PMZ']) > float(fi.pmz[1]):
return False
# 6. Charge 필터링 -> int
if fi.charge:
if int(fi.charge[0]) > 0 and int(cur['Charge']) < int(fi.charge[0]):
return False
if int(fi.charge[1]) > 0 and int(cur['Charge']) > int(fi.charge[1]):
return False
# 7. Peptide 필터링 -> str
if fi.peptide:
if not fi.peptide in cur['Peptide']:
return False
# 8. CalcMass 필터링 -> float
if fi.calcmass:
if float(fi.calcmass[0]) > 0 and float(cur['CalcMass']) < float(fi.calcmass[0]):
return False
if float(fi.calcmass[1]) > 0 and float(cur['CalcMass']) > float(fi.calcmass[1]):
return False
# 9. SA 필터링 -> float
if fi.sa:
if float(fi.sa[0]) > 0 and float(cur['SA']) < float(fi.sa[0]):
return False
if float(fi.sa[1]) > 0 and float(cur['SA']) > float(fi.sa[1]):
return False
# 10. QScore 필터링 -> float
if fi.qscore:
if float(fi.qscore[0]) > 0 and float(cur['QScore']) < float(fi.qscore[0]):
return False
if float(fi.qscore[1]) > 0 and float(cur['QScore']) > float(fi.qscore[1]):
return False
# 11. #Ions 필터링 -> int
if fi.ions:
if int(fi.ions[0]) > 0 and int(cur['#Ions']) < int(fi.ions[0]):
return False
if int(fi.ions[1]) > 0 and int(cur['#Ions']) > int(fi.ions[1]):
return False
# 12. #Sig 필터링 -> int
if fi.sig:
if int(fi.sig[0]) > 0 and int(cur['#Sig']) < int(fi.sig[0]):
return False
if int(fi.sig[1]) > 0 and int(cur['#Sig']) > int(fi.sig[1]):
return False
# 13. ppmError -> float
if fi.ppmerror:
if float(fi.ppmerror[0]) > 0 and float(cur['ppmError']) < float(fi.ppmerror[0]):
return False
if float(fi.ppmerror[1]) and float(cur['ppmError']) > float(fi.ppmerror[1]):
return False
# 14. C13 -> float
if fi.c13:
if float(fi.c13[0]) > 0 and float(cur['C13']) < float(fi.c13[0]):
return False
if float(fi.c13[1]) > 0 and float(cur['C13']) > float(fi.c13[1]):
return False
# 15. expRatio -> float
if fi.expratio:
if float(fi.expratio[0]) > 0 and float(cur['ExpRatio']) < float(fi.expratio[0]):
return False
if float(fi.expratio[1]) > 0 and float(cur['ExpRatio']) > float(fi.expratio[1]):
return False
# 16. ProSites -> str
if fi.protsites:
if not fi.protsites in cur['ProtSites']:
return False
return True
def refilter_spectrums(self):
idx = 0
self.spectrum_list.setRowCount(len(self.all_qscore))
if not len(self.all_qscore):
return
for i in range(0, len(self.result_data_list)):
cur_result = self.result_data_list[i]
if not self.check_spectrum_item(cur_result):
continue
qidx = int(cur_result['Index'])
seq = cur_result['Peptide']
charge = cur_result['Charge']
seq = process_sequence.brace_modifications(seq) # 0723
seq = process_sequence.remove_modifications(seq)
charge = cur_result['Charge']
lib_file_name = cur_result['LibrarySource']
if 'TARGET' in cur_result['ProtSites']:
match = str(cur_result['ProtSites'].replace('\n', '')) + "_" + str(self.target_lib[lib_file_name][str(seq)+'_'+str(charge)]['index'])
else: