-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathresults_abundance.py
More file actions
132 lines (109 loc) · 4.86 KB
/
Copy pathresults_abundance.py
File metadata and controls
132 lines (109 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"""Abundance (ProteomicsLFQ) Results Page."""
import streamlit as st
import pandas as pd
import numpy as np
from pathlib import Path
from scipy.stats import ttest_ind
from src.common.common import page_setup
from statsmodels.stats.multitest import multipletests
from src.common.results_helpers import get_workflow_dir, get_abundance_data
params = page_setup()
st.title("Abundance Quantification")
st.markdown(
"""
View protein and PSM-level quantification from **ProteomicsLFQ**.
This page calculates differential expression statistics between sample groups.
"""
)
if "workspace" not in st.session_state:
st.warning("Please initialize your workspace first.")
st.stop()
results_dir = Path(st.session_state["workspace"]) / "topp-workflow" / "results" / "quant_results"
consensus_out = results_dir / "openms_design_protein_openms.csv"
@st.cache_data
def load_data(file_path):
return pd.read_csv(file_path, sep="\t", comment="#", engine="python")
if consensus_out.exists():
# df = load_data(consensus_out)
# # ratio column removal
# df = df.loc[:, ~df.columns.str.contains('ratio', case=False)]
pre_processing_tab, protein_tab = st.tabs(["Pre-processing", "Protein Table"])
with pre_processing_tab:
# result = get_abundance_data(st.session_state["workspace"])
# DEBUG: 상세 원인 출력 (임시)
try:
result = get_abundance_data(st.session_state["workspace"])
except Exception as e:
st.exception(e)
result = None
if result is None:
ws = st.session_state.get("workspace")
st.error("Debug: get_abundance_data returned None")
st.write("workspace:", ws)
wf = Path(ws) / "topp-workflow"
st.write("workflow dir exists:", wf.exists(), "->", wf)
qdir = wf / "results" / "quant_results"
st.write("quant_dir exists:", qdir.exists(), "->", qdir)
if qdir.exists():
st.write("csv files:", sorted([p.name for p in qdir.glob('*.csv')]))
# show cached param snapshot if available
try:
from src.workflow.ParameterManager import ParameterManager
pm = ParameterManager(wf)
st.write("parameters keys (sample):", list(pm.get_parameters_from_json().items())[:20])
except Exception as e:
st.write("Param manager error:", e)
st.stop()
if result is None:
st.info("💡 Please complete the configuration in the 'Configure' page to see results.")
st.stop()
pivot_df, expr_df, group_map = result
st.write("### Final Results (Group row removed, Stats added)")
st.dataframe(pivot_df.head(10))
with protein_tab:
st.markdown("### Protein-Level Abundance Table")
st.info(
"This protein-level table is generated by grouping all PSMs that map to the "
"same protein and aggregating their intensities across samples.\n\n"
"Additionally, log2 fold change and p-values are calculated between sample groups."
)
# Display group comparison info
groups = sorted(set(group_map.values()))
if len(groups) >= 2:
group1, group2 = sorted(groups)[:2]
st.info(f"Statistical comparison: **{group2} vs {group1}**")
exclude_cols = ["protein", "log2FC", "p-value", "p-adj",
"n_proteins", "n_peptides", "protein_score"]
# Get sample columns (between stats and PeptideSequence)
sample_cols = [c for c in pivot_df.columns if c
not in exclude_cols and "ratio" not in c.lower()]
# Create bar chart column with log2-transformed values
pivot_df["Intensity"] = pivot_df[sample_cols].apply(
lambda row: [np.log2(v + 1) for v in row], axis=1
)
# Reorder columns: place Intensity after p-value
display_cols = ["protein", "log2FC", "p-value", "Intensity"] + sample_cols
available_cols = [c for c in display_cols if c in pivot_df.columns]
st.dataframe(
pivot_df[available_cols].sort_values("p-value"),
column_config={
"Intensity": st.column_config.BarChartColumn(
"Intensity",
help="Sample intensities (log2 scale)",
width="small",
y_min=0,
),
},
width="stretch"
)
else:
st.warning(f"File not found: {consensus_out}")
st.markdown("---")
st.markdown("**Next steps:** Explore statistical visualizations")
col1, col2, col3 = st.columns(3)
with col1:
st.page_link("content/results_volcano.py", label="Volcano Plot", icon="🌋")
with col2:
st.page_link("content/results_pca.py", label="PCA", icon="📊")
with col3:
st.page_link("content/results_heatmap.py", label="Heatmap", icon="🔥")