|
5 | 5 | from scipy.cluster.hierarchy import linkage, leaves_list |
6 | 6 | from scipy.spatial.distance import pdist |
7 | 7 | from src.common.common import page_setup |
8 | | -from src.common.results_helpers import get_abundance_data |
| 8 | +from src.common.results_helpers import get_abundance_data, get_workflow_dir |
| 9 | +from src.workflow.ParameterManager import ParameterManager |
9 | 10 |
|
10 | 11 | params = page_setup() |
11 | 12 | st.title("Heatmap") |
|
29 | 30 |
|
30 | 31 | pivot_df, expr_df, group_map = result |
31 | 32 |
|
32 | | -top_n = st.slider("Number of proteins", 20, 200, 50, key="heatmap_top_n") |
| 33 | +workflow_dir = get_workflow_dir(st.session_state["workspace"]) |
| 34 | +parameter_manager = ParameterManager(workflow_dir, "TOPP Workflow") |
33 | 35 |
|
34 | | -var_series = expr_df.var(axis=1) |
35 | | -top_proteins = var_series.sort_values(ascending=False).head(top_n).index |
36 | | -heatmap_df = expr_df.loc[top_proteins] |
37 | | -heatmap_z = heatmap_df.sub(heatmap_df.mean(axis=1), axis=0).div(heatmap_df.std(axis=1), axis=0) |
38 | | -heatmap_z = heatmap_z.replace([np.inf, -np.inf], np.nan).dropna() |
| 36 | +workflow_params = parameter_manager.get_parameters_from_json() |
| 37 | +analysis_mode = workflow_params.get("analysis-mode", "LFQ") |
39 | 38 |
|
40 | | -if not heatmap_z.empty: |
41 | | - row_linkage = linkage(pdist(heatmap_z.values), method="average") |
42 | | - row_order = leaves_list(row_linkage) |
| 39 | +st.write("Workflow Analysis Mode:", analysis_mode) |
43 | 40 |
|
44 | | - col_linkage = linkage(pdist(heatmap_z.T.values), method="average") |
45 | | - col_order = leaves_list(col_linkage) |
| 41 | +if analysis_mode == "LFQ": |
| 42 | + top_n = st.slider("Number of proteins", 20, 200, 50, key="heatmap_top_n") |
46 | 43 |
|
47 | | - heatmap_clustered = heatmap_z.iloc[row_order, col_order] |
| 44 | + var_series = expr_df.var(axis=1) |
| 45 | + top_proteins = var_series.sort_values(ascending=False).head(top_n).index |
| 46 | + heatmap_df = expr_df.loc[top_proteins] |
| 47 | + heatmap_z = heatmap_df.sub(heatmap_df.mean(axis=1), axis=0).div(heatmap_df.std(axis=1), axis=0) |
| 48 | + heatmap_z = heatmap_z.replace([np.inf, -np.inf], np.nan).dropna() |
48 | 49 |
|
49 | | - fig_heatmap = px.imshow( |
50 | | - heatmap_clustered, |
51 | | - labels=dict(x="Sample", y="Protein", color="Z-score"), |
52 | | - aspect="auto", |
53 | | - color_continuous_scale=[[0.0, "#3b6fb6"], [0.5, "white"], [1.0, "#b40426"]], |
54 | | - zmin=-3, zmax=3 |
55 | | - ) |
| 50 | + if not heatmap_z.empty: |
| 51 | + row_linkage = linkage(pdist(heatmap_z.values), method="average") |
| 52 | + row_order = leaves_list(row_linkage) |
56 | 53 |
|
57 | | - fig_heatmap.update_layout( |
58 | | - height=700, |
59 | | - xaxis={'side': 'bottom'}, |
60 | | - yaxis={'side': 'left'} |
61 | | - ) |
| 54 | + col_linkage = linkage(pdist(heatmap_z.T.values), method="average") |
| 55 | + col_order = leaves_list(col_linkage) |
62 | 56 |
|
63 | | - fig_heatmap.update_xaxes(tickfont=dict(size=10)) |
64 | | - fig_heatmap.update_yaxes(tickfont=dict(size=8)) |
| 57 | + heatmap_clustered = heatmap_z.iloc[row_order, col_order] |
65 | 58 |
|
66 | | - st.plotly_chart(fig_heatmap, use_container_width=True) |
| 59 | + fig_heatmap = px.imshow( |
| 60 | + heatmap_clustered, |
| 61 | + labels=dict(x="Sample", y="Protein", color="Z-score"), |
| 62 | + aspect="auto", |
| 63 | + color_continuous_scale=[[0.0, "#3b6fb6"], [0.5, "white"], [1.0, "#b40426"]], |
| 64 | + zmin=-3, zmax=3 |
| 65 | + ) |
| 66 | + |
| 67 | + fig_heatmap.update_layout( |
| 68 | + height=700, |
| 69 | + xaxis={'side': 'bottom'}, |
| 70 | + yaxis={'side': 'left'} |
| 71 | + ) |
| 72 | + |
| 73 | + fig_heatmap.update_xaxes(tickfont=dict(size=10)) |
| 74 | + fig_heatmap.update_yaxes(tickfont=dict(size=8)) |
| 75 | + |
| 76 | + st.plotly_chart(fig_heatmap, use_container_width=True) |
| 77 | + else: |
| 78 | + st.warning("Insufficient data to generate the heatmap.") |
| 79 | + |
| 80 | + st.markdown("---") |
| 81 | + st.markdown("**Other visualizations:**") |
| 82 | + col1, col2 = st.columns(2) |
| 83 | + with col1: |
| 84 | + st.page_link("content/results_volcano.py", label="Volcano Plot", icon="🌋") |
| 85 | + with col2: |
| 86 | + st.page_link("content/results_pca.py", label="PCA", icon="📊") |
67 | 87 | else: |
68 | | - st.warning("Insufficient data to generate the heatmap.") |
69 | | - |
70 | | -st.markdown("---") |
71 | | -st.markdown("**Other visualizations:**") |
72 | | -col1, col2 = st.columns(2) |
73 | | -with col1: |
74 | | - st.page_link("content/results_volcano.py", label="Volcano Plot", icon="🌋") |
75 | | -with col2: |
76 | | - st.page_link("content/results_pca.py", label="PCA", icon="📊") |
| 88 | + top_n = st.slider("Number of proteins", 20, 200, 50, key="heatmap_top_n") |
| 89 | + |
| 90 | + var_series = expr_df.var(axis=1) |
| 91 | + top_proteins = var_series.sort_values(ascending=False).head(top_n).index |
| 92 | + heatmap_df = expr_df.loc[top_proteins] |
| 93 | + heatmap_z = heatmap_df.sub(heatmap_df.mean(axis=1), axis=0).div(heatmap_df.std(axis=1), axis=0) |
| 94 | + heatmap_z = heatmap_z.replace([np.inf, -np.inf], np.nan).dropna() |
| 95 | + |
| 96 | + if not heatmap_z.empty: |
| 97 | + row_linkage = linkage(pdist(heatmap_z.values), method="average") |
| 98 | + row_order = leaves_list(row_linkage) |
| 99 | + |
| 100 | + col_linkage = linkage(pdist(heatmap_z.T.values), method="average") |
| 101 | + col_order = leaves_list(col_linkage) |
| 102 | + |
| 103 | + heatmap_clustered = heatmap_z.iloc[row_order, col_order] |
| 104 | + |
| 105 | + fig_heatmap = px.imshow( |
| 106 | + heatmap_clustered, |
| 107 | + labels=dict(x="Sample", y="Protein", color="Z-score"), |
| 108 | + aspect="auto", |
| 109 | + color_continuous_scale=[[0.0, "#3b6fb6"], [0.5, "white"], [1.0, "#b40426"]], |
| 110 | + zmin=-3, zmax=3 |
| 111 | + ) |
| 112 | + |
| 113 | + fig_heatmap.update_layout( |
| 114 | + height=700, |
| 115 | + xaxis={'side': 'bottom'}, |
| 116 | + yaxis={'side': 'left'} |
| 117 | + ) |
| 118 | + |
| 119 | + fig_heatmap.update_xaxes(tickfont=dict(size=10)) |
| 120 | + fig_heatmap.update_yaxes(tickfont=dict(size=8)) |
| 121 | + |
| 122 | + st.plotly_chart(fig_heatmap, width="stretch") |
| 123 | + else: |
| 124 | + st.warning("Insufficient data to generate the heatmap.") |
| 125 | + |
| 126 | + st.markdown("---") |
| 127 | + st.markdown("**Other visualizations:**") |
| 128 | + col1, col2 = st.columns(2) |
| 129 | + with col1: |
| 130 | + st.page_link("content/results_volcano.py", label="Volcano Plot", icon="🌋") |
| 131 | + with col2: |
| 132 | + st.page_link("content/results_pca.py", label="PCA", icon="📊") |
0 commit comments