Closed GuoshengMa closed 1 month ago
Hi @GuoshengMa!
Regarding question 1, could you try setting the filter_tables
parameter to False
as in the API docs: https://spatialdata.scverse.org/en/latest/generated/spatialdata.polygon_query.html?
For the visium_sdata
you can check whether the table in here is in fact annotating the particular shapes
element. You can do this with the SpatialData.get_annotated_regions(<AnnData>)
method: https://spatialdata.scverse.org/en/latest/generated/spatialdata.SpatialData.html#spatialdata.SpatialData.get_annotated_regions.
Regarding question 2, this is still not supported yet. The release was only last week, but we are working on it!
Please let me know if I can be of further assistance.
@melonora Great! Question 1 has been successfully resolved! However, I noticed that in the tutorial, this parameter has not been added yet. It would be advisable for you to update the tutorial to prevent others from encountering the same issue :D
In addition, I have another question. I am currently attempting to perform a joint analysis of 10× visium (ST) and CODEX data with the aim of obtaining the cellular composition of each spot in ST corresponding to CODEX. My approach is as follows:
SpatialData
package.polygon_query()
function to obtain the corresponding CODEX data for each spot.After the resolution of question 2, since the CODEX data provides the coordinates of each cell, I wonder if the afore-mentioned analysis can achieve my objective?
I believe this is a valid approach yes! @LucaMarconato any other ideas?
With respect to the notebook, I added a commit in this PR: https://github.com/scverse/spatialdata-notebooks/pull/91.
With that is your issue resolved @GuoshengMa ?
@melonora By setting the filter_tables
parameter to False
, I can successfully obtain tables. However, the tables I obtain do not seem to be filtered and are not specific to the polygon query region.
Here is my code:
# we rounded the coordinates to make it less verbose here in the notebook
# fmt: off
shape0 = (
np.array(
[
[
182.0,181.0,179.0,178.0,174.0,173.0,172.0,168.0,165.0,164.0,164.0,166.0,167.0,168.0,169.0,169.0,168.0,166.0,163.0,163.0,
163.0,164.0,165.0,167.0,168.0,169.0,172.0,173.0,174.0,175.0,180.0,185.0,187.0,188.0,189.0,190.0,191.0,192.0,193.0,194.0,
196.0,198.0,200.0,202.0,205.0,207.0,209.0,211.0,212.0,213.0,215.0,215.0,216.0,216.0,215.0,215.0,214.0,212.0,211.0,209.0,
208.0,208.0,206.0,205.0,204.0,202.0,200.0,196.0,195.0,195.0,195.0,194.0,192.0,190.0,189.0,186.0,184.0,184.0,183.0,184.0,
185.0,186.0,186.0,184.0,182.0,182.0,182.0,183.0,183.0,183.0,182.0,182.0,183.0,183.0,181.0,178.0,178.0,178.0,179.0,180.0,
182.0,182.0,183.0,183.0,182.0,
],
[
105.0,105.0,106.0,107.0,108.0,109.0,110.0,112.0,114.0,115.0,118.0,121.0,122.0,123.0,125.0,126.0,129.0,136.0,140.0,141.0,
143.0,151.0,153.0,155.0,157.0,158.0,160.0,162.0,162.0,163.0,168.0,173.0,174.0,174.0,175.0,176.0,178.0,179.0,179.0,181.0,
181.0,182.0,183.0,183.0,183.0,183.0,182.0,181.0,179.0,177.0,174.0,173.0,170.0,167.0,164.0,160.0,159.0,158.0,159.0,161.0,
161.0,161.0,158.0,156.0,156.0,156.0,157.0,160.0,161.0,162.0,164.0,164.0,164.0,162.0,161.0,160.0,159.0,157.0,156.0,153.0,
151.0,148.0,147.0,145.0,144.0,143.0,141.0,139.0,137.0,136.0,135.0,134.0,132.0,131.0,129.0,126.0,123.0,120.0,118.0,115.0,
112.0,111.0,110.0,109.0,105.0,
],
]
)
* 100
)
# fmt: on
gdf = GeoDataFrame({"geometry": [numpy_to_shapely(shape0)]})
gdf = ShapesModel.parse(gdf, transformations={"aligned": Identity()})
visium_sdata.shapes["lasso"] = gdf
The results from the tutorial are as follows:
{'lasso': AnnData object with n_obs × n_vars = 102 × 18085
obs: 'in_tissue', 'array_row', 'array_col', 'spot_id', 'region', 'dataset', 'clone'
var: 'gene_ids', 'feature_types', 'genome'
uns: 'spatial', 'spatialdata_attrs'
obsm: 'spatial',
'my_shapes': AnnData object with n_obs × n_vars = 139 × 18085
obs: 'in_tissue', 'array_row', 'array_col', 'spot_id', 'region', 'dataset', 'clone'
var: 'gene_ids', 'feature_types', 'genome'
uns: 'spatial', 'spatialdata_attrs'
obsm: 'spatial',
'my_shapes_2': AnnData object with n_obs × n_vars = 142 × 18085
obs: 'in_tissue', 'array_row', 'array_col', 'spot_id', 'region', 'dataset', 'clone'
var: 'gene_ids', 'feature_types', 'genome'
uns: 'spatial', 'spatialdata_attrs'
obsm: 'spatial'}
As you can see, in my case, it seems that polygon_query()
did not return the corresponding AnnData object
for the polygon. What could be the issue?
I will look into the issue a bit later. From our conversation though it is clear that the docstring for this function is not informative enough:) I will change the docstring as well, it is already correctly explained in the notebook that is part of the PR now though.
The main thing that filtered_table
does is filter the rows that are present in the tables annotating elements in the resulting SpatialData object. It is filtered based on which rows rows of the element which the table is annotating are actually present in the volume of the polygon that you query. If this results in an empty table then this table is omitted. In case the parameter is set to False then all filtered tables are returned but without any filtering of the rows
Noted. I trust that you will be able to resolve this issue quickly. Looking forward to your response!
Hi @LucaMarconato ! A few days ago, following the instructions in the
Annotating regions of interest with napari
section, I successfully annotated regions of interest with napari. However, today I encountered an error when running thepolygon_query()
function following the same code.Here is my code:
And here is the error:
Then, I removed table and found it works:
Question1: However, this
SpatialData
object did not havetable
, which prevents us from obtaining the visium information within that region. How can this be resolved?Question2: I noticed in the
Annotating regions of interest with napari
section,Limitations
part, it mentioned thatWe currently don’t support saving circles, ellipses or segments as well as overwriting existing elements. The latter will be possible very soon though.
I was wondering if they are supported now? Below is the error I encountered when trying to use circles: