rm(list=ls())
setwd("/home/yxk/Desktop/Method_test/NISC/POWSC-master/data/")
# library(SingleCellExperiment)
# library(TSCAN)
# library(destiny)
# library(scater)
# library(ggplot2)
# library(ggthemes)
# library(ggbeeswarm)
# library(corrplot)
set.seed(1)
#deng_SCE <- readRDS("deng-reads.rds")
# 使用案例1(Seurat转h5ad)
library(sceasy)
library(reticulate)
library(Seurat)
# library(SeuratData)
# library(SeuratDisk)
use_condaenv('DESC')
file="./es_mef_sce.RData" # single cell experiment
#loompy=reticulate::import('loompy')
load(file)
#sce_object=readRDS(file)## an old seurat: seurat2
sce_object = es_mef_sce
sceasy::convertFormat(sce_object, from="sce", to="anndata",
outFile='es_mef_raw.h5ad')
这个环境是anndata0.7.8的,
rm(list=ls())
setwd("/home/yxk/Desktop/Method_test/NISC/POWSC-master/data/")
# library(SingleCellExperiment)
# library(TSCAN)
# library(destiny)
# library(scater)
# library(ggplot2)
# library(ggthemes)
# library(ggbeeswarm)
# library(corrplot)
set.seed(1)
#deng_SCE <- readRDS("deng-reads.rds")
# 使用案例1(Seurat转h5ad)
library(sceasy)
library(reticulate)
library(Seurat)
# library(SeuratData)
# library(SeuratDisk)
use_condaenv('pyg')
file="./es_mef_sce.RData" # single cell experiment
#loompy=reticulate::import('loompy')
load(file)
#sce_object=readRDS(file)## an old seurat: seurat2
sce_object = es_mef_sce
sceasy::convertFormat(sce_object, from="sce", to="anndata",
outFile='es_mef_raw.h5ad')
这个环境是转换成anndata0.8.0的结果的
sceasy 问题
sceasy在转换时存在一个问题,就是h5ad的数据必须是csr稀疏格式的,而不能是csc稀疏格式的,所以就需要将csc转换成csr格式的
import scanpy as sc
from scipy import sparse
adata = sc.read("./monocyte_desc_use.h5ad")
#adata.X ## CSC format
# <10878x21289 sparse matrix of type '<class 'numpy.float32'>'
# with 11603457 stored elements in Compressed Sparse Column format>
adata.X = sparse.csr_matrix(adata.X.toarray())
adata.X
adata.write("./monocyte_csr.h5ad")
测试如下
rm(list=ls())
suppressPackageStartupMessages(library(sceasy))
suppressPackageStartupMessages(library(reticulate))
use_condaenv('base')
setwd("/data/wangdongxue/yxk/dataset/monocyte/")
# h5ad_file="./monocyte_desc_use.h5ad"
# seurat_file="./monocyte_seurat.rds"
# sce_file="./monocyte_sce.rds"
h5ad_file="./monocyte_desc_use.h5ad"
seurat_file="./monocyte_seurat.rds"
sce_file="./moocyte_sce.rds"
sceasy::convertFormat(h5ad_file, from="anndata", to="seurat",
outFile=seurat_file)
seurat_object=readRDS(seurat_file)
sceasy::convertFormat(seurat_object, from="seurat", to="sce",
outFile=sce_file)
##
错误如下
修正后结果
rm(list=ls())
suppressPackageStartupMessages(library(sceasy))
suppressPackageStartupMessages(library(reticulate))
use_condaenv('base')
setwd("/data/wangdongxue/yxk/dataset/monocyte/")
# h5ad_file="./monocyte_desc_use.h5ad"
# seurat_file="./monocyte_seurat.rds"
# sce_file="./monocyte_sce.rds"
h5ad_file="./monocyte_csr.h5ad"
seurat_file="./monocyte_seurat.rds"
sce_file="./moocyte_sce.rds"
sceasy::convertFormat(h5ad_file, from="anndata", to="seurat",
outFile=seurat_file)
seurat_object=readRDS(seurat_file)
sceasy::convertFormat(seurat_object, from="seurat", to="sce",
outFile=sce_file)
##
结果如下
可以看到转换成功了