You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
is it too simple to be a feature? from the neighborhood features to annotate the cells. given nhoods, the loc of the adata.obs would be: adata.obsm['nhoods'][:, nhoods.astype(int).tolist()].sum(axis=1).A1 > 0
just now I have a use case from da testing result to annotate whether the cells belong to enriched or deficient nhoods:
defannotate_adata(
self,
mdata: MuData,
anno_col: str|None="nhood_da",
feature_key: str|None="rna",
spatialfdr: float|None=0.05,
logfc: float|None=2,
):
"""Assigns a categorical label to cells, based on whether they belongs to nhood enriched or deficient by DA testing results. Args: mdata: MuData object anno_col: Column in adata.obs to hold the annotation labels feature_key: If input data is MuData, specify key to cell-level AnnData object. Returns: None. Adds in place: - `milo_mdata['rna'].obs["nhood_da"]`: assigning a label to each cell """try:
sample_adata=mdata["milo"]
exceptKeyError:
logger.error(
"milo_mdata should be a MuData object with two slots: feature_key and 'milo' - please run milopy.count_nhoods(adata) first"
)
raiseadata=mdata[feature_key]
# check if mdata["milo"].var["SpatialFDR"] and mdata["milo"].var["logFC"] are presentif"SpatialFDR"notinmdata["milo"].var.columnsor"logFC"notinmdata["milo"].var.columns:
raiseValueError(
"mdata['milo'].var['SpatialFDR'] and mdata['milo'].var['logFC'] are not present in the data. Please run milo.da_nhoods() first."
)
# Check column existsifanno_colnotinadata.obs.columns:
adata.obs[anno_col] ="non"enriched_nhoods=mdata["milo"].var_names[(mdata["milo"].var["SpatialFDR"] <spatialfdr) & (mdata["milo"].var["logFC"] >logfc)]
deficient_nhoods=mdata["milo"].var_names[(mdata["milo"].var["SpatialFDR"] <spatialfdr) & (mdata["milo"].var["logFC"] <-logfc)]
enriched_obs=adata.obsm['nhoods'][:, enriched_nhoods.astype(int).tolist()].sum(axis=1).A1>0deficient_obs=adata.obsm['nhoods'][:, deficient_nhoods.astype(int).tolist()].sum(axis=1).A1>0adata.obs.loc[enriched_obs, anno_col] ="enriched"adata.obs.loc[deficient_obs, anno_col] ="deficient"confused_obs=enriched_obs&deficient_obsiflen(confused_obs) >0:
logger.warning(
"Some neighbourhoods are both enriched and deficient. Annotate to confusion."
)
adata.obs[confused_obs, anno_col] ="confusion"
The text was updated successfully, but these errors were encountered:
Description of feature
is it too simple to be a feature? from the neighborhood features to annotate the cells. given nhoods, the loc of the adata.obs would be:
adata.obsm['nhoods'][:, nhoods.astype(int).tolist()].sum(axis=1).A1 > 0
just now I have a use case from da testing result to annotate whether the cells belong to enriched or deficient nhoods:
The text was updated successfully, but these errors were encountered: