Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing layers after conversion from SCE #136

Closed
shaln opened this issue Oct 6, 2023 · 1 comment
Closed

Missing layers after conversion from SCE #136

shaln opened this issue Oct 6, 2023 · 1 comment

Comments

@shaln
Copy link

shaln commented Oct 6, 2023

I am trying to convert an SCE object to Anndata, and noticed that the 'logcounts' assay in the SCE object failed to transfer over to the layers of the Anndata. I'm not sure why this is the case, as using another package for the conversion (sceasy) did not result in this problem. I have attached below the code I used.

import scanpy as sc
import numpy as np
import anndata2ri
import anndata as ad
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.colors as mcolors

# Activate the anndata2ri conversion between SingleCellExperiment and AnnData
anndata2ri.activate()

# Loading the rpy2 extension enables cell magic to be used
# This runs R code in jupyter notebook cells
%load_ext rpy2.ipython

sc.settings.verbosity = 3
sc.logging.print_versions()

%%R -o control_sce
suppressPackageStartupMessages(library(SingleCellExperiment))

# Load SingleCellExperiment object that was previously created when running SlingShot
control_sce <- readRDS("RDS Files/control.int.sce.RDS")
control_sce
class: SingleCellExperiment 
dim: 2002 10194 
metadata(0):
assays(1): logcounts
rownames(2002): Ccl21a Fabp4 ... TdTomato-UTR Pecam1
rowData names(0):
colnames(10194): Cont1_AAACCTGCAAGTTAAG-1 Cont1_AAACCTGGTATGAAAC-1 ...
  ContB_TTTGTCATCGACAGCC-1 ContB_TTTGTCATCTTCGGTC-1
colData names(29): sum detected ... subclusters.sample ident
reducedDimNames(2): PCA UMAP
mainExpName: integrated
altExpNames(0):

control_sce

AnnData object with n_obs × n_vars = 10194 × 2002
    obs: 'sum', 'detected', 'percent_top_50', 'percent_top_100', 'percent_top_200', 'percent_top_500', 'subsets_Mito_sum', 'subsets_Mito_detected', 'subsets_Mito_percent', 'total', 'discard', 'orig.ident', 'condition', 'experiment', 'RNA_snn_res.0.1', 'seurat_clusters', 'cell.type', 'nCount_RNA', 'nFeature_RNA', 'integrated_snn_res.0.1', 'celltype', 'celltype.orig', 'celltype.cond', 'integrated_snn_res.0.2', 'integrated_snn_res.0.3', 'subclusters', 'subclusters.cond', 'subclusters.sample', 'ident'
    obsm: 'X_pca', 'X_umap'

As you can see above, the 'logcounts' assay is present in the SCE object, but there aren't any 'layers' in the AnnData object. Any idea what might have gone wrong here and how to fix this? In case this is helpful to know, the SCE object was previously a Seurat object that I had converted using the as.SingleCellExperiment function in R.

I've also tried using the sceasy package to convert the Seurat object to AnnData in R instead. This way the logcounts assay were successfully imported into the AnnData layers. I imported this AnnData directly into Jupyter for trajectory analysis using PAGA but obtained slightly different plots even though it's the exact same data - will open a separate issue for this on the PAGA page and comment below to link the issues.

@flying-sheep
Copy link
Collaborator

The first assay gets stored in .X:

assay_names = [str(a) for a in se.assayNames(obj)]
# The assays can be stored in an env or elsewise so we don’t use obj.slots['assays']
assays = convert_mats('assay', {n: se.assay(obj, n) for n in assay_names}, transpose=True)
# There’s SingleCellExperiment with no assays
exprs, layers = assays[0], dict(zip(assay_names[1:], assays[1:]))
assert len(exprs.shape) == 2, exprs.shape # noqa: PLR2004

Once we do scverse/anndata#244, this should no longer be a problem

I hope this answered your question. If you have suggestions on how to better document this or improve anndata2ri’s behavior, please comment, and we can reopen this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants