How jsxlei/scale works
The SCALE project is a Python-based tool for single-cell ATAC-seq analysis that uses deep learning (implemented in PyTorch) to perform latent feature extraction. The project is structured as a library (located in the “scale” package) along with a command-line entry point (SCALE.py), a setup script, and accompanying configuration files (like requirements.txt).
Main Components
• Command-line entry point: The SCALE.py script serves as the main execution driver. It parses input arguments, manages runtime options (like choosing between binary or imputed data generation), and triggers the analysis flow.
• Data Ingestion and Preprocessing: The dataset.py module is critical here. It handles importing single-cell ATAC-seq data from multiple input formats (e.g., h5ad files, mtx folders, count matrix files). Include reference to external file formats and data preparation.
• Neural Network Components:
• Model Construction: Represent the model.py module, which builds the deep learning model architecture.
• Network Layers: Use the layer.py module showing that custom neural network layers are defined.
• Loss Calculation: Denote the loss.py module that encapsulates the loss functions for training.
• Utilities and Helpers: The utils.py module provides auxiliary functions, and specifity.py likely encodes specialized operations or metrics.
• Visualization: The plot.py module handles plotting results (e.g., UMAP visualization outputs).
• Packaging and Deployment: The setup.py file and requirements.txt serve as the project's installation and dependency management components.
Relationships and Data Flow
• The SCALE.py entry point first ingests input data (using dataset.py) and configures experiment parameters (through parsing CLI options).
• Data then flows into the neural network part:
○ The dataset is preprocessed before being fed into the model (constructed in model.py using components from layer.py).
○ The loss is computed via loss.py to drive model optimization.
• Trained model outputs, such as the latent feature matrix, saved model file (model.pt) and downstream results (adata.h5ad, umap.pdf) are then generated.
• Visualization functions in plot.py extract and display performance and embedding results.
• Utilities and specific functions (in utils.py and specifity.py) support these processes (e.g., filtering peaks, handling metrics).
Architectural Patterns & Design Principles
• Modularity: Each distinct responsibility (input handling, model building, loss computation, visualization) is separated into its own module.
• CLI-Driven Execution: SCALE.py acts as a controller that orchestrates data loading, model training, and output generation, following a pipeline pattern.
• Reproducibility: The project emphasizes output reproducibility through saved artifacts (model.pt and adata.h5ad) along with comprehensive runtime options.
• Integration with External Libraries: It clearly leverages PyTorch as the core framework and integrates with analysis libraries like scanpy for handling h5ad files.
Relevant Technologies
• Python and PyTorch form the development backbone.
• External libraries for single-cell analysis (e.g., scanpy).
• Data formats include h5ad, txt/tsv/csv, and mtx.
• Visualization (e.g., UMAP)