I am trying to plot the features of my tangram imupted spatial data by using the spatial image and cell segmentation of my reference spatial data. In general, I want to render a plot as below:
However, only replacing the anndata object of the reference .zarr file with the tangram imputed anndata object doesn’t solve the issue. The render_points only renders the transcripts of the reference data. How can I work my way around this?
Also, is it possible to render plots with scanpy/squidpy using the cell segmentation by only transferring the segmentation data to anndata object of the imputed?
Hey @mdka00001, could you share the code of what you’re doing? You’d need to check in the `.uns[“spatialdata_attrs”]` of the adata object whether it actually annotates the element you’re trying to visualise. Check the adata from which you see the points being rendered for reference.
Also, could you elaborate on
Also, is it possible to render plots with scanpy/squidpy using the cell segmentation by only transferring the segmentation data to anndata object of the imputed?
Hi @ttreis . My imputed anndata object also has the following informations:
{‘region’: ‘cellpose_boundaries’,
‘region_key’: ‘region’,
‘instance_key’: ‘instance_id’}
This is my code to replace the table in sdata with my new imputed anndata:
from spatialdata.models import TableModel
"""adaata_gene is the imputed AnnData object with the Tangram predictions.
We will link this to the SpatialData object by ensuring it has the correct metadata and then parsing it with TableModel."""
#Assign metadata columns
adaata_gene.obs['region'] = 'cellpose_boundaries'
#CONVERT TO STRING
adaata_gene.obs['instance_id'] = adaata_gene.obs['cell_id'].astype(str)
#Parse with TableModel
sdata_t2_imputed.table = TableModel.parse(
adaata_gene,
region='cellpose_boundaries',
region_key='region',
instance_key='instance_id',
overwrite_metadata=True
)
But I think this doesnt replace the default points that are in the sdata object from reference spatial data.
Regarding the 2nd query, I wanted to know whether there is any alternative to my first approach where I can transfer the cell_segmentation coordinates from the sdata to the anndata object and render the plots using sq.pl.spatial_segment?
I think your issue is that you’re assinging your result to sdata.table - try assigning it either to a key in sdata.tables[key] or assign a dict to the tables accessor directly like sdata.tables = {"my_key": TableModel.parse()}.
The default table accessor in SpatialData has been deprecated for a few versions now. You could also try explicitly specifiyng the table_name parameter in render_points.
Regarding the 2nd query, I wanted to know whether there is any alternative to my first approach where I can transfer the cell_segmentation coordinates from the sdata to the anndata object and render the plots using sq.pl.spatial_segment?
There might be, but since we’re going to deprecate the native behaviour of sq.pl.spatial_segment in favor of internally using spatialdata-plot soon, I won’t trace in the code how to do that. You could probably ask your favourite LLM on how to hack that into place if you prefer.