@@ -1537,18 +1537,54 @@ def interactive_motif(
15371537 """
15381538 Create an interactive Vitessce widget to explore spatial motifs.
15391539
1540- Builds a minimal AnnData containing only cell type labels and spatial
1541- coordinates from the SpatialQuery object, writes it to a Zarr store,
1542- and launches the Vitessce widget with the SpatialQueryPlugin.
1540+ Builds a minimal AnnData containing cell type labels, spatial coordinates,
1541+ and (optionally) gene expression from the SpatialQuery object, writes it
1542+ to a Zarr store, and launches a Vitessce widget with the SpatialQueryPlugin.
1543+ The widget provides interactive panels for spatial visualization, cell type
1544+ selection, motif enrichment analysis, and gene expression exploration.
15431545
15441546 Parameters
15451547 ----------
15461548 sp : spatial_query
1547- An initialized SpatialQuery instance.
1549+ An initialized SpatialQuery instance. If ``build_gene_index=False``
1550+ and ``sp.adata`` is not None, gene expression data will be included
1551+ in the widget for feature-level exploration.
15481552 zarr_path : str
1549- Path where the Zarr store will be written.
1550- spatialSpotRadius : float, optional
1551- Radius for spatial spots in the visualization, by default 1.
1553+ Path where the Zarr store will be written. If the path already exists,
1554+ its contents will be overwritten with a warning.
1555+ spatialSpotRadius : float, default=1
1556+ Radius for spatial spots in the Vitessce visualization. Adjust based
1557+ on data density and spatial coordinate scale.
1558+
1559+ Returns
1560+ -------
1561+ ipywidgets.Widget
1562+ A Vitessce widget that can be displayed in a Jupyter notebook.
1563+ The widget contains the following views:
1564+
1565+ - **Spatial view**: scatter plot of cells colored by cell type
1566+ - **Layer controller**: toggle visibility and appearance of layers
1567+ - **Cell sets**: browse and select cell types
1568+ - **SpatialQuery**: interactive motif enrichment query panel
1569+ - **SpatialQuery Heatmap**: heatmap of motif enrichment results
1570+ - **Feature list**: gene selection panel (only when expression data is available)
1571+
1572+ Notes
1573+ -----
1574+ This function requires the ``vitessce`` Python package (with the
1575+ ``SpatialQueryPlugin``) to be installed. Install it via::
1576+
1577+ pip install vitessce[all]
1578+
1579+ The generated widget is designed for use in Jupyter notebooks
1580+ (JupyterLab or Jupyter Notebook).
1581+
1582+ Examples
1583+ --------
1584+ >>> from SpatialQuery.spatial_query import spatial_query, interactive_motif
1585+ >>> sq = spatial_query(adata, spatial_key='X_spatial', label_key='cell_type')
1586+ >>> widget = interactive_motif(sq, zarr_path='./my_data.zarr')
1587+ >>> widget
15521588 """
15531589 import os
15541590 import warnings
0 commit comments