$npx -y skills add LeonChaoX/qinyan-academic-skills --skill arboretoInfer gene regulatory networks (GRNs) from gene expression data using scalable algorithms (GRNBoost2, GENIE3). Use when analyzing transcriptomics data (bulk RNA-seq, single-cell RNA-seq) to identify transcription factor-target gene relationships and regulatory interactions. Suppo
| 1 | # Arboreto |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Arboreto is a computational library for inferring gene regulatory networks (GRNs) from gene expression data using parallelized algorithms that scale from single machines to multi-node clusters. |
| 6 | |
| 7 | **Core capability**: Identify which transcription factors (TFs) regulate which target genes based on expression patterns across observations (cells, samples, conditions). |
| 8 | |
| 9 | ## Quick Start |
| 10 | |
| 11 | Install arboreto: |
| 12 | ```bash |
| 13 | uv pip install arboreto |
| 14 | ``` |
| 15 | |
| 16 | Basic GRN inference: |
| 17 | ```python |
| 18 | import pandas as pd |
| 19 | from arboreto.algo import grnboost2 |
| 20 | |
| 21 | if __name__ == '__main__': |
| 22 | # Load expression data (genes as columns) |
| 23 | expression_matrix = pd.read_csv('expression_data.tsv', sep='\t') |
| 24 | |
| 25 | # Infer regulatory network |
| 26 | network = grnboost2(expression_data=expression_matrix) |
| 27 | |
| 28 | # Save results (TF, target, importance) |
| 29 | network.to_csv('network.tsv', sep='\t', index=False, header=False) |
| 30 | ``` |
| 31 | |
| 32 | **Critical**: Always use `if __name__ == '__main__':` guard because Dask spawns new processes. |
| 33 | |
| 34 | ## Core Capabilities |
| 35 | |
| 36 | ### 1. Basic GRN Inference |
| 37 | |
| 38 | For standard GRN inference workflows including: |
| 39 | - Input data preparation (Pandas DataFrame or NumPy array) |
| 40 | - Running inference with GRNBoost2 or GENIE3 |
| 41 | - Filtering by transcription factors |
| 42 | - Output format and interpretation |
| 43 | |
| 44 | **See**: `references/basic_inference.md` |
| 45 | |
| 46 | **Use the ready-to-run script**: `scripts/basic_grn_inference.py` for standard inference tasks: |
| 47 | ```bash |
| 48 | python scripts/basic_grn_inference.py expression_data.tsv output_network.tsv --tf-file tfs.txt --seed 777 |
| 49 | ``` |
| 50 | |
| 51 | ### 2. Algorithm Selection |
| 52 | |
| 53 | Arboreto provides two algorithms: |
| 54 | |
| 55 | **GRNBoost2 (Recommended)**: |
| 56 | - Fast gradient boosting-based inference |
| 57 | - Optimized for large datasets (10k+ observations) |
| 58 | - Default choice for most analyses |
| 59 | |
| 60 | **GENIE3**: |
| 61 | - Random Forest-based inference |
| 62 | - Original multiple regression approach |
| 63 | - Use for comparison or validation |
| 64 | |
| 65 | Quick comparison: |
| 66 | ```python |
| 67 | from arboreto.algo import grnboost2, genie3 |
| 68 | |
| 69 | # Fast, recommended |
| 70 | network_grnboost = grnboost2(expression_data=matrix) |
| 71 | |
| 72 | # Classic algorithm |
| 73 | network_genie3 = genie3(expression_data=matrix) |
| 74 | ``` |
| 75 | |
| 76 | **For detailed algorithm comparison, parameters, and selection guidance**: `references/algorithms.md` |
| 77 | |
| 78 | ### 3. Distributed Computing |
| 79 | |
| 80 | Scale inference from local multi-core to cluster environments: |
| 81 | |
| 82 | **Local (default)** - Uses all available cores automatically: |
| 83 | ```python |
| 84 | network = grnboost2(expression_data=matrix) |
| 85 | ``` |
| 86 | |
| 87 | **Custom local client** - Control resources: |
| 88 | ```python |
| 89 | from distributed import LocalCluster, Client |
| 90 | |
| 91 | local_cluster = LocalCluster(n_workers=10, memory_limit='8GB') |
| 92 | client = Client(local_cluster) |
| 93 | |
| 94 | network = grnboost2(expression_data=matrix, client_or_address=client) |
| 95 | |
| 96 | client.close() |
| 97 | local_cluster.close() |
| 98 | ``` |
| 99 | |
| 100 | **Cluster computing** - Connect to remote Dask scheduler: |
| 101 | ```python |
| 102 | from distributed import Client |
| 103 | |
| 104 | client = Client('tcp://scheduler:8786') |
| 105 | network = grnboost2(expression_data=matrix, client_or_address=client) |
| 106 | ``` |
| 107 | |
| 108 | **For cluster setup, performance optimization, and large-scale workflows**: `references/distributed_computing.md` |
| 109 | |
| 110 | ## Installation |
| 111 | |
| 112 | ```bash |
| 113 | uv pip install arboreto |
| 114 | ``` |
| 115 | |
| 116 | **Dependencies**: scipy, scikit-learn, numpy, pandas, dask, distributed |
| 117 | |
| 118 | ## Common Use Cases |
| 119 | |
| 120 | ### Single-Cell RNA-seq Analysis |
| 121 | ```python |
| 122 | import pandas as pd |
| 123 | from arboreto.algo import grnboost2 |
| 124 | |
| 125 | if __name__ == '__main__': |
| 126 | # Load single-cell expression matrix (cells x genes) |
| 127 | sc_data = pd.read_csv('scrna_counts.tsv', sep='\t') |
| 128 | |
| 129 | # Infer cell-type-specific regulatory network |
| 130 | network = grnboost2(expression_data=sc_data, seed=42) |
| 131 | |
| 132 | # Filter high-confidence links |
| 133 | high_confidence = network[network['importance'] > 0.5] |
| 134 | high_confidence.to_csv('grn_high_confidence.tsv', sep='\t', index=False) |
| 135 | ``` |
| 136 | |
| 137 | ### Bulk RNA-seq with TF Filtering |
| 138 | ```python |
| 139 | from arboreto.utils import load_tf_names |
| 140 | from arboreto.algo import grnboost2 |
| 141 | |
| 142 | if __name__ == '__main__': |
| 143 | # Load data |
| 144 | expression_data = pd.read_csv('rnaseq_tpm.tsv', sep='\t') |
| 145 | tf_names = load_tf_names('human_tfs.txt') |
| 146 | |
| 147 | # Infer with TF restriction |
| 148 | network = grnboost2( |
| 149 | expression_data=expression_data, |
| 150 | tf_names=tf_names, |
| 151 | seed=123 |
| 152 | ) |
| 153 | |
| 154 | network.to_csv('tf_target_network.tsv', sep='\t', index=False) |
| 155 | ``` |
| 156 | |
| 157 | ### Comparative Analysis (Multiple Conditions) |
| 158 | ```python |
| 159 | from arboreto.algo import grnboost2 |
| 160 | |
| 161 | if __name__ == '__main__': |
| 162 | # Infer networks for different conditions |
| 163 | conditions = ['control', 'treatment_24h', 'treatment_48h'] |
| 164 | |
| 165 | for condition in conditions: |
| 166 | data = pd.read_csv(f'{condition}_expression.tsv', sep='\t') |