1. #单细胞亚群的生物学合理命名讨论
    2. rm(list = ls())
    3. library(Seurat)
    4. library(SeuratData)
    5. library(ggplot2)
    6. library(patchwork)
    7. library(dplyr)
    8. load(file = 'basic.sce.pbmc.Rdata')
    9. levels(Idents(pbmc))
    10. # 首先提取T细胞子集
    11. DimPlot(pbmc,
    12. reduction = 'umap',
    13. label = TRUE, pt.size = 0.5) + NoLegend()
    14. FeaturePlot(pbmc, features = c("CD3D","CD3E")) #T细胞常用CD3来分
    15. sce=pbmc
    16. table(Idents(sce))
    17. #取子集
    18. t_sce = sce[, Idents(sce) %in% c('CD8 T')]
    19. #然后进行标准的降维聚类分群
    20. #代码不要变动
    21. #降维聚类分群
    22. sce=t_sce
    23. #归一化
    24. sce <- NormalizeData(sce,
    25. normalization.method = "LogNormalize",
    26. scale.factor = 1e4)
    27. #Find variable features
    28. sce <- FindVariableFeatures(sce,
    29. selection.method = 'vst',
    30. nfeatures = 2000)
    31. #Scale and center the data
    32. sce <- ScaleData(sce,
    33. vars.to.regress = "percent.mt")
    34. #pca
    35. sce <- RunPCA(sce,
    36. features = VariableFeatures(object = sce))
    37. #计算给定数据集的k.param近邻
    38. sce <- FindNeighbors(sce,
    39. dims = 1:10)
    40. #聚类
    41. sce <- FindClusters(sce,
    42. resolution = 1 )
    43. # Look at cluster IDs of the first 5 cells
    44. head(Idents(sce), 5)
    45. table(sce$seurat_clusters)
    46. sce <- RunUMAP(sce, dims = 1:10)
    47. DimPlot(sce,
    48. reduction = 'umap')
    49. #为数据集中的每个标识类查找markers(差异表达基因)
    50. sce.markers <- FindAllMarkers(object = sce,
    51. only.pos = TRUE,
    52. min.pct = 0.25,
    53. thresh.use = 0.25)
    54. DT::datatable(sce.markers)
    55. # write.csv(sce.markers,file=paste0(pro,'_sce.markers.csv'))
    56. save(sce.markers,
    57. file = 'sce.markers-for-cd8-subsets.Rdata')
    58. library(dplyr)
    59. #在seurat4里面,是 avg_log2FC,是V3版本是avg_logFC
    60. top10 <- sce.markers %>% group_by(cluster) %>% top_n(5, avg_log2FC)
    61. DoHeatmap(sce,
    62. top10$gene,
    63. size=3)
    64. p <- DotPlot(sce,
    65. features = unique(top10$gene),
    66. assay='RNA' ) + coord_flip()
    67. p
    68. ggsave('check-top5-for-cd8-subsets.pdf' )
    69. # cytotoxicity (GZMB, PRF1), 0
    70. # naive (LEF1, SELL, TCF7), 1
    71. # LTB T cells , 2
    72. # RPl/s
    73. # 参考: https://mp.weixin.qq.com/s/1YjoX8lTIB0e2vV0Eqey2Q
    74. marker_genes= c("MKI67","TOP2A",'TNFRSF9','MX1',
    75. "SELL","IL7R","CD40LG","ANXA1","FOS")
    76. p <- DotPlot(sce,
    77. features = marker_genes,
    78. assay='RNA' ) + coord_flip() + theme(axis.text.x = element_text(angle = 90))
    79. p
    80. ggsave('check_g1_markers_by_Tcell-SubType.pdf')
    81. marker_genes= c("MKI67","TOP2A",'TNFRSF9','MX1')
    82. FeaturePlot(pbmc,
    83. features = marker_genes)