theislab / scCODA

A Bayesian model for compositional single-cell data analysis
BSD 3-Clause "New" or "Revised" License
141 stars 23 forks source link

Cell identities displaying as numbers? #64

Closed potterae closed 1 year ago

potterae commented 1 year ago

Hi, thank you for developing this package, it is very useful. I am trying to use this to display info regarding varying cell composition among different conditions / samples. Unfortunately, it displays the cell type as a number and not the actual defined cell type. Is there a way to change this so I can have it display the cell identities, not numbers? This is using an integrated seurat object, converted to AnnData format using SeuratDisk.

The python code is below:

import warnings import importlib warnings.filterwarnings("ignore")

import pandas as pd import pickle as pkl import matplotlib.pyplot as plt import anndata as ad import warnings

from sccoda.util import comp_ana as mod from sccoda.util import cell_composition_data as dat from sccoda.util import data_visualization as viz

adata = ad.read_h5ad("/Immune.h5ad") print(adata)

cov_df = pd.DataFrame({"Stage": ["Severe", "CR", "Improving", "Resolved", "No", "No", "No", "No", "No", "No", "No", "No", "No"]}, index=-removed-) print(cov_df)

data_CR = dat.from_scanpy( adata, cell_type_identifier="Idents", sample_identifier="X", covariate_df=cov_df ) print(data_CR)

Stacked barplot for each sample

viz.stacked_barplot(data_CR, feature_name="samples") plt.show()

Stacked barplot output:

print output, data_CR:

       Stage

-removed- AnnData object with n_obs × n_vars = 13 × 13 obs: 'Stage' var: 'n_cells'

Thank you!

potterae commented 1 year ago

I found that when the seurat object was converted to AnnData, it changed the identities to a number; I made a new column in the metadata of the AnnData object which contained the cell type identities from the associated numbers, and this solved the issue. Thanks.