Files
2026-08-21 11:06:49 +08:00

219 lines
6.1 KiB
Markdown
Executable File
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.
# 2026-03-28 ~ 2026-03-29 工作记录 - bbav20311 Promoter分析可视化优化
> 日期: 2026-03-28 15:09 ~ 2026-03-29 02:00
> 参与: xialab的幸运星
> 主题: Promoter分析模块可视化升级与热图融合
---
## 1. 工作目标
优化Promoter(启动子顺式作用元件)分析模块的可视化输出,融合多种热图绘制方法,创建更符合发表要求的组合图。
---
## 2. 主要工作内容
### 2.1 热图绘制方法对比与融合
| 脚本 | 来源 | 特点 | 问题 |
|:---|:---|:---|:---|
| `promoter_v4_final.R` | 现有V4版本 | 7大分类、外部树图、红绿配色 | 连续渐变不够清晰 |
| `promoter_analysis_complete.R` | complete版本 | 方块+数字、蓝白分级 | 元件命名处理逻辑有问题 |
| `promoter_v5_fused_heatmap.R` | **融合版** | V4分类 + complete显示方式 | ✅ 采用 |
**融合策略**:
- 保留V4的7大分类逻辑
- 采用complete的方块+数字显示
- 9级蓝白分级配色
### 2.2 5面板组合图开发 (V6)
创建全新的5面板组合图布局:
```
A (左) B (中左) C (中) D (右) E (最右)
进化树 + 亚家族竖线 + 7大分类堆叠 + 热图(方块+数字) + 图例
```
**文件**: `scripts/promoter_v6_combined.R`
**特点**:
- 画布自动调整 (9000×6000)
- Panel C宽度增加 (8 → 12)
- 热图方格为正方形
- 实线边框 (grey60)
- 0值显示白色背景
### 2.3 集成到分析流程
修改 `apps/cli/run_promoter.py`:
1. **集成V6脚本** - 自动生成5面板组合图
2. **保留其他统计图** - 甜甜圈、柱形图、UpSet等
3. **移除旧版** - `_02_combined.png` 不再生成
4. **修复manifest** - 添加`figures`字段供前端显示
---
## 3. 关键修改文件
### 3.1 新增/修改的R脚本
| 文件 | 路径 | 说明 |
|:---|:---|:---|
| `promoter_v5_fused_heatmap.R` | `scripts/` | 融合版热图 (V5) |
| `promoter_v6_combined.R` | `scripts/` | **5面板组合图 (V6)** |
### 3.2 修改的Python脚本
| 文件 | 路径 | 修改内容 |
|:---|:---|:---|
| `run_promoter.py` | `apps/cli/` | 集成V6,添加figures字段 |
### 3.3 生成的可视化文件
| 文件 | 说明 |
|:---|:---|
| `Ft.SPL_promoter_v6_combined.png` | **新版5面板组合图** |
| `Ft.SPL_promoter_01_heatmap.png` | 独立热图 |
| `Ft.SPL_promoter_03_element_barplot.png` | 元件柱形图 |
| `Ft.SPL_promoter_03b_big7_barplot.png` | 7大分类柱形图 |
| `Ft.SPL_promoter_04_category_stacked.png` | 分类堆叠图 |
| `Ft.SPL_promoter_05_upset.png` | UpSet图 |
| `Ft.SPL_promoter_06_category_donut.png` | 甜甜圈图 |
---
## 4. 7大分类定义
| 分类 | 颜色 | 包含元件 |
|:---|:---|:---|
| Core promoter | #e41a1c | TATA-box, CAAT-box, Inr, Y-patch |
| Light response | #377eb8 | G-box, GT1, I-box, Sp1, Box.4, GATA |
| Hormone signaling | #4daf4a | ABRE, GARE, CGTCA, TCA, TGA, ERE |
| Stress response | #984ea3 | DRE, LTR, ARE, STRE, W-box |
| TF binding | #ff7f00 | MYB, MYC, WRKY |
| Development | #f781bf | RY, AAGAA, CAT, GCN4 |
| Other | #999999 | 未分类 |
---
## 5. 技术细节
### 5.1 热图颜色分级
```r
count_colors <- c(
"[0,1)" = "#f7fbff", # 白色(0值)
"[1,2)" = "#c6dbef", # 浅蓝
"[2,3)" = "#9ecae1",
"[3,5)" = "#6baed6",
"[5,10)" = "#4292c6",
"[10,20)" = "#2171b5",
"[20,50)" = "#08519c",
"[50,100)"= "#08306b",
"[100,200]"="#041d3a" # 深蓝
)
```
### 5.2 画布自适应计算
```r
# 根据内容自动计算画布大小
total_width <- (x_D_right - x_A_left) + 3 # 加上图例空间
total_height <- max_y + 2
max_width <- 30
max_height <- 20
final_width <- min(total_width, max_width)
final_height <- min(total_height, max_height)
```
---
## 6. 测试结果
### 6.1 测试任务
- **任务ID**: job_1774711833127
- **基因**: 24个 Ft.SPL 基因
- **启动子元件**: 3699条记录
### 6.2 生成文件验证
```bash
$ ls final/Ft.SPL_promoter*.png
Ft.SPL_promoter_01_heatmap.png (131K)
Ft.SPL_promoter_03b_big7_barplot.png (38K)
Ft.SPL_promoter_03_element_barplot.png (21K)
Ft.SPL_promoter_04_category_stacked.png (68K)
Ft.SPL_promoter_05_upset.png (32K)
Ft.SPL_promoter_06_category_donut.png (60K)
Ft.SPL_promoter_v6_combined.png (701K) # 新版5面板
```
### 6.3 Manifest验证
```json
{
"figures": [
{"name": "Ft.SPL_promoter_01_heatmap", ...},
{"name": "Ft.SPL_promoter_03_element_barplot", ...},
{"name": "Ft.SPL_promoter_03b_big7_barplot", ...},
{"name": "Ft.SPL_promoter_04_category_stacked", ...},
{"name": "Ft.SPL_promoter_05_upset", ...},
{"name": "Ft.SPL_promoter_06_category_donut", ...},
{"name": "Ft.SPL_promoter_v6_combined", ...} # 新版
]
}
```
---
## 7. 问题与解决
| 问题 | 原因 | 解决方案 |
|:---|:---|:---|
| V6图不显示在结果中 | manifest缺少figures字段 | 添加figures数组 |
| 堆叠图太拥挤 | Panel C宽度不足 | width_C从8增加到12 |
| 热图方格变形 | element_width设置不当 | 改为正方形 (gene_height * 2) |
| 旧版_02_combined仍在生成 | 未移除V2调用 | 修改流程,只生成V6和其他统计图 |
| 其他统计图丢失 | V2调用被跳过 | 先运行V6,再运行V2生成其他图 |
---
## 8. 时间记录
| 时间段 | 时长 | 内容 |
|:---|:---|:---|
| 15:09 - 17:18 | 2小时 | 分析热图绘制方法,创建V5融合版 |
| 17:18 - 20:00 | 3小时 | 开发V6 5面板组合图 |
| 20:00 - 23:30 | 3.5小时 | 集成到流程,修复manifest |
| 23:30 - 02:00 | 2.5小时 | 调试优化,测试验证 |
| **总计** | **11小时** | **完成所有目标** |
---
## 9. 状态
- **V5融合版热图**: ✅ 完成
- **V6 5面板组合图**: ✅ 完成
- **集成到分析流程**: ✅ 完成
- **manifest修复**: ✅ 完成
- **测试验证**: ✅ 通过
---
## 10. 下一步建议
1. **用户反馈收集** - 根据实际使用调整面板宽度
2. **颜色方案优化** - 如有需要可调整7大分类颜色
3. **字体大小调整** - 根据期刊要求调整
4. **批量测试** - 测试更多基因家族数据
---
*记录时间: 2026-03-29 02:00*
*记录位置: `/home/xia-lab/wutx/00test/bbav20311/memory/2026-03-28.md`*
*状态: ✅ 已保存*