常见单细胞数据格式的转换:Seurat, SingleCellExperiment, AnnData
好难哦 呜呜呜 想偷懒不学结构,就会抓瞎,希望能抓瞎到结束不出问题。我之后一定会好好认结构的。。。
#细胞周期可视化----
#很开心 好像找到了原文很吻合的推文
rm(list=ls())
gc()
getwd()
# setwd("E:/R/CCA_learning/fig7")
load("KF.all.Rdata")
# 一、装包----
# BiocManager::install("tricycle")
# BiocManager::install("scater")
{
library(tricycle)
library(scattermore)
library(scater)
}
# 二、创建一个新的SingleCellExperiment对象(af.sce),----
# 并对其进行细胞周期的投影。确保每个单细胞数据都会被关联到一个特定的细胞周期阶段,有助于后续的分析。
af.sce = as.SingleCellExperiment(sce)
af.sce <- project_cycle_space(af.sce,
species = c("human"),
gname.type = "SYMBOL")
# 三、绘制细胞周期位置着色的嵌入散射图----
scater::plotReducedDim(af.sce, dimred = "tricycleEmbedding") +
labs(x = "Projected PC1", y = "Projected PC2") +
ggtitle(sprintf("Projected cell cycle space (n=%d)",
ncol(af.sce))) +
theme_bw(base_size = 14)
af.sce <- estimate_cycle_position(af.sce)
fit.l <- fit_periodic_loess(af.sce$tricyclePosition,
assay(af.sce, 'logcounts')["TP53",],
plot = TRUE,
x_lab = "Cell cycle position \u03b8", y_lab = "log2(TP53)",
fig.title = paste0("Expression of TP53 along \u03b8 (n=",
ncol(af.sce), ")"))
fit.l$fig + theme_bw(base_size = 14)
af.sce <- estimate_Schwabe_stage(af.sce,
gname.type = 'SYMBOL',
species = 'human')
table(af.sce$CCStage %>% is.na())
pdf(file = "07-cell_cycle_density.pdf",width =8,height = 6)
plot_ccposition_den(af.sce$tricyclePosition,
af.sce$orig.ident, 'sample', type = "circular",
bw = 10, fig.title = "Density of cell cycle (\u03b8)") +
theme_bw(base_size = 14)
dev.off()
# 四、绘制可视化tSNE/UMAP散点图----
library(Seurat)
# 创建 Seurat 对象
seurat_obj <- as.Seurat(af.sce, counts = "counts", data = "logcounts")
Idents(seurat_obj)=seurat_obj$CCStage
pdf(file = "07-cellcycle.scRNA.TSEN.pdf",width =7.5,height = 5.5)
DimPlot(seurat_obj, reduction = "TSNE", label = T, label.size = 3.5,pt.size = 2.5)+theme_classic()+theme(panel.border = element_rect(fill=NA,color="black", size=0.5, linetype="solid"),legend.position = "right")
dev.off()
pdf(file = "07-cellcycle.scRNA.UMAP.pdf",width =7.5,height = 5.5)
DimPlot(seurat_obj, reduction = "UMAP", label = T, label.size = 3.5,pt.size = 2.5)+theme_classic()+theme(panel.border = element_rect(fill=NA,color="black", size=0.5, linetype="solid"),legend.position = "right")
dev.off()