前面我在写scanpy的h5ad转为R中的seurat对象时,写了这几个稿子:
万能的网友又给我支招了,这次给我推荐了一个我试过了后觉得超棒的方法:使用 schard 包进行转换,一行代码就可!
我们生信技能树每个月都有一期带领初学者,0基础的生信入门培训,会有各种贴心的答疑,甚至是新叶老师给你的一对一专属答疑,远程代码演示,快来:最新一期在8月4号,感兴趣的可以去看看呀:生信入门&数据挖掘线上直播课8月班。
包的网址:https://github.com/cellgeni/schard
首先安装一下,非常简单:
options(download.file.method = "libcurl")
options(url.method = "libcurl")
## 使用西湖大学的 Bioconductor镜像
options(BioC_mirror="https://mirrors.westlake.edu.cn/bioconductor")
options("repos"=c(CRAN="https://mirrors.westlake.edu.cn/CRAN/"))
getOption('timeout')
options(timeout=10000)
# 安装
devtools::install_github("cellgeni/schard")
丝滑:
先把示例数据下载下来:
或者用我上面开头的帖子中数据
library(schard)
download.file('https://datasets.cellxgene.cziscience.com/c5ac5c36-f60c-4680-8018-2d6cb65c0a37.h5ad','vis.heart.h5ad')
download.file('https://datasets.cellxgene.cziscience.com/8cc521c8-c4ff-4cba-a07b-cae67a9dcba9.h5ad','sn.heart.h5ad')
download.file('https://covid19.cog.sanger.ac.uk/baron16.processed.h5ad','ba16.h5ad')
转为Single Cell Experiment:
# load h5ad as Single Cell Experiment
ba16.sce = schard::h5ad2sce('ba16.h5ad')
ba16.sce
转为Seurat对象:
# load h5ad as Seurat
snhx = schard::h5ad2seurat('sn.heart.h5ad')
snhx
meta <- snhx@meta.data
head(snhx@meta.data)
DimPlot(snhx,group.by = "cell_state")
空转数据转为seurat:
# load all visium samples as single Seurat object
visx = schard::h5ad2seurat_spatial('vis.heart.h5ad')
visx
head(visx@meta.data)
# 可视化
SpatialDimPlot(visx,group.by = "cell_type",ncol = 2)
其他的用法:
# or load as list of Seurat objects (per slide
visl = schard::h5ad2seurat_spatial('vis.heart.h5ad',simplify = FALSE)
# or load raw counts
snhr = schard::h5ad2seurat('sn.heart.h5ad',use.raw = TRUE)
# raw counts for visium
visr = schard::h5ad2seurat_spatial('vis.heart.h5ad',use.raw = TRUE)
是不是超棒!