Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added filtering by a table query as discussed in #626. Added both a standalone function
sd.filter_table_by_query
and a methodsd.SpatialData.filter_table_by_query
.Function signature
sd.filter_by_table_query
is the same, but instead ofself
, you have to provide theSpatialData
object of interest.What expressions can you use?
narwhals
. As long as the method doesn't aggregate.>,>=,<,<=
,==
,is_in
,contains
,starts_with
,ends_with
work.What parts can you filter on?
You can filter on the
obs
andvar
DataFrame attributes ofAnnData
.You can filter on
obs_names
andvar_names
. (usesan.obs_names
, andan.var_names
instead ofan.col
)You can filter on the expression matrix
X
w.r.t layers as well.Some Examples
SpatialData Repr
For context here is what the table looks like:
"21d7"
, and filtervar_names
where we have"ASCT2"
,"ATP5A"
and any marker that starts with "CD".Output
"0"
and"1"
.Output
obs_names
which start with"9"
Output
&
operatorOutput
Output