{"id":18256480,"url":"https://github.com/baderlab/apa-net","last_synced_at":"2025-10-26T20:11:15.740Z","repository":{"id":215168717,"uuid":"738280241","full_name":"BaderLab/APA-Net","owner":"BaderLab","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-14T19:56:39.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-07T05:34:04.694Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BaderLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-02T21:33:53.000Z","updated_at":"2024-11-14T19:56:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"f46f15f9-4c54-4bfb-9b47-8bf7ef0b432f","html_url":"https://github.com/BaderLab/APA-Net","commit_stats":null,"previous_names":["baderlab/apa-net"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BaderLab/APA-Net","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaderLab%2FAPA-Net","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaderLab%2FAPA-Net/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaderLab%2FAPA-Net/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaderLab%2FAPA-Net/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BaderLab","download_url":"https://codeload.github.com/BaderLab/APA-Net/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaderLab%2FAPA-Net/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262900084,"owners_count":23381657,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T10:22:08.689Z","updated_at":"2025-10-26T20:11:15.715Z","avatar_url":"https://github.com/BaderLab.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# APA-Net\n\nAPA-Net is a deep learning model designed for learning context-specific APA (Alternative Polyadenylation) usage. This guide covers the steps necessary to set up and run APA-Net.\n\n## Requirements\n\n- Python 3.8 or higher\n- PyTorch 1.8.0 or higher\n- NumPy\n- Pandas\n- SciPy\n- tqdm\n- wandb (optional, for experiment tracking)\n\n## Installation\n\n### Option 1: Install from source (Recommended)\n\n1. Clone this repository to your local machine:\n```bash\ngit clone https://github.com/BaderLab/APA-Net.git\ncd APA-Net\n```\n\n2. Install dependencies manually for better control:\n```bash\n# For CPU-only version (smaller download)\npip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu\n\n# For GPU version (if you have CUDA)\npip install torch torchvision torchaudio\n\n# Install other dependencies\npip install numpy pandas scipy tqdm wandb\n```\n\n3. Install the package:\n```bash\npip install .\n```\n\n### Option 2: One-command installation\n```bash\npip install .\n```\n*Note: This will install the full PyTorch with CUDA support, which is a large download (~2GB).*\n\n## Data Format\n\nAPA-Net expects input data in `.npy` format with the following structure:\n- **Shape**: `(n_samples, 9)` where each row represents one sample\n- **Columns**:\n  - Column 0: Float value (sample ID/index)\n  - Column 1: String (cell type name)\n  - Column 2: String (additional metadata)\n  - Column 3: Float value \n  - Column 4: String (additional metadata)\n  - Column 5: String (genomic coordinates/switch name)\n  - Column 6: NumPy array of shape `(4, 4000)` - one-hot encoded DNA sequence\n  - Column 7: Float (target APA usage value)\n  - Column 8: NumPy array of shape `(327,)` - cell type profile features\n\n## Usage\n\n### Training the Model\n\nTo train the APA-Net model, use the train_script.py script:\n\n```bash\ncd apamodel\npython train_script.py \\\n  --train_data \"/path/to/train_data.npy\" \\\n  --valid_data \"/path/to/valid_data.npy\" \\\n  --modelfile \"/path/to/model_output.pt\" \\\n  --batch_size 64 \\\n  --epochs 200 \\\n  --device \"cpu\" \\\n  --use_wandb \"False\"\n```\n\n### Testing the Model\n\nYou can test the model with sample data:\n\n```bash\n# Create a simple test script\npython -c \"\nimport sys\nsys.path.append('./apamodel')\nfrom model import APANET, APAData\nimport numpy as np\nimport torch\n\n# Load your data\ndata = np.load('your_data.npy', allow_pickle=True)\n\n# Configure model (using CPU)\nconfig = {\n    'device': 'cpu',\n    'opt': 'Adam',\n    'loss': 'mse',\n    'lr': 2.5e-05,\n    'adam_weight_decay': 0.09,\n    'conv1kc': 128,\n    'conv1ks': 12,\n    'conv1st': 1,\n    'pool1ks': 16,\n    'pool1st': 16,\n    'cnvpdrop1': 0,\n    'Matt_heads': 8,\n    'Matt_drop': 0.2,\n    'fc1_dims': [8192, 4048, 1024, 512, 256],\n    'fc1_dropouts': [0.25, 0.25, 0.25, 0, 0],\n    'fc2_dims': [128, 32, 16, 1],\n    'fc2_dropouts': [0.2, 0.2, 0, 0],\n    'psa_query_dim': 128,\n    'psa_num_layers': 1,\n    'psa_nhead': 1,\n    'psa_dim_feedforward': 1024,\n    'psa_dropout': 0\n}\n\n# Create and test model\nmodel = APANET(config)\nmodel.compile()\nprint('Model created successfully!')\n\"\n```\n\n## Command Line Arguments\n\n- `--train_data`: Path to the training data file (required)\n- `--valid_data`: Path to the validation data file (required)\n- `--modelfile`: Path where the trained model will be saved (required)\n- `--batch_size`: Batch size for training (default: 64)\n- `--epochs`: Number of training epochs (default: 200)\n- `--project_name`: Name of the project for wandb logging (default: \"APA-Net_Training\")\n- `--device`: Device to run the training on - use \"cpu\" or \"cuda:0\" (default: \"cuda:0\")\n- `--use_wandb`: Enable wandb logging - \"True\" or \"False\" (default: \"True\")\n\n## Model Architecture\n\nAPA-Net is a deep neural network that combines:\n- **Convolutional layers** for sequence feature extraction\n- **Self-attention mechanism** for capturing long-range dependencies\n- **Fully connected layers** for prediction\n- **Cell type profile integration** for context-specific modeling\n\nThe model has approximately 301M parameters and processes:\n- Input: DNA sequences (4×4000) + cell type profiles (327 features)\n- Output: APA usage prediction (single value)\n\n## Troubleshooting\n\n### Common Issues\n\n1. **CUDA errors**: If you encounter CUDA-related errors, install the CPU-only version of PyTorch:\n   ```bash\n   pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu\n   ```\n\n2. **Memory issues**: Reduce batch size if you encounter out-of-memory errors:\n   ```bash\n   --batch_size 32\n   ```\n\n3. **Data format errors**: Ensure your data has the correct shape `(n_samples, 9)` with sequences of shape `(4, 4000)` and cell type profiles of shape `(327,)`.\n\n### CPU vs GPU Usage\n\n- **CPU**: Slower but more compatible. Use `--device \"cpu\"`\n- **GPU**: Faster training. Use `--device \"cuda:0\"` (requires CUDA-compatible PyTorch installation)\n\n## Example\n\nHere's a complete example of training APA-Net:\n\n```bash\n# Navigate to the model directory\ncd APA-Net/apamodel\n\n# Train the model\npython train_script.py \\\n  --train_data \"../test_fold_0.npy\" \\\n  --valid_data \"../test_fold_0.npy\" \\\n  --modelfile \"./trained_model.pt\" \\\n  --batch_size 32 \\\n  --epochs 50 \\\n  --device \"cpu\" \\\n  --use_wandb \"False\" \\\n  --project_name \"APA-Net_Test\"\n```\n\n## Analysis and Figures\n\nThe `analysis_and_figures/` directory contains all the code and notebooks used to reproduce the results and figures from our APA-Net research paper. This comprehensive analysis pipeline covers data processing, model evaluation, comparative analysis, and visualization.\n\n### Directory Structure\n\n```\nanalysis_and_figures/\n├── model_performance/          # APA-Net model evaluation and performance analysis\n├── data_processing/            # Data preparation and preprocessing for APA-Net\n├── comparative_analysis/       # Comparative studies (APA vs DE, correlations)\n├── gene_expression/            # Differential gene expression analysis\n├── pathway_analysis/           # Gene set enrichment and pathway analysis\n├── preprocessing/              # Single-cell RNA-seq data preprocessing pipeline\n└── functions/                  # Utility functions and helper scripts\n```\n\n### Getting Started with Analysis\n\n1. **Prerequisites**: Make sure you have the following R and Python packages installed:\n\n**R packages:**\n```r\ninstall.packages(c(\"dplyr\", \"ggplot2\", \"tidyr\", \"viridis\", \"patchwork\", \n                   \"readxl\", \"gridExtra\", \"ggpubr\", \"ggrepel\", \"reshape2\", \n                   \"corrplot\", \"pheatmap\", \"boot\", \"Seurat\", \"scCustomize\"))\n```\n\n**Python packages:**\n```bash\npip install pandas numpy scipy matplotlib seaborn scikit-learn statsmodels\n```\n\n2. **Data Requirements**: The analysis scripts expect data in specific locations. You may need to adjust file paths in the notebooks to match your data directory structure.\n\n### Analysis Modules\n\n#### 1. Model Performance (`model_performance/`)\n- **APA-NET_performance_plots.ipynb**: Generates correlation plots showing model performance across cell types\n- **APA-Net_filter_interactions.ipynb**: Analyzes convolutional filter interactions and RBP binding patterns  \n- **APA-Net_heatmap_for_filter_interactions.ipynb**: Creates heatmaps showing filter-RBP interactions\n\n#### 2. Data Processing (`data_processing/`)\n- **Process_inputs_for_APA-Net.ipynb**: Main data preprocessing pipeline for APA-Net training data\n  - Processes RNA sequences and APA usage data\n  - Generates one-hot encoded sequences\n  - Creates 5-fold cross-validation splits\n  - Formats data for model training\n- **APA_quantification_maaper_apalog_Dec2024.ipynb**: APA event quantification using MAAPER\n- **emprical_fdr_thresholds_maaper_apalog.ipynb**: Determines empirical FDR thresholds for significance testing\n\n#### 3. Comparative Analysis (`comparative_analysis/`)\n- **APA_vs_DE.ipynb**: Compares APA changes with differential expression\n  - Correlation analysis between APA usage and gene expression changes\n  - Cell-type-specific comparisons\n  - Statistical significance testing\n- **apa_correlation_across_celltypes.ipynb**: Cross-cell-type APA correlation analysis\n- **rbp_co_occurance_dissimilarity.ipynb**: RNA-binding protein co-occurrence analysis\n\n#### 4. Gene Expression (`gene_expression/`)\n- **DEG_ALS_genes.R**: Analysis of ALS-associated gene expression\n- **DEG_MAST_analysis.R**: MAST-based differential expression analysis\n- **DEG_pathway_analysis.R**: Pathway enrichment analysis for DEGs\n- **DEG_visualization.R**: Visualization of differential expression results\n\n#### 5. Pathway Analysis (`pathway_analysis/`)\n- **APA_pathway_analysis.R**: Gene set enrichment analysis for APA-affected genes\n  - GO term enrichment\n  - Reactome pathway analysis\n  - Custom gene set analysis\n\n#### 6. Preprocessing (`preprocessing/`)\n- **processing_annotation/**: Single-cell RNA-seq processing pipeline\n  - `01_snRNA_cellranger_preprocess.sh`: Cell Ranger preprocessing\n  - `02_snRNA_process_QC.R`: Quality control and filtering\n  - `03_snRNA_clustering_annotation.R`: Cell clustering and annotation\n  - `04a_snRNA_NSForest1.ipynb` \u0026 `04b_snRNA_NSForest2.ipynb`: NSForest cell type classification\n- **independent_datasets/**: Processing of additional validation datasets\n  - `01_read_matrices.R`: Matrix reading and preprocessing\n  - `02_harmony_int.R`: Harmony integration for batch correction\n  - `03_doublet_removal_annotation.R`: Doublet detection and removal\n\n### Reproducing Key Results\n\n#### Figure Generation\nTo reproduce the main figures from the paper:\n\n1. **Model Performance Plots**:\n   ```bash\n   cd analysis_and_figures/model_performance\n   jupyter notebook APA-NET_performance_plots.ipynb\n   ```\n\n2. **APA Usage Analysis**:\n   ```bash\n   cd analysis_and_figures/visualization  \n   jupyter notebook maaper_volcanos_barplots_figure6.ipynb\n   ```\n\n3. **Comparative Analysis**:\n   ```bash\n   cd analysis_and_figures/comparative_analysis\n   jupyter notebook APA_vs_DE.ipynb\n   ```\n\n#### Data Processing Pipeline\nTo process your own data through the complete pipeline:\n\n1. **Start with raw single-cell data**:\n   ```bash\n   cd analysis_and_figures/preprocessing/processing_annotation\n   bash 01_snRNA_cellranger_preprocess.sh\n   ```\n\n2. **Process and prepare for APA-Net**:\n   ```bash\n   cd analysis_and_figures/data_processing\n   jupyter notebook Process_inputs_for_APA-Net.ipynb\n   ```\n\n### Key Results and Interpretations\n\n- **Model Performance**: APA-Net achieves correlation coefficients of 0.56-0.67 across cell types\n- **Cell-Type Specificity**: Microglia show highest model performance, indicating stronger APA regulatory patterns\n- **Condition Comparison**: Strong correlations (0.65-0.84) between C9ALS and sALS APA changes across cell types\n- **Biological Validation**: APA changes correlate with known ALS pathways and RBP targets\n\n### Data Availability\n\nThe analysis scripts reference several data sources:\n- Single-cell RNA-seq count matrices\n- APA usage quantification results  \n- Cell type annotations\n- RBP expression profiles\n- Reference genome and annotations\n\nPlease ensure you have access to the appropriate datasets before running the analysis scripts.\n\n### Citation\n\nIf you use this analysis pipeline, please cite our paper:\n```\n[[Paper citation to be added upon publication]](https://www.biorxiv.org/content/10.1101/2023.12.22.573083v2)\n```\n\nFor questions about the analysis pipeline, please open an issue in the GitHub repository.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaderlab%2Fapa-net","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaderlab%2Fapa-net","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaderlab%2Fapa-net/lists"}