重构预处理制作

This commit is contained in:
2025-12-14 14:34:26 +08:00
parent da26e0c619
commit 6eeb40d222
19 changed files with 712 additions and 0 deletions

103
main.py Normal file
View File

@@ -0,0 +1,103 @@
"""
高通量筛选与扩胞项目 - 主入口
交互式命令行界面
"""
import os
import sys
# 添加 src 到路径
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
from analysis.database_analyzer import DatabaseAnalyzer
from analysis.report_generator import ReportGenerator
def get_user_input():
"""获取用户输入"""
print("\n" + "=" * 70)
print(" 高通量筛选与扩胞项目 - 数据库分析工具")
print("=" * 70)
# 1. 获取数据库路径
while True:
db_path = input("\n请输入数据库路径: ").strip()
if os.path.exists(db_path):
break
print(f"❌ 路径不存在: {db_path}")
# 2. 获取目标阳离子
cation = input("请输入目标阳离子 [默认: Li]: ").strip() or "Li"
# 3. 获取目标阴离子
anion_input = input("请输入目标阴离子 (用逗号分隔) [默认: O,S,Cl,Br]: ").strip()
if anion_input:
anions = set(a.strip() for a in anion_input.split(','))
else:
anions = {'O', 'S', 'Cl', 'Br'}
# 4. 选择阴离子模式
print("\n阴离子模式选择:")
print(" 1. 仅单一阴离子化合物")
print(" 2. 仅复合阴离子化合物")
print(" 3. 全部 (默认)")
mode_choice = input("请选择 [1/2/3]: ").strip()
mode_map = {'1': 'single', '2': 'mixed', '3': 'all', '': 'all'}
anion_mode = mode_map.get(mode_choice, 'all')
# 5. 并行数
n_jobs_input = input("并行线程数 [默认: 4]: ").strip()
n_jobs = int(n_jobs_input) if n_jobs_input.isdigit() else 4
return {
'database_path': db_path,
'target_cation': cation,
'target_anions': anions,
'anion_mode': anion_mode,
'n_jobs': n_jobs
}
def main():
"""主函数"""
# 获取用户输入
params = get_user_input()
print("\n" + "-" * 70)
print("开始分析数据库...")
print("-" * 70)
# 创建分析器
analyzer = DatabaseAnalyzer(
database_path=params['database_path'],
target_cation=params['target_cation'],
target_anions=params['target_anions'],
anion_mode=params['anion_mode'],
n_jobs=params['n_jobs']
)
# 执行分析
report = analyzer.analyze(show_progress=True)
# 打印报告
ReportGenerator.print_report(report, detailed=True)
# 询问是否导出
export = input("\n是否导出详细结果到CSV? [y/N]: ").strip().lower()
if export == 'y':
output_path = input("输出文件路径 [默认: analysis_report.csv]: ").strip()
output_path = output_path or "analysis_report.csv"
ReportGenerator.export_to_csv(report, output_path)
# 询问是否继续处理
print("\n" + "-" * 70)
proceed = input("是否继续进行预处理? [y/N]: ").strip().lower()
if proceed == 'y':
print("预处理功能将在下一阶段实现...")
# TODO: 调用预处理模块
print("\n分析完成!")
if __name__ == "__main__":
main()