How aertslab/deepscenic works
1. What this repository is
- deepSCENIC is a Python package for building single-cell gene regulatory network models.
- Its core architectural boundary is a multimodal ML pipeline that combines scRNA-seq, scATAC-seq, and DNA sequence to infer TF → region → gene regulation.
2. Primary public API shape
- The package follows a scanpy-style interface with three top-level user-facing modules:
- ds.pp for preprocessing
- ds.tl for modeling / inference / analysis
- ds.pl for plotting and diagnostics
- This is important for diagramming because most user workflows enter through these three layers rather than the low-level internals.
3. Data model boundary
- The repo is built around AnnData / MuData-style objects for storing multimodal single-cell data and annotations.
- Preprocessing functions enrich these containers with TF labels, gene annotations, split masks, and region-to-gene priors.
- Tests and examples use .h5ad files, so file I/O is clearly centered on standard scverse data formats.
4. Preprocessing subsystem (src/deepscenic/pp)
- pp/basic.py and pp/search_space.py handle data preparation.
- This stage is responsible for:
- creating multimodal objects
- marking transcription factors
- attaching gene annotations / chromosome metadata
- computing region-to-gene penalty or search-space constraints
- splitting cells and features for train/test evaluation, including chromosome-based splits
- Architecturally, this is the bridge between raw datasets and the trainable model.
5. Reference data and genome integration
- src/deepscenic/_genome.py, _datasets.py, _data.py, and _io.py form the data/reference layer.
- They appear to manage:
- genome registration from FASTA
- gene and TF reference lookup
- dataset loading and serialization
- schema/type definitions for internal data structures
- The repository’s sequence component depends on a local genome reference, so the genome is a first-class external input to the system.
6. Modeling subsystem (src/deepscenic/models)
- The model package contains the neural network building blocks:
- _encoder.py
- _decoder.py
- _layers.py
- _motifnet.py
- _vae.py
- This suggests a VAE-centered architecture with separate encoder/decoder paths and a motif/sequence-aware component.
- The motif network is likely the point where sequence-derived features are integrated with regulatory inference.
7. Training and execution subsystem (src/deepscenic/tl)
- tl is the main computational orchestration layer.
- Key responsibilities are split across:
- _dataloaders.py for batching and sample access
- _model.py and _loss.py for training logic and optimization objective
- _train.py for the training loop
- _training_state.py for checkpoints / phase state
- _logging.py for run tracking
- _inference.py for evaluation or prediction paths
- The README’s staged workflow reflects this design: initial training, then repeated finetune_r2g phases.
8. Regulatory network inference
- tl/_grn.py extracts gene regulatory networks from the trained model and dataset.
- This is the system’s main analytical output: a GRN structure that can be queried per TF or visualized as a network/heatmap.
- The implied data flow is: trained multimodal model → regulatory scores / edges → GRN object or table → downstream analysis.
9. Perturbation analysis
- tl/_perturbation.py simulates TF knockdown or overexpression.
- This is a separate analytical path from GRN extraction, but it depends on the trained model and the same biological annotations.
- In architecture terms, it is a “what-if” inference layer built on top of the learned regulatory model.
10. Visualization subsystem (src/deepscenic/pl)
- Plotting is organized by analysis domain:
- training diagnostics
- embedding utilities
- genomics views
- GRN plots
- perturbation plots
- sequence interpretation plots
- Notable visualization areas include:
- GRN heatmaps, network plots, cell-type views
- perturbation volcano/co-embedding/heatmaps
- sequence logos and in-silico mutagenesis outputs
- genome browser / arc-style genomics views
- This layer consumes outputs from tl and presents them for interpretation rather than computation.
11. Sequence and external model integration
- The README says the default sequence model is Enformer via enformer-pytorch, with an optional extra install.
- That makes sequence embedding an external model dependency rather than an internally implemented architecture.
- The runtime therefore has a notable boundary between:
- local single-cell/regulatory modeling
- external pretrained sequence representation generation
12. Supporting assets and quality boundary
- docs/ contains tutorials, API docs, architecture notes, and notebooks that mirror the end-to-end workflow.
- tests/ includes integration tests and fixture data for genome, RNA/ATAC matrices, and masks, indicating the repo is organized around reproducible pipeline validation.
- For an architecture diagram, these are supporting layers around the core pipeline, not runtime dependencies.
13. End-to-end data flow
- Typical flow is:
- load scRNA/scATAC data
- create MuData
- attach TF lists, gene annotations, and genome references
- compute region-to-gene constraints and train/test splits
- train the multimodal model
- finetune region-to-gene relationships
- extract GRNs or simulate perturbations
- visualize results through the plotting layer
- The core architectural shape is therefore a data-enrichment pipeline feeding a multimodal neural network, followed by inference/interpretation modules.
Main entry points: tl/__init__.py tl · _vae.py VAE · basic.py Prep core · deepscenic/__init__.py deepscenic
Components 31
Public API
User-facing scanpy-style entry points
- deepscenic · Top-level package namespace and public exports
src/deepscenic/__init__.py - pp · Public preprocessing entry points
src/deepscenic/pp/__init__.py - tl · Public modeling and analysis entry points
src/deepscenic/tl/__init__.py - pl · Public plotting entry points
src/deepscenic/pl/__init__.py
Data & Reference
Containers, I/O, datasets, and genome registration
- Data model · Internal data structures and multimodal containers
src/deepscenic/_data.py - Types · Shared internal type definitions
src/deepscenic/_types.py - Datasets · Dataset access and packaging helpers
src/deepscenic/_datasets.py - I/O · Persistence and file handling
src/deepscenic/_io.py - Genome · Genome registration and sequence reference handling
src/deepscenic/_genome.py - Prep core · Multimodal data preparation and annotation enrichment
src/deepscenic/pp/basic.py - Search space · Region-to-gene priors, penalties, and split logic
src/deepscenic/pp/search_space.py
Modeling
Neural network building blocks
- Encoder · Latent encoding path for multimodal inputs
src/deepscenic/models/_encoder.py - Decoder · Reconstruction and output path
src/deepscenic/models/_decoder.py - Motif net · Sequence-aware regulatory feature integration
src/deepscenic/models/_motifnet.py - VAE · Central variational model combining encoder, decoder, and motif path
src/deepscenic/models/_vae.py - Layers · Shared neural network layers and primitives
src/deepscenic/models/_layers.py
Training & Inference
Orchestration, learning, and downstream analysis
- Loaders · Training batch construction and sample access
src/deepscenic/tl/_dataloaders.py - Loss · Training objective and optimization terms
src/deepscenic/tl/_loss.py - Train loop · Fit/finetune execution loop
src/deepscenic/tl/_train.py - State · Training phase and checkpoint state
src/deepscenic/tl/_training_state.py - Model API · High-level model construction and training interface
src/deepscenic/tl/_model.py - Inference · Evaluation and prediction paths
src/deepscenic/tl/_inference.py - GRN · Extract regulatory networks from trained models
src/deepscenic/tl/_grn.py - Perturbation · TF knockdown and overexpression simulation
src/deepscenic/tl/_perturbation.py - Logging · Training and analysis logging
src/deepscenic/tl/_logging.py
Visualization
Plotting and interpretation
- Training plots · Training diagnostics and convergence views
src/deepscenic/pl/training/_diagnostics.py - Embedding plots · Embedding and latent-space utilities
src/deepscenic/pl/_embedding.py - GRN plots · Heatmaps, cell-type views, and network plots
src/deepscenic/pl/grn/_network.py - Genome views · Arc and browser-style genomic visualizations
src/deepscenic/pl/genomics/_browser.py - Perturbation plots · Volcano, co-embedding, and heatmap plots
src/deepscenic/pl/perturbation/_volcano.py - Sequence plots · Sequence logos and in-silico mutagenesis plots
src/deepscenic/pl/sequence/_logo.py
Connections 32
- deepscenic → pp: exports · Public preprocessing entry point
- deepscenic → tl: exports · Public modeling and analysis entry point
- deepscenic → pl: exports · Public plotting entry point
- pp → Prep core: prepare · Build multimodal containers and enrich annotations
- pp → Search space: constraints · Derive region-to-gene priors and split masks
- Prep core → Data model: uses · Operates on multimodal data containers
- Prep core → Genome: annotates · Attaches genome and sequence reference context
- Search space → Genome: uses · Chromosome and reference-based constraints
- Datasets → I/O: loads · Dataset access relies on serialization and file handling
- I/O → Data model: persists · Reads and writes internal data objects
- Genome → Types: defines · Reference structures use shared schema types
- VAE → Encoder: contains · Latent encoder path
- VAE → Decoder: contains · Output decoder path
- VAE → Motif net: contains · Sequence-aware motif component
- VAE → Layers: builds on · Shared neural primitives
- tl → Loaders: feeds · Batching and sample access for training
- tl → Model API: orchestrates · High-level training/model interface
- Model API → VAE: instantiates · Constructs the central multimodal model
- tl → Loss: optimizes · Training objective computation
- tl → Train loop: runs · Main training and finetuning loop
- Train loop → State: updates · Checkpoint and phase state management
- tl → Inference: predicts · Evaluation and prediction paths
- tl → GRN: extracts · Derives regulatory networks from trained models
- tl → Perturbation: simulates · Runs perturbation analyses on the learned model
- tl → Logging: records · Captures run metrics and training events
- GRN → GRN plots: visualized by · GRN outputs feed network and heatmap views
- Perturbation → Perturbation plots: visualized by · Perturbation outputs feed analysis plots
- Train loop → Training plots: visualized by · Training diagnostics consume loop outputs
- Inference → Embedding plots: visualized by · Latent embeddings and diagnostics
- GRN → Genome views: contextualized by · Genomic views for regulatory interpretation
- Motif net → Sequence plots: interpreted by · Sequence motif outputs support logos and ISM plots
- Prep core → tl: prepares · Preprocessed multimodal objects flow into training