美文网首页
空转第19课生态位绘图补充

空转第19课生态位绘图补充

作者: 单细胞空间交响乐 | 来源:发表于2023-10-31 16:31 被阅读0次

    作者,Evil Genius

    这一篇要实现一下生态位绘图,参考图片在

    首先我们需要理解这个图片的内容,解读如下:Characterizing ST spots by cell type neighborhood. In the top schematic grey spots indicate the 462 presence of the cell type of interest, orange indicates ‘Malignant’ spots, and dashed lines their 463 surrounding spots. the spots are colored by neighborhood 464 macrophage score. 内容就是选择目标spot,分析其周围spot含有细胞类型A的分数(比如肿瘤spot周围spot含有巨噬细胞的含量),并用颜色梯度进行空间展示。

    这么做的意义,To characterize the cell type composition surrounding each ‘Malignant’ spot(目标细胞类型), we calculated, for each cell type, two score indices meant to capture their microenvironment. We defined the ‘neighborhood score’ as the fraction of surrounding spots containing that cell type。This score thus directly measures the cell type composition in the adjacent spots。

    我们来绘制一下,效果如下:


    我们来实现一下:
    加载并读取数据
    library(Seurat)
    library(dplyr)
    library(dbscan)
    library(ggplot2)
    
    cortex_sp = readRDS('/root/singlepipeline/demodata/cell2location/test.corr.rds')
    
    数据处理,单细胞空间联合分析的结果,可以外部读取
    decon_mtrx = t(cortex_sp@assays$predictions@data)
    
    cell_types_all <- colnames(decon_mtrx)[which(colnames(decon_mtrx) != "max")]
    
    decon_df <- decon_mtrx %>%
      data.frame(check.names = F) %>%
      tibble::rownames_to_column("barcodes")
    
    #decon_df$barcodes = rownames(tmp)
    
    cortex_sp@meta.data <- cortex_sp@meta.data %>%
      tibble::rownames_to_column("barcodes") %>%
      dplyr::left_join(decon_df, by = "barcodes") %>%
      tibble::column_to_rownames("barcodes")
    
    ###plot dot
    slice <- names(cortex_sp@images)[1]
    metadata_ds <- data.frame(cortex_sp@meta.data)
    colnames(metadata_ds) <- colnames(cortex_sp@meta.data)
    cell_types_interest <- cell_types_all
    
    metadata_ds <- metadata_ds %>% tibble::rownames_to_column("barcodeID") %>%
                dplyr::mutate(rsum = base::rowSums(.[, cell_types_interest,
                    drop = FALSE])) %>% dplyr::filter(rsum != 0) %>%
                dplyr::select("barcodeID") %>% dplyr::left_join(metadata_ds %>%
                tibble::rownames_to_column("barcodeID"), by = "barcodeID") %>%
                tibble::column_to_rownames("barcodeID")
    
    
    spatial_coord <- data.frame(cortex_sp@images[[slice]]@coordinates) %>%
            tibble::rownames_to_column("barcodeID") %>% dplyr::mutate(imagerow_scaled = imagerow *
            cortex_sp@images[[slice]]@scale.factors$lowres, imagecol_scaled = imagecol *
            cortex_sp@images[[slice]]@scale.factors$lowres) %>% dplyr::inner_join(metadata_ds %>%
            tibble::rownames_to_column("barcodeID"), by = "barcodeID")
    
    临近位点计算

    相关文章

      网友评论

          本文标题:空转第19课生态位绘图补充

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