spatialvi.external.Lambda#
- class spatialvi.external.Lambda(adata, location=None, organism=None, provider='openai', num_parallel=10, n_top_genes=50, resolution=0.5, **kwargs)[source]#
Bases:
objectLanguage-model based cell type annotation.
LAMBDA uses large language models to automatically annotate cell clusters based on differentially expressed marker genes.
- Parameters:
adata¶ (
AnnData) – AnnData with log-normalised expression data; gene symbols must be present inadata.var.index.location¶ (
str|None) – Optional text describing the anatomical location of the sample (e.g. “cerebral cortex”). Passed to the LLM to guide annotation.organism¶ (
str|None) – Optional species name (e.g. “human” or “mouse”). Passed to the LLM.provider¶ (
str) – Backend used for the language model. Possible values include “openai” and “google”. Ensure that the corresponding API key is set in the environment.num_parallel¶ (
int) – Number of clusters to annotate concurrently.n_top_genes¶ (
int) – Number of differentially expressed genes used for annotation.resolution¶ (
float) – Resolution parameter for Leiden clustering when LAMBDA performs automatic clustering.**kwargs¶ (
Any) – Additional arguments passed directly toAgent.adata (AnnData)
location (str | None)
organism (str | None)
provider (str)
num_parallel (int)
n_top_genes (int)
resolution (float)
kwargs (Any)
Examples
>>> import scanpy as sc >>> from spatialvi.external import Lambda >>> adata = sc.read("data.h5ad") >>> model = Lambda(adata, organism="human", location="brain") >>> model.train() # Prepares the agent >>> adata = model.predict() # Annotates clusters >>> print(adata.obs["lambda_0"].value_counts())
- __init__(adata, location=None, organism=None, provider='openai', num_parallel=10, n_top_genes=50, resolution=0.5, **kwargs)[source]#
Methods
__init__(adata[, location, organism, ...])get_annotations([level])Get the annotation results for a specific level.
predict([group_key, groups, ...])Annotate clusters of the dataset with cell type names.
train(*args, **kwargs)Prepare the LAMBDA agent.
- train(*args, **kwargs)[source]#
Prepare the LAMBDA agent.
LAMBDA does not have a trainable model in the usual sense. This method instantiates an
Agentand stores it for subsequent predictions.
- predict(group_key='leiden', groups=None, key_is_hierarchical=False, level=0, store_key_prefix='lambda', **kwargs)[source]#
Annotate clusters of the dataset with cell type names.
- Parameters:
group_key¶ (
str|Iterable[str] |None) – Key(s) inadata.obsdefining the clusters to annotate. IfNone, the agent will perform its own clustering. If a sequence of strings is provided, it encodes a hierarchy of levels.groups¶ (
str|Iterable[str] |None) – Subset of groups to annotate.Nonemeans annotate all groups.key_is_hierarchical¶ (
bool) – Whethergroup_keyencodes a hierarchy.level¶ (
int) – If a hierarchy is present, index of the level to return results for.store_key_prefix¶ (
str) – Prefix under which to store the annotations inadata.obs. Two columns will be created:f"{store_key_prefix}_{level}"for the raw label andf"{store_key_prefix}_score_{level}"for the confidence score.**kwargs¶ (
Any) – Additional keyword arguments forwarded toAgent.annotate.key_is_hierarchical (bool)
level (int)
store_key_prefix (str)
kwargs (Any)
- Return type:
- Returns:
The input AnnData with annotation columns added to
obs.