Skip to content

Commit

Permalink
plot MS2 spectrum
Browse files Browse the repository at this point in the history
  • Loading branch information
MuyaoXi9271 committed Nov 2, 2023
1 parent 6f7f855 commit 56d3497
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions streamlit_app/FAIR_MS_Library_Editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@
# st.write(datasets_metadata[key].keys())
# st.write(datasets[dataset_key])
# st.json(datasets)

if 'spectra' in st.session_state:
spectra = st.session_state["spectra"]
1 change: 1 addition & 0 deletions streamlit_app/pages/1_File_Import.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def extract_metadata(df, keys):
st.write(df_spectra)


st.session_state['spectra'] = spectra
st.session_state['df_spectra'] = df_spectra
st.session_state['len_spectra'] = len(df_spectra)

Expand Down
58 changes: 58 additions & 0 deletions streamlit_app/pages/2_Plot_spectrum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from matchms.plotting.spectrum_plots import plot_spectra_mirror, plot_spectrum
import streamlit as st
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import pubchempy
from rdkit import Chem
from rdkit.Chem import Draw




st.set_page_config(
layout="wide",
page_title="Library Export - FAIR MS Library Curation Editor",
#page_icon="assets/favicon.ico",
menu_items={
'Get Help': 'https://github.com/mzmine/biohack23_p15',
'Report a bug': "https://github.com/mzmine/biohack23_p15/issues/new/choose",
'About': "# This is the creation and curation wizard for FAIR MS Libraries."
}
)


st.markdown("## Plot selected MS2 spectrum")
st.markdown("Please select a spectrum based on compound_name")


spectra = st.session_state['spectra']
df_spectra = st.session_state['df_spectra']

cmp_list = df_spectra["compound_name"].tolist()

st.markdown("## Select a compound name")
cmp_selector = st.selectbox(
"select a compound name",
cmp_list
)

if cmp_selector in cmp_list:
cmp_id = cmp_list.index(cmp_selector)
cmp_smile = df_spectra.loc[cmp_id]["smiles"]


plt_spectrum = spectra[cmp_id]

fig, axs = plt.subplots(1, 2, figsize=(12.8, 4.2), gridspec_kw={'width_ratios': [2, 5]}, sharey=False)
cmp_img = Chem.Draw.MolToImage(Chem.MolFromSmiles(cmp_smile), ax=axs[0])

axs[0].grid(False)
axs[0].tick_params(axis='both', bottom=False, labelbottom=False, left=False, labelleft=False)
axs[0].set_title(cmp_smile)
axs[0].imshow(cmp_img)
axs[0].axis("off")

plot_spectrum(plt_spectrum, axs[1])

st.pyplot(fig)

0 comments on commit 56d3497

Please sign in to comment.