[1]:
library(Seurat)
library(gridExtra)
library(Matrix)
library(ggplot2)
library(harmony)
library(pheatmap)
Loading required package: Rcpp

Mye subtype#

[2]:
source('/home/public/ghx/software/my_seurat.r')
[3]:
RDSPath <- '/home/public/ghx/wuLab/Bladder/1217_all/seu'
[4]:
ct <- 'Mye'
[5]:
mtx <- readRDS(file = file.path(RDSPath,
                        paste0('V1_Celltype_',ct,'_matrix.rds')))
anno <- readRDS(file = file.path(RDSPath,
                        paste0('V1_Celltype_','Mac','_annotation.rds')))
[8]:
table(anno$Mye.ct)

  cDC   Mac   Neu   pDC
  354 12981  8029   155
[10]:
seu.list <- list()
ct.table <- table(anno$Mye.ct)
for(ct in names(ct.table)){
    if(ct == 'Mac'){
        next
    }
    temp.cells <- row.names(anno)[ anno$Mye.ct == ct ]
    temp.anno <- anno[temp.cells,]
    temp.mtx <- mtx[,temp.cells]
    temp.seu <- CreateSeuratObject(counts = temp.mtx,
                                         meta.data = temp.anno,
                                         project = ct)
    temp.seu <- Nml_Scl_Fvg_PCA_Fnb(temp.seu)
    temp.seu <- RunHarmony(temp.seu, theta = 10, verbose = F,
                  group.by.vars = 'patient', plot_convergence = F)
    temp.seu <- RunUMAP(object = temp.seu, reduction.name = 'umap_harmony',
               umap.method = 'umap-learn', metric = 'correlation',
               reduction = 'harmony', dims = 1:20)
    temp.seu <- FindNeighbors(temp.seu, reduction = 'harmony',
                             dims = 1:20, verbose = F)
    temp.seu <- FindClusters(temp.seu, verbose = F,resolution = 1.2)
    p1 <- DimPlot(temp.seu, label = T, pt.size = 1,
                  reduction = 'umap_harmony') +
         labs(title = 'cluster') #+ theme(legend.position = 'none')
    p2 <- DimPlot(temp.seu, label = T, pt.size = 1, group.by = 'orig.ident',
                  reduction = 'umap_harmony') +
         labs(title = 'sample.origin') + theme(legend.position = 'none')
    p3 <- DimPlot(temp.seu, label = T, pt.size = 1, group.by = 'status',
                  reduction = 'umap_harmony') +
         labs(title = 'status') #+ theme(legend.position = 'none')
    p4 <- DimPlot(temp.seu, label = T, pt.size = 1, group.by = 'patient',
                  reduction = 'umap_harmony') +
         labs(title = 'patient') #+ theme(legend.position = 'none')
    p <- arrangeGrob(grobs = list(p1,p2,p3,p4), ncol = 2,
                    top = paste0('MIBC5-16:', ct,' merge'))
    ggsave(plot = p, limitsize = FALSE, width = 10, height = 10,
           filename = file.path('/home/public/ghx/wuLab/Bladder/1217_all/CellTypes/Mye/Merge',
                                paste0('Merge_v1_',ct,'_harmony_overview.jpg')))
    markers <- FindAllMarkers(temp.seu, verbose = F)
    top10 <- extractTopNMarkers(df = markers, top_n = 25)
    p <- DoHeatmap(object = temp.seu, draw.lines = FALSE,
              features = top10$gene, size = 5, angle = 0,
                   disp.min = -2, disp.max = 2) +
            theme(text = element_text(size = 4))
    ggsave(plot = p, limitsize = FALSE, width = 10, height = 10,
           filename = file.path('/home/public/ghx/wuLab/Bladder/1217_all/CellTypes/Mye/Merge',
                                    paste0('Merge_v1_',ct,'_harmony_heatmap.jpg')))
    write.csv(markers,file.path('/home/public/ghx/wuLab/Bladder/1217_all/CellTypes/Mye/Merge',
                             paste0('markers_',ct,'_cluster.csv')))
    saveRDS(temp.seu, file.path(RDSPath,
                                paste0('V1_Celltype_',ct,'_seu.rds')))
    seu.list[[ct]] <- temp.seu
}
Warning message:
“Using `as.character()` on a quosure is deprecated as of rlang 0.3.0.
Please use `as_label()` or `as_name()` instead.
This warning is displayed once per session.”
Warning message in irlba(A = t(x = object), nv = npcs, ...):
“You're computing too large a percentage of total singular values, use a standard svd instead.”
[17]:
ct <- 'Neu'
temp.seu <- seu.list[[ct]]
temp.seu <- FindClusters(temp.seu, verbose = F,resolution = 0.25)
p1 <- DimPlot(temp.seu, label = T, pt.size = 0.1,
              reduction = 'umap_harmony') +
     labs(title = 'cluster') #+ theme(legend.position = 'none')
p2 <- DimPlot(temp.seu, label = T, pt.size = 0.1, group.by = 'orig.ident',
              reduction = 'umap_harmony') +
     labs(title = 'sample.origin') + theme(legend.position = 'none')
p3 <- DimPlot(temp.seu, label = T, pt.size = 0.1, group.by = 'status',
              reduction = 'umap_harmony') +
     labs(title = 'status') #+ theme(legend.position = 'none')
p4 <- DimPlot(temp.seu, label = T, pt.size = 0.1, group.by = 'patient',
              reduction = 'umap_harmony') +
     labs(title = 'patient') #+ theme(legend.position = 'none')
p <- arrangeGrob(grobs = list(p1,p2,p3,p4), ncol = 2,
                top = paste0('MIBC5-16:', ct,' merge'))
ggsave(plot = p, limitsize = FALSE, width = 10, height = 10,
       filename = file.path('/home/public/ghx/wuLab/Bladder/1217_all/CellTypes/Mye/Merge',
                            paste0('Merge_v1_',ct,'_harmony_overview.jpg')))
markers <- FindAllMarkers(temp.seu, verbose = F)
top10 <- extractTopNMarkers(df = markers, top_n = 25)
p <- DoHeatmap(object = temp.seu, draw.lines = FALSE,
          features = top10$gene, size = 5, angle = 0,
               disp.min = -2, disp.max = 2) +
        theme(text = element_text(size = 4))
ggsave(plot = p, limitsize = FALSE, width = 10, height = 10,
       filename = file.path('/home/public/ghx/wuLab/Bladder/1217_all/CellTypes/Mye/Merge',
                                paste0('Merge_v1_',ct,'_harmony_heatmap.jpg')))
write.csv(markers,file.path('/home/public/ghx/wuLab/Bladder/1217_all/CellTypes/Mye/Merge',
                         paste0('markers_',ct,'_cluster.csv')))
saveRDS(temp.seu, file.path(RDSPath,
                            paste0('V1_Celltype_',ct,'_seu.rds')))
[28]:
for(ct in names(seu.list)){
    temp.anno <- seu.list[[ct]]@meta.data
    saveRDS(temp.anno, file.path(RDSPath,
                                 paste0('V1_Celltype_',ct,'_annotation_withAnno.rds')))
}
[ ]: