美文网首页
从AnnData到Seurat-2:将AnnData中的信息展示

从AnnData到Seurat-2:将AnnData中的信息展示

作者: Yayamia | 来源:发表于2022-11-16 12:46 被阅读0次

    Seurat入门中……如有错误,欢迎指出

    1. 如何将AnnData中的obs在Seurat中展示

    sc.pl.umap(adata, color=['cellinteraction_cluster'])不同,Seurat需要定义出Seurat object的ident,DimPlot时会默认展示这个ident

    Idents(seo)<-"cellinteraction_cluster"#为meta.data中的一列
    table(Idents(seo))
    DimPlot(seo, reduction = "pca")
    

    可以用group.by来展示其他meta.data的信息

    DimPlot(seuratObj, reduction = "umap2",group.by = "Group")
    

    2. 如何保留AnnData的layers的信息?

    之前用scDioR进行AnnData和Seurat数据结构的转换时,总是会丢失layers的信息,比如spliced和unspliced的信息。但现在来看,不同的assays其实就相当于AnnData中的不同的layers。完全可以手动把二者提取出矩阵出来再整合。

    举例

    cbmc <- CreateSeuratObject(counts = cbmc.rna)
    # Add ADT data
    cbmc[["ADT"]] <- CreateAssayObject(counts = cbmc.adt)
    # Run analyses by specifying the assay to use
    NormalizeData(object = cbmc, assay = "RNA")
    NormalizeData(object = cbmc, assay = "ADT", method = "CLR")
    
    # Retrieve and set the default assay
    DefaultAssay(object = cbmc)
    DefaultAssay(object = cbmc) <- "ADT"
    DefaultAssay(object = cbmc)
    
    # Pull feature expression from both assays by using keys
    FetchData(object = cbmc, vars = c("rna_CD3E", "adt_CD3"))
    
    # Plot data from multiple assays using keys
    FeatureScatter(object = cbmc, feature1 = "rna_CD3E", feature2 = "adt_CD3")
    

    3.如何保留Scanpy中Umap图的位置?

    从本质上说,Umap图展示就是获得每个细胞在横纵坐标的数值,即UMAP-1和UMAP-2
    该信息在AnnData中保存在.obsm['X_umap']当中,可以直接提取出来,作为meta.data的信息保存

    cell_meta['UMAP1']=adata.obsm['X_umap'][:,0]
    cell_meta['UMAP2']=adata.obsm['X_umap'][:,1]
    

    而在Seurat中,当我们RunUMAP后,我们会在seo@reductions中获得一层降维的数据

    > seo@reductions
    $pca
    A dimensional reduction object with key PC_ 
     Number of dimensions: 50 
     Projected dimensional reduction calculated:  FALSE 
     Jackstraw run: TRUE 
     Computed using assay: RNA 
    
    $umap
    A dimensional reduction object with key UMAP_ 
     Number of dimensions: 2 
     Projected dimensional reduction calculated:  FALSE 
     Jackstraw run: FALSE 
     Computed using assay: RNA 
    
    $tsne
    A dimensional reduction object with key tSNE_ 
     Number of dimensions: 2 
     Projected dimensional reduction calculated:  FALSE 
     Jackstraw run: FALSE 
     Computed using assay: RNA 
    

    每个细胞的UMAP/tSNE坐标轴值保存在该处:

    > seo@reductions$tsne@cell.embeddings
                              tSNE_1        tSNE_2
    AAACCTGAGGAGCGAG    16.717869063 -25.568710284
    AAAGATGAGATGTGTA     2.652637970 -30.593065136
    AAAGATGTCAGGATCT    20.795690308 -24.805323167
    AAAGTAGCATGAACCT    17.382986492 -25.578860343
    AAAGTAGTCATTGCCC    21.395172916 -33.082192622
    

    因此,我们可以复制一层reduction,然后把Scanpy的Umap坐标轴信息替换

    seo@reductions$umap2<-seo@reductions$umap#把在Seurat中降维的数据复制为Umap2
    head(seo@reductions$umap@cell.embeddings)
    scanpy_umap<-seo@meta.data[,c('UMAP1','UMAP2')]
    colnames(scanpy_umap)<-c('UMAP_1','UMAP_2')
    seo@reductions$umap@cell.embeddings<-as.matrix(scanpy_umap)
    > seo@reductions
    $pca
    A dimensional reduction object with key PC_ 
     Number of dimensions: 50 
     Projected dimensional reduction calculated:  FALSE 
     Jackstraw run: TRUE 
     Computed using assay: RNA 
    
    $umap
    A dimensional reduction object with key UMAP_ 
     Number of dimensions: 2 
     Projected dimensional reduction calculated:  FALSE 
     Jackstraw run: FALSE 
     Computed using assay: RNA 
    
    $tsne
    A dimensional reduction object with key tSNE_ 
     Number of dimensions: 2 
     Projected dimensional reduction calculated:  FALSE 
     Jackstraw run: FALSE 
     Computed using assay: RNA 
    
    $umap2
    A dimensional reduction object with key UMAP_ 
     Number of dimensions: 2 
     Projected dimensional reduction calculated:  FALSE 
     Jackstraw run: FALSE 
     Computed using assay: RNA 
    plot1<-DimPlot(seo, reduction = "umap",label = TRUE)+scale_color_npg()
    plot2<-DimPlot(seo, reduction = "umap2",label = TRUE)+scale_color_npg()
    CombinePlots(plots = list(plot1, plot2),legend="bottom")
    

    可以看到Scanpy中Umap的坐标轴值保留了下来

    相关文章

      网友评论

          本文标题:从AnnData到Seurat-2:将AnnData中的信息展示

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