Commit 668f56ff authored by Yan's avatar Yan
Browse files

Export function minor cleanup

parent 202f986f
......@@ -4,6 +4,8 @@ Prasopes is a free and open source Thermo/Finnigan .RAW spectra viewer. It is an
## Usage
If running from cmdline, the first argument is taken as a spectrum file. Otherwise use File -> Open or Ctrl+O to open a spectrum.
For exporting a spectrum use File -> Export or Ctrl+E.
## GUI control ##
* **Doubleclick** resets active graph
......
......@@ -113,7 +113,7 @@ def pick_times(x_min, x_max, mpl_spectrum, data_set, mpl_chromatogram,
if start_scan == end_scan:
if start_scan == 0:
end_scan=1
elif start_scan == None:
elif start_scan is None:
end_scan=len(data_set['chrom_dat'][0, :])
start_scan=end_scan-1
else:
......@@ -257,7 +257,9 @@ def open_file(chrom, spc, d_set, time_sel, an, ms_s, t, fn):
def export(mass_spec, t, filename):
"""exports the chromatogram into the .dat file format"""
if filename is None:
print("Nothing to export, cancelling request")
QtWidgets.QMessageBox.warning(
main_window, "Export spectrum",
"Nothing to export, cancelling request")
return
exp_f_name=QtWidgets.QFileDialog.getSaveFileName(
caption = "Export spectrum",
......@@ -265,24 +267,27 @@ def export(mass_spec, t, filename):
if exp_f_name is '':
return
else:
#fix for Qt5 "Feature"
if exp_f_name[-4:] != '.dat':
exp_f_name = exp_f_name + ".dat"
if os.path.isfile(exp_f_name):
quest = QtWidgets.QMessageBox.warning(
main_window , "Export spectrum",
"{} already exists.\n Do you want to replace it?".\
format(os.path.basename(exp_f_name)),
QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No)
main_window , "Export spectrum",
"{} already exists.\n Do you want to replace it?".\
format(os.path.basename(exp_f_name)),
QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No)
if(hex(quest)) == "0x10000":
return
expf=open(exp_f_name,'w')
expf.write("mass ion_count\n"
"m/z\n"
"{}_{:.4}-{:.4}_minutes_of_the_aquisition\n".format(
filename,t['start'],times['end']))
os.path.basename(filename),
t['start'], t['end']))
for i in range(len(mass_spec['x'])):
expf.write("{} {}\n".format(mass_spec['x'][i],mass_spec['y'][i]))
expf.close
expf.write("{} {}\n".format(
mass_spec['x'][i],mass_spec['y'][i]))
expf.close()
if __name__=="__main__":
......
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