Skip to content

KevinZ的小窝

Menu
  • Home
  • Categories
Menu

单细胞Seurat>h5>h5ad>loom

Posted on 2024年 11月 6日2024年 11月 6日 by KevinZhou
Seurat>h5 (R的Dior包)
# 首先在~/.bashrc中添加以下配置,防止文件只能读/写
export HDF5_USE_FILE_LOCKING="FALSE"
export RHDF5_USE_FILE_LOCKING="FALSE"

# 然后需要创建conda环境
conda create -n dior
conda activate dior
conda install anndata==0.6.19 scipy==1.2.1 -c bioconda
conda install loompy -c bioconda
conda activate dior
R

library(Seurat)
library(dior)
library(SeuratDisk)
library(sceasy)
use_condaenv('sceasy')
loompy <- reticulate::import('loompy')

seurat_obj <- readRDS("seurat_obj.rds")
seurat_obj = DietSeurat(
  seurat_obj,
  counts = TRUE, # so, raw counts save to adata.raw.X
  data = TRUE, # so, log1p counts save to adata.X
  scale.data = FALSE, # set to false, or else will save to adata.X
  features = rownames(seurat_obj), # export all genes, not just top highly variable genes
  assays = "RNA",
  dimreducs = c("pca","umap"),
  graphs = c("RNA_nn", "RNA_snn"), # to RNA_nn -> distances, RNA_snn -> connectivities
  misc = TRUE
)

# step 2: factor to character, or else your factor will be number in adata
i <- sapply(seurat_obj@meta.data, is.factor)
seurat_obj@meta.data[i] <- lapply(seurat_obj@meta.data[i], as.character)

# step 3: convert
# in R
dior::write_h5(seurat_obj, file='seurat_obj.h5', object.type = 'seurat')

h5>h5ad(Python的scanpy+diopy)

import diopy as diopy
adata = diopy.input.read_h5(file = 'seurat_obj.h5')
adata.write("seurat_obj.h5ad")
adata.write_loom("seurat_obj.loom",write_obsm_varm=True)
2024 年 11 月
一 二 三 四 五 六 日
 123
45678910
11121314151617
18192021222324
252627282930  
« 10 月   12 月 »

俺家的猫~

胖达~

© 2026 KevinZ的小窝 |

粤ICP备2023017690号

|

粤公网安备 44010402003004号