【R包报错】使用sceasy包转换rds文件与h5ad文件报错PyType_GetFlags

想要将scanpy的h5ad文件转为rds文件,有一个很方便的包sceasy可以使用,安装简单,代码简易。

安装方式

# bioconda package:

conda install -c bioconda r-sceasy

# R package:

devtools::install_github("cellgeni/sceasy")


#额外需要安装的依赖包
if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

BiocManager::install(c("LoomExperiment", "SingleCellExperiment"))

install.packages('reticulate')

R语言脚本

Seurat to AnnData

sceasy::convertFormat(seurat_object, from="seurat", to="anndata",
                       outFile='filename.h5ad')

 AnnData to Seurat

sceasy::convertFormat(h5ad_file, from="anndata", to="seurat",
                       outFile='filename.rds')

Seurat to SingleCellExperiment

sceasy::convertFormat(seurat_object, from="seurat", to="sce",
                       outFile='filename.rds')

SingleCellExperiment to AnnData 

sceasy::convertFormat(sce_object, from="sce", to="anndata",
                       outFile='filename.h5ad')

SingleCellExperiment to Loom 

sceasy::convertFormat(sce_object, from="sce", to="loom",
                       outFile='filename.loom')

 Loom to AnnData

sceasy::convertFormat('filename.loom', from="loom", to="anndata",
                       outFile='filename.h5ad')

 Loom to SingleCellExperiment

sceasy::convertFormat('filename.loom', from="loom", to="sce",
                       outFile='filename.rds')

批量处理的代码 

library(Seurat)
library(stringr)
library(sceasy)
library(reticulate)
loompy <- reticulate::import('loompy')

use_condaenv('EnvironmentName') #使用的python路径或者conda中python的路径


#h5ad转rds文件,文件夹下所有文件批量转换代码

outdir = 'XXX/Glycine.max/'
setwd(outdir)
file_names <- list.files(path = outdir,  pattern = "\\.h5ad$", full.names = FALSE)
for (i in 1:length(file_names)) 
{
	sample1 <- file_names[i]
    sample2 <- sub("\\..*", "", file_names[i])
	print(sample1)
    h5ad_file=str_c(sample1)  #输入的h5文件路径
    out_file=str_c(outdir2,sample2,".rds")
    sceasy::convertFormat(h5ad_file, from="anndata", to="seurat", outFile=out_file)
}

记住需要添加use_condaenv的python路径,不然会使用默认的python,容易报错。报错如下图所示。use_condaenv('XXX/bin/python')

Error: PyType_GetFlags - /usr/lib64/python2.7/config/libpython2.7.so: undefined symbol: PyType_GetFlags
In addition: Warning message:
In py_initialize(config$python, config$libpython, config$pythonhome,  :
  Python 2 reached EOL on January 1, 2020. Python 2 compatability will be removed in an upcoming reticulaterelease.

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值