preffect_factory.py module
- preffect_factory.core_only_copy(old)
- preffect_factory.factory(task=None, always_save=True, trigger_setup=False, configs=None, preffect_obj=None, inference_obj=None, inference_key=None, fname=None, visualize=True, error_type=None, cluster_omega=False)
Calls _preffect class to perform tasks such as training, inference, reinstatement, clustering, and visualization based on specified configurations.
- Parameters:
task (str, optional) -- The specific task to be executed. Valid options include 'train', 'inference', 'reinstate', 'cluster_latent', 'cluster_counts', and 'visualize_lib_size'.
always_save (bool, optional) -- If True, the current state of the process (Preffect or Inference) will always be saved after execution.
trigger_setup (bool, optional) -- If True, triggers the setup process for the environment before execution.
configs (dict, optional) -- Configuration dictionary specifying details such as paths, device settings, and the specific task to be executed.
preffect_obj (Preffect, optional) -- An instance of the Preffect class, if already instantiated; otherwise, it is created based on the task requirements.
inference_obj (Inference, optional) -- An instance of the Inference class, if already instantiated.
inference_key (str, optional) -- The name identifier for an Inference instance to be fetched from a register.
fname (str, optional) -- The filename to be used for saving outputs, specifically in inference tasks.
visualize (bool, optional) -- If True, enables visualization for relevant tasks.
error_type (str, optional) -- The type of error to be used for error handling and reporting.
cluster_omega (bool, optional) -- If True, enables clustering of omega values.
- Returns:
Depending on the task specified in configs['task']: - Preffect instance for 'train', 'inference', and 'reinstate' tasks. - Cluster instance for 'cluster_latent' and 'cluster_counts' tasks. - Visualization object for 'visualize_lib_size' task.
- Return type:
- Raises:
PreffectError -- If an invalid task is specified or if required resources (like Preffect or Inference instances) are not provided or found for the requested operation.
- preffect_factory.factory_setup(configs)
Sets up the factory environment for processing by initializing paths, ensuring directory existence, and setting up logging and CUDA device configurations.
- Parameters:
configs (dict) --
A dictionary containing configuration settings. Expected keys include:
'input_anndata_path': Path to input Anndata files for basic checks.
'input_inference_anndata_path': Path for input inference Anndata files.
'output_path': Base path where logs and results directories will be created.
'cuda_device_num': Integer specifying the CUDA device number to use.
'no_cuda': Boolean that if True, forces the use of CPU even if CUDA is available.
- Returns:
A tuple containing:
input_log (logging.Logger): Logger for input operations.
forward_log (logging.Logger or None): Logger for forward operations. None if the task is not 'train'.
inference_log (logging.Logger or None): Logger for inference operations. None if the task is not 'train'.
configs (dict): The updated configurations dictionary.
- Return type:
tuple
- Raises:
Exception -- If there is an issue accessing the required Anndata paths, an exception is raised with a message indicating the inaccessible path.
- preffect_factory.generate_and_save_visualizations(inference_instance)
Function which calls visualization tasks and saves the images within preffect_factory.py.
- Parameters:
inference_instance (Inference) -- An instance of the Inference class representing the inference process.
- preffect_factory.setup_cuda(configs)
Set up the CUDA device based on the provided configurations.
- Parameters:
configs (dict) -- A dictionary containing configuration settings. Expected keys include: - 'cuda_device_num': Integer specifying the CUDA device number to use. - 'no_cuda': Boolean that if True, forces the use of CPU even if CUDA is available.
- Returns:
The configured PyTorch device (either CUDA or CPU).
- Return type:
torch.device