Commit c5e759b7 authored by Yan's avatar Yan
Browse files

Cleaned-up after project-tree creation

parent d42e1cf4
......@@ -5,17 +5,21 @@ 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
from rawprasslib import load_raw
import prasopes.graphtools as gt
import prasopes.filetools as ft
import sys
import matplotlib
import numpy as np
import logging
matplotlib.use("Qt5Agg")
def load_file(chrom_plot, spc, d_set, ms_s, fn, chrom_s):
"""populates dataset and plots it"""
lf = ft.open_dial(d_set)
if lf is not None:
gt.populate(chrom_plot, spc, d_set, ms_s, chrom_s)
fn[0] = lf
if __name__ == "__main__":
......@@ -65,11 +69,12 @@ if __name__ == "__main__":
file_menu = QtWidgets.QMenu('&File', main_window)
main_window.menuBar().addMenu(file_menu)
file_menu.addAction('&Open..', lambda: ft.open_file(
file_menu.addAction('&Open..', lambda: load_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('&Export..', lambda: ft.export_dial(
ms, chrom, filename, main_window),
QtCore.Qt.CTRL + QtCore.Qt.Key_E)
file_menu.addAction('&Quit', main_window.close,
QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
......
from PyQt5 import QtCore
from PyQt5 import QtWidgets
from rawParse import load_raw
from rawprasslib import load_raw
import os.path
import logging
import graph_tools as gt
def open_file(chrom_plot, spc, d_set, ms_s, fn, chrom_s):
"""Returns chromatogram, masses and ion intensities"""
fn[0] = QtWidgets.QFileDialog.getOpenFileName(
def open_dial(d_set):
"""Populates dataset, returns filename"""
filename = QtWidgets.QFileDialog.getOpenFileName(
caption="Open spectrum",
filter="Finnigan RAW files (*.raw, *.RAW)")[0]
if fn[0] is not'':
if filename is not'':
d_set['chrom_dat'], d_set['masses'], d_set['matrix'] \
= load_raw(fn[0])
gt.populate(chrom_plot, spc, d_set, ms_s, chrom_s)
= load_raw(filename)
return filename
else:
return None
def export(mass_spec, chrom_spec, fn):
def export_dial(mass_spec, chrom_spec, fn, main_window):
"""exports the chromatogram into the .dat file format"""
if fn[0] is None:
QtWidgets.QMessageBox.warning(
......
from matplotlib.widgets import SpanSelector
import matplotlib
import numpy as np
import logging
import file_tools as ft
def zoom_factory(axis, base_scale, plot_data=dict()):
def zoom_factory(axis, base_scale, plot_data=None):
"""returns zooming functionality to axis"""
def zoom_fun(event, pd, ax, scale):
"""zoom when scrolling"""
......@@ -24,14 +21,17 @@ def zoom_factory(axis, base_scale, plot_data=dict()):
data = event.ydata
new_top = data + (ax.get_ylim()[1] - data) \
* scale_factor
axis.set_ylim([new_top * -0.01, new_top])
ymin = -0.01
if type(pd) is dict and "c_ymin" in pd:
ymin = pd['c_ymin']
axis.set_ylim([new_top * ymin, new_top])
else:
data = event.xdata
x_left = data - ax.get_xlim()[0]
x_right = ax.get_xlim()[1] - data
ax.set_xlim([data - x_left * scale_factor,
data + x_right * scale_factor])
if "annotation" in pd:
if type(pd) is dict and "annotation" in pd:
ann_spec(event.inaxes, pd)
ax.figure.canvas.draw()
......@@ -41,16 +41,19 @@ def zoom_factory(axis, base_scale, plot_data=dict()):
event, plot_data, axis, base_scale))
def pan_factory(axis, plot=dict()):
def pan_factory(axis, plot=None):
"""pan spectrum when you press a button"""
def pan_fun(event, ax):
def pan_fun(event, ax, pd):
# rescale to origin if doubleclicked
if event.dblclick and event.inaxes == ax:
ax.get_figure()
ax.autoscale(True)
ax.set_ylim(ax.get_ylim()[1]*-0.01, ax.get_ylim()[1]*1.1)
if "annotation" in plot:
ann_spec(ax, plot)
if type(pd) is dict and "annotation" in pd:
ann_spec(ax, pd)
ymin = -0.01
if type(pd) is dict and "c_ymin" in pd:
ymin = pd['c_ymin']
ax.set_ylim(ax.get_ylim()[1]*ymin, ax.get_ylim()[1]*1.1)
ax.figure.canvas.draw()
# otherwise pan
elif event.button == 1 and event.inaxes == ax:
......@@ -61,23 +64,23 @@ def pan_factory(axis, plot=dict()):
id_release = fig.canvas.mpl_connect(
'button_release_event',
lambda action: drag_end(
action, id_drag, id_release, plot, ax))
action, id_drag, id_release, pd, ax))
def drag_fun(event, ax):
ax.drag_pan(1, 'x', event.x, event.y)
ax.figure.canvas.draw()
def drag_end(event, id_drag, id_release, chart, ax):
def drag_end(event, id_drag, id_release, pd, ax):
if event.button == 1:
fig.canvas.mpl_disconnect(id_drag)
fig.canvas.mpl_disconnect(id_release)
if "annotation" in chart:
ann_spec(ax, chart)
if type(pd) is dict and "annotation" in pd:
ann_spec(ax, pd)
ax.figure.canvas.draw()
fig = axis.get_figure()
fig.canvas.mpl_connect('button_press_event',
lambda action: pan_fun(action, axis))
lambda action: pan_fun(action, axis, plot))
def pick_masses(x_min, x_max, mpl_spectrum, mass_spect):
......@@ -131,6 +134,7 @@ def pick_times(x_min, x_max, mpl_spectrum, data_set, mpl_chromatogram,
dots_y = data_set['chrom_dat'][1, start_scan:end_scan]
mpl_chromatogram.plot(dots_x, dots_y, 'b.')
def ann_spec(ms_spec, msdata, ann_limit=0.01):
"""annotate spectrum
......@@ -189,6 +193,7 @@ def ann_spec(ms_spec, msdata, ann_limit=0.01):
'{0:.2f}'.format(msdata['x'][i]), xy=(msdata['x'][i], msdata['y'][i]),
textcoords='data'))
def pop_plot(plot, plot_data):
"""Define and populate plot"""
plot_data['line'] = plot.plot(plot_data['x'], plot_data['y'])
......@@ -201,6 +206,7 @@ def pop_plot(plot, plot_data):
if "annotation" in plot_data:
ann_spec(plot, plot_data)
def populate(mpl_chromatogram, mpl_spectrum, data_set,
mass_spect, chrom_spect):
"""populate the GUI plots with desired dataset"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment