cellink.utils.one_hot_encode_genotypes#
- cellink.utils.one_hot_encode_genotypes(adata)#
Convert genotypes to one-hot encoding.
This function takes the genotype data in
adataand converts it into a one-hot encoded format. Each genotype (e.g., homozygous reference, heterozygous, homozygous alternate) is transformed into a binary vector representation.Params#
- adata
The annotated data matrix of shape
n_obsxn_vars. Rows correspond to individuals and columns to variants.
- rtype:
- returns:
Returns the one-hot encoded genotypes or updates
adatawith the new representation, depending oninplace.
Example
>>> import numpy as np >>> from anndata import AnnData >>> adata = AnnData( ... np.array( ... [ ... [0, 1, 2], ... [1, 0, 1], ... [2, 2, 0], ... ] ... ) ... ) >>> one_hot_encoded = one_hot_encode_genotypes(adata, key_added="one_hot", inplace=False) >>> one_hot_encoded array([[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
- [[0, 1, 0],
[1, 0, 0], [0, 1, 0]],
- [[0, 0, 1],
[0, 0, 1], [1, 0, 0]]])