$npx -y skills add LeonChaoX/qinyan-academic-skills --skill genimlThis skill should be used when working with genomic interval data (BED files) for machine learning tasks. Use for training region embeddings (Region2Vec, BEDspace), single-cell ATAC-seq analysis (scEmbed), building consensus peaks (universes), or any ML-based analysis of genomic
| 1 | # Geniml: Genomic Interval Machine Learning |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Geniml is a Python package for building machine learning models on genomic interval data from BED files. It provides unsupervised methods for learning embeddings of genomic regions, single cells, and metadata labels, enabling similarity searches, clustering, and downstream ML tasks. |
| 6 | |
| 7 | ## Installation |
| 8 | |
| 9 | Install geniml using uv: |
| 10 | |
| 11 | ```bash |
| 12 | uv uv pip install geniml |
| 13 | ``` |
| 14 | |
| 15 | For ML dependencies (PyTorch, etc.): |
| 16 | |
| 17 | ```bash |
| 18 | uv uv pip install 'geniml[ml]' |
| 19 | ``` |
| 20 | |
| 21 | Development version from GitHub: |
| 22 | |
| 23 | ```bash |
| 24 | uv uv pip install git+https://github.com/databio/geniml.git |
| 25 | ``` |
| 26 | |
| 27 | ## Core Capabilities |
| 28 | |
| 29 | Geniml provides five primary capabilities, each detailed in dedicated reference files: |
| 30 | |
| 31 | ### 1. Region2Vec: Genomic Region Embeddings |
| 32 | |
| 33 | Train unsupervised embeddings of genomic regions using word2vec-style learning. |
| 34 | |
| 35 | **Use for:** Dimensionality reduction of BED files, region similarity analysis, feature vectors for downstream ML. |
| 36 | |
| 37 | **Workflow:** |
| 38 | 1. Tokenize BED files using a universe reference |
| 39 | 2. Train Region2Vec model on tokens |
| 40 | 3. Generate embeddings for regions |
| 41 | |
| 42 | **Reference:** See `references/region2vec.md` for detailed workflow, parameters, and examples. |
| 43 | |
| 44 | ### 2. BEDspace: Joint Region and Metadata Embeddings |
| 45 | |
| 46 | Train shared embeddings for region sets and metadata labels using StarSpace. |
| 47 | |
| 48 | **Use for:** Metadata-aware searches, cross-modal queries (region→label or label→region), joint analysis of genomic content and experimental conditions. |
| 49 | |
| 50 | **Workflow:** |
| 51 | 1. Preprocess regions and metadata |
| 52 | 2. Train BEDspace model |
| 53 | 3. Compute distances |
| 54 | 4. Query across regions and labels |
| 55 | |
| 56 | **Reference:** See `references/bedspace.md` for detailed workflow, search types, and examples. |
| 57 | |
| 58 | ### 3. scEmbed: Single-Cell Chromatin Accessibility Embeddings |
| 59 | |
| 60 | Train Region2Vec models on single-cell ATAC-seq data for cell-level embeddings. |
| 61 | |
| 62 | **Use for:** scATAC-seq clustering, cell-type annotation, dimensionality reduction of single cells, integration with scanpy workflows. |
| 63 | |
| 64 | **Workflow:** |
| 65 | 1. Prepare AnnData with peak coordinates |
| 66 | 2. Pre-tokenize cells |
| 67 | 3. Train scEmbed model |
| 68 | 4. Generate cell embeddings |
| 69 | 5. Cluster and visualize with scanpy |
| 70 | |
| 71 | **Reference:** See `references/scembed.md` for detailed workflow, parameters, and examples. |
| 72 | |
| 73 | ### 4. Consensus Peaks: Universe Building |
| 74 | |
| 75 | Build reference peak sets (universes) from BED file collections using multiple statistical methods. |
| 76 | |
| 77 | **Use for:** Creating tokenization references, standardizing regions across datasets, defining consensus features with statistical rigor. |
| 78 | |
| 79 | **Workflow:** |
| 80 | 1. Combine BED files |
| 81 | 2. Generate coverage tracks |
| 82 | 3. Build universe using CC, CCF, ML, or HMM method |
| 83 | |
| 84 | **Methods:** |
| 85 | - **CC (Coverage Cutoff)**: Simple threshold-based |
| 86 | - **CCF (Coverage Cutoff Flexible)**: Confidence intervals for boundaries |
| 87 | - **ML (Maximum Likelihood)**: Probabilistic modeling of positions |
| 88 | - **HMM (Hidden Markov Model)**: Complex state modeling |
| 89 | |
| 90 | **Reference:** See `references/consensus_peaks.md` for method comparison, parameters, and examples. |
| 91 | |
| 92 | ### 5. Utilities: Supporting Tools |
| 93 | |
| 94 | Additional tools for caching, randomization, evaluation, and search. |
| 95 | |
| 96 | **Available utilities:** |
| 97 | - **BBClient**: BED file caching for repeated access |
| 98 | - **BEDshift**: Randomization preserving genomic context |
| 99 | - **Evaluation**: Metrics for embedding quality (silhouette, Davies-Bouldin, etc.) |
| 100 | - **Tokenization**: Region tokenization utilities (hard, soft, universe-based) |
| 101 | - **Text2BedNN**: Neural search backends for genomic queries |
| 102 | |
| 103 | **Reference:** See `references/utilities.md` for detailed usage of each utility. |
| 104 | |
| 105 | ## Common Workflows |
| 106 | |
| 107 | ### Basic Region Embedding Pipeline |
| 108 | |
| 109 | ```python |
| 110 | from geniml.tokenization import hard_tokenization |
| 111 | from geniml.region2vec import region2vec |
| 112 | from geniml.evaluation import evaluate_embeddings |
| 113 | |
| 114 | # Step 1: Tokenize BED files |
| 115 | hard_tokenization( |
| 116 | src_folder='bed_files/', |
| 117 | dst_folder='tokens/', |
| 118 | universe_file='universe.bed', |
| 119 | p_value_threshold=1e-9 |
| 120 | ) |
| 121 | |
| 122 | # Step 2: Train Region2Vec |
| 123 | region2vec( |
| 124 | token_folder='tokens/', |
| 125 | save_dir='model/', |
| 126 | num_shufflings=1000, |
| 127 | embedding_dim=100 |
| 128 | ) |
| 129 | |
| 130 | # Step 3: Evaluate |
| 131 | metrics = evaluate_embeddings( |
| 132 | embeddings_file='model/embeddings.npy', |
| 133 | labels_file='metadata.csv' |
| 134 | ) |
| 135 | ``` |
| 136 | |
| 137 | ### scATAC-seq Analysis Pipeline |
| 138 | |
| 139 | ```python |
| 140 | import scanpy as sc |
| 141 | from geniml.scembed import ScEmbed |
| 142 | from geniml.io import tokenize_cells |
| 143 | |
| 144 | # Step 1: Load data |
| 145 | adata = sc.read_h5ad('scatac_data.h5ad') |
| 146 | |
| 147 | # Step 2: Tokenize cells |
| 148 | tokenize_cells( |
| 149 | adata='scatac_data.h5ad', |