moscot.problems.space.MappingProblem.prepare

MappingProblem.prepare(sc_attr, batch_key=None, spatial_key='spatial', var_names=None, normalize_spatial=True, joint_attr=None, cost='sq_euclidean', cost_kwargs=mappingproxy({}), a=None, b=None, xy_callback=None, x_callback=None, y_callback=None, xy_callback_kwargs=mappingproxy({}), x_callback_kwargs=mappingproxy({}), y_callback_kwargs=mappingproxy({}), subset=None, reference=None)[source]

Prepare the mapping problem problem.

See also

Parameters:
  • sc_attr (Union[str, Mapping[str, Any], None]) –

    How to get the data for the quadratic term. Usually, it’s the X attribute, which contains normalized counts, but a different modality or a pre-computed PCA can also be used. Valid options are:

    • str - a key in obsm.

    • dict - it should contain 'attr' and 'key', the attribute and key in AnnData, and optionally 'tag' from the tags.

    By default, tag = 'point_cloud' is used.

  • batch_key (Optional[str]) – Key in obs where the slices are stored.

  • spatial_key (Union[str, Mapping[str, Any]]) – Key in obsm where the spatial coordinates are stored.

  • var_names (Optional[Sequence[str]]) –

    Genes in var_names for the linear term in the fused case. Valid options are:

    See also the joint_attribute parameter.

  • normalize_spatial (bool) – Whether to normalize the spatial coordinates. If True, the coordinates are normalized by standardizing them.

  • joint_attr (Union[str, Mapping[str, Any], None]) –

    How to get the data for the linear term in the fused case:

    • None - PCA on X is computed.

    • str - key in obsm where the data is stored.

    • dict - it should contain 'attr' and 'key', the attribute and key in AnnData, and optionally 'tag' from the tags.

  • cost (Union[Literal['euclidean', 'sq_euclidean', 'cosine', 'pnorm_p', 'sq_pnorm', 'geodesic'], Mapping[Literal['xy', 'x', 'y'], Literal['euclidean', 'sq_euclidean', 'cosine', 'pnorm_p', 'sq_pnorm', 'geodesic']]]) –

    Cost function to use. Valid options are:

  • cost_kwargs (Union[Mapping[str, Any], Mapping[Literal['x', 'y', 'xy'], Mapping[str, Any]]]) – Keyword arguments for the BaseCost or any backend-specific cost.

  • a (Optional[str]) –

    Source marginals. Valid options are:

  • b (Optional[str]) –

    Target marginals. Valid options are:

  • xy_callback (Literal['local-pca'] | ~typing.Callable[[~typing.Literal['xy', 'x', 'y'], ~anndata._core.anndata.AnnData, ~anndata._core.anndata.AnnData | None], ~moscot.utils.tagged_array.TaggedArray | None] | None)

  • x_callback (Literal['local-pca'] | ~typing.Callable[[~typing.Literal['xy', 'x', 'y'], ~anndata._core.anndata.AnnData, ~anndata._core.anndata.AnnData | None], ~moscot.utils.tagged_array.TaggedArray | None] | None)

  • y_callback (Literal['local-pca'] | ~typing.Callable[[~typing.Literal['xy', 'x', 'y'], ~anndata._core.anndata.AnnData, ~anndata._core.anndata.AnnData | None], ~moscot.utils.tagged_array.TaggedArray | None] | None)

  • xy_callback_kwargs (Mapping[str, Any])

  • x_callback_kwargs (Mapping[str, Any])

  • y_callback_kwargs (Mapping[str, Any])

  • subset (Sequence[Tuple[K, K]] | None)

  • reference (Any | None)

Return type:

MappingProblem[TypeVar(K, bound= Hashable)]

Returns:

: Returns self and updates the following fields:

  • problems - the prepared subproblems.

  • solutions - set to an empty dict.

  • spatial_key - key in obsm where the spatial coordinates are stored.

  • batch_key - key in obs where batches are stored.

  • stage - set to 'prepared'.

  • problem_kind - set to 'quadratic' (if both spatial_key and sc_attr are passed)

    or 'linear' (if both spatial_key and sc_attr are None).