How alleninstitute/txtox works
Project type and purpose
• This is an ML research or engineering codebase for spatial transcriptomics. Its core functionality is to train and evaluate graph-based neural networks (GNNs) and MLPs on spatial gene-expression data. It provides:
• Data ingestion and preprocessing (txtox/data)
• Model definitions (txtox/models)
• Training loops and experiment orchestration (txtox/trainers)
• Interactive analyses and prototyping via Jupyter notebooks
File structure
• Top-level:
• notebooks/ – dozens of exploratory and result-generation notebooks (data prep, model tests, uncertainty estimation, clustering)
• txtox/ – the Python package, subdivided into:
– data/ (datamodules.py, datasets.py)
– models/ (various GNN variants, simple models)
– trainers/ (one module per model variant + common trainers.py)
– utils.py
• pyproject.toml & config.toml – project metadata and paths
• development artifacts: .gitignore, .pre-commit-config.yaml
README for architectural hints
• Dependencies: PyTorch, PyTorch-Geometric (PyG), Lightning, MLflow, TensorBoard
• Config: paths defined in config.toml, loaded by DataModules
a. Main components to represent
1. Environment & Dependencies
– Conda environment with CUDA, PyTorch, PyG, Lightning, MLflow, TensorBoard
2. Configuration
– config.toml / pyproject.toml (data_root path)
3. Data Layer
– Raw data on disk (data_root)
– txtox/data/datasets.py (Dataset classes)
– txtox/data/datamodules.py (Lightning DataModule orchestrator)
4. Model Layer
– txtox/models (all GNN and simple model classes)
5. Training Orchestration
– txtox/trainers (Lightning Trainer wrappers, experiment logic, hyperparameters)
6. Experiment Interface
– notebooks/ (calls into txtox package API, visualizes results)
7. Logging & Monitoring
– MLflow (parameter/metric tracking)
– TensorBoard (visualizations)
8. Utility Layer
– txtox/utils.py (shared helpers, e.g., seed setting, metric functions)
b. Relationships & data flows
• Config → DataModule → Dataset reads raw files
• DataLoader (inside Lightning) feeds batches to Model
• Model forward/backward integrated with Lightning Trainer
• Trainer logs metrics to MLflow & TensorBoard
• Utilities called throughout for preprocessing, metrics, logging setup
c. Architectural patterns & principles
• Layered architecture: Data → Model → Training → Logging
• Separation of concerns via:
– DataModule (data orchestration) vs. Dataset (I/O)
– Model classes decoupled from training logic
– Trainer modules encapsulate experiment loop & hyperparams
• Use of PyTorch Lightning as a framework for clean training loops
• Extensibility: adding a new GNN variant just requires a new model.py + trainer.py
d. Key technologies & libraries
• PyTorch & Torch-Vision (core deep learning)
• PyTorch-Geometric (graph data structures & layers)
• Lightning (structured training loops, callbacks)
• MLflow & TensorBoard (experiment tracking & visualization)
• Jupyter notebooks (interactive prototyping, result analysis)
Detailed level of granularity
• Inside “txtox/models”, optionally show 2–3 representative classes (e.g., gnn.py, simple.py, gnn_het_reg.py)
• Inside “txtox/trainers”, highlight the generic Trainer base vs. model-specific trainers
• How config.toml is loaded by DataModule at initialization
• Interaction with external GPU/CUDA resources via the environment block