Entering edit mode
8 months ago
Does anyone knows how to convert an h5ad file into an .rds file using a python script?
Does anyone knows how to convert an h5ad file into an .rds file using a python script?
import numpy as np
import pandas as pd
import scanpy as sc
import scipy
import os
import scipy.io as io
!mkdir matrix_files
adata = sc.read_h5ad('YourData.h5ad')
adata = adata.raw.to_adata()
with open('matrix_files/barcodes.tsv', 'w') as f:
for item in adata.obs_names:
f.write(item + '\n')
with open('matrix_files/features.tsv', 'w') as f:
for item in ['\t'.join([x,x,'Gene Expression']) for x in adata.var_names]:
f.write(item + '\n')
io.mmwrite('matrix_files/matrix', adata.X.T)
!ls matrix_files
!gzip matrix_files/*
!ls matrix_files
adata.obs.to_csv('metadata.csv')
library(Seurat)
raw_data=Read10X("matrix_files")
metadata=read.csv("metadata.csv")
gc()
data_so=CreateSeuratObject(counts = raw_data, meta.data = metadata)
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.