Skip to content

Add gene_symbols parameter to render_shapes, render_points, render_labels#578

Merged
timtreis merged 4 commits intomainfrom
fix/issue-247-gene-symbols
Apr 5, 2026
Merged

Add gene_symbols parameter to render_shapes, render_points, render_labels#578
timtreis merged 4 commits intomainfrom
fix/issue-247-gene-symbols

Conversation

@timtreis
Copy link
Copy Markdown
Member

@timtreis timtreis commented Apr 5, 2026

Summary

  • Adds a gene_symbols parameter to render_shapes(), render_points(), and render_labels(), mirroring scanpy's established pattern
  • When var_names are ENSEMBL IDs, users can now color by gene symbols stored in a var column (e.g., color="TP53", gene_symbols="gene_symbol")
  • Fully backward compatible — gene_symbols=None (default) preserves all existing behavior

Closes #247

How it works

When color="TP53" isn't found in obs.columns or var_names, and gene_symbols="gene_symbol" is provided, the code looks up "TP53" in adata.var["gene_symbol"], maps it to the corresponding var_name (index), and proceeds with normal rendering. This happens in _validate_col_for_column_table() via a new _resolve_gene_symbols() helper.

timtreis and others added 4 commits April 5, 2026 17:55
…bels (#247)

Allow coloring by gene symbols when var_names are ENSEMBL IDs, mirroring
scanpy's gene_symbols parameter. When provided, the code looks up the
color key in the specified adata.var column and maps it back to the
actual var_name before proceeding with the normal rendering pipeline.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Avoid mutating col_for_color inside the auto-detect loop — resolve
gene symbol to var_name only once after the table is selected.
Add non-visual tests for the auto-detect path, missing symbol, and
missing column error cases.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…t loop

Avoid calling _resolve_gene_symbols twice for the winning table by
caching the result during the filtering loop. Add a warning when
a gene symbol maps to multiple var_names.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Generated from CI runner (py3.11-stable).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.51%. Comparing base (303140c) to head (49eddb6).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/spatialdata_plot/pl/utils.py 90.90% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #578      +/-   ##
==========================================
+ Coverage   75.36%   75.51%   +0.15%     
==========================================
  Files          10       10              
  Lines        2935     2986      +51     
  Branches      684      699      +15     
==========================================
+ Hits         2212     2255      +43     
- Misses        441      445       +4     
- Partials      282      286       +4     
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/basic.py 83.98% <ø> (ø)
src/spatialdata_plot/pl/utils.py 66.19% <90.90%> (+0.59%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timtreis timtreis merged commit 4b7b1f9 into main Apr 5, 2026
8 checks passed
@timtreis timtreis deleted the fix/issue-247-gene-symbols branch April 6, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a gene_symbols parameter to render_shapes and render_points

2 participants