troutpy.tl.image_intensities_per_transcript

troutpy.tl.image_intensities_per_transcript#

troutpy.tl.image_intensities_per_transcript(sdata, image_key, scale, transcript_key, extracellular=False, copy=True, gene_key='gene')#

Extract image intensities at transcript locations and store them as a new table.

For each transcript, the pixel value of every channel (and z-slice, if present) of sdata.images[image_key][scale] nearest to its rescaled coordinates is extracted into an AnnData stored at sdata["image_intensity_per_transcript"].

Parameters:
  • sdata (spatialdata.SpatialData) – The input SpatialData object.

  • image_key (str) – Key of the image layer in sdata.images.

  • scale (str) – Scale of the image to use (e.g. "scale0").

  • transcript_key (str) – Key of the transcript points layer in sdata.points.

  • extracellular (bool, optional) – If True, only transcripts where extracellular is True are used. Otherwise all transcripts are used. Defaults to False.

  • copy (bool, optional) – If True, return the modified SpatialData object. Otherwise modify sdata in place and return None. Defaults to True.

  • gene_key (str, optional) – Column holding the gene assigned to each transcript. Defaults to "gene".

Return type:

SpatialData | None

Returns:

spatialdata.SpatialData or None SpatialData with the added "image_intensity_per_transcript" table if copy=True; otherwise None.

Raises:

KeyError – If image_key or transcript_key is not found in sdata.