-
Notifications
You must be signed in to change notification settings - Fork 71
Added filter_table_by_query
#894
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #894 +/- ##
==========================================
- Coverage 92.10% 92.09% -0.01%
==========================================
Files 48 48
Lines 7433 7442 +9
==========================================
+ Hits 6846 6854 +8
- Misses 587 588 +1
🚀 New features to boost your workflow:
|
Hey @srivarra, thanks for the PR! Sorry for not getting to it earlier, last months have been a bit hectic with the PhD, but checking it now. Might incorporate a tutorial notebook given that people could be new to this way of writing queries, but in any case I am in favor of this kind of syntax. |
@melonora No worries, hope the PhD is going well! Sounds good I'll draft up a tutorial notebook and request a review when it's done. |
Awesome! |
@melonora Would the proper process be:
tyty |
@srivarra Just open a PR in scverse/spatialdata-notebooks:) As a title you can give it |
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
Other things to note:
I added a more complex SpatialData for testing in
conftest.py
. I do not know if this should be there or somewhere else, or if I should make better use of what's there currently.Notebook: Table Queries