• gpnmb+ gpnmb-AT2 cell空转映射 上皮细胞的空转映射


    这里是引用

    library(Seurat)
    library(dplyr)
    library(cowplot)
    library(ggplot2)
    library(harmony)
    library(patchwork)
    library(openxlsx)
    file = "G:/silicosis/sicosis/YSQ/2022-8-2_EPITHELIAL"##	改成想存放文件的路径
    dir.create(file)
    setwd(file)
    getwd()
    path=getwd()
    load("G:\\silicosis\\sicosis\\YSQ\\3-23_EPITHELIAL\\silicosi_AT2.rds")
    
    DotPlot(subset_data,features = "Gpnmb")
    DotPlot(subset_data,features = "Gpnmb",group.by = "stim")
    label = as.character(Idents(subset_data))
    label
    levels(label)
    table(label)
    label[which(label %in% c("AT2 cell-1", "AT2 cell-2", "Igha+ AT2  cell"))] = "AT2 cell"
    label[which(label %in% "AT2 cell" & subset_data$RNA@counts["Gpnmb", ] > 0)] = "Gpnmb+ AT2 cell"
    label[which(label %in% "AT2 cell" & subset_data$RNA@counts["Gpnmb", ] == 0)] = "Gpnmb- AT2 cell"
    #label = factor(label, levels = c(levels(Idents(subset_data))[1:17], "Gpnmb+ AT2 cell", "Gpnmb- AT2 cell"))
    table(label)
    
    #label = factor(label, levels = c("Gpnmb+ AT2 cell", "Gpnmb- AT2 cell"))
    
    subset_data$my_group=label
    Idents(subset_data)=subset_data$my_group
    Idents(subset_data)
    markers_for_gpnmb_postive_and_gpnmb_negtive=FindMarkers(subset_data,ident.1 ="Gpnmb+ AT2 cell",
                                                            ident.2 = "Gpnmb- AT2 cell")
    head(markers_for_gpnmb_postive_and_gpnmb_negtive)
    getwd()
    write.xlsx(markers_for_gpnmb_postive_and_gpnmb_negtive,file = "differential_markers_for_gpnmb_postive_and_gpnmb_negtive.xlsx",
               col.names=T, row.names=T)
    
    #save(subset_data,file = "subsetdata_for_gpnmb+_.rds")
    load("G:\\silicosis\\sicosis\\YSQ\\2022-8-2_EPITHELIAL\\spatialMapping\\Gpnmb\\subsetdata_for_gpnmb+_.rds")
    Idents(subset_data)=subset_data$stim
    
    
    
    
    
    
    
    
    
    
    
    
    
    #2
    ##gpnmb阳性 和阴性在空转上的映射
    load("G:/silicosis/sicosis/silicosis-1122-merge/silicosis_cluster_merge.rds")## 17226 25002
    
    
    #阳性的AT2细胞在四个组别空转上的分布;
    
    {
      getwd()
      dir.create(paste(path, "spatialMapping", "Gpnmb", sep = "/"),recursive = TRUE)
      setwd(paste(path, "spatialMapping", "Gpnmb", sep = "/"))
      getwd()
      
      label = as.character(Idents(All.merge))
      label
      #Igha+ AT2  cell 
      #字体容易出错
      label[which(label %in% c("AT2 cell-1", "AT2 cell-2", "Igha+ AT2  cell"))] = "AT2 cell"
      label[which(label %in% "AT2 cell" & All.merge$RNA@counts["Gpnmb", ] > 0)] = "Gpnmb+ AT2 cell"
      label[which(label %in% "AT2 cell" & All.merge$RNA@counts["Gpnmb", ] == 0)] = "Gpnmb- AT2 cell"
      levels(label)
      table(label)
      label = factor(label, levels = c(levels(Idents(All.merge))[1:17], "Gpnmb+ AT2 cell", "Gpnmb- AT2 cell"))
     levels(label)
     levels(Idents(All.merge))
    
      table(label) 
     
      All.merge.SCT <- CreateSeuratObject(counts = All.merge@assays$RNA@counts, project = "silicosis")	#17226	26758
      All.merge.SCT = SCTransform(All.merge.SCT, verbose = FALSE) %>% RunPCA(verbose = FALSE)  #默认3000个HVG
      
      All.merge.SCT$cell.type = label
      table(All.merge.SCT$cell.type)
      dim(All.merge.SCT@assays$SCT@scale.data)
      cell.type = All.merge.SCT$cell.type
      
      library(Seurat)
      library(dplyr)
      library(cowplot)
      library(ggplot2)
      library(RColorBrewer)
      library(patchwork)
      SpatialColors <- colorRampPalette(colors = rev(x = brewer.pal(n = 11, name = "Spectral")))
      
    
      
      #################sio2_56
      #load("/data/home/longmin/code_test/silicosis_scRNAseq/unknown/ST_mapping_1012/sio2_56_sct.rds")
      getwd()
      load("G:/silicosis/需求/矽肺-数据分析结果-0119-yll/矽肺-数据分析结果-0119/sio2_56_sct.rds")
      anterset.sio2_56_sct <- FindTransferAnchors(reference = All.merge.SCT,query = sio2_56_sct,normalization.method="SCT")
      predictions.assay.sio2_56_sct <- TransferData(anchorset = anterset.sio2_56_sct, refdata = All.merge.SCT$cell.type, prediction.assay = TRUE, dims = 1:30)
      sio2_56_sct[["predictions"]] <- predictions.assay.sio2_56_sct
      DefaultAssay(sio2_56_sct) <- "predictions"
      save(sio2_56_sct,file="sio2_56_sct.prediction.rds")
      rowSums(sio2_56_sct$predictions@data)
      dim(sio2_56_sct$predictions@data)
      sio2_56_sct$predictions@data = sio2_56_sct$predictions@data[c(levels(cell.type), "max"), ]
      rowSums(sio2_56_sct$predictions@data)
      pre.mat = sio2_56_sct$predictions@data[-dim(sio2_56_sct$predictions@data)[1],]
      pre.mat.sum = data.frame(cell.type = rownames(pre.mat),score = rowSums(pre.mat))
      pdf("SiO2_56_spot_cell_type_prediction_split.pdf")
      for(i in levels(cell.type)){
        p <- SpatialPlot(sio2_56_sct, features=i, pt.size.factor=1.6)+scale_fill_gradientn(limits=c(0,1),colours=SpatialColors(n=100))+labs(title = "SiO2_56")
        print(p)
      }
      dev.off() 
      num = nrow(sio2_56_sct$predictions@data)
      max_index = apply(sio2_56_sct$predictions@data[-num,],2,which.max)
      max_cell_type = rownames(sio2_56_sct$predictions@data)[max_index]
      max_cell_type = factor(max_cell_type, levels=levels(cell.type))
      table(max_cell_type)
      spot.mat = data.frame(table(max_cell_type))
      colnames(spot.mat) = c("cell.type", "spot.num")
      spot.num.score = merge(spot.mat, pre.mat.sum, by.x="cell.type", sort=F)
      write.xlsx(spot.num.score, "SiO2_56_cellType_spotNum_score.xlsx", col.names=T, row.names=F)
      sio2_56_sct$spot.cell.type = max_cell_type
      pdf("SiO2_56_spot_cell_type_prediction_all.pdf", width = 10)
      SpatialPlot(sio2_56_sct, group.by="spot.cell.type")+labs(title = "SiO2_56")+guides(fill = guide_legend(override.aes = list(size = 5)))
      dev.off() 
      pdf("SiO2_56_max_spot_cellType.pdf")
      for (i in levels(cell.type)){
        idx = which(max_cell_type == i)
        cell = colnames(sio2_56_sct)[idx]
        if(length(idx)!=0){
          p = SpatialPlot(sio2_56_sct, cells.highlight=cell)+theme(legend.position="None")+labs(title=i)
          print(p)
        }
      }
      dev.off()
      
      
      #################sio2_7
      #load("/data/home/longmin/code_test/silicosis_scRNAseq/unknown/ST_mapping_1012/sio2_7_sct.rds")
      load("G:/silicosis/需求/矽肺-数据分析结果-0119-yll/矽肺-数据分析结果-0119/sio2_7_sct.rds")
      anterset.sio2_7_sct <- FindTransferAnchors(reference = All.merge.SCT,query = sio2_7_sct,normalization.method="SCT")
      predictions.assay.sio2_7_sct <- TransferData(anchorset = anterset.sio2_7_sct, refdata = All.merge.SCT$cell.type, prediction.assay = TRUE, dims = 1:30)
      sio2_7_sct[["predictions"]] <- predictions.assay.sio2_7_sct
      DefaultAssay(sio2_7_sct) <- "predictions"
     # save(sio2_7_sct,file="sio2_7_sct.prediction.rds")
     #load("G:\\silicosis\\sicosis\\YSQ\\2022-8-2_EPITHELIAL\\spatialMapping\\Gpnmb\\sio2_7_sct.prediction.rds")
       rowSums(sio2_7_sct$predictions@data)
      dim(sio2_7_sct$predictions@data)
      sio2_7_sct$predictions@data = sio2_7_sct$predictions@data[c(levels(cell.type), "max"), ]
      rowSums(sio2_7_sct$predictions@data)
      pre.mat = sio2_7_sct$predictions@data[-dim(sio2_7_sct$predictions@data)[1],]
      pre.mat.sum = data.frame(cell.type = rownames(pre.mat),score = rowSums(pre.mat))
      pdf("SiO2_7_spot_cell_type_prediction_split.pdf")
      for(i in levels(cell.type)){
        p <- SpatialPlot(sio2_7_sct, features=i, pt.size.factor=1.6)+scale_fill_gradientn(limits=c(0,1),colours=SpatialColors(n=100))+labs(title = "SiO2_7")
        print(p)
      }
      dev.off() 
      num = nrow(sio2_7_sct$predictions@data)
      max_index = apply(sio2_7_sct$predictions@data[-num,],2,which.max)
      max_cell_type = rownames(sio2_7_sct$predictions@data)[max_index]
      max_cell_type = factor(max_cell_type, levels=levels(cell.type))
      table(max_cell_type)
      spot.mat = data.frame(table(max_cell_type))
      colnames(spot.mat) = c("cell.type", "spot.num")
      spot.num.score = merge(spot.mat, pre.mat.sum, by.x="cell.type", sort=F)
      library(openxlsx)
      write.xlsx(spot.num.score, "SiO2_7_cellType_spotNum_score.xlsx", col.names=T, row.names=F)
      sio2_7_sct$spot.cell.type = max_cell_type
      pdf("SiO2_7_spot_cell_type_prediction_all.pdf")
      SpatialPlot(sio2_7_sct, group.by="spot.cell.type")+labs(title = "SiO2_7")+guides(fill = guide_legend(override.aes = list(size = 5)))
      dev.off() 
      pdf("SiO2_7_max_spot_cellType.pdf")
      for (i in levels(cell.type)){
        idx = which(max_cell_type == i)
        cell = colnames(sio2_7_sct)[idx]
        if(length(idx)!=0){
          p = SpatialPlot(sio2_7_sct, cells.highlight=cell)+theme(legend.position="None")+labs(title=i)
          print(p)
        }
      }
      dev.off()
      
      #################NS_56
      #load("/data/home/longmin/code_test/silicosis_scRNAseq/unknown/ST_mapping_1012/NS_56_sct.rds")
      #################NS_56
      load("G:/silicosis/需求/矽肺-数据分析结果-0119-yll/矽肺-数据分析结果-0119/NS_56_sct.rds")
      
      anterset.NS_56_sct <- FindTransferAnchors(reference = All.merge.SCT,query = NS_56_sct,normalization.method="SCT")
      predictions.assay.NS_56_sct <- TransferData(anchorset = anterset.NS_56_sct, refdata = All.merge.SCT$cell.type, prediction.assay = TRUE, dims = 1:30)
      NS_56_sct[["predictions"]] <- predictions.assay.NS_56_sct
      DefaultAssay(NS_56_sct) <- "predictions"
      save(NS_56_sct,file="NS_56_sct.prediction.rds")
      rowSums(NS_56_sct$predictions@data)
      dim(NS_56_sct$predictions@data)
      NS_56_sct$predictions@data = NS_56_sct$predictions@data[c(levels(cell.type), "max"), ]
      rowSums(NS_56_sct$predictions@data)
      pre.mat = NS_56_sct$predictions@data[-dim(NS_56_sct$predictions@data)[1],]
      pre.mat.sum = data.frame(cell.type = rownames(pre.mat),score = rowSums(pre.mat))
      pdf("NS_56_spot_cell_type_prediction_split.pdf")
      for(i in levels(cell.type)){
        p <- SpatialPlot(NS_56_sct, features=i, pt.size.factor=1.6)+scale_fill_gradientn(limits=c(0,1),colours=SpatialColors(n=100))+labs(title = "NS_56")
        print(p)
      }
      dev.off() 
      num = nrow(NS_56_sct$predictions@data)
      max_index = apply(NS_56_sct$predictions@data[-num,],2,which.max)
      max_cell_type = rownames(NS_56_sct$predictions@data)[max_index]
      max_cell_type = factor(max_cell_type, levels=levels(cell.type))
      table(max_cell_type)
      spot.mat = data.frame(table(max_cell_type))
      colnames(spot.mat) = c("cell.type", "spot.num")
      spot.num.score = merge(spot.mat, pre.mat.sum, by.x="cell.type", sort=F)
      write.xlsx(spot.num.score, "NS_56_cellType_spotNum_score.xlsx", col.names=T, row.names=F)
      NS_56_sct$spot.cell.type = max_cell_type
      pdf("NS_56_spot_cell_type_prediction_all.pdf")
      SpatialPlot(NS_56_sct, group.by="spot.cell.type")+labs(title = "NS_56")+guides(fill = guide_legend(override.aes = list(size = 5)))
      dev.off() 
      pdf("NS_56_max_spot_cellType.pdf")
      for (i in levels(cell.type)){
        idx = which(max_cell_type == i)
        cell = colnames(NS_56_sct)[idx]
        if(length(idx)!=0){
          p = SpatialPlot(NS_56_sct, cells.highlight=cell)+theme(legend.position="None")+labs(title=i)
          print(p)
        }
      }
      dev.off()
      
      
      #################NS_7
      #load("/data/home/longmin/code_test/silicosis_scRNAseq/unknown/ST_mapping_1012/NS_7_sct.rds")
      
      load("G:/silicosis/需求/矽肺-数据分析结果-0119-yll/矽肺-数据分析结果-0119/NS_7_sct.rds")
      anterset.NS_7_sct <- FindTransferAnchors(reference = All.merge.SCT,query = NS_7_sct,normalization.method="SCT")
      predictions.assay.NS_7_sct <- TransferData(anchorset = anterset.NS_7_sct, refdata = All.merge.SCT$cell.type, prediction.assay = TRUE, dims = 1:30)
      NS_7_sct[["predictions"]] <- predictions.assay.NS_7_sct
      DefaultAssay(NS_7_sct) <- "predictions"
      save(NS_7_sct,file="NS_7_sct.prediction.rds")
      rowSums(NS_7_sct$predictions@data)
      dim(NS_7_sct$predictions@data)
      NS_7_sct$predictions@data = NS_7_sct$predictions@data[c(levels(cell.type), "max"), ]
      rowSums(NS_7_sct$predictions@data)
      pre.mat = NS_7_sct$predictions@data[-dim(NS_7_sct$predictions@data)[1],]
      pre.mat.sum = data.frame(cell.type = rownames(pre.mat),score = rowSums(pre.mat))
      pdf("NS_7_spot_cell_type_prediction_split.pdf")
      for(i in levels(cell.type)){
        p <- SpatialPlot(NS_7_sct, features=i, pt.size.factor=1.6)+scale_fill_gradientn(limits=c(0,1),colours=SpatialColors(n=100))+labs(title = "NS_7")
        print(p)
      }
      dev.off() 
      num = nrow(NS_7_sct$predictions@data)
      max_index = apply(NS_7_sct$predictions@data[-num,],2,which.max)
      max_cell_type = rownames(NS_7_sct$predictions@data)[max_index]
      max_cell_type = factor(max_cell_type, levels=levels(cell.type))
      table(max_cell_type)
      spot.mat = data.frame(table(max_cell_type))
      colnames(spot.mat) = c("cell.type", "spot.num")
      spot.num.score = merge(spot.mat, pre.mat.sum, by.x="cell.type", sort=F)
      write.xlsx(spot.num.score, "NS_7_cellType_spotNum_score.xlsx", col.names=T, row.names=F)
      NS_7_sct$spot.cell.type = max_cell_type
      pdf("NS_7_spot_cell_type_prediction_all.pdf")
      SpatialPlot(NS_7_sct, group.by="spot.cell.type")+labs(title = "NS_7")+guides(fill = guide_legend(override.aes = list(size = 5)))
      dev.off() 
      pdf("NS_7_max_spot_cellType.pdf")
      for (i in levels(cell.type)){
        idx = which(max_cell_type == i)
        cell = colnames(NS_7_sct)[idx]
        if(length(idx)!=0){
          p = SpatialPlot(NS_7_sct, cells.highlight=cell)+theme(legend.position="None")+labs(title=i)
          print(p)
        }
      }
      dev.off()
    }
    
    
    
    
    
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
  • 相关阅读:
    Java毕设项目——超市POS收银管理系统(java+SSM+Maven+Mysql+Jsp)
    AUTOSAR汽车电子嵌入式编程精讲300篇-汽车 CAN FD 总线应用研究
    基于像素预测和位平面压缩的加密图像可逆数据隐藏附matlab代码(论文复现)
    「Java核心面试系列」Spring面试核心49问(附答案)
    ADB命令
    Tableau3——文本表,树形图,词云图
    Windows AD共享权限管理工具
    phoenix安装
    基于加权对立和贪婪搜索多模态工程问题的黑猩猩优化算法(Matlab代码实现)
    Selenium自动化测试框架工作原理你明白了吗?
  • 原文地址:https://blog.csdn.net/qq_52813185/article/details/126130629