broadinstitute / Tangram

Spatial alignment of single cell transcriptomic data.
BSD 3-Clause "New" or "Revised" License
238 stars 46 forks source link

Interpretation of tangram_ct_pred #112

Open abhishekmaj08 opened 6 months ago

abhishekmaj08 commented 6 months ago

Greetings,

I am using Tangram to annotate my spatial data (10X) using single cell data. I would like to better understand the output of project_cell_annotations().

It says “INFO:root:spatial prediction dataframe is saved in obsm tangram_ct_pred of the spatial AnnData.”

I looked at the tangram_ct_pred matrix. It is a voxel X annotation matrix. I would like to understand each entry in the matrix. From the values, it does not seem like probability value ( there are values > 2). So is it some kind of score? What is its scale. How do I convert each row in to a set of probability values over the different annotations for each individual cell (each row sum = 1)? Or like a percentage composition set of values for each cell (each row sum = 1). How to best interpret values?

gaddamshreya1 commented 6 months ago

Hi @abhishekmaj08, thank you for your patience!! More importantly, thank you for your interest in Tangram.

project_cell_annotations is a method which leads to the creation of tangram_ct_pred dataframe inobsm which transfers cell annotations onto to space using the mapping matrix. You are right, these aren't probability values. When we take a look at this method, we can see that tangram_ct_pred is a dot product between mapping matrix.T(voxel x cell) and one hot encoding of cell types across all cells in the single cell data.

df = one_hot_encoding(adata_map.obs[annotation])
tangram_ct_pred = ad_map.X.T @ df

The idea behind this dataframe to support plotting cell type annotations in space in case of a soft assignment mapping. The tangram_ct_pred is clipped and normalized and then these values become the proportion of a certain cell type in each spot.

May I ask: are you trying to compute out the percentage of each cell type within each voxel? or like assign a single cell type to each voxel? Because for either of these tasks I would recommend using the mapping matrix which is the probability values of assigning each cell to a voxel.

I hope this explanation is useful to you! Otherwise, please let me know. I'm happy to help :)

Li-ZhiD commented 2 months ago

Hi, I would like to know how to assign a cell type to each spot. Would using the maximum value in tangram_ct_pred to determine the cell type for each spot be suitable?