scgpt.utils package

Submodules

scgpt.utils.util module

class scgpt.utils.util.MainProcessOnly(obj)[source]

Bases: object

scgpt.utils.util.add_file_handler(logger: Logger, log_file_path: Path)[source]

Add a file handler to the logger.

scgpt.utils.util.category_str2int(category_strs: List[str]) List[int][source]
scgpt.utils.util.eval_scib_metrics(adata: AnnData, batch_key: str = 'str_batch', label_key: str = 'celltype', notes: Optional[str] = None) Dict[source]
scgpt.utils.util.find_required_colums(adata: AnnData, id: str, configs_dir: Union[str, Path], update: bool = False) List[Optional[str]][source]

Find the required columns in AnnData, including celltype column, str_celltype column, the gene name column, and the experimental batch key.

This function asks the user to input the required column names if the first time loading the data. The names are saved in the config file and will be automatically loaded next time.

Parameters:
  • adata (AnnData) – The AnnData object.

  • id (str) – The id of the AnnData object, will be used as the file name for saving the config file.

  • configs_dir (Union[str, Path]) – The directory of saved config files.

  • update (bool) – Whether to update the config file.

Returns:

The required columns, including celltype_col, str_celltype_col,

gene_col, and batch_col.

Return type:

List[Optional[str]]

scgpt.utils.util.gene_vocabulary()[source]

Generate the gene name2id and id2name dictionaries.

scgpt.utils.util.get_free_gpu()[source]
scgpt.utils.util.get_git_commit()[source]
scgpt.utils.util.histogram(*data: List[ndarray], label: List[str] = ['train', 'valid'], color: List[str] = ['blue', 'red'], figsize: Tuple[int, int] = (9, 4), title: Optional[str] = None, show: bool = False, save: Optional[str] = None) Axes[source]

Plot histogram of the data.

Parameters:
  • data (List[np.ndarray]) – The data to plot.

  • label (List[str]) – The label of the data.

  • color (List[str]) – The color of the data.

  • figsize (Tuple[int, int]) – The size of the figure.

  • title (Optional[str]) – The title of the figure.

  • show (bool) – Whether to show the figure.

  • save (Optional[str]) – The path to save the figure.

Returns:

The axes of the figure.

Return type:

axes.Axes

scgpt.utils.util.isnotebook() bool[source]

check whether excuting in jupyter notebook.

scgpt.utils.util.main_process_only(func)[source]
scgpt.utils.util.map_raw_id_to_vocab_id(raw_ids: Union[ndarray, Tensor], gene_ids: ndarray) Union[ndarray, Tensor][source]

Map some raw ids which are indices of the raw gene names to the indices of the

Parameters:
  • raw_ids – the raw ids to map

  • gene_ids – the gene ids to map to

scgpt.utils.util.set_seed(seed)[source]

set random seed.

scgpt.utils.util.tensorlist2tensor(tensorlist, pad_value)[source]

Module contents