alphapepttools.pp.drop_singleton_batches

alphapepttools.pp.drop_singleton_batches#

alphapepttools.pp.drop_singleton_batches(adata, batch)#

Drop samples from batches that contain only a single sample.

Parameters:
  • adata (AnnData) – Annotated data matrix, where rows are cells and columns are features

  • batch (str) – Name of the batch feature in obs, the variation associated with this feature will be corrected

Return type:

AnnData

Returns:

Annotated data matrix with samples from singleton batches removed

Examples

import anndata as ad
import pandas as pd
import numpy as np
from alphapepttools.pp.batch_correction import drop_singleton_batches

# Create a sample AnnData object with singleton batches
data = np.random.rand(5, 3)
obs = pd.DataFrame({"batch": ["A", "B", "B", "C", "D"]})
var = pd.DataFrame(index=["gene1", "gene2", "gene3"])
adata = ad.AnnData(X=data, obs=obs, var=var)

# Apply the function to drop singleton batches
adata_filtered = drop_singleton_batches(adata, batch="batch")
print(adata_filtered.shape)  # (2, 3) - only samples from batch "B" remain