troutpy.pl.spatial_transcripts

troutpy.pl.spatial_transcripts#

troutpy.pl.spatial_transcripts(sdata, gene_key='gene', gene_list=None, color_key='point_source_cellular', shapes_key='cell_boundaries', table_key='table', structure_table_key='structure_table', source_table_key='source_score', colormap='30colors', continuous_colormap='viridis', boundary_linewidth=0.5, boundary_zorder=4, scatter_size=1.0, alpha=0.8, use_roi=False, roi=(0, 20000, 0, 20000), figsize=(8, 8), title='Cell Boundaries + Transcripts', vmin=None, vmax=None, rasterize=True, missing_val_sentinel=-1)#

Plot spatial transcripts colored by a grouping variable, overlaid on cell boundaries.

For color_key="point_source_cellular" (the default), transcripts are colored by whether they overlap a cell ("cellular transcripts") or, for extracellular transcripts, by their predicted source category from sdata[source_table_key]. For any other color_key, the column is taken directly from the transcripts table if present, otherwise looked up from sdata[source_table_key], sdata[structure_table_key], or sdata[table_key] (in that order) via structure_id/cell_id mappings.

Parameters:
  • sdata (SpatialData) – SpatialData object containing the "transcripts" points element, the cell boundary shapes, and the tables referenced by table_key, structure_table_key, and source_table_key.

  • gene_key (str (default: 'gene')) – Column in the transcripts table containing gene names.

  • gene_list (Optional[list[str]] (default: None)) – If provided, restrict the plot to transcripts of these genes.

  • color_key (str (default: 'point_source_cellular')) – Column (or derived category) used to color transcripts. See above for the special handling of "point_source_cellular".

  • shapes_key (str (default: 'cell_boundaries')) – Key of the cell boundary shapes element in sdata.

  • table_key (str (default: 'table')) – Key of the cell-level table in sdata, used as a fallback source for color_key.

  • structure_table_key (str (default: 'structure_table')) – Key of the segmentation-free structure table in sdata, used as a fallback source for color_key via structure_id.

  • source_table_key (str (default: 'source_score')) – Key of the source-score table in sdata, used as a fallback source for color_key.

  • colormap (str (default: '30colors')) – Colormap for categorical color_key values, resolved via troutpy.pl.get_palette(), or a continuous colormap name or ListedColormap if color_key is numeric.

  • continuous_colormap (str (default: 'viridis')) – Fallback continuous colormap used when colormap is not a valid matplotlib colormap and color_key is numeric.

  • boundary_linewidth (float (default: 0.5)) – Line width of the cell boundary outlines.

  • boundary_zorder (int (default: 4)) – Z-order of the cell boundary outlines.

  • scatter_size (float (default: 1.0)) – Marker size for background ("Unmapped") transcripts; foreground transcripts are plotted at 1.5x this size.

  • alpha (float (default: 0.8)) – Transparency of background ("Unmapped") transcripts.

  • use_roi (bool (default: False)) – Whether to restrict the plot to the region defined by roi.

  • roi (tuple[float, float, float, float] (default: (0, 20000, 0, 20000))) – Region of interest as (xmin, xmax, ymin, ymax), used if use_roi is True.

  • figsize (tuple[float, float] (default: (8, 8))) – Size of the figure.

  • title (str (default: 'Cell Boundaries + Transcripts')) – Title of the plot.

  • vmin (Optional[float] (default: None)) – Minimum value for color scaling, if color_key is numeric.

  • vmax (Optional[float] (default: None)) – Maximum value for color scaling, if color_key is numeric.

  • rasterize (bool (default: True)) – Whether to rasterize the scatter points (recommended for large point counts).

  • missing_val_sentinel (int | str | float (default: -1)) – Value in color_key to treat as missing, in addition to actual NaN values.

Return type:

tuple[Figure, Axes]

Returns:

The figure and axes containing the plot.