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)#

Extracts extracellular RNA data and associated NMF factor loadings, intersects the gene annotations between the extracellular data and the cellular data, and applies the NMF factors to annotate the cellular data with exRNA-related factors.

Parameters:
  • sdata (spatialdata.SpatialData) – The AnnData object containing both extracellular and cellular data.

  • layer_factors (str) – The key in sdata that contains the extracellular RNA data with NMF factors. Default is ‘nmf_data’.

  • copy (bool) – Wether to save the sdata object in a separate object

Return type:

SpatialData

Returns:

sdata The updated sdata object with annotated cellular data that includes the applied exRNA factors as new columns.

Notes

The function assumes that the extracellular RNA data is stored in sdata[layer_factors] and that the NMF factor loadings are stored in the uns attribute of the extracellular dataset as ‘H_nmf’. The factor scores are added to the obs attribute of the cellular data.