-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbioinfo-app.py
More file actions
135 lines (113 loc) · 4.87 KB
/
Copy pathbioinfo-app.py
File metadata and controls
135 lines (113 loc) · 4.87 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
133
134
135
import streamlit as st
from auth.auth_utils import check_auth, logout
from auth.admin_panel import admin_panel_block
# ======================
# 页面设置 (必须在最前面)
# ======================
st.set_page_config(
page_title="恩泽康泰-生信分析原型机",
layout="wide"
)
# ======================
# 认证检查
# ======================
if check_auth():
# 侧边栏显示用户信息和退出按钮
st.sidebar.write(f"当前用户: **{st.session_state['username']}** ({st.session_state['role']})")
logout()
st.sidebar.divider()
try:
# ======================
# 原有模块导入
# ======================
from modules.data_loader import load_expression, load_annotation
from modules.gene_search import gene_search_block
from modules.heatmap import heatmap_block
from modules.pca import pca_block
from modules.basic_plots import barplot_block, lineplot_block, violin_block
# ======================
# 新增模块导入
# ======================
from modules.diff_analysis import diff_block
from modules.correlation import correlation_block
from modules.plsda import plsda_block
from modules.time_series import kmeans_time_block
from modules.venn_plot import venn_block
from modules.network import network_block
from modules.diff_manager import diff_manager_block
from modules.diff_report import diff_report_block
st.title("🧬 恩泽康泰交互式生信数据可视化平台")
# ======================
# 菜单构建
# ======================
menu_options = [
"🔥表达量热图",
"🔭PCA分析",
"📊常规柱状图",
"🎻 Violin 图",
"📈动态折线图",
"🧪差异分析",
"📐相关性分析",
"🧭PLS-DA",
"⏱序列分析",
"🕸网络互作"
]
# 如果是管理员,增加后台管理选项
if st.session_state['role'] == 'admin':
menu_options.append("🛠 用户管理后台")
analysis_type = st.sidebar.selectbox(
"选择功能模块",
menu_options
)
# 记录模块切换日志
if 'last_analysis_type' not in st.session_state or st.session_state['last_analysis_type'] != analysis_type:
from auth.database import log_action
log_action(st.session_state['username'], "切换模块", f"进入模块: {analysis_type}")
st.session_state['last_analysis_type'] = analysis_type
# ======================
# 管理员后台逻辑
# ======================
if analysis_type == "🛠 用户管理后台":
admin_panel_block()
else:
# ======================
# 数据加载与生信分析逻辑
# ======================
df = load_expression()
annotation_col = load_annotation()
if df is not None:
# 基因搜索
df_show = gene_search_block(df)
if analysis_type == "🔥表达量热图":
heatmap_block(df, df_show, annotation_col)
elif analysis_type == "🔭PCA分析":
pca_block(df, annotation_col)
elif analysis_type == "📊常规柱状图":
barplot_block(df, annotation_col)
elif analysis_type == "🎻 Violin 图":
violin_block(df, annotation_col)
elif analysis_type == "📈动态折线图":
lineplot_block(df, annotation_col)
elif analysis_type == "🧪差异分析":
diff_block(df, df_show, annotation_col)
elif analysis_type == "📐相关性分析":
correlation_block(df, df_show, annotation_col)
elif analysis_type == "🧭PLS-DA":
plsda_block(df, annotation_col)
elif analysis_type == "⏱序列分析":
kmeans_time_block(df)
elif analysis_type == "🕸网络互作":
st.subheader("🕸 网络互作分析")
st.info("需要基因互作 edge 表(gene1, gene2)")
edge_file = st.file_uploader("上传网络文件", type=["csv"])
if edge_file:
import pandas as pd
edge_df = pd.read_csv(edge_file)
network_block(edge_df)
else:
st.info("请先上传表达矩阵以开始分析")
except Exception as e:
st.error("🚨 系统发生未预期错误,请检查输入数据或联系管理员")
st.exception(e)
else:
st.info("请登录以访问生信分析平台")