scgpt.utils package

scgpt.utils.util

class scgpt.utils.util.MainProcessOnly(obj)[源代码]

基类:object

scgpt.utils.util.add_file_handler(logger: Logger, log_file_path: Path)[源代码]

Add a file handler to the logger.

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

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.

参数:
  • 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.

返回:

The required columns, including celltype_col, str_celltype_col,

gene_col, and batch_col.

返回类型:

List[Optional[str]]

scgpt.utils.util.gene_vocabulary()[源代码]

Generate the gene name2id and id2name dictionaries.

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

Plot histogram of the data.

参数:
  • 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.

返回:

The axes of the figure.

返回类型:

axes.Axes

scgpt.utils.util.isnotebook() bool[源代码]

check whether excuting in jupyter notebook.

scgpt.utils.util.main_process_only(func)[源代码]
scgpt.utils.util.map_raw_id_to_vocab_id(raw_ids: ndarray | Tensor, gene_ids: ndarray) ndarray | Tensor[源代码]

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

参数:
  • raw_ids – the raw ids to map

  • gene_ids – the gene ids to map to

scgpt.utils.util.set_seed(seed)[源代码]

set random seed.

scgpt.utils.util.tensorlist2tensor(tensorlist, pad_value)[源代码]

Module contents