moscot icon indicating copy to clipboard operation
moscot copied to clipboard

incorrect arguments passed to `annotation_mapping`

Open giovp opened this issue 6 months ago • 0 comments

This happens when the method annotation_mapping is used in the MappingProblem,

Here, the adata_sp has a batch value, and the annotation_mapping should be done for each batch separately. Howevr, this call would fail

mp.annotation_mapping(
    mapping_mode="max",
    source=0,
    target="ref",
    annotation_label="celltype",
    forward=False,
)

and it can be fixed with

mp.adata_sc.obs["<batch_key>"] = 10

that is, passing a dummy batch key to the single cell data.

To reproduce

Details
import anndata as ad
import moscot as mt
import pandas as pd
from moscot import datasets
from moscot.problems.space import MappingProblem

adata_sc = mt.datasets.drosophila(spatial=False)
adata_sp = datasets.drosophila(spatial=True)
adata_sc, adata_sp

adata_sp.obs["fov"] = 0
adata_sp2 = adata_sp.copy()
adata_sp2.obs["fov"] = 1
adata_sp = ad.concat([adata_sp, adata_sp2])
adata_sc.obs["celltype"] = "annotation"
adata_sc.obs["celltype"] = pd.Categorical(adata_sc.obs["celltype"])
adata_sp

import pandas as pd

adata_sp.obs["fov"] = pd.Categorical(adata_sp.obs["fov"])

mp = MappingProblem(adata_sc=adata_sc, adata_sp=adata_sp)
mp = mp.prepare(
    sc_attr={"attr": "obsm", "key": "X_pca"}, xy_callback="local-pca", batch_key="fov"
)

mp = mp.solve()

mp

mp.adata_sc.obs["fov"] = 10

# mp.adata_sc

mp.annotation_mapping(
    mapping_mode="max",
    source=0,
    target="ref",
    annotation_label="celltype",
    forward=False,
)

giovp avatar Sep 05 '24 17:09 giovp