Skip to content

Commit

Permalink
MS2 spec selection via selectbox
Browse files Browse the repository at this point in the history
  • Loading branch information
axelwalter committed Dec 21, 2023
1 parent de72db5 commit 050e0ec
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions pages/1_👀_View_Raw_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
df[df["mslevel"] == 2],
)

df_MS2["precursormz"] = df_MS2["precursormz"].apply(lambda x: str(round(x, 5)))
df_MS2["RT"] = df_MS2["RT"].apply(lambda x: str(round(x, 1)))

if not df_MS1.empty:
tabs = st.tabs(["📈 Base peak chromatogram and MS1 spectra",
"📈 Peak map and MS2 spectra"])
Expand All @@ -47,7 +50,7 @@
show_fig(fig, title.replace(" ", "_"))

with tabs[1]:
with st.form("update 2D map", border=False):
with st.form("2D-peak-map-form", border=False):
st.number_input(
"2D map intensity cutoff",
0,
Expand All @@ -62,30 +65,19 @@
df_MS2,
st.session_state["2D-map-intensity-cutoff"],
)
map_points = plotly_events(map2D)
# Determine RT and mz positions from clicks in the map to get closest MS2 spectrum
if not df_MS2.empty:
st.markdown("💡 Click anywhere to show the closest MS2 spectrum.")
if map_points:
rt = map_points[0]["x"]
prec_mz = map_points[0]["y"]
else:
rt = df_MS2.iloc[0, 2]
prec_mz = df_MS2.iloc[0, 0]
spec = df_MS2.loc[
(
abs(df_MS2["RT"] - rt) +
abs(df_MS2["precursormz"] - prec_mz)
).idxmin(),
:,
]
title = f"MS2 spectrum @precursor m/z {round(spec['precursormz'], 4)} @RT {round(spec['RT'], 2)}"
show_fig(map2D, f"{selected_file}-2D-peak-map")
# Determine RT and mz positions from clicks in the map to get closest MS2 spectrum
if not df_MS2.empty:
spec = st.selectbox("select MS2 spectrum", df_MS2.apply(lambda x: f"{x['precursormz']}@{x['RT']}", axis=1))
precursormz_value, rt_value = spec.split("@")
spec = df_MS2[(df_MS2['precursormz'] == precursormz_value) & (df_MS2['RT'] == rt_value)].iloc[0]
title = f"MS2 spectrum @precursor m/z {spec['precursormz']} @RT {spec['RT']}"

ms2_fig = plot_ms_spectrum(
spec,
title,
"#00CC96"
)
show_fig(ms2_fig, title.replace(" ", "_"))
ms2_fig = plot_ms_spectrum(
spec,
title,
"#00CC96"
)
show_fig(ms2_fig, title.replace(" ", "_"))

save_params(params)

0 comments on commit 050e0ec

Please sign in to comment.