sparrow.im.transcript_density#
- sparrow.im.transcript_density(sdata, img_layer='raw_image', points_layer='transcripts', n_sample=15000000, name_x='x', name_y='y', name_z=None, name_gene_column='gene', z_index=None, scaling_factor=100, chunks=1024, crd=None, to_coordinate_system='global', scale_factors=None, output_layer='transcript_density', overwrite=False)#
Calculate the transcript density using gaussian filter and add it to the provided spatial data.
This function computes the density of transcripts in the spatial data, scales and smooths it, and then adds the resulting density image to the spatial data object.
- Parameters:
sdata (
SpatialData
) – Data containing spatial information.img_layer (
Optional
[str
] (default:'raw_image'
)) – The layer of the SpatialData object used for determining image boundary. Defaults to the last layer if set to None.img_layer
andpoints_layer
should be registered in coordinate systemto_coordinate_system
.points_layer (
str
(default:'transcripts'
)) – The layer name that contains the transcript data points, by default “transcripts”.n_sample (
Optional
[int
] (default:15000000
)) – The number of transcripts to sample for calculation of transcript density.name_x (
str
(default:'x'
)) – Column name for x-coordinates of the transcripts in the points layer, by default “x”.name_y (
str
(default:'y'
)) – Column name for y-coordinates of the transcripts in the points layer, by default “y”.name_z (
Optional
[str
] (default:None
)) – Column name for z-coordinates of the transcripts in the points layer, by default None.name_gene_column (
str
(default:'gene'
)) – Column name in the points_layer representing gene information.z_index (
Optional
[int
] (default:None
)) – The z index in the points layer for which to calculate transcript density. If set to None for a 3D points layer (andname_z
is not equal to None), an y-x transcript density projection will be calculated.scaling_factor (
float
(default:100
)) – Factor to scale the transcript density image, by default 100.chunks (
int
(default:1024
)) – Chunksize for calculation of density using gaussian filter.crd (
Optional
[Tuple
[int
,int
,int
,int
]] (default:None
)) – The coordinates for a region of interest in the format (xmin, xmax, ymin, ymax). If provided, the density is computed only for this region, by default None.to_coordinate_system (
str
(default:'global'
)) – The coordinate system that holdsimg_layer
andpoints_layer
.scale_factors (
Optional
[Sequence
[Union
[dict
[str
,int
],int
]]] (default:None
)) – Scale factors to apply for multiscale.output_layer (
str
(default:'transcript_density'
)) – The name of the output image layer in the SpatialData where the transcript density will be added, by default “transcript_density”.overwrite (
bool
(default:False
)) – If True overwrites the element if it already exists.
- Return type:
SpatialData
- Returns:
: Updated spatial data object with the added transcript density layer as an image layer.
Examples
>>> sdata = SpatialData(...) >>> sdata = transcript_density(sdata, points_layer="transcripts", crd=(2000, 4000, 2000, 4000))