Skip to content

Commit

Permalink
Updated spectrum viewer, truncated files are covered now, cleaned up …
Browse files Browse the repository at this point in the history
…code
  • Loading branch information
JB-MS committed Aug 21, 2019
1 parent bfd606a commit c92b944
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
2 changes: 1 addition & 1 deletion example_scripts/gzip_mzml.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3.4
#!/usr/bin/env python3

import sys
import os
Expand Down
50 changes: 24 additions & 26 deletions example_scripts/spectrum_viewer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python3

from __future__ import print_function

import sys
import os

Expand All @@ -17,6 +15,15 @@
print('loading run...')
run = pymzml.run.Reader(sys.argv[1])

all_ids = []
for spec_id, offset in run.info['offset_dict'].items():
try:
all_ids.append(int(spec_id))
except:
continue
FIRST_SPECTRUM_ID = min(all_ids)
LAST_SPECTRUM_ID = max(all_ids)

p = pymzml.plot.Factory()
p.new_plot()

Expand All @@ -27,10 +34,8 @@
tic_y.append(y)
max_tic = max(tic_y)


app = dash.Dash(__name__)


app.layout = html.Div([
dcc.Graph(
id='spectrum-plot',
Expand All @@ -46,7 +51,7 @@
),
dcc.Input(
id='spectrum-input-field',
value=1,
value=FIRST_SPECTRUM_ID,
type='text',
style={
'width': '20%',
Expand All @@ -64,15 +69,20 @@
),
])

spectra_buffer = {}

def get_spectrum(spectrum_id):
if spectrum_id not in spectra_buffer.keys():
spectrum = run[spectrum_id]
spectra_buffer[spectrum_id] = spectrum
return run[spectrum_id]

def sanitize_id(spectrum_id_from_input):
if spectrum_id_from_input not in [None, '']:
spectrum_id = int(spectrum_id_from_input)
else:
spectrum = spectra_buffer[spectrum_id]
return spectrum
spectrum_id = FIRST_SPECTRUM_ID
if spectrum_id < FIRST_SPECTRUM_ID:
spectrum_id = FIRST_SPECTRUM_ID
if spectrum_id > LAST_SPECTRUM_ID:
spectrum_id = LAST_SPECTRUM_ID
return spectrum_id


@app.callback(
Expand All @@ -82,12 +92,7 @@ def get_spectrum(spectrum_id):
]
)
def update_TIC(spectrum_id_from_input=None):
if spectrum_id_from_input not in [None, '']:
spectrum_id = int(spectrum_id_from_input)
else:
spectrum_id = 1
if spectrum_id > run.info['spectrum_count']:
spectrum_id = run.info['spectrum_count']
spectrum_id = sanitize_id(spectrum_id_from_input)
spectrum = get_spectrum(spectrum_id)
rt = spectrum.scan_time[0]
figure = {
Expand Down Expand Up @@ -125,19 +130,12 @@ def update_TIC(spectrum_id_from_input=None):
dash.dependencies.Input('spectrum-input-field', 'value'),
]
)
def trigger_new_spec_from_slider( spectrum_id_from_input=None):
if spectrum_id_from_input not in [None, '']:
spectrum_id = int(spectrum_id_from_input)
else:
spectrum_id = 1
# print(type(spectrum_id))
if spectrum_id > run.info['spectrum_count']:
spectrum_id = run.info['spectrum_count']
def trigger_new_spec_from_input( spectrum_id_from_input=None):
spectrum_id = sanitize_id(spectrum_id_from_input)
spectrum = get_spectrum(spectrum_id)
return update_figure(spectrum)



def update_figure(spectrum):
spectrum_plot = p.add(
spectrum.peaks('centroided'),
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ plotly == 4.1.0
pynumpress >= 0.0.4
regex
ms_deisotope == 0.0.9
dash
dash == 1.1.1

0 comments on commit c92b944

Please sign in to comment.