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 fromsdata[source_table_key]. For any othercolor_key, the column is taken directly from the transcripts table if present, otherwise looked up fromsdata[source_table_key],sdata[structure_table_key], orsdata[table_key](in that order) viastructure_id/cell_idmappings.- Parameters:
sdata (
SpatialData) – SpatialData object containing the"transcripts"points element, the cell boundary shapes, and the tables referenced bytable_key,structure_table_key, andsource_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 insdata.table_key (
str(default:'table')) – Key of the cell-level table insdata, used as a fallback source forcolor_key.structure_table_key (
str(default:'structure_table')) – Key of the segmentation-free structure table insdata, used as a fallback source forcolor_keyviastructure_id.source_table_key (
str(default:'source_score')) – Key of the source-score table insdata, used as a fallback source forcolor_key.colormap (
str(default:'30colors')) – Colormap for categoricalcolor_keyvalues, resolved viatroutpy.pl.get_palette(), or a continuous colormap name orListedColormapifcolor_keyis numeric.continuous_colormap (
str(default:'viridis')) – Fallback continuous colormap used whencolormapis not a valid matplotlib colormap andcolor_keyis 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 byroi.roi (
tuple[float,float,float,float] (default:(0, 20000, 0, 20000))) – Region of interest as(xmin, xmax, ymin, ymax), used ifuse_roiisTrue.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, ifcolor_keyis numeric.vmax (
Optional[float] (default:None)) – Maximum value for color scaling, ifcolor_keyis 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 incolor_keyto treat as missing, in addition to actualNaNvalues.
- Return type:
- Returns:
The figure and axes containing the plot.