diffbio 0.1.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.
Files changed (202) hide show
  1. diffbio/__init__.py +39 -0
  2. diffbio/configs.py +75 -0
  3. diffbio/constants.py +204 -0
  4. diffbio/core/__init__.py +127 -0
  5. diffbio/core/base_operators.py +612 -0
  6. diffbio/core/data_types.py +260 -0
  7. diffbio/core/gnn_components.py +629 -0
  8. diffbio/core/graph_utils.py +149 -0
  9. diffbio/core/neural_components.py +270 -0
  10. diffbio/core/optimal_transport.py +133 -0
  11. diffbio/core/soft_ops/__init__.py +216 -0
  12. diffbio/core/soft_ops/_projections_permutahedron.py +1864 -0
  13. diffbio/core/soft_ops/_projections_simplex.py +240 -0
  14. diffbio/core/soft_ops/_projections_transport.py +508 -0
  15. diffbio/core/soft_ops/_sorting_network.py +204 -0
  16. diffbio/core/soft_ops/_types.py +15 -0
  17. diffbio/core/soft_ops/_utils.py +342 -0
  18. diffbio/core/soft_ops/autograd_safe.py +120 -0
  19. diffbio/core/soft_ops/comparison.py +235 -0
  20. diffbio/core/soft_ops/elementwise.py +309 -0
  21. diffbio/core/soft_ops/logical.py +146 -0
  22. diffbio/core/soft_ops/quantile.py +376 -0
  23. diffbio/core/soft_ops/selection.py +236 -0
  24. diffbio/core/soft_ops/sorting.py +926 -0
  25. diffbio/core/soft_ops/straight_through.py +261 -0
  26. diffbio/core/uncertainty.py +279 -0
  27. diffbio/evaluation/__init__.py +42 -0
  28. diffbio/evaluation/adapters.py +409 -0
  29. diffbio/evaluation/graders.py +223 -0
  30. diffbio/evaluation/problem.py +157 -0
  31. diffbio/evaluation/runner.py +277 -0
  32. diffbio/losses/__init__.py +59 -0
  33. diffbio/losses/alignment_losses.py +222 -0
  34. diffbio/losses/biological_regularization.py +288 -0
  35. diffbio/losses/metric_losses.py +139 -0
  36. diffbio/losses/singlecell_losses.py +387 -0
  37. diffbio/losses/statistical_losses.py +345 -0
  38. diffbio/operators/__init__.py +60 -0
  39. diffbio/operators/_count_vae.py +197 -0
  40. diffbio/operators/_loss_balancing.py +65 -0
  41. diffbio/operators/_masked_gene_transformer.py +118 -0
  42. diffbio/operators/_transformer_validation.py +50 -0
  43. diffbio/operators/alignment/__init__.py +51 -0
  44. diffbio/operators/alignment/profile_hmm.py +350 -0
  45. diffbio/operators/alignment/scoring.py +127 -0
  46. diffbio/operators/alignment/smith_waterman.py +261 -0
  47. diffbio/operators/alignment/soft_msa.py +419 -0
  48. diffbio/operators/assembly/__init__.py +27 -0
  49. diffbio/operators/assembly/gnn_assembly.py +252 -0
  50. diffbio/operators/assembly/metagenomic_binning.py +296 -0
  51. diffbio/operators/crispr/__init__.py +17 -0
  52. diffbio/operators/crispr/guide_scoring.py +269 -0
  53. diffbio/operators/drug_discovery/__init__.py +133 -0
  54. diffbio/operators/drug_discovery/_graph_utils.py +142 -0
  55. diffbio/operators/drug_discovery/admet_predictor.py +285 -0
  56. diffbio/operators/drug_discovery/attentive_fp.py +411 -0
  57. diffbio/operators/drug_discovery/dti.py +261 -0
  58. diffbio/operators/drug_discovery/fingerprint.py +490 -0
  59. diffbio/operators/drug_discovery/maccs_keys.py +267 -0
  60. diffbio/operators/drug_discovery/message_passing.py +200 -0
  61. diffbio/operators/drug_discovery/primitives.py +242 -0
  62. diffbio/operators/drug_discovery/property_predictor.py +163 -0
  63. diffbio/operators/drug_discovery/similarity.py +193 -0
  64. diffbio/operators/epigenomics/__init__.py +35 -0
  65. diffbio/operators/epigenomics/chromatin_state.py +491 -0
  66. diffbio/operators/epigenomics/contextual.py +288 -0
  67. diffbio/operators/epigenomics/fno_peak_calling.py +153 -0
  68. diffbio/operators/epigenomics/peak_calling.py +555 -0
  69. diffbio/operators/foundation_models/__init__.py +119 -0
  70. diffbio/operators/foundation_models/adapters.py +114 -0
  71. diffbio/operators/foundation_models/contracts.py +245 -0
  72. diffbio/operators/foundation_models/embedding_probe.py +83 -0
  73. diffbio/operators/foundation_models/experimental.py +128 -0
  74. diffbio/operators/foundation_models/foundation_model.py +332 -0
  75. diffbio/operators/foundation_models/frozen.py +59 -0
  76. diffbio/operators/foundation_models/precomputed.py +270 -0
  77. diffbio/operators/foundation_models/transformer_encoder.py +564 -0
  78. diffbio/operators/mapping/__init__.py +17 -0
  79. diffbio/operators/mapping/neural_mapper.py +493 -0
  80. diffbio/operators/metabolomics/__init__.py +39 -0
  81. diffbio/operators/metabolomics/spectral_similarity.py +315 -0
  82. diffbio/operators/molecular_dynamics/__init__.py +51 -0
  83. diffbio/operators/molecular_dynamics/force_field.py +265 -0
  84. diffbio/operators/molecular_dynamics/integrator.py +304 -0
  85. diffbio/operators/molecular_dynamics/primitives.py +115 -0
  86. diffbio/operators/multiomics/__init__.py +38 -0
  87. diffbio/operators/multiomics/hic_contact.py +377 -0
  88. diffbio/operators/multiomics/multiomics_vae.py +325 -0
  89. diffbio/operators/multiomics/spatial_deconvolution.py +316 -0
  90. diffbio/operators/multiomics/spatial_gene_detection.py +493 -0
  91. diffbio/operators/normalization/__init__.py +42 -0
  92. diffbio/operators/normalization/embedding.py +222 -0
  93. diffbio/operators/normalization/phate.py +400 -0
  94. diffbio/operators/normalization/umap.py +261 -0
  95. diffbio/operators/normalization/vae_normalizer.py +258 -0
  96. diffbio/operators/population/__init__.py +17 -0
  97. diffbio/operators/population/ancestry_estimation.py +274 -0
  98. diffbio/operators/preprocessing/__init__.py +76 -0
  99. diffbio/operators/preprocessing/adapter_removal.py +311 -0
  100. diffbio/operators/preprocessing/duplicate_filter.py +317 -0
  101. diffbio/operators/preprocessing/error_correction.py +287 -0
  102. diffbio/operators/protein/__init__.py +31 -0
  103. diffbio/operators/protein/secondary_structure.py +509 -0
  104. diffbio/operators/quality_filter.py +128 -0
  105. diffbio/operators/rna_structure/__init__.py +35 -0
  106. diffbio/operators/rna_structure/rna_folding.py +509 -0
  107. diffbio/operators/rnaseq/__init__.py +23 -0
  108. diffbio/operators/rnaseq/motif_discovery.py +251 -0
  109. diffbio/operators/rnaseq/splicing_psi.py +216 -0
  110. diffbio/operators/singlecell/__init__.py +193 -0
  111. diffbio/operators/singlecell/ambient_removal.py +333 -0
  112. diffbio/operators/singlecell/archetypes.py +191 -0
  113. diffbio/operators/singlecell/batch_correction.py +288 -0
  114. diffbio/operators/singlecell/cell_annotation.py +519 -0
  115. diffbio/operators/singlecell/communication.py +704 -0
  116. diffbio/operators/singlecell/differential_distribution.py +243 -0
  117. diffbio/operators/singlecell/doublet_detection.py +657 -0
  118. diffbio/operators/singlecell/downsampling.py +166 -0
  119. diffbio/operators/singlecell/enhanced_batch_correction.py +519 -0
  120. diffbio/operators/singlecell/grn_inference.py +336 -0
  121. diffbio/operators/singlecell/imputation.py +429 -0
  122. diffbio/operators/singlecell/knockdown_filter.py +176 -0
  123. diffbio/operators/singlecell/ot_trajectory.py +277 -0
  124. diffbio/operators/singlecell/simulation.py +444 -0
  125. diffbio/operators/singlecell/sindy_grn.py +247 -0
  126. diffbio/operators/singlecell/soft_clustering.py +211 -0
  127. diffbio/operators/singlecell/spatial_domains.py +677 -0
  128. diffbio/operators/singlecell/switch_de.py +184 -0
  129. diffbio/operators/singlecell/trajectory.py +447 -0
  130. diffbio/operators/singlecell/velocity.py +361 -0
  131. diffbio/operators/statistical/__init__.py +35 -0
  132. diffbio/operators/statistical/em_quantification.py +260 -0
  133. diffbio/operators/statistical/hmm.py +234 -0
  134. diffbio/operators/statistical/nb_glm.py +272 -0
  135. diffbio/operators/variant/__init__.py +64 -0
  136. diffbio/operators/variant/classifier.py +333 -0
  137. diffbio/operators/variant/cnn_classifier.py +255 -0
  138. diffbio/operators/variant/cnv_segmentation.py +678 -0
  139. diffbio/operators/variant/deepvariant_pileup.py +426 -0
  140. diffbio/operators/variant/pileup.py +240 -0
  141. diffbio/operators/variant/quality_recalibration.py +274 -0
  142. diffbio/pipelines/__init__.py +65 -0
  143. diffbio/pipelines/differential_expression.py +279 -0
  144. diffbio/pipelines/enhanced_variant_calling.py +326 -0
  145. diffbio/pipelines/perturbation.py +407 -0
  146. diffbio/pipelines/preprocessing.py +267 -0
  147. diffbio/pipelines/single_cell.py +366 -0
  148. diffbio/pipelines/variant_calling.py +490 -0
  149. diffbio/samplers/__init__.py +9 -0
  150. diffbio/samplers/perturbation_sampler.py +142 -0
  151. diffbio/sequences/__init__.py +34 -0
  152. diffbio/sequences/dna.py +239 -0
  153. diffbio/sources/__init__.py +149 -0
  154. diffbio/sources/_anndata_shared.py +89 -0
  155. diffbio/sources/_batch_iteration.py +37 -0
  156. diffbio/sources/_benchmark_source.py +152 -0
  157. diffbio/sources/_indexed_batch_source.py +38 -0
  158. diffbio/sources/_utils.py +45 -0
  159. diffbio/sources/anndata_interop.py +387 -0
  160. diffbio/sources/anndata_source.py +361 -0
  161. diffbio/sources/archive_ii.py +174 -0
  162. diffbio/sources/balifam.py +207 -0
  163. diffbio/sources/bam.py +265 -0
  164. diffbio/sources/bengrn_ground_truth.py +306 -0
  165. diffbio/sources/contextual_epigenomics.py +242 -0
  166. diffbio/sources/dti.py +359 -0
  167. diffbio/sources/embeddings.py +203 -0
  168. diffbio/sources/encode_peaks.py +223 -0
  169. diffbio/sources/fasta.py +226 -0
  170. diffbio/sources/immune_human.py +172 -0
  171. diffbio/sources/indexed_embeddings.py +128 -0
  172. diffbio/sources/indexed_view.py +191 -0
  173. diffbio/sources/molnet.py +493 -0
  174. diffbio/sources/multiomics.py +279 -0
  175. diffbio/sources/pancreas.py +108 -0
  176. diffbio/sources/perturbation/__init__.py +69 -0
  177. diffbio/sources/perturbation/_types.py +51 -0
  178. diffbio/sources/perturbation/_utils.py +125 -0
  179. diffbio/sources/perturbation/concat_source.py +115 -0
  180. diffbio/sources/perturbation/control_mapping.py +215 -0
  181. diffbio/sources/perturbation/experiment_config.py +261 -0
  182. diffbio/sources/perturbation/h5_metadata_cache.py +218 -0
  183. diffbio/sources/perturbation/output_space.py +52 -0
  184. diffbio/sources/perturbation/perturbation_source.py +513 -0
  185. diffbio/sources/seqfish.py +145 -0
  186. diffbio/sources/sequence_foundation.py +68 -0
  187. diffbio/sources/singlecell_foundation.py +68 -0
  188. diffbio/splitters/__init__.py +63 -0
  189. diffbio/splitters/base.py +251 -0
  190. diffbio/splitters/molecular.py +330 -0
  191. diffbio/splitters/perturbation.py +199 -0
  192. diffbio/splitters/random.py +217 -0
  193. diffbio/splitters/sequence.py +201 -0
  194. diffbio/utils/__init__.py +55 -0
  195. diffbio/utils/dependency_runtime.py +115 -0
  196. diffbio/utils/nn_utils.py +157 -0
  197. diffbio/utils/quality.py +45 -0
  198. diffbio/utils/training.py +585 -0
  199. diffbio-0.1.0.dist-info/METADATA +480 -0
  200. diffbio-0.1.0.dist-info/RECORD +202 -0
  201. diffbio-0.1.0.dist-info/WHEEL +4 -0
  202. diffbio-0.1.0.dist-info/licenses/LICENSE +21 -0
diffbio/__init__.py ADDED
@@ -0,0 +1,39 @@
1
+ """DiffBio: End-to-end differentiable bioinformatics pipelines built on the wider JAX/NNX ecosystem.
2
+
3
+ This package provides differentiable bioinformatics pipeline components that
4
+ integrate with Datarax, Artifex, Opifex, and Calibrax for gradient-based
5
+ optimization of genomics workflows.
6
+
7
+ Key components:
8
+ - sequences: Biological sequence data types (DNA, RNA, Protein)
9
+ - operators: Differentiable bioinformatics operators (alignment, quality filtering)
10
+ - losses: Loss functions and biological regularization
11
+ - pipelines: Pre-built differentiable pipeline templates
12
+ - configs: Base configuration classes for operators
13
+ - constants: Centralized constants for the library
14
+ """
15
+
16
+ from diffbio import (
17
+ configs,
18
+ constants,
19
+ evaluation,
20
+ losses,
21
+ operators,
22
+ pipelines,
23
+ sequences,
24
+ utils,
25
+ )
26
+
27
+ __version__ = "0.1.0"
28
+
29
+ __all__ = [
30
+ "__version__",
31
+ "configs",
32
+ "constants",
33
+ "evaluation",
34
+ "losses",
35
+ "operators",
36
+ "pipelines",
37
+ "sequences",
38
+ "utils",
39
+ ]
diffbio/configs.py ADDED
@@ -0,0 +1,75 @@
1
+ """Base configuration classes for DiffBio operators.
2
+
3
+ This module provides base configuration classes that reduce duplication
4
+ across operator configs by providing common fields with sensible defaults.
5
+
6
+ Note: The `stochastic` and `stream_name` fields are already defined in
7
+ datarax.core.config.OperatorConfig, so we don't re-declare them here.
8
+ DiffBio configs inherit these fields automatically.
9
+ """
10
+
11
+ from dataclasses import dataclass
12
+
13
+ from datarax.core.config import OperatorConfig
14
+
15
+ from diffbio.constants import (
16
+ DEFAULT_DROPOUT_RATE,
17
+ DEFAULT_HIDDEN_DIM,
18
+ DEFAULT_NUM_CLASSES,
19
+ DEFAULT_NUM_LAYERS,
20
+ DEFAULT_TEMPERATURE,
21
+ )
22
+
23
+
24
+ def apply_stochastic_sampling_defaults(
25
+ config: OperatorConfig,
26
+ *,
27
+ stream_name: str = "sample",
28
+ ) -> None:
29
+ """Apply DiffBio's default stochastic sampling contract to a config.
30
+
31
+ Args:
32
+ config: Operator config instance being finalized in ``__post_init__``.
33
+ stream_name: Default RNG stream name to use when none is supplied.
34
+ """
35
+ object.__setattr__(config, "stochastic", True)
36
+ if config.stream_name is None:
37
+ object.__setattr__(config, "stream_name", stream_name)
38
+
39
+
40
+ @dataclass(frozen=True)
41
+ class TemperatureConfig(OperatorConfig):
42
+ """Configuration for operators with temperature parameter.
43
+
44
+ Use this base class for operators that use temperature-based
45
+ smoothing (logsumexp relaxation, soft thresholding, etc.).
46
+
47
+ Attributes:
48
+ temperature: Temperature for smooth operations.
49
+ Lower = sharper (closer to hard operations).
50
+ Higher = smoother (more gradient flow).
51
+ learnable_temperature: Whether temperature is a learnable parameter.
52
+ If True, temperature will be an nnx.Param that receives gradients.
53
+ """
54
+
55
+ temperature: float = DEFAULT_TEMPERATURE
56
+ learnable_temperature: bool = False
57
+
58
+
59
+ @dataclass(frozen=True)
60
+ class ClassifierConfig(OperatorConfig):
61
+ """Base configuration for classifier operators.
62
+
63
+ Provides common fields for neural network classifiers.
64
+
65
+ Attributes:
66
+ num_classes: Number of output classes.
67
+ hidden_dim: Hidden layer dimension.
68
+ num_layers: Number of hidden layers.
69
+ dropout_rate: Dropout rate for regularization.
70
+ """
71
+
72
+ num_classes: int = DEFAULT_NUM_CLASSES
73
+ hidden_dim: int = DEFAULT_HIDDEN_DIM
74
+ num_layers: int = DEFAULT_NUM_LAYERS
75
+ dropout_rate: float = DEFAULT_DROPOUT_RATE
diffbio/constants.py ADDED
@@ -0,0 +1,204 @@
1
+ """Centralized constants for DiffBio.
2
+
3
+ This module provides centralized constants used across operators, pipelines,
4
+ and utilities. Using these constants ensures consistency and makes maintenance
5
+ easier.
6
+ """
7
+
8
+ from enum import StrEnum
9
+
10
+ # =============================================================================
11
+ # Neural Network Architecture Defaults
12
+ # =============================================================================
13
+
14
+ DEFAULT_HIDDEN_DIM = 64
15
+ """Default hidden layer dimension for MLP architectures."""
16
+
17
+ DEFAULT_HIDDEN_DIM_LARGE = 128
18
+ """Larger hidden dimension for complex models."""
19
+
20
+ DEFAULT_EMBEDDING_DIM = 64
21
+ """Default embedding dimension for sequence embeddings."""
22
+
23
+ DEFAULT_DROPOUT_RATE = 0.1
24
+ """Default dropout rate for regularization."""
25
+
26
+ DEFAULT_NUM_LAYERS = 2
27
+ """Default number of hidden layers in MLPs."""
28
+
29
+ DEFAULT_TEMPERATURE = 1.0
30
+ """Default temperature for logsumexp smoothing and softmax."""
31
+
32
+
33
+ # =============================================================================
34
+ # Quality Score Constants (Phred Scale)
35
+ # =============================================================================
36
+
37
+ PHRED_QUALITY_MAX = 40.0
38
+ """Maximum Phred quality score (99.99% accuracy)."""
39
+
40
+ PHRED_QUALITY_THRESHOLD = 20.0
41
+ """Default Phred quality threshold (99% accuracy, 1% error rate)."""
42
+
43
+ PHRED_QUALITY_MIN = 0.0
44
+ """Minimum Phred quality score."""
45
+
46
+
47
+ # =============================================================================
48
+ # Alignment Constants
49
+ # =============================================================================
50
+
51
+ DEFAULT_GAP_OPEN = -10.0
52
+ """Default gap opening penalty for alignment."""
53
+
54
+ DEFAULT_GAP_EXTEND = -1.0
55
+ """Default gap extension penalty for alignment."""
56
+
57
+ DNA_MATCH_SCORE = 2.0
58
+ """Default match score for DNA alignment."""
59
+
60
+ DNA_MISMATCH_SCORE = -1.0
61
+ """Default mismatch penalty for DNA alignment."""
62
+
63
+
64
+ # =============================================================================
65
+ # Numerical Stability Constants
66
+ # =============================================================================
67
+
68
+ EPSILON = 1e-8
69
+ """Small value for numerical stability in divisions and log operations."""
70
+
71
+ EPSILON_LOG = 1e-10
72
+ """Smaller epsilon specifically for log operations to prevent -inf."""
73
+
74
+ DISTANCE_MASK_SENTINEL = 1e10
75
+ """Large value used to mask out self-distances in pairwise distance matrices."""
76
+
77
+
78
+ # =============================================================================
79
+ # Pileup and Coverage Constants
80
+ # =============================================================================
81
+
82
+ DEFAULT_PILEUP_WINDOW_SIZE = 21
83
+ """Default window size for pileup context."""
84
+
85
+ DEFAULT_MIN_COVERAGE = 1
86
+ """Default minimum coverage threshold."""
87
+
88
+ DEFAULT_MAX_COVERAGE = 100
89
+ """Default maximum coverage for normalization."""
90
+
91
+
92
+ # =============================================================================
93
+ # Variant Calling Constants
94
+ # =============================================================================
95
+
96
+ DEFAULT_NUM_CLASSES = 3
97
+ """Default number of variant classes (REF, SNV, INDEL)."""
98
+
99
+
100
+ class ClassifierType(StrEnum):
101
+ """Classifier type for variant calling pipelines."""
102
+
103
+ MLP = "mlp"
104
+ """Multi-layer perceptron classifier."""
105
+
106
+ CNN = "cnn"
107
+ """Convolutional neural network classifier."""
108
+
109
+
110
+ # =============================================================================
111
+ # DNA/RNA Constants
112
+ # =============================================================================
113
+
114
+ DNA_ALPHABET_SIZE = 4
115
+ """Size of DNA alphabet (A, C, G, T)."""
116
+
117
+ RNA_ALPHABET_SIZE = 4
118
+ """Size of RNA alphabet (A, C, G, U)."""
119
+
120
+ PROTEIN_ALPHABET_SIZE = 20
121
+ """Size of standard protein alphabet."""
122
+
123
+
124
+ # =============================================================================
125
+ # VAE / Latent Space Constants
126
+ # =============================================================================
127
+
128
+ DEFAULT_LATENT_DIM = 10
129
+ """Default latent dimension for VAE models."""
130
+
131
+ DEFAULT_BETA_VAE = 1.0
132
+ """Default beta parameter for beta-VAE (KL weight)."""
133
+
134
+
135
+ # =============================================================================
136
+ # Graph Neural Network Constants
137
+ # =============================================================================
138
+
139
+ DEFAULT_NODE_FEATURES = 32
140
+ """Default node feature dimension for GNN."""
141
+
142
+ DEFAULT_EDGE_FEATURES = 8
143
+ """Default edge feature dimension for GNN."""
144
+
145
+ DEFAULT_NUM_HEADS = 4
146
+ """Default number of attention heads."""
147
+
148
+
149
+ # =============================================================================
150
+ # HMM Constants
151
+ # =============================================================================
152
+
153
+ DEFAULT_HMM_STATES = 3
154
+ """Default number of hidden states for HMM."""
155
+
156
+ DEFAULT_HMM_EMISSIONS = 4
157
+ """Default number of emissions for HMM (matches DNA alphabet)."""
158
+
159
+
160
+ # =============================================================================
161
+ # Sequence Length Limits
162
+ # =============================================================================
163
+
164
+ DEFAULT_MAX_SEQ_LENGTH = 1000
165
+ """Default maximum sequence length."""
166
+
167
+ DEFAULT_MAX_ALIGNMENT_LENGTH = 500
168
+ """Default maximum alignment length."""
169
+
170
+
171
+ # =============================================================================
172
+ # Data Dictionary Keys
173
+ # =============================================================================
174
+ # These constants ensure consistent key naming across operators
175
+
176
+
177
+ class DataKeys:
178
+ """Standard keys for data dictionaries in DiffBio operators."""
179
+
180
+ # Sequence data
181
+ SEQUENCE = "sequence"
182
+ SEQ1 = "seq1"
183
+ SEQ2 = "seq2"
184
+ READS = "reads"
185
+
186
+ # Quality and positions
187
+ QUALITY = "quality"
188
+ QUALITY_SCORES = "quality_scores"
189
+ POSITIONS = "positions"
190
+
191
+ # Pileup related
192
+ PILEUP = "pileup"
193
+ PILEUP_WINDOW = "pileup_window"
194
+ COVERAGE = "coverage"
195
+ MEAN_QUALITY = "mean_quality"
196
+
197
+ # Classification outputs
198
+ LOGITS = "logits"
199
+ PROBABILITIES = "probabilities"
200
+
201
+ # Alignment outputs
202
+ SCORE = "score"
203
+ ALIGNMENT_MATRIX = "alignment_matrix"
204
+ SOFT_ALIGNMENT = "soft_alignment"
@@ -0,0 +1,127 @@
1
+ """Core module for DiffBio.
2
+
3
+ This module provides foundational components for building differentiable
4
+ bioinformatics operators:
5
+
6
+ - **soft_ops**: Differentiable soft operations (soft sorting, argmax,
7
+ comparisons, logical ops, selection, quantile, straight-through estimators)
8
+ - **base_operators**: Domain-specific base classes (TemperatureOperator,
9
+ SequenceOperator, EncoderDecoderOperator, GraphOperator, HMMOperator)
10
+ - **neural_components**: DiffBio-specific neural network modules
11
+ (GumbelSoftmaxModule, GraphMessagePassing)
12
+ - **gnn_components**: Graph attention modules
13
+ (GraphAttentionLayer, GraphAttentionBlock, GATv2Layer, GATv2Block)
14
+ - **optimal_transport**: Optimal transport solvers (SinkhornLayer)
15
+ - **data_types**: Type aliases and protocols for type safety
16
+
17
+ Usage::
18
+
19
+ from diffbio.core import soft_ops
20
+ from diffbio.core import TemperatureOperator
21
+ from diffbio.core import GraphAttentionLayer, GATv2Layer
22
+ from diffbio.core import SinkhornLayer
23
+ from diffbio.core.data_types import SequenceData
24
+ from diffbio.core.soft_ops import SoftBool, SoftIndex
25
+ """
26
+
27
+ import diffbio.core.base_operators as _base_operators
28
+ import diffbio.core.gnn_components as _gnn_components
29
+ import diffbio.core.graph_utils as _graph_utils
30
+ import diffbio.core.neural_components as _neural_components
31
+ import diffbio.core.optimal_transport as _optimal_transport
32
+ import diffbio.core.soft_ops as soft_ops # noqa: F401 -- public submodule
33
+
34
+ # Soft operation types (re-exported for convenience)
35
+ SoftBool = soft_ops.SoftBool
36
+ SoftIndex = soft_ops.SoftIndex
37
+
38
+ # Base operators
39
+ TemperatureOperator = _base_operators.TemperatureOperator
40
+ SequenceOperator = _base_operators.SequenceOperator
41
+ EncoderDecoderOperator = _base_operators.EncoderDecoderOperator
42
+ GraphOperator = _base_operators.GraphOperator
43
+ HMMOperator = _base_operators.HMMOperator
44
+
45
+ # Neural components
46
+ GumbelSoftmaxModule = _neural_components.GumbelSoftmaxModule
47
+ GraphMessagePassing = _neural_components.GraphMessagePassing
48
+ PositionalEncoding = _neural_components.PositionalEncoding
49
+ SinusoidalPositionalEncoding = _neural_components.SinusoidalPositionalEncoding
50
+ RoPE = _neural_components.RoPE
51
+ ResidualBlock1D = _neural_components.ResidualBlock1D
52
+ ResidualBlock2D = _neural_components.ResidualBlock2D
53
+
54
+ # GNN components
55
+ GraphAttentionLayer = _gnn_components.GraphAttentionLayer
56
+ GraphAttentionBlock = _gnn_components.GraphAttentionBlock
57
+ GATv2Layer = _gnn_components.GATv2Layer
58
+ GATv2Block = _gnn_components.GATv2Block
59
+
60
+ # Optimal transport
61
+ SinkhornLayer = _optimal_transport.SinkhornLayer
62
+
63
+ # Graph utilities
64
+ compute_pairwise_distances = _graph_utils.compute_pairwise_distances
65
+ compute_knn_graph = _graph_utils.compute_knn_graph
66
+ compute_fuzzy_membership = _graph_utils.compute_fuzzy_membership
67
+ symmetrize_graph = _graph_utils.symmetrize_graph
68
+
69
+ # Data types (including SoftBool and SoftIndex from soft_ops)
70
+ from diffbio.core.data_types import ( # noqa: E402
71
+ AlignmentResultData,
72
+ BatchArray,
73
+ DifferentiableOperator,
74
+ GraphData,
75
+ LatentData,
76
+ LossFunction,
77
+ MetadataDict,
78
+ OperatorOutput,
79
+ PositionWeightMatrix,
80
+ Probability,
81
+ ProbabilityArray,
82
+ Regularizer,
83
+ ScoreMatrix,
84
+ SequenceArray,
85
+ SequenceData,
86
+ SequenceEncoder,
87
+ StateDict,
88
+ Temperature,
89
+ VariantData,
90
+ )
91
+
92
+ __all__ = [ # pyright: ignore[reportUnsupportedDunderAll]
93
+ # Soft operations (full module)
94
+ "soft_ops",
95
+ "SoftBool",
96
+ "SoftIndex",
97
+ # Base operators
98
+ *_base_operators.__all__,
99
+ # GNN components
100
+ *_gnn_components.__all__,
101
+ # Graph utilities
102
+ *_graph_utils.__all__,
103
+ # Neural components
104
+ *_neural_components.__all__,
105
+ # Optimal transport
106
+ *_optimal_transport.__all__,
107
+ # Data types
108
+ "SequenceData",
109
+ "AlignmentResultData",
110
+ "VariantData",
111
+ "LatentData",
112
+ "GraphData",
113
+ "StateDict",
114
+ "MetadataDict",
115
+ "OperatorOutput",
116
+ "DifferentiableOperator",
117
+ "SequenceEncoder",
118
+ "LossFunction",
119
+ "Regularizer",
120
+ "Temperature",
121
+ "Probability",
122
+ "SequenceArray",
123
+ "BatchArray",
124
+ "ProbabilityArray",
125
+ "ScoreMatrix",
126
+ "PositionWeightMatrix",
127
+ ]