Skip to content

Integration

mina.integration.patpy.PrecomputedSampleRepresentation

Bases: SampleRepresentationMethod

Wrap a precomputed sample-by-feature matrix for patpy tools.

This is useful when sample-level representations were computed outside patpy, for example using MINA, MOFA, PCA, or another latent-variable model.

Parameters:

Name Type Description Default
representation DataFrame

DataFrame with samples in rows and latent variables/features in columns.

required
metadata DataFrame or None

Optional sample-level metadata. Its index must contain the same sample IDs as representation.index.

None
metric str

Distance metric passed to scipy.spatial.distance.pdist.

'euclidean'
seed int

Random seed used by patpy embedding methods.

67

prepare_anndata(adata=None)

Skip AnnData preparation.

Parameters:

Name Type Description Default
adata AnnData or None

Ignored placeholder for compatibility with the patpy interface.

None

Returns:

Type Description
None

The representation is already sample-level and no preparation is needed.

calculate_distance_matrix(force: bool = False, dist: str | None = None) -> np.ndarray

Calculate a sample-by-sample distance matrix.

Parameters:

Name Type Description Default
force bool

If True, recompute distances even when cached distances exist.

False
dist str or None

Distance metric passed to scipy.spatial.distance.pdist. If None, self.metric is used.

None

Returns:

Name Type Description
distances ndarray

Square sample-by-sample distance matrix.

to_adata(metadata: pd.DataFrame | None = None, *args, **kwargs) -> ad.AnnData

Convert the precomputed sample representation to an AnnData object.

Parameters:

Name Type Description Default
metadata DataFrame or None

Optional metadata to pass to the patpy conversion. If None, the metadata stored on the representation is used.

None
*args tuple

Additional positional arguments passed to the parent method.

()
**kwargs dict

Additional keyword arguments passed to the parent method.

{}

Returns:

Name Type Description
adata AnnData

AnnData representation produced by the parent patpy method.