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
See Mapping gene expression in space on how to prepare and solve the
MappingProblem
.
- 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:dict
- it should contain'attr'
and'key'
, the attribute and key inAnnData
, and optionally'tag'
from thetags
.
By default,
tag = 'point_cloud'
is used.batch_key (
Optional
[str
]) – Key inobs
where the slices are stored.spatial_key (
Union
[str
,Mapping
[str
,Any
]]) – Key inobsm
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:Sequence
- use a subset of genes. If an empty sequence, the problem will correspond to the pure Gromov-Wasserstein case.
See also the
joint_attribute
parameter.normalize_spatial (
bool
) – Whether to normalize the spatial coordinates. IfTrue
, 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:
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:
str
- name of the cost function for all terms, seeget_available_costs()
.dict
- a dictionary with the following keys and values:'xy'
- cost function for the linear term.'x'
- cost function for the source quadratic term.'y'
- cost function for the target quadratic term.
cost_kwargs (
Union
[Mapping
[str
,Any
],Mapping
[Literal
['x'
,'y'
,'xy'
],Mapping
[str
,Any
]]]) – Keyword arguments for theBaseCost
or any backend-specific cost.Source marginals. Valid options are:
Target marginals. Valid options are:
xy_callback (
Union
[Literal
['local-pca'
],Callable
[[Literal
['xy'
,'x'
,'y'
],AnnData
,Optional
[AnnData
]],Optional
[TaggedArray
]],None
]) – Callback function used to prepare the data in the linear term.x_callback (
Union
[Literal
['local-pca'
],Callable
[[Literal
['xy'
,'x'
,'y'
],AnnData
,Optional
[AnnData
]],Optional
[TaggedArray
]],None
]) – Callback function used to prepare the data in the source quadratic term.y_callback (
Union
[Literal
['local-pca'
],Callable
[[Literal
['xy'
,'x'
,'y'
],AnnData
,Optional
[AnnData
]],Optional
[TaggedArray
]],None
]) – Callback function used to prepare the data in the target quadratic term.xy_callback_kwargs (
Mapping
[str
,Any
]) – Keyword arguments for thexy_callback
.x_callback_kwargs (
Mapping
[str
,Any
]) – Keyword arguments for thex_callback
.y_callback_kwargs (
Mapping
[str
,Any
]) – Keyword arguments for they_callback
.subset (
Optional
[Sequence
[Tuple
[TypeVar
(K
, bound=Hashable
),TypeVar
(K
, bound=Hashable
)]]]) – Subset ofobs['{key}']
for theExplicitPolicy
. Only used whenpolicy = 'explicit'
.reference (
Optional
[Any
]) – Reference for theSubsetPolicy
. Only used whenpolicy = 'star'
.
- Return type:
MappingProblem
[TypeVar
(K
, bound=Hashable
)]- Returns:
: Returns self and updates the following fields:
problems
- the prepared subproblems.spatial_key
- key inobsm
where the spatial coordinates 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).