autoencodix 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of autoencodix might be problematic. Click here for more details.

Files changed (91) hide show
  1. autoencodix/__init__.py +27 -0
  2. autoencodix/base/.ipynb_checkpoints/_base_pipeline-checkpoint.py +1274 -0
  3. autoencodix/base/.ipynb_checkpoints/_base_trainer-checkpoint.py +247 -0
  4. autoencodix/base/__init__.py +21 -0
  5. autoencodix/base/_base_autoencoder.py +138 -0
  6. autoencodix/base/_base_dataset.py +103 -0
  7. autoencodix/base/_base_evaluator.py +34 -0
  8. autoencodix/base/_base_loss.py +311 -0
  9. autoencodix/base/_base_pipeline.py +1355 -0
  10. autoencodix/base/_base_predictor.py +6 -0
  11. autoencodix/base/_base_preprocessor.py +1033 -0
  12. autoencodix/base/_base_trainer.py +259 -0
  13. autoencodix/base/_base_visualizer.py +578 -0
  14. autoencodix/base/sampleconfig.yaml +132 -0
  15. autoencodix/configs/__init__.py +21 -0
  16. autoencodix/configs/default_config.py +652 -0
  17. autoencodix/configs/disentanglix_config.py +15 -0
  18. autoencodix/configs/maskix_config.py +39 -0
  19. autoencodix/configs/ontix_config.py +35 -0
  20. autoencodix/configs/stackix_config.py +33 -0
  21. autoencodix/configs/vanillix_config.py +18 -0
  22. autoencodix/configs/varix_config.py +15 -0
  23. autoencodix/configs/xmodalix_config.py +43 -0
  24. autoencodix/disentanglix.py +72 -0
  25. autoencodix/evaluate/.ipynb_checkpoints/evaluate-checkpoint.py +532 -0
  26. autoencodix/evaluate/__init__.py +4 -0
  27. autoencodix/evaluate/_general_evaluator.py +730 -0
  28. autoencodix/evaluate/_xmodalix_evaluator.py +376 -0
  29. autoencodix/imagix.py +76 -0
  30. autoencodix/losses/disentanglix_loss.py +215 -0
  31. autoencodix/losses/maskix_loss.py +94 -0
  32. autoencodix/losses/vanillix_loss.py +28 -0
  33. autoencodix/losses/varix_loss.py +102 -0
  34. autoencodix/losses/xmodal_loss.py +304 -0
  35. autoencodix/maskix.py +108 -0
  36. autoencodix/modeling/.ipynb_checkpoints/__init__-checkpoint.py +16 -0
  37. autoencodix/modeling/.ipynb_checkpoints/_captum_forward-checkpoint.py +16 -0
  38. autoencodix/modeling/__init__.py +20 -0
  39. autoencodix/modeling/_captum_forward.py +20 -0
  40. autoencodix/modeling/_classifier.py +45 -0
  41. autoencodix/modeling/_imagevae_architecture.py +296 -0
  42. autoencodix/modeling/_imgfast_architecture.py +288 -0
  43. autoencodix/modeling/_layer_factory.py +71 -0
  44. autoencodix/modeling/_maskix_architecture.py +190 -0
  45. autoencodix/modeling/_ontix_architecture.py +305 -0
  46. autoencodix/modeling/_vanillix_architecture.py +136 -0
  47. autoencodix/modeling/_varix_architecture.py +192 -0
  48. autoencodix/notebooks/__init__.py +0 -0
  49. autoencodix/ontix.py +136 -0
  50. autoencodix/py.typed +0 -0
  51. autoencodix/stackix.py +122 -0
  52. autoencodix/trainers/__init__.py +6 -0
  53. autoencodix/trainers/_general_trainer.py +525 -0
  54. autoencodix/trainers/_maskix_trainer.py +116 -0
  55. autoencodix/trainers/_ontix_trainer.py +77 -0
  56. autoencodix/trainers/_stackix_orchestrator.py +522 -0
  57. autoencodix/trainers/_stackix_trainer.py +209 -0
  58. autoencodix/trainers/_xmodal_trainer.py +1006 -0
  59. autoencodix/utils/.ipynb_checkpoints/_explainer-checkpoint.py +118 -0
  60. autoencodix/utils/.ipynb_checkpoints/_model_output-checkpoint.py +30 -0
  61. autoencodix/utils/.ipynb_checkpoints/_utils-checkpoint.py +626 -0
  62. autoencodix/utils/.ipynb_checkpoints/adata_converter-checkpoint.py +99 -0
  63. autoencodix/utils/.ipynb_checkpoints/feature_importance-checkpoint.py +823 -0
  64. autoencodix/utils/__init__.py +22 -0
  65. autoencodix/utils/_annealer.py +193 -0
  66. autoencodix/utils/_bulkreader.py +232 -0
  67. autoencodix/utils/_explainer.py +246 -0
  68. autoencodix/utils/_imgreader.py +404 -0
  69. autoencodix/utils/_internals.py +23 -0
  70. autoencodix/utils/_llm_explainer.py +318 -0
  71. autoencodix/utils/_losses.py +20 -0
  72. autoencodix/utils/_model_output.py +30 -0
  73. autoencodix/utils/_result.py +393 -0
  74. autoencodix/utils/_screader.py +76 -0
  75. autoencodix/utils/_traindynamics.py +187 -0
  76. autoencodix/utils/_utils.py +690 -0
  77. autoencodix/utils/adata_converter.py +111 -0
  78. autoencodix/utils/example_data.py +398 -0
  79. autoencodix/utils/feature_importance.py +829 -0
  80. autoencodix/utils/prompts.py +21 -0
  81. autoencodix/vanillix.py +141 -0
  82. autoencodix/varix.py +80 -0
  83. autoencodix/visualize/__init__.py +5 -0
  84. autoencodix/visualize/_general_visualizer.py +913 -0
  85. autoencodix/visualize/_imagix_visualizer.py +111 -0
  86. autoencodix/visualize/_xmodal_visualizer.py +841 -0
  87. autoencodix/visualize/visualize.py +1214 -0
  88. autoencodix/xmodalix.py +318 -0
  89. autoencodix-0.2.0.dist-info/METADATA +143 -0
  90. autoencodix-0.2.0.dist-info/RECORD +91 -0
  91. autoencodix-0.2.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,21 @@
1
+ PROMPT = """
2
+ You are a bioinformatics expert.
3
+ I will provide a latent dimension name and a list of genes identified as top contributors to that dimension (derived using Captum). Your task is to analyze only the genes provided and derive biologically plausible interpretations of what the latent dimension may represent.
4
+ Please produce the following:
5
+ 1. A concise explanation of the dominant biological themes represented by the provided gene set.
6
+ 2. One to three mechanistic hypotheses describing potential biological processes, regulatory programs, or cellular states captured by this latent dimension.
7
+ 3. A summary of pathways, processes, or molecular functions that may be implicated (using only GO, KEGG, or other standard pathway resources if accessible).
8
+ 4. A TLDR summarizing the key biological insight.
9
+ Output Format:
10
+ Output ONLY a valid JSON object with the following keys. Do not include any other text, explanations, or markdown outside the JSON. Use double quotes around text blocks (strings) but never inside a text block. Ensure no trailing commas.
11
+ - "TLDR": a one-sentence high-level summary (string without quotes).
12
+ - "DETAILS": an object with these exact keys:
13
+ - "dominant_themes": concise explanation of the dominant biological themes (string without quotes).
14
+ - "hypotheses": array of 1-3 mechanistic hypotheses (array of strings without quotes).
15
+ - "pathways_summary": summary of implicated pathways/processes/functions (string without quotes).
16
+ Constraints:
17
+ - Do not invent gene names or functions. Use only the genes provided.
18
+ - Base all interpretations strictly on the supplied gene list and standard biological knowledge resources.
19
+ Input genes:
20
+ {gene_block}
21
+ """
@@ -0,0 +1,141 @@
1
+ from typing import Dict, Optional, Type, Union, List
2
+
3
+ import numpy as np
4
+ import torch
5
+
6
+ from autoencodix.base._base_dataset import BaseDataset
7
+ from autoencodix.base._base_preprocessor import BasePreprocessor
8
+ from autoencodix.base._base_loss import BaseLoss
9
+ from autoencodix.data.datapackage import DataPackage
10
+ from autoencodix.base._base_pipeline import BasePipeline
11
+ from autoencodix.base._base_trainer import BaseTrainer
12
+ from autoencodix.base._base_evaluator import BaseEvaluator
13
+ from autoencodix.base._base_visualizer import BaseVisualizer
14
+ from autoencodix.base._base_autoencoder import BaseAutoencoder
15
+ from autoencodix.data._datasetcontainer import DatasetContainer
16
+ from autoencodix.data._datasplitter import DataSplitter
17
+ from autoencodix.data._numeric_dataset import NumericDataset
18
+ from autoencodix.data.general_preprocessor import GeneralPreprocessor
19
+ from autoencodix.evaluate._general_evaluator import GeneralEvaluator
20
+ from autoencodix.modeling._vanillix_architecture import VanillixArchitecture
21
+ from autoencodix.trainers._general_trainer import GeneralTrainer
22
+ from autoencodix.utils._result import Result
23
+ from autoencodix.configs.default_config import DefaultConfig
24
+ from autoencodix.configs.vanillix_config import VanillixConfig
25
+ from autoencodix.utils._losses import VanillixLoss
26
+ from autoencodix.visualize._general_visualizer import GeneralVisualizer
27
+
28
+
29
+ class Vanillix(BasePipeline):
30
+ """Vanillix specific version of the BasePipeline class.
31
+
32
+ Inherits preprocess, fit, predict, evaluate, and visualize methods from BasePipeline.
33
+ This class extends BasePipeline. See the parent class for a full list
34
+ of attributes and methods.
35
+
36
+ Additional Attributes:
37
+ _default_config: Is set to VanillixConfig here.
38
+
39
+ """
40
+
41
+ def __init__(
42
+ self,
43
+ data: Optional[Union[DataPackage, DatasetContainer]] = None,
44
+ trainer_type: Type[BaseTrainer] = GeneralTrainer,
45
+ dataset_type: Type[BaseDataset] = NumericDataset,
46
+ model_type: Type[BaseAutoencoder] = VanillixArchitecture,
47
+ loss_type: Type[BaseLoss] = VanillixLoss,
48
+ preprocessor_type: Type[BasePreprocessor] = GeneralPreprocessor,
49
+ visualizer: Type[BaseVisualizer] = GeneralVisualizer,
50
+ evaluator: Optional[Type[BaseEvaluator]] = GeneralEvaluator,
51
+ result: Optional[Result] = None,
52
+ datasplitter_type: Type[DataSplitter] = DataSplitter,
53
+ custom_splits: Optional[Dict[str, np.ndarray]] = None,
54
+ config: Optional[DefaultConfig] = None,
55
+ ontologies: Optional[Union[List, Dict]] = None,
56
+ ) -> None:
57
+ """Initialize Vanillix pipeline with customizable components.
58
+
59
+ Some components are passed as types rather than instances because they require
60
+ data that is only available after preprocessing.
61
+
62
+ See implementation of parent class for list of full Args.
63
+ """
64
+ self._default_config = VanillixConfig()
65
+ super().__init__(
66
+ data=data,
67
+ dataset_type=dataset_type,
68
+ trainer_type=trainer_type,
69
+ model_type=model_type,
70
+ loss_type=loss_type,
71
+ preprocessor_type=preprocessor_type,
72
+ visualizer=visualizer,
73
+ evaluator=evaluator,
74
+ result=result,
75
+ datasplitter_type=datasplitter_type,
76
+ config=config,
77
+ custom_split=custom_splits,
78
+ ontologies=ontologies,
79
+ )
80
+
81
+ def sample_latent_space(
82
+ self,
83
+ n_samples: int,
84
+ split: str = "test",
85
+ epoch: int = -1,
86
+ ) -> torch.Tensor:
87
+ """Samples latent space points from the empirical latent distribution.
88
+
89
+ This method draws new latent points by fitting a diagonal Gaussian
90
+ distribution to the latent codes of the specified split and epoch, and
91
+ sampling from it. This enables approximate generative sampling for
92
+ autoencoders that do not model uncertainty explicitly.
93
+
94
+ Args:
95
+ n_samples: The number of latent points to sample. Must be a positive
96
+ integer.
97
+ split: The split to sample from (train, valid, test), default is test.
98
+ epoch: The epoch to sample from, default is the last epoch (-1).
99
+
100
+ Returns:
101
+ z: torch.Tensor - The sampled latent space points.
102
+
103
+ Raises:
104
+ ValueError: If the model has not been trained, latent codes have not
105
+ been computed, or n_samples is not a positive integer.
106
+ TypeError: If the stored latent codes are not numpy arrays.
107
+ """
108
+
109
+ if not hasattr(self, "_trainer") or self._trainer is None:
110
+ raise ValueError("Model is not trained yet. Please train the model first.")
111
+ if self.result.latentspaces is None:
112
+ raise ValueError("Model has no stored latent codes for sampling.")
113
+ if not isinstance(n_samples, int) or n_samples <= 0:
114
+ raise ValueError("n_samples must be a positive integer.")
115
+
116
+ Z = self.result.latentspaces.get(split=split, epoch=epoch)
117
+
118
+ if not isinstance(Z, np.ndarray):
119
+ raise TypeError(
120
+ f"Expected latent codes to be of type numpy.ndarray, got {type(Z)}."
121
+ )
122
+
123
+ Z_t = torch.from_numpy(Z).to(
124
+ device=self._trainer._model.device,
125
+ dtype=self._trainer._model.dtype,
126
+ )
127
+
128
+ with torch.no_grad():
129
+ # Fit empirical diagonal Gaussian
130
+ global_mu = Z_t.mean(dim=0)
131
+ global_std = Z_t.std(dim=0)
132
+
133
+ eps = torch.randn(
134
+ n_samples,
135
+ Z_t.shape[1],
136
+ device=Z_t.device,
137
+ dtype=Z_t.dtype,
138
+ )
139
+
140
+ z = global_mu + eps * global_std
141
+ return z
autoencodix/varix.py ADDED
@@ -0,0 +1,80 @@
1
+ from typing import Dict, Optional, Type, Union, List
2
+ import torch
3
+ import numpy as np
4
+
5
+ from autoencodix.base._base_dataset import BaseDataset
6
+ from autoencodix.utils._utils import config_method
7
+ from autoencodix.base._base_loss import BaseLoss
8
+ from autoencodix.base._base_pipeline import BasePipeline
9
+ from autoencodix.base._base_evaluator import BaseEvaluator
10
+ from autoencodix.base._base_trainer import BaseTrainer
11
+ from autoencodix.base._base_visualizer import BaseVisualizer
12
+ from autoencodix.base._base_preprocessor import BasePreprocessor
13
+ from autoencodix.base._base_autoencoder import BaseAutoencoder
14
+ from autoencodix.data._datasetcontainer import DatasetContainer
15
+ from autoencodix.data._datasplitter import DataSplitter
16
+ from autoencodix.data.datapackage import DataPackage
17
+ from autoencodix.data._numeric_dataset import NumericDataset
18
+ from autoencodix.data.general_preprocessor import GeneralPreprocessor
19
+ from autoencodix.evaluate._general_evaluator import GeneralEvaluator
20
+ from autoencodix.modeling._varix_architecture import VarixArchitecture
21
+ from autoencodix.trainers._general_trainer import GeneralTrainer
22
+ from autoencodix.utils._result import Result
23
+ from autoencodix.configs.default_config import DefaultConfig
24
+ from autoencodix.configs.varix_config import VarixConfig
25
+ from autoencodix.utils._losses import VarixLoss
26
+ from autoencodix.visualize._general_visualizer import GeneralVisualizer
27
+
28
+
29
+ class Varix(BasePipeline):
30
+ """Varix specific version of the BasePipeline class.
31
+
32
+ Inherits preprocess, fit, predict, evaluate, and visualize methods from BasePipeline.
33
+ This class extends BasePipeline. See the parent class for a full list
34
+ of attributes and methods.
35
+
36
+ Additional Attributes:
37
+ _default_config: Is set to VarixConfig here.
38
+
39
+ """
40
+
41
+ def __init__(
42
+ self,
43
+ data: Optional[Union[DataPackage, DatasetContainer]] = None,
44
+ trainer_type: Type[BaseTrainer] = GeneralTrainer,
45
+ dataset_type: Type[BaseDataset] = NumericDataset,
46
+ model_type: Type[BaseAutoencoder] = VarixArchitecture,
47
+ loss_type: Type[BaseLoss] = VarixLoss,
48
+ preprocessor_type: Type[BasePreprocessor] = GeneralPreprocessor,
49
+ visualizer: Type[BaseVisualizer] = GeneralVisualizer,
50
+ evaluator: Optional[Type[BaseEvaluator]] = GeneralEvaluator,
51
+ result: Optional[Result] = None,
52
+ datasplitter_type: Type[DataSplitter] = DataSplitter,
53
+ custom_splits: Optional[Dict[str, np.ndarray]] = None,
54
+ ontologies: Optional[Union[List, Dict]] = None,
55
+ config: Optional[DefaultConfig] = None,
56
+ ) -> None:
57
+ """Initialize Varix pipeline with customizable components.
58
+
59
+ Some components are passed as types rather than instances because they require
60
+ data that is only available after preprocessing.
61
+
62
+ See parent class for full list of Args.
63
+
64
+ """
65
+ self._default_config = VarixConfig()
66
+ super().__init__(
67
+ data=data,
68
+ dataset_type=dataset_type,
69
+ trainer_type=trainer_type,
70
+ model_type=model_type,
71
+ loss_type=loss_type,
72
+ preprocessor_type=preprocessor_type,
73
+ visualizer=visualizer,
74
+ evaluator=evaluator,
75
+ result=result,
76
+ datasplitter_type=datasplitter_type,
77
+ config=config,
78
+ custom_split=custom_splits,
79
+ ontologies=ontologies,
80
+ )
@@ -0,0 +1,5 @@
1
+ from ._general_visualizer import GeneralVisualizer
2
+ from ._xmodal_visualizer import XModalVisualizer
3
+ from .visualize import Visualizer
4
+
5
+ __all__ = ["GeneralVisualizer", "XModalVisualizer", "Visualizer"]