mantispy.tl.aggregate#
- mantispy.tl.aggregate(adata, by=('Metadata_Plate', 'Metadata_Well'), func='median', min_cells=10, layer=None, use_rep=None, count_key='Metadata_CellCount', site_key='Metadata_SiteCount')[source]#
Aggregate
adatato one profile per group.- Parameters:
- adata
AnnData Single cells, or profiles to aggregate further, as its recorded resolution says.
- by
Sequence[str] (default:('Metadata_Plate', 'Metadata_Well')) Columns defining a profile. The default is one profile per well.
- func
str(default:'median') "median"(the pycytominer default) or"mean".- min_cells
int(default:10) Groups with fewer cells than this are dropped.
- layer
str|None(default:None) Aggregate this layer instead of
X.- use_rep
str|None(default:None) Aggregate this
obsmrepresentation (e.g. an embedding frompp.tvn/pp.harmony) instead ofX; the result’sXholds the reduced representation andvaris a plain range index, since the axes are not named features. Mutually exclusive withlayer.- count_key
str(default:'Metadata_CellCount') obscolumn the cell count is written to, and read from whenadataholds profiles.- site_key
str(default:'Metadata_SiteCount') obscolumn the number of fields of view is written to, and read from whenadataholds profiles.
- adata
- Return type:
- Returns:
A new
AnnDatawith one row per group.varis carried over unchanged;obsholds the grouping columns,count_key,site_keywhen the fields of view are known, and every otherMetadata_column that is constant within every group.count_keyis the number of cells behind a row, so its scope followsby: grouping by site counts the cells of one field of view, grouping by well those of every field. Profiles contribute the cells they carry rather than one each, and profiles that carry no count give an unknown one.site_keyis the number of fields that contributed cells, summed where the rows carry it and counted fromMetadata_Siteotherwise. The resolution recorded is"well"whenbyholds bothMetadata_PlateandMetadata_Well, since a finer grouping such as one row per site is still per-well or finer, and"aggregate"otherwise.- Raises:
ValueError –
funcis not one ofFUNCTIONS, oruse_repandlayerare both given, oruse_repis not a 2-D representation inobsm.
Notes
This uses mantispy’s own NaN-skipping kernel rather than
scanpy.get.aggregate(), which propagates NaN and is slower on both mean and median.