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

Filter spatialData #280

Open
lopollar opened this issue May 31, 2023 · 2 comments · May be fixed by #626
Open

Filter spatialData #280

lopollar opened this issue May 31, 2023 · 2 comments · May be fixed by #626

Comments

@lopollar
Copy link

lopollar commented May 31, 2023

Idea for enhancement:
Add a filter option to the spatialdata object, where it is possible to filter out certain cells, based on a column in the table.
This can be relevant to for example large cells.
In line with the sc.pp.filter_cells.
A similar function exists in spatialdata: sdata.pp.get_elements, but this does not work on obs or shapes information.
This would then work on shapes and table simultaneously.
Currently, I only get this to work by overwriting the objects, as shown here.
Is there a better way?

for i in [*sdata.shapes]:
    sdata[i].index = sdata[i].index.astype("str")
    sdata.add_shapes(
        name=i,
        shapes=spatialdata.models.ShapesModel.parse(
            sdata[i][np.isin(sdata[i].index.values, sdata.table.obs.index.values)]
        ),
        overwrite=True,
    )
@giovp
Copy link
Member

giovp commented Jun 22, 2023

this is very much in the roadmap @lopollar , thanks for bringing it up!

I think this could be done in two different ways (both could be supported)

sdata = sdata[sdata.table.obs.celltype == "celltypeA"]
>>> sdata.table.obs.celltype.unique()
["celltypeA"]

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.query.html

wdyt?

@lopollar
Copy link
Author

Hi,
For me, the first feels like how I wouldcode it myself, so I would prefer that one!
Thank you for taking my suggestion into account!

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