Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

让我们把细胞类群功能刻画与数目统计画在一起吧 #4172

Closed
ixxmu opened this issue Nov 30, 2023 · 1 comment
Closed

让我们把细胞类群功能刻画与数目统计画在一起吧 #4172

ixxmu opened this issue Nov 30, 2023 · 1 comment

Comments

@ixxmu
Copy link
Owner

ixxmu commented Nov 30, 2023

https://mp.weixin.qq.com/s/_W1OT8fEcD8k3pLgCB0Oqw

@ixxmu
Copy link
Owner Author

ixxmu commented Nov 30, 2023

让我们把细胞类群功能刻画与数目统计画在一起吧 by YuLabSMU

一如即往,来一段无脑的Seurat操作:

library(Seurat)
pbmc_counts <- Read10X(
  data.dir = file.path(input_dir, "filtered_gene_bc_matrices/hg19/")
)
pbmc <- CreateSeuratObject(counts = pbmc_counts, project = "pbmc3k",
                           min.cells = 3)

pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^MT-")
pbmc <- subset(pbmc,
  subset = nFeature_RNA > 200 & nFeature_RNA < 2500 & percent.mt < 5
)
pbmc <- NormalizeData(pbmc, normalization.method = "LogNormalize",
                      scale.factor = 10000)
pbmc <- ScaleData(pbmc)

pbmc <- FindVariableFeatures(pbmc, selection.method = "vst",
                             nfeatures = 2000)
pbmc <- RunPCA(pbmc, features = VariableFeatures(object = pbmc))
pbmc <- RunUMAP(pbmc, dims = 1:10)

pbmc <- FindNeighbors(pbmc, dims = 1:10)
pbmc <- FindClusters(pbmc, resolution = 0.5)


seurat_cluster_id <- c("Naive CD4 T""CD14+ Mono""Memory CD4 T""B",
                       "CD8 T""FCGR3A+ Mono""NK""DC""Platelet")
names(seurat_cluster_id) <- levels(pbmc)
pbmc <- RenameIdents(pbmc, seurat_cluster_id)

找找Markers吧

pbmc.markers <- FindAllMarkers(pbmc, only.pos = TRUE)

pbmc.markers %>%
    group_by(cluster) %>%
    dplyr::filter(avg_log2FC > 1) %>%
    slice_head(n = 20) %>%
    ungroup() -> top20

拿出前20来当Markers。

来个富集分析吧


library(clusterProfiler)
bitr(top20$gene'SYMBOL''ENTREZID''org.Hs.eg.db') -> gg

top20 <- merge(top20, gg, by.x='gene', by.y = 'SYMBOL')
head(top20)
kk <- compareCluster(ENTREZID~cluster, data = top20, fun=enrichKEGG)

可视化来串场吧

先来一段我们富集分析的经典点图:

library(enrichplot)
g <- dotplot(kk) + 
  aes(x=sub("\n.*""", Cluster)) + 
  xlab("Cell Clusters")

【和降维图保持一致的细胞类群统计图】,再用这篇文章介绍的方法先来画图:

librrary(ggsc)
p = sc_dim(pbmc) + sc_dim_geom_label()
p2 = sc_dim_count(p) + 
  coord_cartesian() + 
  ggfun::theme_noxaxis() +
  xlab(NULL)

见证奇怪的时刻到了:

library(aplot)
insert_top(g, p2, height=.2)

有了aplot这个神奇的包,本来两个对不齐的图,现在完美地对齐了。于是能够同时展示细胞类型的数目,和刻画通路的富集分析结果。这也对应到了上次说到的KISS原则,简单简洁优雅。

@ixxmu ixxmu changed the title archive_request 让我们把细胞类群功能刻画与数目统计画在一起吧 Nov 30, 2023
@ixxmu ixxmu closed this as completed Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant