美文网首页单细胞测序
代码库1-Seurat代码

代码库1-Seurat代码

作者: 江湾青年 | 来源:发表于2021-10-14 18:17 被阅读0次

    Seurat标准流程

    # 读取数据
    pbmc <- CreateSeuratObject(counts = data)
    pbmc <- NormalizeData(pbmc)
    pbmc <- FindVariableFeatures(pbmc, selection.method = "vst", nfeatures = 2000)
    LabelPoints(plot = VariableFeaturePlot(pbmc), points = head(VariableFeatures(pbmc), 10), repel = TRUE)
    pbmc <- ScaleData(pbmc)
    pbmc <- RunPCA(pbmc)   
    ElbowPlot(pbmc)
    pbmc <- RunUMAP(pbmc, dims = 1:20)          
    DimPlot(pbmc, reduction = "umap")
    # 聚类
    pbmc <- FindNeighbors(pbmc, dims = 1:20)
    pbmc <- FindClusters(pbmc, resolution = 0.5)
    # 寻找差异基因
    cluster1.markers <- FindMarkers(pbmc, ident.1 = 0, logfc.threshold = 0.25, test.use = "roc", only.pos = TRUE)
    pbmc.markers <- FindAllMarkers(pbmc, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.25)
    pbmc.markers %>% group_by(cluster) %>% top_n(n = 2, wt = avg_logFC)
    top10 <- pbmc.markers %>% group_by(cluster) %>% top_n(n = 10, wt = avg_logFC)
    # 可视化marker基因
    VlnPlot(pbmc, features = c("MS4A1", "CD79A"))
    FeaturePlot(pbmc, features = c("MS4A1", "CD79A"))
    
    

    一行版

    pbmc <- CreateSeuratObject(data) %>% NormalizeData(verbose = FALSE) %>% 
    FindVariableFeatures(verbose = FALSE) %>% ScaleData(verbose = FALSE) %>% 
    RunPCA(npcs = 20,verbose = FALSE) %>% RunUMAP(dims = 1:20,verbose = FALSE) %>% 
    FindNeighbors(dims = 1:20,verbose = FALSE) %>% 
    FindClusters(resolution = resolution, verbose = FALSE)
    DimPlot(pbmc, reduction = "umap",group.by = 'true',label = T)
    

    SCTransform

    pbmc <- CreateSeuratObject(data) %>% PercentageFeatureSet(pattern = "^MT-", col.name = "percent.mt") %>% 
        SCTransform(vars.to.regress = "percent.mt") %>% RunPCA() %>% FindNeighbors(dims = 1:30) %>% 
        RunUMAP(dims = 1:30) %>% FindClusters()
    

    相关文章

      网友评论

        本文标题:代码库1-Seurat代码

        本文链接:https://www.haomeiwen.com/subject/euvjnltx.html