4 单个亚群细分

##########################################细分

library(Seurat)

library(dplyr)

###############Myeloid

Myeloid<-subset(sce.mergeTEN, idents = c(16))

Myeloid <- NormalizeData(Myeloid, normalization.method = "LogNormalize", scale.factor = 10000)

Myeloid <- FindVariableFeatures(Myeloid, selection.method = "vst", nfeatures = 2000)

Myeloid@[email protected]

length(Myeloid@[email protected])

###scaling the data###

all.genes <- rownames(Myeloid)

all.genes[1000:10010]

Myeloid <- ScaleData(Myeloid,vars.to.regress = c("percent.mt"))

Myeloid

###perform linear dimensional reduction###

Myeloid <- RunPCA(Myeloid, features = VariableFeatures(object = Myeloid))

print(Myeloid[["pca"]], dims = 1:5, nfeatures = 5)

#dev.off()

VizDimLoadings(Myeloid, dims = 1:2, reduction = "pca")

ElbowPlot(Myeloid,ndims = 50)

####cluster the cells###

Myeloid <- FindNeighbors(Myeloid, dims = 1:30)

####Run non-linear dimensional reduction (UMAP/tSNE)###

Myeloid <- RunUMAP(Myeloid, dims = 1:30)

Myeloid<-RunTSNE(Myeloid,dims=1:30)

Myeloid <- FindClusters(Myeloid, resolution = 1)###

DimPlot(Myeloid, reduction = "umap",label = T)

DimPlot(Myeloid, reduction = "tsne",label = T)

table(Idents(Myeloid))

#FindAllMarkers

Myeloid.markers <- FindAllMarkers(Myeloid, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.25)

markers_df = Myeloid.markers %>% group_by(cluster)

write.csv(markers_df,"/home/yifan/project/LJ.22.02.sc/rdata/Myeloid.markers.csv")

########################判断细胞种类

############巨噬细胞6;M1(FCGR3A)和M2(CD163)

FeaturePlot(Myeloid,features = c("Cd163","Cd68","Cd11b","F4/80","MerTK","Cd68",

                                      "Fcgr3a","Cd163"),min.cutoff = 0,max.cutoff = 0.01,reduction = "umap",label = T)

###########################SingleR对小鼠免疫单细胞自动注释

library(SingleR)

sce_for_SingleR <- GetAssayData(Myeloid, slot="data")

[email protected]$seurat_clusters

#############

mouseImmu <- ImmGenData()

pred.mouseImmu <- SingleR(test = sce_for_SingleR, ref = mouseImmu, labels = mouseImmu$label.main,

                          method = "cluster", clusters = clusters,

                          assay.type.test = "logcounts", assay.type.ref = "logcounts")

#################

mouseRNA <- MouseRNAseqData()

pred.mouseRNA <- SingleR(test = sce_for_SingleR, ref = mouseRNA, labels = mouseRNA$label.fine ,

                        method = "cluster", clusters = clusters,

                        assay.type.test = "logcounts", assay.type.ref = "logcounts")

cellType=data.frame(ClusterID=levels([email protected]$seurat_clusters),

                    mouseImmu=pred.mouseImmu$labels,

                    mouseRNA=pred.mouseRNA$labels )

###############展示柱状图

library(ggplot2)

###################

ggplot() + geom_bar(data = [email protected], aes(x = orig.ident, fill = factor(seurat_clusters)),

                    +                    position = "fill")

ggplot() + geom_bar(data = [email protected], aes(x = seurat_clusters, fill = factor(orig.ident)),

                    +                    position = "fill")

########

DimPlot(Myeloid, reduction = "umap",label = TRUE, group.by="orig.ident")

DimPlot(Myeloid,reduction = "umap",label = T,split.by = "orig.ident")

FeaturePlot(Myeloid,features = c("Zabp1"),min.cutoff = 0,max.cutoff = 0.01,reduction = "umap",label = T)

#############

saveRDS(Myeloid,file="/home/yifan/project/LJ.22.02.sc/rdata/Myeloid.rds")

你可能感兴趣的:(4 单个亚群细分)