__main__.py 3.2 KB
Newer Older
Yan's avatar
Yan committed
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
#!/usr/bin/env python3

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.widgets import SpanSelector
from PyQt5 import QtCore
from PyQt5 import QtWidgets
from rawParse import load_raw
import graph_tools as gt
import file_tools as ft
import os.path
import sys
import matplotlib
import numpy as np
import logging
matplotlib.use("Qt5Agg")




if __name__ == "__main__":
    # ds for data_set, ms for mass_spec_dataset, chrom for chrom_dataset
    ds = dict(chrom_dat=None, masses=None, matrix=None)
    ms = dict(x=[0], y=[0], line=None, annotation=[],
              name="Spectrum", xlabel="m/z", ylabel="ion count")
    chrom = dict(x=[0], y=[0], line=None, t_start=None, t_end=None,
                 name="Chromatogram", xlabel="time(min)",
                 ylabel="total ion count")
    filename = [None]

    p_logger = logging.getLogger('parseLogger')
    logging.basicConfig()
    p_logger.setLevel("WARN")

    graph = Figure(figsize=(5, 4), dpi=100)
    graph.patch.set_facecolor("None")

    chromatogram = graph.add_subplot(211, facecolor=(1, 1, 1, 0.8))
    spectrum = graph.add_subplot(212, facecolor=(1, 1, 1, 0.8))
    graph.tight_layout()

    mpl_canvas = FigureCanvas(graph)
    mpl_canvas.setStyleSheet("background-color:transparent;")
    mpl_canvas.setAutoFillBackground(False)
    mpl_canvas.setFocusPolicy(QtCore.Qt.ClickFocus)
    
    gt.pan_factory(chromatogram)
    gt.zoom_factory(chromatogram, 1.15)
    gt.pan_factory(spectrum, ms)
    gt.zoom_factory(spectrum, 1.15, ms)
    gt.mass_selector = SpanSelector(
        spectrum, lambda x_min, x_max: gt.pick_masses(
            x_min, x_max, spectrum, ms),
        'horizontal', useblit=True, rectprops=dict(
            alpha=0.15, facecolor='purple'), button=3)
    gt.time_selector = SpanSelector(
         chromatogram, lambda x_min, x_max: gt.pick_times(
             x_min, x_max, spectrum, ds, chromatogram, ms, chrom), 
         'horizontal', useblit=True, rectprops=dict(
             alpha=0.15, facecolor='purple'), button=3)

    app = QtWidgets.QApplication(sys.argv)
    main_window = QtWidgets.QMainWindow()
    main_window.setWindowTitle("Prasopes")

    file_menu = QtWidgets.QMenu('&File', main_window)
    main_window.menuBar().addMenu(file_menu)
    file_menu.addAction('&Open..', lambda: ft.open_file(
        chromatogram, spectrum, ds, ms, filename, chrom),
        QtCore.Qt.CTRL + QtCore.Qt.Key_O)
    file_menu.addAction('&Export..', lambda: ft.export(
        ms, chrom, filename), QtCore.Qt.CTRL + QtCore.Qt.Key_E)
    file_menu.addAction('&Quit', main_window.close,
                        QtCore.Qt.CTRL + QtCore.Qt.Key_Q)

    main_widget = QtWidgets.QWidget(main_window)
    main_window.setCentralWidget(main_widget)

    layout = QtWidgets.QVBoxLayout(main_widget)
    layout.addWidget(mpl_canvas)
    mpl_canvas.setFocus()

    if len(sys.argv) == 2:
        raw_file = sys.argv[1]
        filename[0] = raw_file
        ds['chrom_dat'], ds['masses'], ds['matrix'] = load_raw(raw_file)
        gt.populate(chromatogram, spectrum, ds, ms, chrom)
    else:
        gt.pop_plot(spectrum, ms)
        gt.pop_plot(chromatogram, chrom)

    main_window.show()
    sys.exit(app.exec_())