Files
RGC-ADOA/script/04c_marker_dotplot_full.py
rain 092f39a662 chore: 初始化 RGC-ADOA 分析仓库
纳入 script/doc/ref/output 及配置;忽略 data/(26G 原始/中间数据)。
git 身份:rain <wjs_Rain@126.com>。
2026-09-18 18:21:19 +08:00

66 lines
2.2 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
04c_marker_dotplot_full.py — 用完整官方表 S3 marker 列表重画注释证据 dotplot
S3 全量 32 基因 + 我们补充的 marker(S3 未覆盖的细胞类型用 "***" 分组标注)
产出:output/04_annotation/marker_dotplot_fullS3.png
"""
from pathlib import Path
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import scanpy as sc
OUT = Path("output/04_annotation")
plt.rcParams.update({"figure.dpi": 300, "savefig.dpi": 300, "font.size": 8})
# 官方表 S3 全量
S3 = {
"Rod": ["Cnga1", "Cngb1", "Gnat1", "Rho", "Rp1", "Sag", "Ush2a"],
"Cone": ["Arr3", "Cngb3", "Gnat2", "Opn1mw"],
"RGC": ["Rbpms", "Slc17a6", "Thy1"],
"Amacrine": ["Gad1", "Gad2", "Grm5", "Slc6a5", "Tfap2b"],
"Muller": ["Rlbp1", "Slc1a3"],
"Uveal": ["Gpnmb", "Tyr"],
"Bipolar": ["Cabp5", "Grm6", "Kcnb2", "Prkca"],
"Horizontal": ["Lhx1", "Onecut2", "Prox1"],
"Pericyte": ["Pdgfrb", "Rgs5"],
}
# 本项目补充(S3 未覆盖的细胞类型/补充基因)
EXTRA = {
"Muller+": ["Glul"],
"Bipolar+": ["Vsx2"],
"Microglia*": ["Aif1", "C1qa", "C1qb", "Tmem119", "Hexb"],
"Astrocyte*": ["Gfap", "S100b", "Aqp4"],
"Endothelial*": ["Pecam1", "Cldn5", "Kdr"],
"Oligodendrocyte*": ["Mog", "Plp1", "Mbp"],
}
adata = sc.read_h5ad("data/03_annotated.h5ad")
var = set(adata.raw.var_names)
panel = {}
for src in (S3, EXTRA):
for ct, gs in src.items():
ok = [g for g in gs if g in var]
missing = set(gs) - set(ok)
if missing:
print(f"[警告] {ct} 缺失: {missing}")
panel[ct] = ok
# 按注释细胞类型排序 cluster
order = (
adata.obs.groupby("leiden_0.8", observed=True)["cell_type"]
.agg(lambda x: x.mode()[0])
.sort_values()
)
adata.obs["ct_cluster"] = adata.obs["cell_type"].astype(str) + " | c" + adata.obs["leiden_0.8"].astype(str)
ct_order = sorted(adata.obs["ct_cluster"].unique(), key=lambda s: (s.split(" | ")[0], int(s.split(" | c")[1])))
fig = sc.pl.dotplot(
adata, var_names=panel, groupby="ct_cluster", categories_order=ct_order,
use_raw=True, show=False, return_fig=True,
)
fig.savefig(OUT / "marker_dotplot_fullS3.png", bbox_inches="tight")
print("Done ->", OUT / "marker_dotplot_fullS3.png")