cellgeni / sceasy

A package to help convert different single-cell data formats to each other
GNU General Public License v3.0
346 stars 52 forks source link

sce to anndata - Adata does not contain a `counts` layer in `adata.layers[`counts`]` #53

Open stemangiola opened 2 years ago

stemangiola commented 2 years ago

Hello,

I have a singleCellExeriment

> counts_SCE
class: SingleCellExperiment 
dim: 277 3276 
metadata(0):
assays(2): counts logcounts
rownames(277): CD80 CD86 ... CD4 CD340-erb-B2-HER-2
rowData names(0):
colnames(3276): 2_CTGATCCAGGCTGAAC-1 4_AATGCCATCCAAGCTA-1 ... 6_AGCGATTAGAAGCGCT-1 6_CAGTGCGAGTAGGAAG-1
colData names(78): nCount_RNA nFeature_RNA ... n_cells ident

I convert to h5ad with

sceasy::convertFormat(counts_SCE, from="sce", to="anndata", outFile='software/scib-pipeline/data/pbmc_CD8.h5ad')

Then I call a third party pipeline that gives me the error, that I don't understand (I am R user only)

Adata does not contain a `counts` layer in `adata.layers[`counts`]`

should I change the name of the sce assays? I also tried

sceasy::convertFormat(counts_SCE, from="sce", to="anndata", main_layer = "counts", transfer_layers = "counts",  outFile='software/scib-pipeline/data/pbmc_CD8.h5ad')

With no improvements.

Any idea why a counts is expected in anndata, when counts is already an assay names counts?

ziyan109 commented 2 years ago

Hi, I recently had a similar issue converting Seurat to Adata, then I looked into their annotation:

#main_layer Slot in `assay` to be converted to AnnData.X, may bE "counts", "data", "scale.data", default "data" (str)
 #' @param transfer_layers If specified, convert slots to AnnData.layers[<slot>] (vector of str)

I solved my problem by setting main_layer="data" and transfer_layer = "counts". In your case I think main_layer and transfer_layers need to be different as there's one line in the function: transfer_layers <- transfer_layers[transfer_layers != main_layer]

Here's the function page https://rdrr.io/github/cellgeni/sceasy/src/R/functions.R