Commit e4b5c834 authored by Yan's avatar Yan
Browse files

Fix for export malfunction, minor fixes

parent 668f56ff
......@@ -127,12 +127,15 @@ def pick_times(x_min, x_max, mpl_spectrum, data_set, mpl_chromatogram,
else:
start_scan -=1
end_scan = start_scan + 2
slims = [mpl_spectrum.get_xlim(),mpl_spectrum.get_ylim()]
mpl_spectrum.clear()
annotations.clear()
mass_spect['x'] = data_set['masses']
mass_spect['y'] = np.mean(data_set['matrix'][start_scan:end_scan]
, axis=0)
spectrum_plot(spectrum, mass_spect['x'], mass_spect['y'], annotations)
spectrum_plot(mpl_spectrum, mass_spect['x'], mass_spect['y'], annotations)
mpl_spectrum.set_xlim(slims[0])
mpl_spectrum.set_ylim(slims[1])
mpl_chromatogram.clear()
chrom_plot(mpl_chromatogram, data_set['chrom_dat'][0, :],
data_set['chrom_dat'][1, :])
......@@ -212,9 +215,11 @@ def ann_spec(ms_spec, mass, intensities, annotations, ann_limit=0.01):
s_peaks = sub_peaks(peaks, mass, intensities,
ms_spec.get_xlim()[1] - ms_spec.get_xlim()[0],
ms_spec.get_ylim()[1] - ms_spec.get_ylim()[0])
#delete objects from the spectra
for intensity in annotations:
intensity.remove()
#remove them from tracking
annotations.clear()
for i in s_peaks:
......@@ -222,41 +227,42 @@ def ann_spec(ms_spec, mass, intensities, annotations, ann_limit=0.01):
'{0:.2f}'.format(mass[i]), xy=(mass[i], intensities[i]),
textcoords='data'))
def spectrum_plot(spc, mass, intensity,an):
def pop_plot(plot, x_val, y_val, labels, annotation=False):
"""Define and populate plot"""
line = plot.plot(x_val, y_val)
plot.set_title(labels['name'], loc ="right")
plot.set_xlabel(labels['x'])
plot.set_ylabel(labels['y'])
plot.set_ylim(plot.get_ylim()[1] * -0.01,
plot.get_ylim()[1] * 1.1)
plot.ticklabel_format(scilimits=(0, 0), axis='y')
if annotation is not False:
ann_spec(plot, x_val, y_val, annotation)
def spectrum_plot(spc, mass, intensity, an):
"""Define and populate spectrum"""
spc.plot(mass, intensity)
spc.set_title("Spectrum:", loc ="right")
spc.set_xlabel("m/z")
spc.set_ylabel("ion count")
spc.set_ylim(spc.get_ylim()[1] * -0.01, )
spc.ticklabel_format(scilimits=(0, 0), axis='y')
ann_spec(spc, mass, intensity, an)
pop_plot(spc, mass, intensity, dict(
name="Spectrum",x="m/z",y="ion count"), an)
def chrom_plot(chrom, times, tic):
"""Define and populate chromatogram"""
chrom.plot(times, tic)
chrom.set_ylim(chrom.get_ylim()[1] * -0.011,
chrom.get_ylim()[1] * 1.1)
chrom.set_title("Chromatogram:", loc ="right")
chrom.set_xlabel("time (min)")
chrom.set_ylabel("total ion count")
chrom.ticklabel_format(scilimits=(0, 0), axis='y')
pop_plot(chrom, times, tic, dict(
name="Chromatogram",x="time(min)",y="total ion count"))
def open_file(chrom, spc, d_set, time_sel, an, ms_s, t, fn):
"""Returns chromatogram, masses and ion intensities"""
filename=QtWidgets.QFileDialog.getOpenFileName(
fn[0]=QtWidgets.QFileDialog.getOpenFileName(
caption = "Open spectrum",
filter="Finnigan RAW files (*.raw, *.RAW)")[0]
if filename is '':
if fn[0] is '':
return
fn = filename
d_set['chrom_dat'], d_set['masses'], d_set['matrix'] \
= load_raw(filename)
= load_raw(fn[0])
populate(chrom, spc, d_set, time_sel, an, ms_s, t)
def export(mass_spec, t, filename):
def export(mass_spec, t, fn):
"""exports the chromatogram into the .dat file format"""
if filename is None:
if fn[0] is None:
QtWidgets.QMessageBox.warning(
main_window, "Export spectrum",
"Nothing to export, cancelling request")
......@@ -282,7 +288,7 @@ def export(mass_spec, t, filename):
expf.write("mass ion_count\n"
"m/z\n"
"{}_{:.4}-{:.4}_minutes_of_the_aquisition\n".format(
os.path.basename(filename),
os.path.basename(fn[0]),
t['start'], t['end']))
for i in range(len(mass_spec['x'])):
expf.write("{} {}\n".format(
......@@ -296,7 +302,7 @@ if __name__=="__main__":
#mass spectrometry set
ms = dict(x=None,y=None)
times = dict(start=None,end=None)
filename = None
filename = [None]
p_logger = logging.getLogger('parseLogger')
logging.basicConfig()
......@@ -353,7 +359,7 @@ if __name__=="__main__":
if len(sys.argv) == 2:
raw_file=sys.argv[1]
filename=raw_file
filename[0]=raw_file
ds['chrom_dat'],ds['masses'],ds['matrix'] = load_raw(raw_file)
populate(chromatogram, spectrum, ds, timeSelector, annotation,
ms, times)
......
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