Skip to content

Nbhd color values - #291

Draft
cornhundred wants to merge 11 commits into
mainfrom
nbhd_color_values
Draft

Nbhd color values#291
cornhundred wants to merge 11 commits into
mainfrom
nbhd_color_values

Conversation

@cornhundred

@cornhundred cornhundred commented Jan 31, 2026

Copy link
Copy Markdown
Collaborator

PR #291: Neighborhood Attribute Coloring & Enrichment Linking Improvements

Summary

This PR adds support for coloring neighborhoods by numerical attributes (gene expression, GDF properties) and improves the Clustergram-Enrich widget linking using jslink for more reliable communication.

New Features

🎨 Neighborhood Attribute Coloring

  • New nbhd_adata parameter on Landscape: Pass an AnnData with neighborhoods as obs and attributes (genes, populations, etc.) as var

    landscape = dega.viz.Landscape(
        technology='Xenium',
        base_url=base_url,
        adata=adata,
        nbhd_adata=adata_nbg,  # NEW: neighborhood × gene matrix
    )
  • Dropdown for GDF attributes: Numeric columns from neighborhood GeoDataFrame are now available in a color dropdown (e.g., area, perimeter)

  • nbhd_gene entity type: New entity type for Clustergrams where rows are genes aggregated at the neighborhood level

    mat_nbg = dega.clust.Matrix(
        adata_nbg, 
        col_entity='nbhd',
        row_entity='nbhd_gene'  # Enables enrichment analysis
    )
  • data_type field in AxisEntity: Allows specifying the underlying data type for analysis purposes, independent of the spatial entity

🔗 Simplified Clustergram-Enrich Linking

  • Replaced Python observers with jslink: More reliable trait synchronization that works even when Python kernel restarts

    jslink((cgm, "selected_genes"), (enrich, "gene_list"))
  • Removed link_clustergram_to_enrich function: No longer needed since jslink handles the connection

  • Simplified API: Removed row_enrich/col_enrich parameters (jslink syncs all selected genes)

Bug Fixes

  • Neighborhoods with zero expression now transparent: Fixed the minimum opacity issue that made zero-valued neighborhoods appear pink

Files Changed

File Changes
src/celldega/viz/widget.py Added nbhd_adata parameter, attribute request/response traitlets
src/celldega/viz/__init__.py Simplified enrichment linking with jslink
src/celldega/clust/constants.py Added data_type field and nbhd_gene entity
js/ui/nbhd_attr_dropdown.js New dropdown UI for neighborhood coloring
js/deck-gl/layers/nbhd_layer.js Support for gene expression coloring
js/widget_interactions/update_ist_landscape_from_cgm.js Handle nbhd_gene and nbhd_var entities

Usage Example

# Create neighborhood gene expression matrix
adata_nbg = dega.tl.calc_nbhd_by_gene(adata, adata_nbhd)

# Create Landscape with neighborhood data
landscape = dega.viz.Landscape(
    technology='Xenium',
    base_url=base_url,
    adata=adata,
    nbhd_adata=adata_nbg,
)

# Create Clustergram with nbhd_gene entity
mat_nbg = dega.clust.Matrix(adata_nbg, col_entity='nbhd', row_entity='nbhd_gene')
mat_nbg.norm(axis='row', by='zscore')
mat_nbg.cluster()
cgm_nbg = dega.viz.Clustergram(matrix=mat_nbg)

# Display with enrichment
dega.viz.landscape_clustergram(landscape, cgm_nbg, enrich=True)

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.

1 participant