Closed mariafiruleva closed 4 years ago
Is the error message complete in the following line?
File "/nfs/home/mfiruleva/.local/lib/python3.7/site-packages/pandas/core/series
Could you also provide version information for the following python packages: anndata, h5py, pandas?
nh3, thanks for the quick reply.
(base) mfiruleva@sphinx:~$ conda list | grep 'pandas\|loompy\|anndata\|h5py'
anndata 0.6.19 py_0 bioconda
h5py 2.9.0 py37h7918eee_0
loompy 2.0.16 py_0 bioconda
pandas 0.24.2 py37he6710b0_0
Thanks @mariafiruleva , could you provide a small seurat object from your data that help us reproduce the issue? When using the "pbmc_small" object provided by Seurat, converting to anndata ends up successfully.
@nh3 , oh, yes, I can convert pbmc_small object too. Hope you can help with my dataset.
Source of data: link.
Code:
library(dplyr)
library(functools)
library(ggplot2)
library(gridExtra)
library(Matrix)
library(sctransform)
library(Seurat)
## FUNCTIONS
add_metadata <- function(data) {
mito.genes <-
grep(pattern = "^Mt\\.|^MT\\.|^mt\\.|^Mt-|^MT-|^mt-",
x = rownames(x = GetAssayData(object = data)),
value = TRUE)
percent.mito <-
Matrix::colSums(GetAssayData(object = data, slot = "counts")[mito.genes, ]) /
Matrix::colSums(GetAssayData(object = data, slot = "counts"))
data[['percent.mito']] <- percent.mito
data[['percent.mito_log10']] <- log10(data[['percent.mito']])
data[['nCount_RNA_log10']] <- log10(data[['nCount_RNA']])
data[['nFeature_RNA_log10']] <- log10(data[['nFeature_RNA']])
data[['nCount_RNA_log2']] <- log2(data[['nCount_RNA']])
data[['nFeature_RNA_log2']] <- log2(data[['nFeature_RNA']])
data[['scaled_mito']] <- scale(percent.mito)
data[['scaled_nCount_RNA']] <- scale(data[['nCount_RNA_log10']])
data
}
get_conf_interval <- function(dataset, parameter) {
left <- mean(dataset[[parameter]][[1]]) - qnorm(0.975)
right <- mean(dataset[[parameter]][[1]]) + qnorm(0.975)
return(c(left, right))
}
## GATHERING DATA TOGETHER
fdata <- get(load("/scratch/mfiruleva/data/var/www/html/SRA/SRA.final/SRA592147_SRS2384613.sparse.RData"))
fdata@Dimnames[[1]] <-
make.names(gsub(".ENS.*", "", fdata@Dimnames[[1]]), unique = T)
whole <- CreateSeuratObject(
counts = fdata,
min.cells = 2,
min.features = 200,
project = "SRA592147"
)
whole <- add_metadata(whole)
## FILTER MT CONTENT
mt_dist <- as.data.frame(whole[['scaled_mito']][[1]])
colnames(mt_dist) <- 'scaled_mito'
whole <-
subset(
x = whole,
subset = scaled_mito < get_conf_interval(whole, 'scaled_mito')[2]
)
## NORMALIZATION
whole <-
SCTransform(
whole,
ncells=min(100000, ncol(whole)),
vars.to.regress = c("percent.mito"),
verbose = T,
conserve.memory = T
)
gc()
## PCA
whole <- RunPCA(object = whole, features = VariableFeatures(object = whole), npcs=50)
## TSNE
whole <-
RunTSNE(whole, dims = 1:20, tsne.method = "FIt-SNE",
fast_tsne_path = "/nfs/home/kzajcev/FIt-SNE/bin/fast_tsne", nthreads = 4, max_iter = 2000)
## UMAP
whole <- RunUMAP(whole, dims = 1:20)
## CLUSTERING
whole <- FindNeighbors(object = whole, dims = 1:20)
whole <- FindClusters(object = whole, resolution = 0.6)
## SAVING
file_out <- paste0("SRA592147", '.RData')
save(list = c('whole', 'whole.markers'), file = file_out)
After that, I run:
library(Seurat)
library(sceasy)
load('SRA592147.RData')
library(reticulate)
use_condaenv('anaconda3', required = T)
loompy <- reticulate::import('loompy')
adata <- sceasy:::seurat2anndata(whole, outFile="data.h5ad")
And get the error.
UPD: I see, the reason of the problem is this line:
data[['scaled_mito']] <- scale(percent.mito)
Because scale() returns a dataframe.
Thanks for the amazing tool!
And sorry fot the issue. :(
Dear sceasy team,
I try to conver Seurat object to h5ad and get this error in any case, except of integrated object.
data can be any Seurat object performed using standard approaches.
Session info: