# ============================================================================== # 云生信 (www.biocloudservice.com) 大内存生信交付 · 标准复现与本地改图脚本 (示例模板) # ============================================================================== # 运行环境声明:前半段全量整合基于云生信大内存标准环境 (Linux, R 4.3.2, Seurat 5.1.0, # harmony 1.2.0, 峰值物理内存需求 >= 128 GB) 验证通过。 # 售后边界说明:本脚本供论文 Methods 方法学溯源及下游图表配色/字号微调使用; # 不包含个人笔记本本地 C++ 依赖装包排错及本地爆内存调优服务。 # 免折腾提示 :全量对象 full_integrated.rds 默认在云端高速缓存保留 7 天; # 如需继续细分亚群或跑拟时序,可直接转入【云生信预装服务器 / BioAgent】免重传加载。 # ============================================================================== # ------------------------------------------------------------------------------ # 第一部分:本地笔记本 1 秒改图代码(仅需几 MB 的 01_slim_plotting_bundle_demo.csv) # 普通 8G/16G 办公电脑无需加载 20GB 原始 RDS,直接运行下方代码即可修改配色与排版! # ------------------------------------------------------------------------------ library(ggplot2) slim_df <- read.csv("01_slim_plotting_bundle_demo.csv", stringsAsFactors = FALSE) bright_palette <- c( "SPP1+ Macrophage" = "#E65100", "Kupffer Macrophage" = "#2E7D32", "CAF Fibroblast" = "#1565C0", "Exhausted CD8+ T" = "#6A1B9A", "Effector CD8+ T" = "#00838F", "Malignant Hepatocyte" = "#C62828", "Normal Hepatocyte" = "#558B2F", "Endothelial" = "#0277BD", "B / Plasma" = "#AD1457" ) p_umap <- ggplot(slim_df, aes(x = umap_1, y = umap_2, color = cell_type)) + geom_point(size = 2.2, alpha = 0.88) + scale_color_manual(values = bright_palette) + facet_wrap(~ group) + theme_bw(base_size = 13) + theme( panel.grid = element_blank(), strip.background = element_rect(fill = "#F0F7FF", color = "#BFDBFE"), strip.text = element_text(face = "bold", color = "#0F172A"), legend.title = element_blank() ) + labs( title = "Single-Cell UMAP by Group (Slim Plotting Bundle Demo)", x = "UMAP 1", y = "UMAP 2" ) ggsave("Fig1_UMAP_custom_style.pdf", p_umap, width = 9.5, height = 4.6) # ------------------------------------------------------------------------------ # 第二部分:云端大内存节点全量整合溯源脚本(供论文 Methods 核对参数) # 警告:全量 >100,000 细胞请勿在 <64GB 内存个人电脑直接运行此段 # ------------------------------------------------------------------------------ if (FALSE) { library(Seurat) library(harmony) options(future.globals.maxSize = 64 * 1024^3) plan("sequential") # 防止多进程复制大矩阵导致内存翻倍溢出 sc_obj <- readRDS("raw_merged_cohort.rds") sc_obj[["percent.mt"]] <- PercentageFeatureSet(sc_obj, pattern = "^MT-") sc_obj <- subset(sc_obj, subset = nFeature_RNA >= 200 & nFeature_RNA <= 7500 & percent.mt <= 15) sc_obj <- NormalizeData(sc_obj, normalization.method = "LogNormalize", scale.factor = 10000) sc_obj <- FindVariableFeatures(sc_obj, selection.method = "vst", nfeatures = 2500) sc_obj <- ScaleData(sc_obj, features = VariableFeatures(sc_obj)) # 仅对高变基因 Scale,省 70% 内存 sc_obj <- RunPCA(sc_obj, features = VariableFeatures(sc_obj), npcs = 30, verbose = FALSE) gc() sc_obj <- RunHarmony(sc_obj, group.by.vars = "sample_id", dims.use = 1:30) sc_obj <- RunUMAP(sc_obj, reduction = "harmony", dims = 1:30) sc_obj <- FindNeighbors(sc_obj, reduction = "harmony", dims = 1:30) sc_obj <- FindClusters(sc_obj, resolution = 0.5) # 1. 保存全量对象(云端暂存 7 天,供后续亚群细分/拟时序无缝调用) saveRDS(sc_obj, file = "full_integrated_harmony.rds", compress = FALSE) # 2. 自动剥离原始大矩阵,导出几 MB 轻量画图包供客户本地电脑秒开改图 umap_mat <- Embeddings(sc_obj, "umap") slim_export <- cbind( cell_barcode = rownames(sc_obj@meta.data), sc_obj@meta.data[, c("sample_id", "group", "patient", "cell_type")], umap_1 = round(umap_mat[, 1], 3), umap_2 = round(umap_mat[, 2], 3) ) write.csv(slim_export, file = "01_slim_plotting_bundle.csv", row.names = FALSE) } # --- Papers Methods Reference Template --- # Single-cell transcriptomic quality control and batch integration were performed in R (v4.3.2) # using Seurat (v5.1.0). Cells with <200 or >7,500 detected genes or >15% mitochondrial UMI counts # were excluded. Log-normalized counts and top 2,500 highly variable features were used for PCA (30 PCs), # followed by sample-level batch correction via Harmony (v1.2.0, dims 1:30) and UMAP visualization.