Files
openpipeline/target/executable/integrate/scvi/set_var_index.py
CI cd5554d22f Build branch main with version main (173327cc)
Build pipeline: vsh-ci-build-template-k4qzr

Source commit: 173327cc56

Source message: Cellranger multi conversion: fix combined AB + CB probe experiments (#1062)
2025-08-22 08:50:18 +00:00

25 lines
738 B
Python

import anndata as ad
import re
def set_var_index(adata: ad.AnnData, var_name: str | None = None) -> ad.AnnData:
"""Sanitize gene names and set the index of the .var DataFrame.
Parameters
----------
adata : AnnData
Annotated data object
var_name : str | None
Name of the column in `adata.var` that contains the gene names, if None, the existing index will be sanitized but not replaced.
Returns
-------
AnnData
Copy of `adata` with sanitized and replaced index
"""
if var_name:
adata.var.index = [re.sub("\\.[0-9]+$", "", s) for s in adata.var[var_name]]
else:
adata.var.index = [re.sub("\\.[0-9]+$", "", s) for s in adata.var.index]
return adata