Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/extend info #3

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pymzml
pymzml==2.4.7
dash==1.8.0
58 changes: 53 additions & 5 deletions spectrum_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@
import dash_core_components as dcc
import dash_html_components as html

ACCESSIONS_INFO=[
("MS:1000130", "positive scan"),
("MS:1000128", "profile spectrum"),
("MS:1000504", "base peak m/z"),
("MS:1000505", "base peak intensity" ),
("MS:1000285", "total ion current" ),
("MS:1000528", "lowest observed m/z" ),
("MS:1000527", "highest observed m/z" ),
# ("MS:1000796", "spectrum title" ),
("MS:1000512", "filter string" ),
("MS:1000616", "preset scan configuration" ),
("MS:1000927", "ion injection time" ),
("MS:1000501", "scan window lower limit"),
("MS:1000500", "scan window upper limit"),
]

print('loading run...')
run = pymzml.run.Reader(sys.argv[1])
Expand All @@ -36,11 +51,11 @@

tic_annotation = []

for n, RT in enumerate(tic_x):
for spec_id, RT in zip(all_ids, tic_x):
tic_annotation.append(
'RT: {0:1.3f}<br>ID: {1}'.format(
RT,
all_ids[n]
spec_id
)
)

Expand Down Expand Up @@ -196,7 +211,8 @@ def update_figure(spectrum):
new_spectrum_plot['y'] = spectrum_plot['y']
new_spectrum_plot['line']={'color':'black'}
# print(spectrum_plot)
title = 'Spectrum {0} @ RT: {1} [{2}s] of run {3}'.format(
title = 'MS{0} Spectrum {1} @ RT: {2:1.3f} [{3}s] of run {4}'.format(
spectrum.ms_level,
spectrum.ID,
spectrum.scan_time[0],
spectrum.scan_time[1],
Expand All @@ -209,15 +225,47 @@ def update_figure(spectrum):
if key in tmp_selected_precursors.keys():
format_str_template += format_template.format(tmp_selected_precursors[key])
title += format_str_template
info_text='spectrum info'
for ms_acc, acc_name in ACCESSIONS_INFO:
acc_value = spectrum.get(ms_acc,None)
if acc_value is not None:
info_text +='<br>{0}: {1}'.format(acc_name, acc_value)
max_x = max([x for x in new_spectrum_plot['x'] if x is not None])
max_y = max([y for y in new_spectrum_plot['y'] if y is not None])
info_plot=go.Scatter(
x=[max_x-5],
y=[max_y+max_y/20],
text=[info_text],
mode='markers',
marker={'color':'black'},
hoverinfo='text'
)
return {
'data': [new_spectrum_plot],
'data': [new_spectrum_plot, info_plot],
'layout': go.Layout(
xaxis={ 'title': 'm/z'},
yaxis={'title': 'Intensity',},
margin={'l': 40, 'b': 40, 't': 80, 'r': 10},
legend={'x': 0, 'y': 1},
hovermode='closest',
title = title
title = title,
showlegend=False,
annotations=[
{
"x": max_x-5,
"y":max_y+max_y/20,
"xref": "x",
"yref": "y",
"text": 'info',
"textangle": 0,
"font": {"size": 10, "color": 'black'},
"align": "center",
"showarrow": False,
"xanchor": "center",
"yanchor": "bottom",
# 'textposition': 'top'
}
]
)
}

Expand Down