美文网首页单细胞seurat
seurat对象中细胞identity的获取、设置与操纵

seurat对象中细胞identity的获取、设置与操纵

作者: 单链结合蛋白 | 来源:发表于2022-02-09 22:27 被阅读0次

    前两天遇到了一个小问题:初步注释细胞发现,使用RenameIdents后细胞类型的levels与我想要的排序不符。例如,我实际得到的level为: cancer_cell1 T_cells cancer_cell2 cancer_cell3 B_cells.但是我想要把cancer_cell cluster与免疫细胞的排列成:cancer_cell1 cancer_cell2 cancer_cell3 T_cells B_cells。搜所了一下,结果方法很简单。

    
    # Reorder identity classes
    
    levels(x = pbmc_small)
    
    #> [1] "B" "A" "C"
    
    levels(x = pbmc_small) <- c('C', 'A', 'B')
    
    levels(x = pbmc_small)
    
    #> [1] "C" "A" "B"
    
    

    seurat处理identity的函数有

    
    Idents(object, ...)
    
    Idents(object, ...) <- value
    
    RenameIdents(object, ...)
    
    ReorderIdent(object, var, ...)
    
    SetIdent(object, ...)
    
    StashIdent(object, save.name, ...)
    
    # S3 method for Seurat
    
    Idents(object, ...)
    
    # S3 method for Seurat
    
    Idents(object, cells = NULL, drop = FALSE, ...) <- value
    
    # S3 method for Seurat
    
    ReorderIdent(
    
      object,
    
      var,
    
      reverse = FALSE,
    
      afxn = mean,
    
      reorder.numeric = FALSE,
    
      ...
    
    )
    
    # S3 method for Seurat
    
    RenameIdents(object, ...)
    
    # S3 method for Seurat
    
    SetIdent(object, cells = NULL, value, ...)
    
    # S3 method for Seurat
    
    StashIdent(object, save.name = "orig.ident", ...)
    
    # S3 method for Seurat
    
    droplevels(x, ...)
    
    # S3 method for Seurat
    
    levels(x)
    
    # S3 method for Seurat
    
    levels(x) <- value
    
    
    
    # 获取细胞identy
    
    Idents(pbmc_small)
    
    # 设置细胞identy
    
    # 可以用来指定某些细胞为新的名称
    
    #例如将前4个细胞的identity修改为a,其余不变
    
    Idents(pbmc_small, cells = 1:4) <- 'a'
    
    head(Idents(pbmc_small))
    
    # 使用matadata来设置identity
    
    colnames(pbmc_small[[]])
    
    Idents(pbmc_small) <- 'RNA_snn_res.1'
    
    levels(pbmc_small)
    
    # 修改细胞identity的名字
    
    # 可以提供任意数量,例如,原始的level有20,修改2个,剩余的18个保持不变
    
    levels(pbmc_small)
    
    pbmc_small <- RenameIdents(pbmc_small, '0' = 'A', '2' = 'C')
    
    levels(pbmc_small)
    
    # 这里也可以写成
    
    identityMapping <- c('0' = 'A', '2' = 'C')
    
    pbmc_small <- RenameIdents(pbmc_small, identityMapping )
    
    # 使用SetIdent设置细胞的identity
    
    cells.use <- WhichCells(pbmc_small, idents = '1')
    
    pbmc_small <- SetIdent(pbmc_small, cells = cells.use, value = 'B')
    
    #将细胞的identity加到matadata上
    
    head(pbmc_small[[]])
    
    pbmc_small <- StashIdent(pbmc_small, save.name = 'idents')
    
    head(pbmc_small[[]])
    
    # 获取seurat对象的细胞identity的水平
    
    levels(x = pbmc_small)
    
    # 调整细胞identity的水平
    
    levels(x = pbmc_small)
    
    levels(x = pbmc_small) <- c('C', 'A', 'B')
    
    levels(x = pbmc_small)
    
    

    感觉上面的函数基本上涵盖了操纵identity的所有需求。

    如有错误,可以在评论初指正。

    参考

    相关文章

      网友评论

        本文标题:seurat对象中细胞identity的获取、设置与操纵

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