terra.infer

Contents

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. Run 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.

  • 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)) – If True will return gene_embedding.

  • return_cosine_sim (bool (default: False)) – If True will 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 of cell or/and neighborhood.

  • return_gene_per_data (bool (default: False)) – If True will return gene_embedding for each gene per dataset.

  • return_gene_marker_score (bool (default: False)) – If True will compute and return gene marker scores.

  • return_distance (bool (default: False)) – If True will compute and return distance between cosine sim of cell_neb and cell_cell matrix.

  • include_spatial_cell_emb (bool (default: False)) – If True also return spatial cell embedding.

Return type:

AnnData

Returns:

adata: An AnnData object with the stored embeddings and labels.