troutpy.pl.spatial_transcripts_source

troutpy.pl.spatial_transcripts_source#

troutpy.pl.spatial_transcripts_source(sdata, cell_color_key='leiden', extra_color_key='leiden', gene_list=None, gene_key='gene', separate_compartments=False, use_roi=False, roi=None, padding=0, point_size=0.1, min_score=0.1, show_edges=False, edge_alpha=0.1, fig_bg_color='white', ambient_color='grey', palette='tab20', shapes_key='cell_boundaries', boundary_linewidth=0.5, boundary_zorder=4)#

Plot transcripts colored by intracellular and extracellular source cell type, overlaid on cell boundaries.

Intracellular (“cell body”) transcripts are colored by cell_color_key from sdata["table"].obs. Extracellular transcripts with an assignment_score of at least min_score (in sdata["source_score"].obs) are considered “halo” transcripts and colored by extra_color_key, taken either directly from sdata["source_score"].obs or, if not present there, via each transcript’s predicted parent cell in sdata["table"].obs. Remaining “ambient” transcripts are plotted in ambient_color.

Parameters:
  • sdata (SpatialData) – SpatialData object containing the "table" and "source_score" tables, the "transcripts" points element, and the cell boundary shapes.

  • cell_color_key (str (default: 'leiden')) – Column in sdata["table"].obs used to color intracellular transcripts.

  • extra_color_key (str (default: 'leiden')) – Column used to color extracellular (“halo”) transcripts, looked up in sdata["source_score"].obs or, as a fallback, in sdata["table"].obs.

  • gene_list (Union[str, list[str], None] (default: None)) – Specific gene(s) to isolate. If provided, only transcripts of these genes are plotted.

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

  • separate_compartments (bool (default: False)) – If True, intracellular and extracellular transcripts get separate legend entries/colors ("Cell: X" / "Extra: X"); if False, they share a single "Cluster: X"-style legend.

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

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

  • padding (float (default: 0)) – If roi is not used, crop this many units from each side of the full transcript extent.

  • point_size (float (default: 0.1)) – Base marker size for transcripts; foreground (labeled) transcripts are plotted at twice this size.

  • min_score (float (default: 0.1)) – Minimum assignment_score for an extracellular transcript to be considered assigned (“halo”) to a cell.

  • show_edges (bool (default: False)) – Whether to draw edges connecting halo transcripts to their assigned cell’s centroid.

  • edge_alpha (float (default: 0.1)) – Transparency of the edges, if show_edges is True.

  • fig_bg_color (str (default: 'white')) – Background color of the figure and axes.

  • ambient_color (str (default: 'grey')) – Color for unassigned (“ambient”) transcripts.

  • palette (str (default: 'tab20')) – Matplotlib colormap name used to assign colors to categories.

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

  • 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.

Return type:

tuple[Figure, Axes] | tuple[None, None]

Returns:

The figure and axes containing the plot, or (None, None) if gene_list is provided and no transcripts match.