troutpy.tl.factors_to_cells

troutpy.tl.factors_to_cells#

troutpy.tl.factors_to_cells(sdata, extracellular_layer='segmentation_free_table', cellular_layer='table', copy=None)#

Project extracellular-RNA factor loadings onto the cellular table for shared genes.

Intersects the gene annotations between the extracellular and cellular tables, and multiplies the cellular expression matrix by the (gene-subset) factor loadings to obtain per-cell factor scores.

Parameters:
  • sdata (spatialdata.SpatialData) – SpatialData object containing both the extracellular and cellular tables.

  • extracellular_layer (str, optional) – Key in sdata for the extracellular table with NMF/LDA/DRVI gene loadings in .varm["gene_loadings"]. Defaults to "segmentation_free_table".

  • cellular_layer (str, optional) – Key in sdata for the cellular table to annotate. Defaults to "table".

  • copy (bool, optional) – If truthy, return the modified SpatialData object; otherwise modify sdata in place and return None.

Return type:

SpatialData

Returns:

spatialdata.SpatialData or None sdata with sdata[cellular_layer].obsm["factors_cell_loadings"] set to the per-cell factor scores (restricted to genes shared with extracellular_layer) if copy is truthy; otherwise None.