terra.infer#
- terra.infer(args, dataset, load_folder_path, dataset_ids=None, obs_cols=None, uns_cols=None, emb_layers=None, cell_gene_ids=[], neighborhood_gene_ids=[], agg_type='avg', masked_tokens=None, agg_excluded_genes=None, top_k=None, return_gene=True, return_cosine_sim=False, compute_cosine_with_list=[], return_gene_per_data=False, return_gene_marker_score=False, return_distance=False, include_spatial_cell_emb=False, ignore_spc_tokens=True, debug=False)#
Use a trained model for inference, returning cell, neighborhood and optionally gene embeddings.
Run a forward pass on a given dataset and return cell, neighborhood and (optionally) gene embeddings (cell and neighborhood gene embeddings).
- Parameters:
args (
dict) – Dictionary containing the hyperparameters from the config file.dataset (
CellBaseDataset) – Cell dataset for which embeddings will be inferred.load_folder_path (
str) – Path where the checkpoint is stored.dataset_ids (
Optional[list] (default:None)) – List of dataset IDs used to select metadata when collecting AnnData from the raw data folder. IfNone, no dataset-ID filtering is applied.obs_cols (
Optional[list] (default:None)) – List ofadata.obscolumn names to retrieve from the metadata AnnDatas.uns_cols (
Optional[list] (default:None)) – List ofadata.unskeys to retrieve from the metadata AnnDatas.emb_layers (
Optional[list] (default:None)) – Layers for which to retrieve the embedding.cell_gene_ids (
list(default:[])) – List with gene IDs for which cell gene embeddings will be retrieved.neighborhood_gene_ids (
list(default:[])) – List with gene IDs for which neighborhood gene embeddings will be retrived.agg_type (
Literal['cls','avg','weighted_avg'] (default:'avg')) – Specifies how (aggregated) cell and neighborhood embeddings are computed from individual gene embeddings.masked_tokens (
Optional[list[int]] (default:None)) – List of tokens to be masked by the attention mask during inference.agg_excluded_genes (
Optional[list[int]] (default:None)) – List of tokens to be excluded from the aggregation.top_k (
Optional[int] (default:None)) – Include only top_k genes in aggregation.return_gene (
bool(default:True)) – IfTruewill return gene_embedding.return_cosine_sim (
bool(default:False)) – IfTruewill compute and return cosine_sim matrix.compute_cosine_with_list (
list[str] (default:[])) – A list that defines the items with which we want to compute cosine similarity. It could have value ofcellor/andneighborhood.return_gene_per_data (
bool(default:False)) – IfTruewill return gene_embedding for each gene per dataset.return_gene_marker_score (
bool(default:False)) – IfTruewill compute and return gene marker scores.return_distance (
bool(default:False)) – IfTruewill compute and return distance between cosine sim of cell_neb and cell_cell matrix.include_spatial_cell_emb (
bool(default:False)) – IfTruealso return spatial cell embedding.ignore_spc_tokens (
bool(default:True)) – Whether to ignore special tokens when retrieving layer embeddings.debug (
bool(default:False)) – IfTrue, log additional diagnostic statistics about the embeddings and masks during inference.
- Returns:
adata (
AnnData) – An AnnData object with the stored embeddings and labels.