Skip to content

Commit c1c441e

Browse files
committed
gnps annotations
- always fetch annotations - they are stores in a df in session state - not used now
1 parent 83a6033 commit c1c441e

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

pages/1_📁_Data_Preparation.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@
3636
task_id_default = ""
3737
disabled = False
3838
task_id = st.text_input("GNPS task ID", task_id_default, disabled=disabled)
39-
c1, c2 = st.columns(2)
40-
merge_annotations = c1.checkbox("Annotate metabolites", True, help="Merge annotations from GNPS FBMN and analog search if available.")
39+
_, c2, _ = st.columns(3)
4140
if c2.button("Load filed from GNPS", type="primary", disabled=len(task_id) == 0, use_container_width=True):
42-
st.session_state["ft_gnps"], st.session_state["md_gnps"] = load_from_gnps(task_id, merge_annotations)
41+
st.session_state["ft_gnps"], st.session_state["md_gnps"] = load_from_gnps(task_id)
4342

4443
if "ft_gnps" in st.session_state:
4544
if not st.session_state["ft_gnps"].empty:

src/common.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"df_important_features",
1515
"df_oob",
1616
"ft_gnps",
17-
"md_gnps")
17+
"md_gnps",
18+
"df_gnps_annotations")
1819

1920
corrections_map = {"Bonferroni": "bonf",
2021
"Sidak": "sidak",

src/fileselection.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,24 @@ def load_example():
5454
return ft, md
5555

5656
@st.cache_data
57-
def load_from_gnps(task_id, merge_annotations):
57+
def load_from_gnps(task_id):
5858
try: # GNPS2 will run here
5959
ft = workflow_fbmn.get_quantification_dataframe(task_id, gnps2=True)
6060
md = workflow_fbmn.get_metadata_dataframe(task_id, gnps2=True).set_index("filename")
61-
if merge_annotations:
62-
an = taskresult.get_gnps2_task_resultfile_dataframe(task_id, "nf_output/library/merged_results_with_gnps.tsv")[["#Scan#", "Compound_Name"]].set_index("#Scan#")
61+
an = taskresult.get_gnps2_task_resultfile_dataframe(task_id, "nf_output/library/merged_results_with_gnps.tsv")[["#Scan#", "Compound_Name"]].set_index("#Scan#")
6362
except urllib.error.HTTPError: # GNPS1 task IDs can not be retrieved and throw HTTP Error 500
6463
ft_url = f"https://proteomics2.ucsd.edu/ProteoSAFe/DownloadResultFile?task={task_id}&file=quantification_table_reformatted/&block=main"
6564
md_url = f"https://proteomics2.ucsd.edu/ProteoSAFe/DownloadResultFile?task={task_id}&file=metadata_merged/&block=main"
6665
ft = pd.read_csv(ft_url)
6766
md = pd.read_csv(md_url, sep = "\t", index_col="filename")
68-
if merge_annotations:
69-
an_url = f"https://proteomics2.ucsd.edu/ProteoSAFe/DownloadResultFile?task={task_id}&file=DB_result/&block=main"
70-
an = pd.read_csv(an_url, sep = "\t")[["#Scan#", "Compound_Name"]].set_index("#Scan#")
71-
if merge_annotations:
72-
ft.index = pd.Index(ft.apply(lambda x: f'{an.loc[x["row ID"], "Compound_Name"]}_{round(x["row m/z"], 4)}_{round(x["row retention time"], 2)}' if x["row ID"] in an.index else f'{x["row ID"]}_{round(x["row m/z"], 4)}_{round(x["row retention time"], 2)}', axis=1))
73-
else:
74-
ft.index = pd.Index(ft.apply(lambda x: f'{x["row ID"]}_{round(x["row m/z"], 4)}_{round(x["row retention time"], 2)}', axis=1))
67+
an_url = f"https://proteomics2.ucsd.edu/ProteoSAFe/DownloadResultFile?task={task_id}&file=DB_result/&block=main"
68+
an = pd.read_csv(an_url, sep = "\t")[["#Scan#", "Compound_Name"]].set_index("#Scan#")
69+
70+
index_with_annotations = pd.Index(ft.apply(lambda x: f'{x["row ID"]}_{round(x["row m/z"], 4)}_{round(x["row retention time"], 2)}', axis=1))
71+
ft.index = index_with_annotations
72+
st.session_state["df_gnps_annotations"].index = index_with_annotations
73+
st.session_state["df_gnps_annotations"]["GNPS annotation"] = ft["row ID"].apply(lambda x: an.loc[x, "Compound_Name"] if x in an.index else pd.NA)
74+
st.session_state["df_gnps_annotations"].dropna(inplace=True)
7575
return ft, md
7676

7777
def load_ft(ft_file):

0 commit comments

Comments
 (0)