digital-embryo/README.md
2025-07-26 11:41:02 +08:00

116 lines
2.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 安装 Vite 创建工具(只需一次)
```
npm create vite@latest embryo-frontend -- --template react-ts
cd embryo-frontend
npm install
npm install three @react-three/fiber @react-three/drei
npm install zustand axios react-router-dom
npm run dev
cd ..
mkdir embryo-backend
cd embryo-backend
```
# 创建虚拟环境(推荐)
安装uv<https://docs.astral.sh/uv/getting-started/installation/>
```
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
```
# 运行
```
.\start-dev.ps1
```
<http://localhost:5000/api/gene/SOX2>
## 脚本功能:
1. **同时启动两个服务**
- 前端:在 `embryo-frontend` 目录中运行 `npm run dev`
- 后端:使用 `uv run` 运行 `embryo-backend/app.py`
2. **智能检查**
- 验证目录和文件是否存在
- 监控服务状态
- 提供彩色输出和状态信息
3. **优雅的停止机制**
- 使用 Ctrl+C 可以同时停止两个服务
- 自动清理后台作业
## 使用方法:
在项目根目录中运行:
```powershell
.\start-dev.ps1
```
或者如果需要执行权限:
```powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
.\start-dev.ps1
```
## 预期输出:
- 前端开发服务器通常运行在:`http://localhost:5173`
- 后端API服务器通常运行在`http://localhost:5000`
脚本会显示启动状态,并在两个服务都启动后保持运行状态。按 Ctrl+C 可以同时停止所有服务。
现在您可以使用这个脚本来快速启动整个开发环境了!
# 20250721 3D点云可视化
```
npm install three
```
# 20250721生成假的胚胎数据
```
uv run FakeEmbyro.py
cd embryo-frontend
npm install chart.js react-chartjs-2
```
```
import numpy as np
import pandas as pd
import anndata as ad
import os
script_path = os.path.dirname(os.path.realpath(__file__))
N = 1500
radius = 10
np.random.seed(42)
phi = np.random.uniform(0, np.pi, N)
theta = np.random.uniform(0, 2 * np.pi, N)
x = radius * np.sin(phi) * np.cos(theta)
y = radius * np.sin(phi) * np.sin(theta)
z = radius * 0.7 * np.cos(phi)
genes = ["SOX2", "NANOG", "POU5F1", "T", "OTX2", "ZIC2", "FOXA2", "LEFTY1"]
expression_data = {
gene: np.exp(-(x**2 + y**2 + z**2) / (2 * radius**2)) + 0.1 * np.random.rand(N)
for gene in genes
}
obs = pd.DataFrame({"cell_id": [f"cell_{i}" for i in range(N)]}, index=[f"cell_{i}" for i in range(N)])
var = pd.DataFrame(index=genes)
obsm = {"spatial": np.vstack([x, y, z]).T}
X = np.vstack([expression_data[gene] for gene in genes]).T # shape (N, G)
adata = ad.AnnData(X=X, obs=obs, var=var, obsm=obsm)
adata.write(f"{script_path}/CS9.h5ad")
```