Put dataset launch commands first in each downstream task README
Browse filesUpdate the five task READMEs to put complete per-dataset launch commands at the beginning. Add dataset command indexes to both project READMEs. All 15 existing command blocks remain unchanged. No source code, weights, configuration, raw data, or other repository files are modified.
- BioMod/README.md +30 -0
- BioMod/cell_annotation/README.md +292 -282
- BioMod/drug_combination/README.md +172 -170
- BioMod/drug_response/README.md +73 -70
- BioMod/gene_perturbation/README.md +333 -333
- BioMod/zero_shot_batch/README.md +187 -187
- README.md +30 -0
BioMod/README.md
CHANGED
|
@@ -212,6 +212,36 @@ default with `RUN_TRAINING = False`; zero-shot inference uses
|
|
| 212 |
path checks before enabling execution. The shell variable `BIOMOD_ROOT` is for
|
| 213 |
the command examples only and does not override notebook configuration cells.
|
| 214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
## Data Layout
|
| 216 |
|
| 217 |
The Hugging Face repository includes datasets under the project-root `data/`
|
|
|
|
| 212 |
path checks before enabling execution. The shell variable `BIOMOD_ROOT` is for
|
| 213 |
the command examples only and does not override notebook configuration cells.
|
| 214 |
|
| 215 |
+
## Commands by dataset
|
| 216 |
+
|
| 217 |
+
Each row below links to a separate, complete launch command for that task and
|
| 218 |
+
dataset or condition. Commands specify the input paths and output directory;
|
| 219 |
+
you do not need to adapt a command from another dataset. Run them in Bash from
|
| 220 |
+
the outer repository root after activating the environment. Read any
|
| 221 |
+
dataset-specific input caveats before launching.
|
| 222 |
+
|
| 223 |
+
| Task | Dataset or condition | Launch command |
|
| 224 |
+
| --- | --- | --- |
|
| 225 |
+
| Cell annotation | Kim Lung | [Complete command](cell_annotation/README.md#1-kim-lung) |
|
| 226 |
+
| Cell annotation | Immune | [Complete command](cell_annotation/README.md#2-immune) |
|
| 227 |
+
| Cell annotation | Liver | [Complete command](cell_annotation/README.md#3-liver) |
|
| 228 |
+
| Cell annotation | MS (paired train/test files) | [Complete command](cell_annotation/README.md#4-ms) |
|
| 229 |
+
| Cell annotation | hPancreas (hp14 paired files) | [Complete command](cell_annotation/README.md#5-hpancreas) |
|
| 230 |
+
| Cell annotation | Zheng68K | [Complete command](cell_annotation/README.md#6-zheng68k) |
|
| 231 |
+
| Cell annotation | Myeloid (reference/query files) | [Complete command](cell_annotation/README.md#7-myeloid) |
|
| 232 |
+
| Zero-shot evaluation | hPNC | [Complete command](zero_shot_batch/README.md#1-hpnc) |
|
| 233 |
+
| Zero-shot evaluation | BMMC | [Complete command](zero_shot_batch/README.md#2-bmmc) |
|
| 234 |
+
| Zero-shot evaluation | Kim Lung: malignant cells retained | [Complete command](zero_shot_batch/README.md#3-kim-lung-malignant-cells-retained) |
|
| 235 |
+
| Zero-shot evaluation | Kim Lung: malignant cells removed | [Complete command](zero_shot_batch/README.md#4-kim-lung-malignant-cells-removed) |
|
| 236 |
+
| Single-drug response | GDSC-CCLE joint inputs | [Complete command](drug_response/README.md#run-the-bundled-gdsc-ccle-collection) |
|
| 237 |
+
| Drug-combination synergy | Bundled training and validation collection | [Complete command](drug_combination/README.md#run-the-bundled-training-and-validation-collection) |
|
| 238 |
+
| Gene perturbation | Norman | [Complete command](gene_perturbation/README.md#2-run-the-bundled-norman-simulation-split) |
|
| 239 |
+
|
| 240 |
+
Paired training/test files and complementary drug/cell inputs belong to one
|
| 241 |
+
run configuration. Historical reference copies do not add datasets. The
|
| 242 |
+
[optional drug-combination cross-validation command](drug_combination/README.md#optional-five-fold-cross-validation-on-the-same-collection)
|
| 243 |
+
uses the same collection under a different validation protocol.
|
| 244 |
+
|
| 245 |
## Data Layout
|
| 246 |
|
| 247 |
The Hugging Face repository includes datasets under the project-root `data/`
|
BioMod/cell_annotation/README.md
CHANGED
|
@@ -1,282 +1,292 @@
|
|
| 1 |
-
# Cell Annotation with BioMod
|
| 2 |
-
|
| 3 |
-
Fine-tune BioMod to predict cell-type labels from single-cell gene expression.
|
| 4 |
-
The training script supports frozen, partially unfrozen, and fully trainable
|
| 5 |
-
backbones with several cell-embedding heads.
|
| 6 |
-
|
| 7 |
-
##
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
|
| 14 |
-
|
|
| 15 |
-
|
|
| 16 |
-
| [
|
| 17 |
-
|
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
The
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
--
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
--
|
| 107 |
-
--
|
| 108 |
-
--
|
| 109 |
-
--
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
--
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
--
|
| 130 |
-
--
|
| 131 |
-
--
|
| 132 |
-
--
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
--
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
--
|
| 173 |
-
--
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
--
|
| 207 |
-
--
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
--
|
| 220 |
-
--
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
--
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
--
|
| 245 |
-
--
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
--
|
| 258 |
-
--
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
[
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Cell Annotation with BioMod
|
| 2 |
+
|
| 3 |
+
Fine-tune BioMod to predict cell-type labels from single-cell gene expression.
|
| 4 |
+
The training script supports frozen, partially unfrozen, and fully trainable
|
| 5 |
+
backbones with several cell-embedding heads.
|
| 6 |
+
|
| 7 |
+
## Dataset Commands
|
| 8 |
+
|
| 9 |
+
| Dataset | Complete launch command |
|
| 10 |
+
| --- | --- |
|
| 11 |
+
| Kim Lung | [Command](#1-kim-lung) |
|
| 12 |
+
| Immune | [Command](#2-immune) |
|
| 13 |
+
| Liver | [Command](#3-liver) |
|
| 14 |
+
| MS (paired train/test files) | [Command](#4-ms) |
|
| 15 |
+
| hPancreas (hp14 paired files) | [Command](#5-hpancreas) |
|
| 16 |
+
| Zheng68K | [Command](#6-zheng68k) |
|
| 17 |
+
| Myeloid (reference/query files) | [Command](#7-myeloid) |
|
| 18 |
+
|
| 19 |
+
The manuscript's annotation task covers seven benchmarks. The commands below
|
| 20 |
+
map those benchmarks to the files currently bundled in this repository; paired
|
| 21 |
+
files are one benchmark, not two separate datasets. Kim Lung has an unresolved
|
| 22 |
+
missing-label policy documented in its section.
|
| 23 |
+
|
| 24 |
+
Run from the outer repository root after installing the environment. Explicit
|
| 25 |
+
relative paths resolve from the working directory. Each command writes to its
|
| 26 |
+
own `tutorial_runs/` directory. Ordinary `python` supports one GPU; CUDA DDP with
|
| 27 |
+
multiple processes additionally requires a working NCCL environment.
|
| 28 |
+
|
| 29 |
+
The command blocks use Bash line continuations (`\`). Run them in Bash, such as
|
| 30 |
+
Linux, WSL or Git Bash. In PowerShell, join each command into a single line
|
| 31 |
+
instead of copying the Bash continuation characters.
|
| 32 |
+
|
| 33 |
+
### Training Protocol and Limits
|
| 34 |
+
|
| 35 |
+
The settings shared by these examples follow the available options for the
|
| 36 |
+
annotation method described in manuscript Section 4.5 (PDF pages 24–25): attention
|
| 37 |
+
pooling, a three-layer classifier, dropout 0.2, full encoder-path fine-tuning,
|
| 38 |
+
AdamW, backbone and head learning rates of `1e-4`, and weight decay `0.01`.
|
| 39 |
+
The script applies cosine annealing internally. `--label_smoothing 0` selects
|
| 40 |
+
the plain cross-entropy loss shown in the manuscript instead of the script's
|
| 41 |
+
default label smoothing of 0.1.
|
| 42 |
+
|
| 43 |
+
The manuscript does not specify the annotation batch size, epoch limit, patience,
|
| 44 |
+
or complete seed list in this section. The examples explicitly use batch size
|
| 45 |
+
32, 50 epochs, patience 10 and seed 0 as launch settings; these values are not
|
| 46 |
+
claimed to reproduce the reported five-run results. Reduce the batch size to
|
| 47 |
+
fit available GPU memory and retain the actual experiment settings for reporting.
|
| 48 |
+
The best checkpoint is selected by validation macro-F1, then evaluated on the
|
| 49 |
+
test set.
|
| 50 |
+
|
| 51 |
+
The classification report and confusion matrix include every declared class,
|
| 52 |
+
including rows with zero test support. The report's macro average covers this
|
| 53 |
+
full class list. Training and evaluation `macro_f1` values use the classes
|
| 54 |
+
present in the true or predicted labels, so the two averages can differ when
|
| 55 |
+
some declared classes are absent from both. Checkpoint selection keeps the
|
| 56 |
+
existing validation metric.
|
| 57 |
+
|
| 58 |
+
For single files, the entry point creates a stratified 70% / 10% / 20% split.
|
| 59 |
+
For paired files, it splits the supplied training file 90% / 10% and uses the
|
| 60 |
+
entire supplied test file for final evaluation. Stored split columns in `obs`
|
| 61 |
+
are not used. The manuscript does not list these exact filenames, so the
|
| 62 |
+
reference/query mapping is based on the bundled file organization and metadata.
|
| 63 |
+
|
| 64 |
+
Both expression filtering thresholds are explicitly zero to preserve the supplied
|
| 65 |
+
cells and genes. The entry point reads `adata.X` as supplied: it does not select
|
| 66 |
+
`layers["counts"]` or `.raw`, normalize counts, or apply `log1p`. Metadata checks
|
| 67 |
+
do not establish that each expression matrix has the intended preprocessing.
|
| 68 |
+
Model training and manuscript-result reproduction have not been validated by
|
| 69 |
+
these command examples.
|
| 70 |
+
|
| 71 |
+
### 1. Kim Lung
|
| 72 |
+
|
| 73 |
+
**Conditional configuration: missing-label handling must be resolved before
|
| 74 |
+
benchmarking.** The file contains 32,493 cells, including 2,021 cells with missing
|
| 75 |
+
`cell_type`. The current classifier converts labels to strings, so the command
|
| 76 |
+
below would treat missing values as an extra class instead of excluding them.
|
| 77 |
+
The manuscript does not specify the annotation policy for these cells. This
|
| 78 |
+
block records the intended file and fields; it is not a verified reproduction
|
| 79 |
+
command. Do not silently relabel or remove cells from the original file.
|
| 80 |
+
|
| 81 |
+
```bash
|
| 82 |
+
python BioMod/cell_annotation/train.py \
|
| 83 |
+
--data_path data/downstream/final_data/Kim2020_Lung.h5ad \
|
| 84 |
+
--label_column cell_type --gene_name_column gene_name \
|
| 85 |
+
--val_ratio 0.1 --test_ratio 0.2 \
|
| 86 |
+
--biomod_checkpoint weight/BioMod.pth --config_pkl weight/BioMod.pkl \
|
| 87 |
+
--biomod_data_dir model_dependencies/biomod_data_all \
|
| 88 |
+
--gene_list_path model_dependencies/selected_genes_27k.txt \
|
| 89 |
+
--gene2ens_file model_dependencies/gene2ens.csv --gene_mapping_path model_dependencies/gene2ens.csv \
|
| 90 |
+
--gene2vec_data_path model_dependencies/selected_gene2vec_27k.npy \
|
| 91 |
+
--head_type attn_pool --finetune_mode full --cls_decoder_layers 3 \
|
| 92 |
+
--dropout 0.2 --label_smoothing 0 \
|
| 93 |
+
--lr_head 1e-4 --lr_backbone 1e-4 --weight_decay 0.01 \
|
| 94 |
+
--min_genes 0 --min_cells 0 \
|
| 95 |
+
--batch_size 32 --epochs 50 --patience 10 --seed 0 \
|
| 96 |
+
--save_test_artifacts --output_dir tutorial_runs/cell_annotation_kim_lung --run_name seed0
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
### 2. Immune
|
| 100 |
+
|
| 101 |
+
Use the 33,506-cell matrix and its 16 `final_annotation` classes. Gene symbols
|
| 102 |
+
are stored in `var.index`. A new stratified 70% / 10% / 20% split is created.
|
| 103 |
+
|
| 104 |
+
```bash
|
| 105 |
+
python BioMod/cell_annotation/train.py \
|
| 106 |
+
--data_path data/downstream/final_data/Immune_ALL_human.h5ad \
|
| 107 |
+
--label_column final_annotation --gene_name_column index \
|
| 108 |
+
--val_ratio 0.1 --test_ratio 0.2 \
|
| 109 |
+
--biomod_checkpoint weight/BioMod.pth --config_pkl weight/BioMod.pkl \
|
| 110 |
+
--biomod_data_dir model_dependencies/biomod_data_all \
|
| 111 |
+
--gene_list_path model_dependencies/selected_genes_27k.txt \
|
| 112 |
+
--gene2ens_file model_dependencies/gene2ens.csv --gene_mapping_path model_dependencies/gene2ens.csv \
|
| 113 |
+
--gene2vec_data_path model_dependencies/selected_gene2vec_27k.npy \
|
| 114 |
+
--head_type attn_pool --finetune_mode full --cls_decoder_layers 3 \
|
| 115 |
+
--dropout 0.2 --label_smoothing 0 \
|
| 116 |
+
--lr_head 1e-4 --lr_backbone 1e-4 --weight_decay 0.01 \
|
| 117 |
+
--min_genes 0 --min_cells 0 \
|
| 118 |
+
--batch_size 32 --epochs 50 --patience 10 --seed 0 \
|
| 119 |
+
--save_test_artifacts --output_dir tutorial_runs/cell_annotation_immune --run_name seed0
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
### 3. Liver
|
| 123 |
+
|
| 124 |
+
Use the 8,444-cell matrix and its 20 `cell_type` classes. Gene symbols are stored
|
| 125 |
+
in `var.index`. A new stratified 70% / 10% / 20% split is created.
|
| 126 |
+
|
| 127 |
+
```bash
|
| 128 |
+
python BioMod/cell_annotation/train.py \
|
| 129 |
+
--data_path data/downstream/final_data/liver.h5ad \
|
| 130 |
+
--label_column cell_type --gene_name_column index \
|
| 131 |
+
--val_ratio 0.1 --test_ratio 0.2 \
|
| 132 |
+
--biomod_checkpoint weight/BioMod.pth --config_pkl weight/BioMod.pkl \
|
| 133 |
+
--biomod_data_dir model_dependencies/biomod_data_all \
|
| 134 |
+
--gene_list_path model_dependencies/selected_genes_27k.txt \
|
| 135 |
+
--gene2ens_file model_dependencies/gene2ens.csv --gene_mapping_path model_dependencies/gene2ens.csv \
|
| 136 |
+
--gene2vec_data_path model_dependencies/selected_gene2vec_27k.npy \
|
| 137 |
+
--head_type attn_pool --finetune_mode full --cls_decoder_layers 3 \
|
| 138 |
+
--dropout 0.2 --label_smoothing 0 \
|
| 139 |
+
--lr_head 1e-4 --lr_backbone 1e-4 --weight_decay 0.01 \
|
| 140 |
+
--min_genes 0 --min_cells 0 \
|
| 141 |
+
--batch_size 32 --epochs 50 --patience 10 --seed 0 \
|
| 142 |
+
--save_test_artifacts --output_dir tutorial_runs/cell_annotation_liver --run_name seed0
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
### 4. MS
|
| 146 |
+
|
| 147 |
+
Keep the 13,468-cell external test file separate. The 7,844-cell training file
|
| 148 |
+
is split 90% / 10% for training and validation. All 18 test labels occur in the
|
| 149 |
+
training file. Some training classes contain only three or four cells, so a
|
| 150 |
+
small validation split may not contain every rare class.
|
| 151 |
+
|
| 152 |
+
Use `index_column`, which contains Ensembl IDs in both files. The training file
|
| 153 |
+
has an index *named* `gene_name`, but no `var["gene_name"]` column. Consequently,
|
| 154 |
+
the unmodified `--dataset_preset ms` gene-column default is incompatible with
|
| 155 |
+
that file. The explicit configuration below avoids that default.
|
| 156 |
+
|
| 157 |
+
```bash
|
| 158 |
+
python BioMod/cell_annotation/train.py \
|
| 159 |
+
--train_data_path data/downstream/final_data/MS/c_data.h5ad \
|
| 160 |
+
--test_data_path data/downstream/final_data/MS/filtered_ms_adata.h5ad \
|
| 161 |
+
--label_column celltype --test_label_column celltype --gene_name_column index_column \
|
| 162 |
+
--val_ratio 0.1 \
|
| 163 |
+
--biomod_checkpoint weight/BioMod.pth --config_pkl weight/BioMod.pkl \
|
| 164 |
+
--biomod_data_dir model_dependencies/biomod_data_all \
|
| 165 |
+
--gene_list_path model_dependencies/selected_genes_27k.txt \
|
| 166 |
+
--gene2ens_file model_dependencies/gene2ens.csv --gene_mapping_path model_dependencies/gene2ens.csv \
|
| 167 |
+
--gene2vec_data_path model_dependencies/selected_gene2vec_27k.npy \
|
| 168 |
+
--head_type attn_pool --finetune_mode full --cls_decoder_layers 3 \
|
| 169 |
+
--dropout 0.2 --label_smoothing 0 \
|
| 170 |
+
--lr_head 1e-4 --lr_backbone 1e-4 --weight_decay 0.01 \
|
| 171 |
+
--min_genes 0 --min_cells 0 \
|
| 172 |
+
--batch_size 32 --epochs 50 --patience 10 --seed 0 \
|
| 173 |
+
--save_test_artifacts --output_dir tutorial_runs/cell_annotation_ms --run_name seed0
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
### 5. hPancreas
|
| 177 |
+
|
| 178 |
+
The 10,600-cell training file declares 14 categorical labels and contains cells
|
| 179 |
+
from 13 of them. `MHC class II` is already declared in its `Celltype` categories
|
| 180 |
+
with a training count of **0**; the 4,218-cell test file contains **5** such cells.
|
| 181 |
+
The entry point preserves the predefined training categories when constructing
|
| 182 |
+
the classifier and label encoder, including categories with zero training cells.
|
| 183 |
+
It does not create cells, add test cells to training, or infer the class list from
|
| 184 |
+
the test labels. Stratification still operates only on the observed training
|
| 185 |
+
cells. Keeping the output category does not supply positive training examples
|
| 186 |
+
for it.
|
| 187 |
+
|
| 188 |
+
Both files use `Celltype` and gene symbols in `var.index`. This annotation
|
| 189 |
+
benchmark is distinct from the 16,382-cell hPNC integration dataset.
|
| 190 |
+
|
| 191 |
+
```bash
|
| 192 |
+
python BioMod/cell_annotation/train.py \
|
| 193 |
+
--train_data_path data/downstream/final_data/hp14/demo_train_with_MHC_class_II.h5ad \
|
| 194 |
+
--test_data_path data/downstream/final_data/hp14/demo_test.h5ad \
|
| 195 |
+
--label_column Celltype --test_label_column Celltype --gene_name_column index \
|
| 196 |
+
--val_ratio 0.1 \
|
| 197 |
+
--biomod_checkpoint weight/BioMod.pth --config_pkl weight/BioMod.pkl \
|
| 198 |
+
--biomod_data_dir model_dependencies/biomod_data_all \
|
| 199 |
+
--gene_list_path model_dependencies/selected_genes_27k.txt \
|
| 200 |
+
--gene2ens_file model_dependencies/gene2ens.csv --gene_mapping_path model_dependencies/gene2ens.csv \
|
| 201 |
+
--gene2vec_data_path model_dependencies/selected_gene2vec_27k.npy \
|
| 202 |
+
--head_type attn_pool --finetune_mode full --cls_decoder_layers 3 \
|
| 203 |
+
--dropout 0.2 --label_smoothing 0 \
|
| 204 |
+
--lr_head 1e-4 --lr_backbone 1e-4 --weight_decay 0.01 \
|
| 205 |
+
--min_genes 0 --min_cells 0 \
|
| 206 |
+
--batch_size 32 --epochs 50 --patience 10 --seed 0 \
|
| 207 |
+
--save_test_artifacts --output_dir tutorial_runs/cell_annotation_hpancreas --run_name seed0
|
| 208 |
+
```
|
| 209 |
+
|
| 210 |
+
### 6. Zheng68K
|
| 211 |
+
|
| 212 |
+
Use the 68,450-cell matrix and its 11 `celltype` classes. Gene symbols are stored
|
| 213 |
+
in `var.index`. The 20% test split contains 13,690 cells, matching the test-set
|
| 214 |
+
size reported in the manuscript; exact cell identities still depend on the seed
|
| 215 |
+
and input ordering.
|
| 216 |
+
|
| 217 |
+
```bash
|
| 218 |
+
python BioMod/cell_annotation/train.py \
|
| 219 |
+
--data_path data/downstream/final_data/Zheng68K.h5ad \
|
| 220 |
+
--label_column celltype --gene_name_column index \
|
| 221 |
+
--val_ratio 0.1 --test_ratio 0.2 \
|
| 222 |
+
--biomod_checkpoint weight/BioMod.pth --config_pkl weight/BioMod.pkl \
|
| 223 |
+
--biomod_data_dir model_dependencies/biomod_data_all \
|
| 224 |
+
--gene_list_path model_dependencies/selected_genes_27k.txt \
|
| 225 |
+
--gene2ens_file model_dependencies/gene2ens.csv --gene_mapping_path model_dependencies/gene2ens.csv \
|
| 226 |
+
--gene2vec_data_path model_dependencies/selected_gene2vec_27k.npy \
|
| 227 |
+
--head_type attn_pool --finetune_mode full --cls_decoder_layers 3 \
|
| 228 |
+
--dropout 0.2 --label_smoothing 0 \
|
| 229 |
+
--lr_head 1e-4 --lr_backbone 1e-4 --weight_decay 0.01 \
|
| 230 |
+
--min_genes 0 --min_cells 0 \
|
| 231 |
+
--batch_size 32 --epochs 50 --patience 10 --seed 0 \
|
| 232 |
+
--save_test_artifacts --output_dir tutorial_runs/cell_annotation_zheng68k --run_name seed0
|
| 233 |
+
```
|
| 234 |
+
|
| 235 |
+
### 7. Myeloid
|
| 236 |
+
|
| 237 |
+
Use the 9,748-cell reference file for training/validation and retain the
|
| 238 |
+
3,430-cell query file as the external test set. The reference contains 21
|
| 239 |
+
observed labels and the query contains 11; every query label occurs in the
|
| 240 |
+
reference. Both files use `cell_type` and gene symbols in `var.index`.
|
| 241 |
+
|
| 242 |
+
```bash
|
| 243 |
+
python BioMod/cell_annotation/train.py \
|
| 244 |
+
--train_data_path data/downstream/final_data/Myeloid/reference_adata.h5ad \
|
| 245 |
+
--test_data_path data/downstream/final_data/Myeloid/query_adata.h5ad \
|
| 246 |
+
--label_column cell_type --test_label_column cell_type --gene_name_column index \
|
| 247 |
+
--val_ratio 0.1 \
|
| 248 |
+
--biomod_checkpoint weight/BioMod.pth --config_pkl weight/BioMod.pkl \
|
| 249 |
+
--biomod_data_dir model_dependencies/biomod_data_all \
|
| 250 |
+
--gene_list_path model_dependencies/selected_genes_27k.txt \
|
| 251 |
+
--gene2ens_file model_dependencies/gene2ens.csv --gene_mapping_path model_dependencies/gene2ens.csv \
|
| 252 |
+
--gene2vec_data_path model_dependencies/selected_gene2vec_27k.npy \
|
| 253 |
+
--head_type attn_pool --finetune_mode full --cls_decoder_layers 3 \
|
| 254 |
+
--dropout 0.2 --label_smoothing 0 \
|
| 255 |
+
--lr_head 1e-4 --lr_backbone 1e-4 --weight_decay 0.01 \
|
| 256 |
+
--min_genes 0 --min_cells 0 \
|
| 257 |
+
--batch_size 32 --epochs 50 --patience 10 --seed 0 \
|
| 258 |
+
--save_test_artifacts --output_dir tutorial_runs/cell_annotation_myeloid --run_name seed0
|
| 259 |
+
```
|
| 260 |
+
|
| 261 |
+
## Notebook
|
| 262 |
+
|
| 263 |
+
See the [task notebook](tutorial.ipynb) for a step-by-step workflow.
|
| 264 |
+
|
| 265 |
+
## Files
|
| 266 |
+
|
| 267 |
+
| File or directory | Purpose |
|
| 268 |
+
| --- | --- |
|
| 269 |
+
| [README.md](README.md) | File guide and command-line training example. |
|
| 270 |
+
| [tutorial.ipynb](tutorial.ipynb) | Task configuration, execution, and result review in a Jupyter notebook. |
|
| 271 |
+
| [train.py](train.py) | Train and evaluate the cell-type classifier with the BioMod backbone. |
|
| 272 |
+
|
| 273 |
+
## Optional Module Sources
|
| 274 |
+
|
| 275 |
+
The optional [Hallmark and Reactome source definitions](../../model_dependencies/biomod_data_sources/)
|
| 276 |
+
are stored separately from this task. They include
|
| 277 |
+
[Hallmark modules](../../model_dependencies/biomod_data_sources/biomod1_hallmarks.json),
|
| 278 |
+
[filtered Reactome modules](../../model_dependencies/biomod_data_sources/biomod2_reactome_2022_filtered.json),
|
| 279 |
+
and a [JSON loading helper](../../model_dependencies/biomod_data_sources/load_biomod.py).
|
| 280 |
+
These source resources are not the default runtime module definitions for the
|
| 281 |
+
supplied checkpoint. The dataset commands use
|
| 282 |
+
`model_dependencies/biomod_data_all/` with the matching BioMod weights and configuration.
|
| 283 |
+
|
| 284 |
+
## Related Datasets
|
| 285 |
+
|
| 286 |
+
`BMMC_processed.h5ad`, `human_pancreas_norm_complexBatch_with_gene_name.h5ad`,
|
| 287 |
+
and the lung file without malignant cells belong to the documented
|
| 288 |
+
[zero-shot integration conditions](../zero_shot_batch/README.md#dataset-commands).
|
| 289 |
+
`norman/perturb_processed.h5ad` belongs to
|
| 290 |
+
[gene perturbation prediction](../gene_perturbation/README.md).
|
| 291 |
+
Their presence in the data directory does not add annotation benchmarks to the
|
| 292 |
+
seven listed above.
|
BioMod/drug_combination/README.md
CHANGED
|
@@ -1,170 +1,172 @@
|
|
| 1 |
-
# Drug Combination Synergy Prediction with BioMod
|
| 2 |
-
|
| 3 |
-
This task predicts drug-combination synergy using BioMod cell embeddings from
|
| 4 |
-
the BioMod encoder and GCN-based drug molecular graph encoders. Use the
|
| 5 |
-
[BioMod model weights and matching configuration](../../README.md#biomod-model-weights).
|
| 6 |
-
|
| 7 |
-
It is adapted from scLong's drug-combination implementation
|
| 8 |
-
(DeepDDs), replacing the scfm/geneformer cell-line representation with
|
| 9 |
-
BioMod.
|
| 10 |
-
|
| 11 |
-
##
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
| 19 |
-
|
|
| 20 |
-
|
|
| 21 |
-
|
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
The
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
-
|
| 57 |
-
-
|
| 58 |
-
-
|
| 59 |
-
-
|
| 60 |
-
-
|
| 61 |
-
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
``
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
###
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
|
| 137 |
-
|
|
| 138 |
-
| `--
|
| 139 |
-
| `--
|
| 140 |
-
| `--
|
| 141 |
-
| `--
|
| 142 |
-
| `--
|
| 143 |
-
| `--
|
| 144 |
-
| `--
|
| 145 |
-
| `--
|
| 146 |
-
| `--
|
| 147 |
-
| `--
|
| 148 |
-
| `--
|
| 149 |
-
| `--
|
| 150 |
-
| `--
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
- `
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
# Drug Combination Synergy Prediction with BioMod
|
| 2 |
+
|
| 3 |
+
This task predicts drug-combination synergy using BioMod cell embeddings from
|
| 4 |
+
the BioMod encoder and GCN-based drug molecular graph encoders. Use the
|
| 5 |
+
[BioMod model weights and matching configuration](../../README.md#biomod-model-weights).
|
| 6 |
+
|
| 7 |
+
It is adapted from scLong's drug-combination implementation
|
| 8 |
+
(DeepDDs), replacing the scfm/geneformer cell-line representation with
|
| 9 |
+
BioMod.
|
| 10 |
+
|
| 11 |
+
## Dataset Commands
|
| 12 |
+
|
| 13 |
+
### Bundled dataset
|
| 14 |
+
|
| 15 |
+
The current entry point uses one collection with separate training and validation
|
| 16 |
+
inputs under `data/downstream/final_data/drug_combination_synergy/data_summary/`.
|
| 17 |
+
|
| 18 |
+
| Input below `data_summary/` | Purpose |
|
| 19 |
+
| --- | --- |
|
| 20 |
+
| `new_labels_0_10.csv` | 12,415 training records with `drug1`, `drug2`, `cell`, and `label` columns. |
|
| 21 |
+
| `new_cell_features_954.csv` | Training expression; the loader removes the transcript-ID row and obtains 31 cell rows by 954 genes. |
|
| 22 |
+
| `test_data/independent_input.csv` | 668 validation records used for checkpoint selection. |
|
| 23 |
+
| `test_data/independent_cell_features_954.csv` | Validation expression; the loader removes the transcript-ID row and obtains 1,019 cell rows by 954 genes. |
|
| 24 |
+
|
| 25 |
+
The directory name `test_data/` is retained for compatibility. The current script
|
| 26 |
+
uses these files as validation inputs. Drug molecular graphs are constructed from
|
| 27 |
+
the SMILES strings already stored in the label tables' `drug1` and `drug2` columns.
|
| 28 |
+
`smiles_0_10.csv` and the other source tables are retained for reference and are not
|
| 29 |
+
additional required inputs to this entry point.
|
| 30 |
+
|
| 31 |
+
The older `data/downstream/final_data/drug_response_pytorch/drug_combination/`
|
| 32 |
+
package is a reference copy, not another dataset for this task.
|
| 33 |
+
|
| 34 |
+
### Dependencies
|
| 35 |
+
|
| 36 |
+
- PyTorch
|
| 37 |
+
- PyTorch Geometric (`torch_geometric`)
|
| 38 |
+
- RDKit
|
| 39 |
+
- networkx
|
| 40 |
+
- scikit-learn
|
| 41 |
+
- pandas, numpy
|
| 42 |
+
|
| 43 |
+
### Run the bundled training and validation collection
|
| 44 |
+
|
| 45 |
+
Activate the environment described in the [project README](../../README.md), then
|
| 46 |
+
run these commands in Bash from the outer repository root containing `BioMod/`,
|
| 47 |
+
`data/`, `model_dependencies/`, and `weight/`. The backslashes continue commands
|
| 48 |
+
across lines in Bash; they are not PowerShell continuation characters. Use a
|
| 49 |
+
Linux or WSL Bash shell with the required environment. Built-in resource defaults
|
| 50 |
+
resolve from the script location; explicit relative paths resolve from the
|
| 51 |
+
working directory.
|
| 52 |
+
|
| 53 |
+
```bash
|
| 54 |
+
python BioMod/drug_combination/train.py \
|
| 55 |
+
--data_dir data/downstream/final_data/drug_combination_synergy/data_summary \
|
| 56 |
+
--label_file new_labels_0_10.csv \
|
| 57 |
+
--cell_file new_cell_features_954.csv \
|
| 58 |
+
--validation_label_file test_data/independent_input.csv \
|
| 59 |
+
--validation_cell_file test_data/independent_cell_features_954.csv \
|
| 60 |
+
--checkpoint_path weight/BioMod.pth \
|
| 61 |
+
--hyper_params_path weight/BioMod.pkl \
|
| 62 |
+
--biomod_data_dir model_dependencies/biomod_data_all \
|
| 63 |
+
--n_folds 1 \
|
| 64 |
+
--epochs 500 \
|
| 65 |
+
--batch_size 256 \
|
| 66 |
+
--pool_method max \
|
| 67 |
+
--output_dir tutorial_runs/drug_combination_synergy
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
These are example settings for the bundled inputs, not a verified reproduction
|
| 71 |
+
of manuscript results. The default domain-generalization mode trains on the full
|
| 72 |
+
training collection and selects a checkpoint using the separate validation
|
| 73 |
+
collection. `--n_folds 1` requests one run; leaving its default of 5 in this mode
|
| 74 |
+
repeats full-training/full-validation runs rather than performing five-fold
|
| 75 |
+
cross-validation.
|
| 76 |
+
|
| 77 |
+
The manuscript describes the 668-sample collection as an independent test set.
|
| 78 |
+
The current code uses it for checkpoint selection, so its reported AUROC is a
|
| 79 |
+
validation result and must not be presented as an independent final test estimate.
|
| 80 |
+
|
| 81 |
+
#### Optional five-fold cross-validation on the same collection
|
| 82 |
+
|
| 83 |
+
This is an alternative validation protocol, not a second dataset. The current
|
| 84 |
+
implementation still reads all four input tables before selecting the held-out
|
| 85 |
+
folds from the training collection.
|
| 86 |
+
|
| 87 |
+
```bash
|
| 88 |
+
python BioMod/drug_combination/train.py \
|
| 89 |
+
--data_dir data/downstream/final_data/drug_combination_synergy/data_summary \
|
| 90 |
+
--checkpoint_path weight/BioMod.pth \
|
| 91 |
+
--hyper_params_path weight/BioMod.pkl \
|
| 92 |
+
--biomod_data_dir model_dependencies/biomod_data_all \
|
| 93 |
+
--no_domain_gen \
|
| 94 |
+
--n_folds 5 \
|
| 95 |
+
--epochs 500 \
|
| 96 |
+
--batch_size 256 \
|
| 97 |
+
--pool_method max \
|
| 98 |
+
--output_dir tutorial_runs/drug_combination_synergy_cv
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
#### Input and cache changes
|
| 102 |
+
|
| 103 |
+
Use `--gene_list_path`, `--gene_mapping_path`, `--gene2vec_path`, and
|
| 104 |
+
`--symbol2ens_path` only when replacing the bundled shared assets. After changing
|
| 105 |
+
model weights, pooling, or input tables, append `--force_preprocess` to regenerate
|
| 106 |
+
the embedding cache and the PyG datasets under `data_summary/processed/`; an
|
| 107 |
+
existing cache is not automatically keyed by all model and input settings.
|
| 108 |
+
|
| 109 |
+
The input files and command arguments have been checked. This documentation update
|
| 110 |
+
did not execute training or verify checkpoint performance.
|
| 111 |
+
|
| 112 |
+
## Notebook
|
| 113 |
+
|
| 114 |
+
See the [task notebook](tutorial.ipynb) for a step-by-step workflow.
|
| 115 |
+
|
| 116 |
+
## Files
|
| 117 |
+
|
| 118 |
+
| File or directory | Purpose |
|
| 119 |
+
| --- | --- |
|
| 120 |
+
| [README.md](README.md) | File guide, model and data descriptions, training commands, and evaluation details. |
|
| 121 |
+
| [tutorial.ipynb](tutorial.ipynb) | Task configuration, execution, and result review in a Jupyter notebook. |
|
| 122 |
+
| [train.py](train.py) | Train and validate drug-combination synergy prediction with drug graph encoders and BioMod cell embeddings. |
|
| 123 |
+
|
| 124 |
+
## Model Architecture
|
| 125 |
+
|
| 126 |
+
| Component | Description |
|
| 127 |
+
| --- | --- |
|
| 128 |
+
| Drug branch | Three PyG GCNConv layers (78 -> 78 -> 156 -> 312), `global_max_pool`, and two fully connected layers to 128 dimensions |
|
| 129 |
+
| Cell branch | Pretrained BioMod encoder, configurable pooling, and an MLP to 128 dimensions |
|
| 130 |
+
| Fusion layer | `concat(drug1, drug2, cell) = 384 -> MLP -> 2-class prediction` |
|
| 131 |
+
|
| 132 |
+
The drug1 and drug2 branches share weights, matching scLong.
|
| 133 |
+
|
| 134 |
+
## Main Arguments
|
| 135 |
+
|
| 136 |
+
| Argument | Default | Description |
|
| 137 |
+
| --- | --- | --- |
|
| 138 |
+
| `--checkpoint_path` | Required | Path to the BioMod model weights |
|
| 139 |
+
| `--hyper_params_path` | Required | Path to the BioMod hyper-parameter pkl file |
|
| 140 |
+
| `--biomod_data_dir` | None | Directory containing module data files |
|
| 141 |
+
| `--data_dir` | `data/downstream/final_data/drug_combination_synergy/data_summary` | Data directory |
|
| 142 |
+
| `--validation_label_file` | `test_data/independent_input.csv` | Validation labels for checkpoint selection; legacy alias: `--test_label_file` |
|
| 143 |
+
| `--validation_cell_file` | `test_data/independent_cell_features_954.csv` | Validation cell features; legacy alias: `--test_cell_file` |
|
| 144 |
+
| `--batch_size` | 256 | Training batch size |
|
| 145 |
+
| `--lr` | 1e-4 | Learning rate |
|
| 146 |
+
| `--epochs` | 100 | Number of training epochs |
|
| 147 |
+
| `--n_folds` | 5 | Number of folds |
|
| 148 |
+
| `--domain_gen` | True | Domain generalization mode: train on the full training set and select checkpoints using a separate validation set |
|
| 149 |
+
| `--eval_interval` | 5 | Evaluate every N epochs |
|
| 150 |
+
| `--pool_method` | mean | BioMod pooling method (`mean`, `max`, or `concat`) |
|
| 151 |
+
| `--cache_emb` | True | Cache cell embeddings to a `.npy` file |
|
| 152 |
+
| `--force_preprocess` | False | Force regeneration of the PyG dataset |
|
| 153 |
+
|
| 154 |
+
## Outputs
|
| 155 |
+
|
| 156 |
+
Results are saved under `--output_dir` (default: `BioMod/drug_combination/results/` relative to the repository root):
|
| 157 |
+
|
| 158 |
+
- `best_model_fold{i}.pt` - model weights selected by the highest validation AUC for each fold
|
| 159 |
+
- `fpr_tpr_fold{i}.pkl` - validation FPR/TPR curve data for drawing ROC curves
|
| 160 |
+
- `cell_emb_cache_{pool_method}.npy` - cached BioMod cell embeddings
|
| 161 |
+
|
| 162 |
+
## Evaluation Metrics
|
| 163 |
+
|
| 164 |
+
Every `--eval_interval` epochs, the script evaluates AUC, PR_AUC, ACC, BACC,
|
| 165 |
+
PREC, TPR, and KAPPA on the validation set, matching scLong's metric definitions.
|
| 166 |
+
The checkpoint with the highest validation AUC is saved for each fold. In
|
| 167 |
+
`--no_domain_gen` mode, each held-out fold serves as the validation set.
|
| 168 |
+
|
| 169 |
+
This naming update preserves the data, splits, checkpoint-selection behavior,
|
| 170 |
+
output filenames, metric column names, and legacy dataset cache IDs. It does not
|
| 171 |
+
create or evaluate an independent final test set; the reported values are
|
| 172 |
+
validation results used during model selection, not final test estimates.
|
BioMod/drug_response/README.md
CHANGED
|
@@ -1,70 +1,73 @@
|
|
| 1 |
-
# Drug Response Prediction with BioMod
|
| 2 |
-
|
| 3 |
-
Predict drug response from drug molecular graphs and BioMod cell embeddings.
|
| 4 |
-
The training script combines a graph-based drug encoder with the pretrained
|
| 5 |
-
BioMod backbone.
|
| 6 |
-
|
| 7 |
-
##
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
`data/downstream/final_data/
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Drug Response Prediction with BioMod
|
| 2 |
+
|
| 3 |
+
Predict drug response from drug molecular graphs and BioMod cell embeddings.
|
| 4 |
+
The training script combines a graph-based drug encoder with the pretrained
|
| 5 |
+
BioMod backbone.
|
| 6 |
+
|
| 7 |
+
## Dataset Commands
|
| 8 |
+
|
| 9 |
+
### Bundled dataset
|
| 10 |
+
|
| 11 |
+
The current entry point uses one joint GDSC-CCLE collection. GDSC supplies drug
|
| 12 |
+
information and responses; CCLE supplies cell-line annotations and expression.
|
| 13 |
+
They are complementary inputs to one run, rather than separate training datasets.
|
| 14 |
+
Use the cleaned collection under
|
| 15 |
+
`data/downstream/final_data/single_drug_response/data/`.
|
| 16 |
+
|
| 17 |
+
| Input below the data directory | Purpose |
|
| 18 |
+
| --- | --- |
|
| 19 |
+
| `GDSC/1.Drug_listMon Jun 24 09_00_55 2019.csv` | Map drug IDs to PubChem IDs. |
|
| 20 |
+
| `GDSC/drug_graph_feat/*.hkl` | Precomputed molecular graphs; 223 files are bundled. |
|
| 21 |
+
| `CCLE/Cell_lines_annotations_20181226.txt` | Map cell-line IDs to cancer types. |
|
| 22 |
+
| `CCLE/genomic_expression_561celllines_697genes_demap_features.csv` | Expression for 561 cell lines and 697 genes. |
|
| 23 |
+
| `CCLE/GDSC_IC50.csv` | Drug-response matrix used to construct matched response records. |
|
| 24 |
+
|
| 25 |
+
The older `data/downstream/final_data/drug_response_pytorch/` package is retained
|
| 26 |
+
for reference. It is not an additional dataset for this task. Files under
|
| 27 |
+
`single_drug_response/optional_reference/` are not consumed by this entry point.
|
| 28 |
+
|
| 29 |
+
### Run the bundled GDSC-CCLE collection
|
| 30 |
+
|
| 31 |
+
Activate the environment described in the [project README](../../README.md), then
|
| 32 |
+
run these commands in Bash from the outer repository root containing `BioMod/`,
|
| 33 |
+
`data/`, `model_dependencies/`, and `weight/`. The backslashes continue commands
|
| 34 |
+
across lines in Bash; they are not PowerShell continuation characters. Use a
|
| 35 |
+
Linux or WSL Bash shell with the required environment. Built-in resource defaults
|
| 36 |
+
resolve from the script location; explicit relative paths resolve from the
|
| 37 |
+
working directory.
|
| 38 |
+
|
| 39 |
+
```bash
|
| 40 |
+
python BioMod/drug_response/train.py \
|
| 41 |
+
--gpu_id 0 \
|
| 42 |
+
--data_path data/downstream/final_data/single_drug_response/data \
|
| 43 |
+
--checkpoint_path weight/BioMod.pth \
|
| 44 |
+
--hyper_params_path weight/BioMod.pkl \
|
| 45 |
+
--biomod_data_dir model_dependencies/biomod_data_all \
|
| 46 |
+
--epochs 300 \
|
| 47 |
+
--batch_size 32 \
|
| 48 |
+
--pool_method max \
|
| 49 |
+
--save_dir tutorial_runs/drug_response_gdsc_ccle
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
This is a command for the bundled inputs, with example training settings. It has
|
| 53 |
+
not been validated as a reproduction of the manuscript results. The current code
|
| 54 |
+
uses a fixed seed of 0 and splits matched records by cancer type into approximately
|
| 55 |
+
95% training and 5% validation. Validation Pearson correlation determines the best
|
| 56 |
+
checkpoint. It does not create a separate final test set, and it does not implement
|
| 57 |
+
the manuscript's 70%/10%/20% train/validation/test protocol.
|
| 58 |
+
|
| 59 |
+
The data and asset paths have been checked for existence. A complete training run
|
| 60 |
+
and checkpoint performance have not been verified by this documentation update.
|
| 61 |
+
|
| 62 |
+
## Notebook
|
| 63 |
+
|
| 64 |
+
See the [task notebook](tutorial.ipynb) for a step-by-step workflow.
|
| 65 |
+
|
| 66 |
+
## Files
|
| 67 |
+
|
| 68 |
+
| File or directory | Purpose |
|
| 69 |
+
| --- | --- |
|
| 70 |
+
| [README.md](README.md) | File guide and command-line training example. |
|
| 71 |
+
| [tutorial.ipynb](tutorial.ipynb) | Task configuration, execution, and result review in a Jupyter notebook. |
|
| 72 |
+
| [train.py](train.py) | Load drug-response data, build the model, train, and evaluate validation metrics. |
|
| 73 |
+
|
BioMod/gene_perturbation/README.md
CHANGED
|
@@ -1,333 +1,333 @@
|
|
| 1 |
-
# Gene Perturbation Prediction with BioMod
|
| 2 |
-
|
| 3 |
-
This document describes the BioMod gene perturbation workflow (GEARS), using
|
| 4 |
-
the `BioMod` encoder. The
|
| 5 |
-
[BioMod model weights and matching configuration](../../README.md#biomod-model-weights)
|
| 6 |
-
are shared with the other downstream tasks.
|
| 7 |
-
|
| 8 |
-
##
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
| 16 |
-
|
|
| 17 |
-
|
|
| 18 |
-
|
|
| 19 |
-
|
|
| 20 |
-
|
|
| 21 |
-
|
|
| 22 |
-
|
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
-
|
| 46 |
-
|
| 47 |
-
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
```
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
##
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
- `
|
| 166 |
-
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
**
|
| 175 |
-
|
| 176 |
-
- `--
|
| 177 |
-
-
|
| 178 |
-
|
| 179 |
-
## Comparison with Original sclong
|
| 180 |
-
|
| 181 |
-
### Main Differences
|
| 182 |
-
|
| 183 |
-
1. **Model architecture**:
|
| 184 |
-
- **Original sclong**: uses `DualEncoderSCFM` and directly processes gene sequences.
|
| 185 |
-
- **Module version**: uses `BioMod` and processes module-based data.
|
| 186 |
-
|
| 187 |
-
2. **Data representation**:
|
| 188 |
-
- **Original sclong**: gene-level embeddings come directly from encoder outputs.
|
| 189 |
-
- **Module version**: gene-level embeddings are recovered from module encodings by mean pooling.
|
| 190 |
-
|
| 191 |
-
3. **Input format**:
|
| 192 |
-
- **Original sclong**: directly inputs gene expression vectors.
|
| 193 |
-
- **Module version**: keeps the same external input format but internally processes data with module embeddings.
|
| 194 |
-
|
| 195 |
-
### Performance Comparison
|
| 196 |
-
|
| 197 |
-
To compare model performance:
|
| 198 |
-
|
| 199 |
-
1. **Run original scLong** using its own documentation and a separate checkout
|
| 200 |
-
of the upstream GEARS code. That external workflow is not bundled here.
|
| 201 |
-
|
| 202 |
-
2. **Run BioMod** using the complete
|
| 203 |
-
[Norman simulation command](#2-run-the-bundled-norman-simulation-split) above.
|
| 204 |
-
|
| 205 |
-
3. **Compare metrics**:
|
| 206 |
-
|
| 207 |
-
- MSE (Mean Squared Error)
|
| 208 |
-
- Pearson correlation
|
| 209 |
-
- MSE and Pearson correlation for the top 20 DE genes
|
| 210 |
-
- Direction accuracy and related metrics
|
| 211 |
-
|
| 212 |
-
Results are saved under each `result_dir`. Compare these metrics to evaluate the
|
| 213 |
-
module version.
|
| 214 |
-
|
| 215 |
-
## Technical Details
|
| 216 |
-
|
| 217 |
-
### Module-to-Gene Mapping
|
| 218 |
-
|
| 219 |
-
In `SCFM_BioMod`, `gene_to_modules` records which modules contain each gene:
|
| 220 |
-
|
| 221 |
-
```python
|
| 222 |
-
self.gene_to_modules = {} # {gene_idx: [module_idx1, module_idx2, ...]}
|
| 223 |
-
for module_idx, module_genes in enumerate(module_sets):
|
| 224 |
-
for gene_idx in module_genes:
|
| 225 |
-
if gene_idx < len(scfm_genes):
|
| 226 |
-
if gene_idx not in self.gene_to_modules:
|
| 227 |
-
self.gene_to_modules[gene_idx] = []
|
| 228 |
-
self.gene_to_modules[gene_idx].append(module_idx)
|
| 229 |
-
```
|
| 230 |
-
|
| 231 |
-
### Gene Embedding Recovery Strategy
|
| 232 |
-
|
| 233 |
-
For each gene:
|
| 234 |
-
|
| 235 |
-
1. If the gene appears in some modules, average the encodings of those modules.
|
| 236 |
-
2. If the gene does not appear in any module, use the global average of all modules as a fallback.
|
| 237 |
-
|
| 238 |
-
This strategy:
|
| 239 |
-
|
| 240 |
-
- Makes full use of module information.
|
| 241 |
-
- Provides a reasonable embedding for genes absent from all modules.
|
| 242 |
-
- Keeps embedding dimensionality similar to the original model.
|
| 243 |
-
|
| 244 |
-
## File Structure
|
| 245 |
-
|
| 246 |
-
```text
|
| 247 |
-
BioMod/gene_perturbation/ # Perturbation response prediction
|
| 248 |
-
├── components/ # Model, data, training, and evaluation helpers
|
| 249 |
-
│ ├── __init__.py
|
| 250 |
-
│ ├── data_utils.py
|
| 251 |
-
│ ├── dataset.py
|
| 252 |
-
│ ├── inference.py
|
| 253 |
-
│ ├── model.py
|
| 254 |
-
│ ├── trainer.py
|
| 255 |
-
│ ├── training_utils.py
|
| 256 |
-
│ └── utils.py
|
| 257 |
-
├── README.md
|
| 258 |
-
├── train.py
|
| 259 |
-
└── tutorial.ipynb
|
| 260 |
-
```
|
| 261 |
-
|
| 262 |
-
## Notes
|
| 263 |
-
|
| 264 |
-
1. **Module data format**: make sure the gene indices or names in the module data match the BioMod gene list.
|
| 265 |
-
2. **Gene mapping**: provide `gene_mapping_path` if the module data use gene symbols.
|
| 266 |
-
3. **Memory usage**: the module version may require more memory because it maintains the module-to-gene mapping.
|
| 267 |
-
4. **Training stability**: use the same learning rate and training strategy as original sclong when possible.
|
| 268 |
-
|
| 269 |
-
## Troubleshooting
|
| 270 |
-
|
| 271 |
-
### Issue 1: Module Data Not Found
|
| 272 |
-
|
| 273 |
-
- Check whether `--biomod_data_path` or `--biomod_data_dir` is correct.
|
| 274 |
-
- Make sure the module data file exists and has the expected format.
|
| 275 |
-
|
| 276 |
-
### Issue 2: Gene Mapping Failed
|
| 277 |
-
|
| 278 |
-
- Check whether `--gene_mapping_path` is correct.
|
| 279 |
-
- Make sure the gene mapping file is a CSV containing `Approved symbol` and `Ensembl gene ID` columns.
|
| 280 |
-
|
| 281 |
-
### Issue 3: Model Loading Failed
|
| 282 |
-
|
| 283 |
-
- Check whether the checkpoint path is correct.
|
| 284 |
-
- Make sure `hyper_params` contains the required module information.
|
| 285 |
-
|
| 286 |
-
## Gene-Based vs Module-Based Methods
|
| 287 |
-
|
| 288 |
-
This implementation supports two feature extraction modes controlled by
|
| 289 |
-
`--use_biomod_level`.
|
| 290 |
-
|
| 291 |
-
### Method 1: Gene-Based (Default, Recommended)
|
| 292 |
-
|
| 293 |
-
Use the complete [Norman simulation command](#2-run-the-bundled-norman-simulation-split)
|
| 294 |
-
above. It uses gene-level recovery by omitting `--use_biomod_level`; this is a
|
| 295 |
-
boolean switch, so do not append a value such as `False`.
|
| 296 |
-
|
| 297 |
-
**Characteristics**:
|
| 298 |
-
|
| 299 |
-
- Recovers gene-level embeddings from module encodings.
|
| 300 |
-
- Fully compatible with the original GEARS architecture.
|
| 301 |
-
- Downstream tasks operate at gene level, including the GNN and decoder.
|
| 302 |
-
- Outputs gene-level predictions.
|
| 303 |
-
|
| 304 |
-
### Method 2: Module-Based (Experimental, Not Fully Implemented)
|
| 305 |
-
|
| 306 |
-
The `--use_biomod_level` switch selects an experimental mode whose downstream
|
| 307 |
-
architecture is incomplete. It is not included in the runnable
|
| 308 |
-
[Norman simulation command](#2-run-the-bundled-norman-simulation-split). Use the
|
| 309 |
-
default gene-level workflow for the bundled dataset.
|
| 310 |
-
|
| 311 |
-
**Characteristics**:
|
| 312 |
-
|
| 313 |
-
- Directly uses module-level encodings.
|
| 314 |
-
- Preserves the full module-level information.
|
| 315 |
-
- **Note**: module-level downstream tasks are not fully implemented in the current version.
|
| 316 |
-
- Requires redesigning the downstream architecture, including the GNN and decoder.
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
## References
|
| 320 |
-
|
| 321 |
-
- Original GEARS code is an external reference and is not included in this source directory.
|
| 322 |
-
- BioMod model: `BioMod/models_biomod.py`
|
| 323 |
-
- Module data processing: `BioMod/biomod_dataset.py`
|
| 324 |
-
|
| 325 |
-
## Optional external annotation resources
|
| 326 |
-
|
| 327 |
-
The bundled Norman data include `go.csv`. If that network must be regenerated,
|
| 328 |
-
provide `gene2go_path` to `get_go_auto` or set `BIOMOD_GENE2GO_PATH` to the
|
| 329 |
-
appropriate `gene2go_all.pkl` file. This annotation file is not bundled.
|
| 330 |
-
|
| 331 |
-
The optional `get_high_umi_idx` helper requires `high_umi_path` or
|
| 332 |
-
`BIOMOD_HIGH_UMI_PATH` pointing to `genes_with_hi_mean.npy`; that resource is also
|
| 333 |
-
not bundled. Neither helper silently searches an old workstation path.
|
|
|
|
| 1 |
+
# Gene Perturbation Prediction with BioMod
|
| 2 |
+
|
| 3 |
+
This document describes the BioMod gene perturbation workflow (GEARS), using
|
| 4 |
+
the `BioMod` encoder. The
|
| 5 |
+
[BioMod model weights and matching configuration](../../README.md#biomod-model-weights)
|
| 6 |
+
are shared with the other downstream tasks.
|
| 7 |
+
|
| 8 |
+
## Dataset Commands
|
| 9 |
+
|
| 10 |
+
### 1. Bundled dataset: Norman
|
| 11 |
+
|
| 12 |
+
Norman is the only perturbation dataset currently bundled with this repository.
|
| 13 |
+
The following files are present under `data/downstream/final_data/norman/`:
|
| 14 |
+
|
| 15 |
+
| Input | Purpose |
|
| 16 |
+
| --- | --- |
|
| 17 |
+
| `perturb_processed.h5ad` | Processed expression and perturbation annotations. |
|
| 18 |
+
| `data_pyg/cell_graphs.pkl` | Prepared per-cell PyG graph cache. |
|
| 19 |
+
| `splits/norman_simulation_1_0.75.pkl` | Existing simulation split for seed 1 and training-gene fraction 0.75. |
|
| 20 |
+
| `splits/norman_simulation_1_0.75_subgroup.pkl` | Test-condition categories for that simulation split. |
|
| 21 |
+
| `go.csv` | Gene Ontology similarity graph. |
|
| 22 |
+
| `simulation_1_0.75_0.4_20_co_expression_network.csv` | Coexpression graph for the same split and default graph settings. |
|
| 23 |
+
|
| 24 |
+
These files were checked for existence without deserializing the graph cache,
|
| 25 |
+
split files, or model weights. The shared BioMod weights, configuration, module
|
| 26 |
+
JSON, gene list, gene2vec array, and gene-mapping CSV are also present at the paths
|
| 27 |
+
used below.
|
| 28 |
+
|
| 29 |
+
The loader also contains support for other public perturbation datasets, including
|
| 30 |
+
Adamson and Dixit, but their data are not bundled. They require separate data
|
| 31 |
+
preparation or downloading and are not additional ready-to-run local collections.
|
| 32 |
+
|
| 33 |
+
### 2. Run the bundled Norman simulation split
|
| 34 |
+
|
| 35 |
+
Activate the environment described in the [project README](../../README.md), then
|
| 36 |
+
run this command in Bash from the outer repository root containing `BioMod/`,
|
| 37 |
+
`data/`, `model_dependencies/`, and `weight/`. A Linux CUDA/NCCL environment is
|
| 38 |
+
required, including when using Linux through WSL. The backslashes continue the
|
| 39 |
+
command across lines in Bash; they are not PowerShell continuation characters.
|
| 40 |
+
One GPU still requires the distributed launcher. Built-in asset defaults resolve
|
| 41 |
+
from the script location; explicit relative paths resolve from the working
|
| 42 |
+
directory.
|
| 43 |
+
|
| 44 |
+
```bash
|
| 45 |
+
python -m torch.distributed.run --standalone --nproc_per_node=1 \
|
| 46 |
+
BioMod/gene_perturbation/train.py \
|
| 47 |
+
--data_dir data/downstream/final_data \
|
| 48 |
+
--data_name norman \
|
| 49 |
+
--split simulation \
|
| 50 |
+
--seed 1 \
|
| 51 |
+
--train_gene_set_size 0.75 \
|
| 52 |
+
--scfm_hyper_params_path weight/BioMod.pkl \
|
| 53 |
+
--scfm_ckpt_path weight/BioMod.pth \
|
| 54 |
+
--biomod_data_dir model_dependencies/biomod_data_all \
|
| 55 |
+
--gene_mapping_path model_dependencies/gene2ens.csv \
|
| 56 |
+
--scfm_genes_list_path model_dependencies/selected_genes_27k.txt \
|
| 57 |
+
--scfm_gene2vec_file model_dependencies/selected_gene2vec_27k.npy \
|
| 58 |
+
--finetune_method frozen \
|
| 59 |
+
--result_dir tutorial_runs/gene_perturbation_norman \
|
| 60 |
+
--run_name norman_biomod \
|
| 61 |
+
--epochs 20 \
|
| 62 |
+
--batch_size 32 \
|
| 63 |
+
--lr 1e-3
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
The split arguments select the bundled split and graph caches. The explicit
|
| 67 |
+
`--finetune_method frozen` setting selects the frozen pretrained branch described
|
| 68 |
+
in the manuscript; omitting it uses the script's current full-fine-tuning default.
|
| 69 |
+
To use several GPUs, change `--nproc_per_node` to the number of available GPUs.
|
| 70 |
+
|
| 71 |
+
This is a single bundled-data run with example training settings, not a verified
|
| 72 |
+
reproduction of the manuscript's repeated-seed results. The training code selects
|
| 73 |
+
the checkpoint with the lowest validation MSE on the top 20 differentially
|
| 74 |
+
expressed genes and then evaluates that checkpoint on the test split. The stored
|
| 75 |
+
split contents, reported cell counts, and model performance were not revalidated
|
| 76 |
+
by this documentation update.
|
| 77 |
+
|
| 78 |
+
Norman already includes `go.csv`, so no external GO annotation file is required
|
| 79 |
+
for this command. If regenerating a missing GO graph for prepared data, supply a
|
| 80 |
+
compatible `gene2go_all.pkl` through `BIOMOD_GENE2GO_PATH`; that optional annotation
|
| 81 |
+
resource is not bundled. Different seeds or split settings require new split and
|
| 82 |
+
coexpression caches and do not reuse the files listed above.
|
| 83 |
+
|
| 84 |
+
### 3. Arguments
|
| 85 |
+
|
| 86 |
+
**Model arguments** (defaults point to the bundled BioMod assets):
|
| 87 |
+
|
| 88 |
+
- `--scfm_hyper_params_path`: path to the BioMod model configuration file.
|
| 89 |
+
- `--scfm_ckpt_path`: path to the BioMod model weights.
|
| 90 |
+
- `--biomod_data_path` or `--biomod_data_dir`: required only when the model configuration does not already contain module definitions.
|
| 91 |
+
|
| 92 |
+
**Recommended arguments**:
|
| 93 |
+
|
| 94 |
+
- `--gene_mapping_path`: gene mapping file, especially when module data use gene symbols.
|
| 95 |
+
- `--scfm_genes_list_path`: BioMod gene list file.
|
| 96 |
+
- `--scfm_gene2vec_file`: path to the gene2vec file.
|
| 97 |
+
|
| 98 |
+
**Optional arguments**:
|
| 99 |
+
|
| 100 |
+
- `--use_biomod_level`: use module-level features. This is experimental and is not fully supported at the moment.
|
| 101 |
+
- Default: False, meaning gene-level features are used and recommended.
|
| 102 |
+
|
| 103 |
+
## Notebook
|
| 104 |
+
|
| 105 |
+
See the [task notebook](tutorial.ipynb) for a step-by-step workflow.
|
| 106 |
+
|
| 107 |
+
## Files
|
| 108 |
+
|
| 109 |
+
| File or directory | Purpose |
|
| 110 |
+
| --- | --- |
|
| 111 |
+
| [README.md](README.md) | File guide, model details, training commands, and troubleshooting notes. |
|
| 112 |
+
| [tutorial.ipynb](tutorial.ipynb) | Task configuration, execution, and result review in a Jupyter notebook. |
|
| 113 |
+
| [train.py](train.py) | Configure and launch distributed gene perturbation training. |
|
| 114 |
+
| [components/](components/) | Model, data-processing, training, and evaluation helpers. |
|
| 115 |
+
| [components/model.py](components/model.py) | Define the BioMod-backed GEARS model and recover gene-level features. |
|
| 116 |
+
| [components/trainer.py](components/trainer.py) | Manage model training, checkpointing, and evaluation. |
|
| 117 |
+
| [components/dataset.py](components/dataset.py) | Prepare perturbation datasets, splits, and graph data loaders. |
|
| 118 |
+
| [components/data_utils.py](components/data_utils.py) | Compute differential-expression annotations and construct data splits. |
|
| 119 |
+
| [components/inference.py](components/inference.py) | Run inference and compute perturbation prediction metrics. |
|
| 120 |
+
| [components/training_utils.py](components/training_utils.py) | Provide distributed training, checkpoint, logging, and optimization helpers. |
|
| 121 |
+
| [components/utils.py](components/utils.py) | Provide perturbation parsing, gene-network, loss, and prediction utilities. |
|
| 122 |
+
| [components/__init__.py](components/__init__.py) | Mark the helper directory as a Python package. |
|
| 123 |
+
|
| 124 |
+
## Overview
|
| 125 |
+
|
| 126 |
+
This adaptation replaces the original GEARS gene perturbation model based on
|
| 127 |
+
`DualEncoderSCFM` with `BioMod`. The main adaptation points
|
| 128 |
+
are:
|
| 129 |
+
|
| 130 |
+
1. **Model architecture adaptation**: replace the original dual-encoder model with a module-based encoder-only model.
|
| 131 |
+
2. **Data format adaptation**: handle module-based input data.
|
| 132 |
+
3. **Embedding extraction adaptation**: recover gene-level embeddings from module encodings.
|
| 133 |
+
|
| 134 |
+
## Main Adaptations
|
| 135 |
+
|
| 136 |
+
### 1. `SCFM_BioMod` (`components/model.py`)
|
| 137 |
+
|
| 138 |
+
`SCFM_BioMod` wraps `BioMod` and provides these functions:
|
| 139 |
+
|
| 140 |
+
- **Input handling**: reindex input gene expression values to the BioMod gene order.
|
| 141 |
+
- **Module encoding**: obtain module-level encodings from `BioMod`.
|
| 142 |
+
- **Gene embedding recovery**: recover gene-level embeddings from module encodings.
|
| 143 |
+
- For each gene, find all modules that contain it.
|
| 144 |
+
- Average the encodings of those modules to obtain the gene embedding.
|
| 145 |
+
- If a gene is not included in any module, use the global average as a fallback.
|
| 146 |
+
- **Output reindexing**: reindex gene embeddings back to the input gene order.
|
| 147 |
+
|
| 148 |
+
**Key adaptation**:
|
| 149 |
+
|
| 150 |
+
```python
|
| 151 |
+
# Recover gene-level embeddings from module encodings.
|
| 152 |
+
for gene_idx in range(len(self.scfm_index_positions) - 1):
|
| 153 |
+
if gene_idx in self.gene_to_modules:
|
| 154 |
+
module_indices = self.gene_to_modules[gene_idx]
|
| 155 |
+
module_embs = module_encodings[:, module_indices, :] # B, num_modules_for_gene, D
|
| 156 |
+
gene_emb = module_embs.mean(dim=1) # B, D
|
| 157 |
+
else:
|
| 158 |
+
gene_emb = module_encodings.mean(dim=1) # B, D (global average)
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
### 2. `GEARS_Model_BioMod` (`components/model.py`)
|
| 162 |
+
|
| 163 |
+
`GEARS_Model_BioMod` inherits the original GEARS architecture. Main changes:
|
| 164 |
+
|
| 165 |
+
- **Use `SCFM_BioMod`** instead of the original `SCFM_different_genes`.
|
| 166 |
+
- **Module data loading** supports loading module data from hyper-parameters or file paths.
|
| 167 |
+
- **Other components remain unchanged**, including the GNN layers and decoder.
|
| 168 |
+
|
| 169 |
+
### 3. Training Script (`train.py`)
|
| 170 |
+
|
| 171 |
+
The training script is based on `GEARS/train_dual_ddp_reduce_dec.py`. Main changes:
|
| 172 |
+
|
| 173 |
+
- **Model class**: use `GEARS_Model_BioMod` instead of `GEARS_Model_Acc`.
|
| 174 |
+
- **New arguments**:
|
| 175 |
+
- `--biomod_data_path`: path to one module JSON file.
|
| 176 |
+
- `--biomod_data_dir`: directory containing module JSON files.
|
| 177 |
+
- `--gene_mapping_path`: CSV file mapping gene symbols to Ensembl IDs.
|
| 178 |
+
|
| 179 |
+
## Comparison with Original sclong
|
| 180 |
+
|
| 181 |
+
### Main Differences
|
| 182 |
+
|
| 183 |
+
1. **Model architecture**:
|
| 184 |
+
- **Original sclong**: uses `DualEncoderSCFM` and directly processes gene sequences.
|
| 185 |
+
- **Module version**: uses `BioMod` and processes module-based data.
|
| 186 |
+
|
| 187 |
+
2. **Data representation**:
|
| 188 |
+
- **Original sclong**: gene-level embeddings come directly from encoder outputs.
|
| 189 |
+
- **Module version**: gene-level embeddings are recovered from module encodings by mean pooling.
|
| 190 |
+
|
| 191 |
+
3. **Input format**:
|
| 192 |
+
- **Original sclong**: directly inputs gene expression vectors.
|
| 193 |
+
- **Module version**: keeps the same external input format but internally processes data with module embeddings.
|
| 194 |
+
|
| 195 |
+
### Performance Comparison
|
| 196 |
+
|
| 197 |
+
To compare model performance:
|
| 198 |
+
|
| 199 |
+
1. **Run original scLong** using its own documentation and a separate checkout
|
| 200 |
+
of the upstream GEARS code. That external workflow is not bundled here.
|
| 201 |
+
|
| 202 |
+
2. **Run BioMod** using the complete
|
| 203 |
+
[Norman simulation command](#2-run-the-bundled-norman-simulation-split) above.
|
| 204 |
+
|
| 205 |
+
3. **Compare metrics**:
|
| 206 |
+
|
| 207 |
+
- MSE (Mean Squared Error)
|
| 208 |
+
- Pearson correlation
|
| 209 |
+
- MSE and Pearson correlation for the top 20 DE genes
|
| 210 |
+
- Direction accuracy and related metrics
|
| 211 |
+
|
| 212 |
+
Results are saved under each `result_dir`. Compare these metrics to evaluate the
|
| 213 |
+
module version.
|
| 214 |
+
|
| 215 |
+
## Technical Details
|
| 216 |
+
|
| 217 |
+
### Module-to-Gene Mapping
|
| 218 |
+
|
| 219 |
+
In `SCFM_BioMod`, `gene_to_modules` records which modules contain each gene:
|
| 220 |
+
|
| 221 |
+
```python
|
| 222 |
+
self.gene_to_modules = {} # {gene_idx: [module_idx1, module_idx2, ...]}
|
| 223 |
+
for module_idx, module_genes in enumerate(module_sets):
|
| 224 |
+
for gene_idx in module_genes:
|
| 225 |
+
if gene_idx < len(scfm_genes):
|
| 226 |
+
if gene_idx not in self.gene_to_modules:
|
| 227 |
+
self.gene_to_modules[gene_idx] = []
|
| 228 |
+
self.gene_to_modules[gene_idx].append(module_idx)
|
| 229 |
+
```
|
| 230 |
+
|
| 231 |
+
### Gene Embedding Recovery Strategy
|
| 232 |
+
|
| 233 |
+
For each gene:
|
| 234 |
+
|
| 235 |
+
1. If the gene appears in some modules, average the encodings of those modules.
|
| 236 |
+
2. If the gene does not appear in any module, use the global average of all modules as a fallback.
|
| 237 |
+
|
| 238 |
+
This strategy:
|
| 239 |
+
|
| 240 |
+
- Makes full use of module information.
|
| 241 |
+
- Provides a reasonable embedding for genes absent from all modules.
|
| 242 |
+
- Keeps embedding dimensionality similar to the original model.
|
| 243 |
+
|
| 244 |
+
## File Structure
|
| 245 |
+
|
| 246 |
+
```text
|
| 247 |
+
BioMod/gene_perturbation/ # Perturbation response prediction
|
| 248 |
+
├── components/ # Model, data, training, and evaluation helpers
|
| 249 |
+
│ ├── __init__.py
|
| 250 |
+
│ ├── data_utils.py
|
| 251 |
+
│ ├── dataset.py
|
| 252 |
+
│ ├── inference.py
|
| 253 |
+
│ ├── model.py
|
| 254 |
+
│ ├── trainer.py
|
| 255 |
+
│ ├── training_utils.py
|
| 256 |
+
│ └── utils.py
|
| 257 |
+
├── README.md
|
| 258 |
+
├── train.py
|
| 259 |
+
└── tutorial.ipynb
|
| 260 |
+
```
|
| 261 |
+
|
| 262 |
+
## Notes
|
| 263 |
+
|
| 264 |
+
1. **Module data format**: make sure the gene indices or names in the module data match the BioMod gene list.
|
| 265 |
+
2. **Gene mapping**: provide `gene_mapping_path` if the module data use gene symbols.
|
| 266 |
+
3. **Memory usage**: the module version may require more memory because it maintains the module-to-gene mapping.
|
| 267 |
+
4. **Training stability**: use the same learning rate and training strategy as original sclong when possible.
|
| 268 |
+
|
| 269 |
+
## Troubleshooting
|
| 270 |
+
|
| 271 |
+
### Issue 1: Module Data Not Found
|
| 272 |
+
|
| 273 |
+
- Check whether `--biomod_data_path` or `--biomod_data_dir` is correct.
|
| 274 |
+
- Make sure the module data file exists and has the expected format.
|
| 275 |
+
|
| 276 |
+
### Issue 2: Gene Mapping Failed
|
| 277 |
+
|
| 278 |
+
- Check whether `--gene_mapping_path` is correct.
|
| 279 |
+
- Make sure the gene mapping file is a CSV containing `Approved symbol` and `Ensembl gene ID` columns.
|
| 280 |
+
|
| 281 |
+
### Issue 3: Model Loading Failed
|
| 282 |
+
|
| 283 |
+
- Check whether the checkpoint path is correct.
|
| 284 |
+
- Make sure `hyper_params` contains the required module information.
|
| 285 |
+
|
| 286 |
+
## Gene-Based vs Module-Based Methods
|
| 287 |
+
|
| 288 |
+
This implementation supports two feature extraction modes controlled by
|
| 289 |
+
`--use_biomod_level`.
|
| 290 |
+
|
| 291 |
+
### Method 1: Gene-Based (Default, Recommended)
|
| 292 |
+
|
| 293 |
+
Use the complete [Norman simulation command](#2-run-the-bundled-norman-simulation-split)
|
| 294 |
+
above. It uses gene-level recovery by omitting `--use_biomod_level`; this is a
|
| 295 |
+
boolean switch, so do not append a value such as `False`.
|
| 296 |
+
|
| 297 |
+
**Characteristics**:
|
| 298 |
+
|
| 299 |
+
- Recovers gene-level embeddings from module encodings.
|
| 300 |
+
- Fully compatible with the original GEARS architecture.
|
| 301 |
+
- Downstream tasks operate at gene level, including the GNN and decoder.
|
| 302 |
+
- Outputs gene-level predictions.
|
| 303 |
+
|
| 304 |
+
### Method 2: Module-Based (Experimental, Not Fully Implemented)
|
| 305 |
+
|
| 306 |
+
The `--use_biomod_level` switch selects an experimental mode whose downstream
|
| 307 |
+
architecture is incomplete. It is not included in the runnable
|
| 308 |
+
[Norman simulation command](#2-run-the-bundled-norman-simulation-split). Use the
|
| 309 |
+
default gene-level workflow for the bundled dataset.
|
| 310 |
+
|
| 311 |
+
**Characteristics**:
|
| 312 |
+
|
| 313 |
+
- Directly uses module-level encodings.
|
| 314 |
+
- Preserves the full module-level information.
|
| 315 |
+
- **Note**: module-level downstream tasks are not fully implemented in the current version.
|
| 316 |
+
- Requires redesigning the downstream architecture, including the GNN and decoder.
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
## References
|
| 320 |
+
|
| 321 |
+
- Original GEARS code is an external reference and is not included in this source directory.
|
| 322 |
+
- BioMod model: `BioMod/models_biomod.py`
|
| 323 |
+
- Module data processing: `BioMod/biomod_dataset.py`
|
| 324 |
+
|
| 325 |
+
## Optional external annotation resources
|
| 326 |
+
|
| 327 |
+
The bundled Norman data include `go.csv`. If that network must be regenerated,
|
| 328 |
+
provide `gene2go_path` to `get_go_auto` or set `BIOMOD_GENE2GO_PATH` to the
|
| 329 |
+
appropriate `gene2go_all.pkl` file. This annotation file is not bundled.
|
| 330 |
+
|
| 331 |
+
The optional `get_high_umi_idx` helper requires `high_umi_path` or
|
| 332 |
+
`BIOMOD_HIGH_UMI_PATH` pointing to `genes_with_hi_mean.npy`; that resource is also
|
| 333 |
+
not bundled. Neither helper silently searches an old workstation path.
|
BioMod/zero_shot_batch/README.md
CHANGED
|
@@ -1,187 +1,187 @@
|
|
| 1 |
-
# BioMod Zero-Shot Embeddings and Batch-Effect Evaluation
|
| 2 |
-
|
| 3 |
-
This directory contains code for extracting BioMod cell embeddings and
|
| 4 |
-
evaluating batch effects without fine-tuning. Use the
|
| 5 |
-
[BioMod model weights and matching configuration](../../README.md#biomod-model-weights).
|
| 6 |
-
|
| 7 |
-
##
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
The
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
--
|
| 72 |
-
--
|
| 73 |
-
--
|
| 74 |
-
--
|
| 75 |
-
--
|
| 76 |
-
--
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
--
|
| 93 |
-
--
|
| 94 |
-
--
|
| 95 |
-
--
|
| 96 |
-
--
|
| 97 |
-
--
|
| 98 |
-
--
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
--
|
| 114 |
-
--
|
| 115 |
-
--
|
| 116 |
-
--
|
| 117 |
-
--
|
| 118 |
-
--
|
| 119 |
-
--
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
## Outputs and Metric Definitions
|
| 144 |
-
|
| 145 |
-
Each output directory contains:
|
| 146 |
-
|
| 147 |
-
- `sclong_module_batch_cell_emb_mode.csv`: metrics with `metric`, `label` and
|
| 148 |
-
`value` columns.
|
| 149 |
-
- `sclong_module_batch_cell_emb_mode_ce.npy`: one embedding row per processed
|
| 150 |
-
input cell, before the metric-only removal of missing batch/label values.
|
| 151 |
-
|
| 152 |
-
With `--metrics_mode scgpt`, the script reports individual scIB metrics plus:
|
| 153 |
-
|
| 154 |
-
- `avg_bio = (NMI_cluster/label + ARI_cluster/label + ASW_label) / 3`.
|
| 155 |
-
- `avg_batch = (graph_conn + ASW_label/batch) / 2`.
|
| 156 |
-
|
| 157 |
-
The manuscript defines `avg_score = 0.6 * avg_bio + 0.4 * avg_batch`, but the
|
| 158 |
-
current entry point does not write an `avg_score` row. Compute that aggregate
|
| 159 |
-
from the two reported values when needed; do not mistake `ASW_label/batch`
|
| 160 |
-
alone for the overall score. `--metrics_mode simple` computes only the batch
|
| 161 |
-
silhouette metric and is not the manuscript's complete metric bundle.
|
| 162 |
-
|
| 163 |
-
The manuscript reports five runs with seeds 0–4. This entry point has no general
|
| 164 |
-
`--seed` argument or five-run driver. The existing `--shuffle_seed` controls an
|
| 165 |
-
optional gene-to-module reshuffling experiment; it is not an evaluation seed
|
| 166 |
-
and must not be used as a substitute. Reproducing the reported run-to-run
|
| 167 |
-
variation requires the original randomization protocol.
|
| 168 |
-
|
| 169 |
-
## Gene Alignment and Optional Workflows
|
| 170 |
-
|
| 171 |
-
The gene column is mapped to the model vocabulary, with unavailable model genes
|
| 172 |
-
filled with zero. `--gene_col` takes an actual `adata.var` column name; to use
|
| 173 |
-
`var.index`, omit this argument with `--dataset_preset auto`. The optional
|
| 174 |
-
`lung` preset supplies `gene_name`, `sample` and `cell_type`, while the examples
|
| 175 |
-
above make every field explicit.
|
| 176 |
-
|
| 177 |
-
Keep saved embedding rows aligned with the original input when plotting.
|
| 178 |
-
The [task notebook](tutorial.ipynb) provides result-review cells, and
|
| 179 |
-
[tools/](tools/) contains standalone plotting and sequencing-depth workflows.
|
| 180 |
-
Reduced-depth evaluation is an additional analysis, not a fifth integration
|
| 181 |
-
condition in the manuscript. The supplied counts layers and any source file
|
| 182 |
-
must remain unchanged unless a separate preprocessing task is explicitly chosen.
|
| 183 |
-
|
| 184 |
-
The remaining bundled H5AD files serve the documented
|
| 185 |
-
[annotation benchmarks](../cell_annotation/README.md#dataset-commands) and
|
| 186 |
-
[gene perturbation task](../gene_perturbation/README.md); their presence does not
|
| 187 |
-
establish additional manuscript integration benchmarks.
|
|
|
|
| 1 |
+
# BioMod Zero-Shot Embeddings and Batch-Effect Evaluation
|
| 2 |
+
|
| 3 |
+
This directory contains code for extracting BioMod cell embeddings and
|
| 4 |
+
evaluating batch effects without fine-tuning. Use the
|
| 5 |
+
[BioMod model weights and matching configuration](../../README.md#biomod-model-weights).
|
| 6 |
+
|
| 7 |
+
## Dataset Commands
|
| 8 |
+
|
| 9 |
+
The manuscript evaluates three atlases under four conditions: hPNC, BMMC, and
|
| 10 |
+
Kim Lung with and without malignant cells. Each command below evaluates one
|
| 11 |
+
complete bundled file with `--n_cells all`, max pooling and the scIB metric
|
| 12 |
+
bundle selected by `--metrics_mode scgpt`. These choices follow manuscript
|
| 13 |
+
Section 4.6 (PDF page 25). No additional gene or cell filtering is enabled.
|
| 14 |
+
|
| 15 |
+
Run from the outer repository root after installing the environment. Each
|
| 16 |
+
condition has a separate output directory. A batch size of 1 limits the per-step
|
| 17 |
+
inference memory requirement; all cells are still processed. This is a launch
|
| 18 |
+
setting, not a batch size reported in the manuscript. The complete expression
|
| 19 |
+
matrix and metric calculations can still require substantial host memory.
|
| 20 |
+
|
| 21 |
+
The command blocks use Bash line continuations (`\`). Run them in Bash, such as
|
| 22 |
+
Linux, WSL or Git Bash. In PowerShell, join each command into a single line
|
| 23 |
+
instead of copying the Bash continuation characters.
|
| 24 |
+
|
| 25 |
+
The encoder receives only expression values, not batch or cell-type labels.
|
| 26 |
+
The batch and label fields below are used for evaluation after embedding
|
| 27 |
+
extraction. The entry point reads `adata.X` without additional normalization or
|
| 28 |
+
`log1p`; it does not select counts layers or `.raw`. The commands establish
|
| 29 |
+
file/field wiring, not preprocessing correctness or reproduced performance.
|
| 30 |
+
|
| 31 |
+
| Condition | Cells embedded | Genes in file | Label field | Batch field | Observed batches |
|
| 32 |
+
| --- | ---: | ---: | --- | --- | ---: |
|
| 33 |
+
| [hPNC](#1-hpnc) | 16,382 | 19,093 | `celltype` | `tech` | 9 |
|
| 34 |
+
| [BMMC](#2-bmmc) | 90,261 | 14,087 | `cell_type` | `batch` | 12 |
|
| 35 |
+
| [Kim Lung, malignant cells retained](#3-kim-lung-malignant-cells-retained) | 32,493 | 20,793 | `cell_type` | `sample` | 14 |
|
| 36 |
+
| [Kim Lung, malignant cells removed](#4-kim-lung-malignant-cells-removed) | 21,955 | 20,793 | `cell_type` | `sample` | 14 |
|
| 37 |
+
|
| 38 |
+
### 1. hPNC
|
| 39 |
+
|
| 40 |
+
Use the 16,382-cell pancreas atlas, not the paired `hp14/` files used for
|
| 41 |
+
annotation. Its `tech` field contains nine observed values: `celseq`, `celseq2`,
|
| 42 |
+
`fluidigmc1`, `inDrop1`–`inDrop4`, `smarter` and `smartseq2`. The manuscript states
|
| 43 |
+
six batches. No six-batch harmonization is defined in the current entry point;
|
| 44 |
+
this command evaluates the nine values stored in the file and must not be
|
| 45 |
+
presented as a verified six-batch reproduction.
|
| 46 |
+
|
| 47 |
+
```bash
|
| 48 |
+
python BioMod/zero_shot_batch/evaluate.py \
|
| 49 |
+
--data_path data/downstream/final_data/human_pancreas_norm_complexBatch_with_gene_name.h5ad \
|
| 50 |
+
--dataset_preset auto --gene_col gene_name --batch_key tech --label_key celltype \
|
| 51 |
+
--scfm_ckpt_path weight/BioMod.pth --scfm_hyper_params_path weight/BioMod.pkl \
|
| 52 |
+
--biomod_data_dir model_dependencies/biomod_data_all \
|
| 53 |
+
--gene2vec_path model_dependencies/selected_gene2vec_27k.npy \
|
| 54 |
+
--gene_mapping_path model_dependencies/gene2ens.csv \
|
| 55 |
+
--scfm_genes_file model_dependencies/selected_genes_27k.txt \
|
| 56 |
+
--n_cells all --batch_size 1 --pool_method max --metrics_mode scgpt \
|
| 57 |
+
--min_genes_per_cell 0 --min_cells_per_gene 0 \
|
| 58 |
+
--output_dir tutorial_runs/zero_shot_hPNC
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
### 2. BMMC
|
| 62 |
+
|
| 63 |
+
Use the stored `gene_id` column, which decodes to Ensembl identifiers, and the
|
| 64 |
+
45 observed `cell_type` classes. The gene column has 98 missing entries and 36
|
| 65 |
+
duplicate nonmissing identifiers. The current mapping leaves missing IDs
|
| 66 |
+
unmapped and uses the last input column for duplicate IDs; it does not aggregate
|
| 67 |
+
duplicates. These existing input semantics have not been changed.
|
| 68 |
+
|
| 69 |
+
```bash
|
| 70 |
+
python BioMod/zero_shot_batch/evaluate.py \
|
| 71 |
+
--data_path data/downstream/final_data/BMMC_processed.h5ad \
|
| 72 |
+
--dataset_preset auto --gene_col gene_id --batch_key batch --label_key cell_type \
|
| 73 |
+
--scfm_ckpt_path weight/BioMod.pth --scfm_hyper_params_path weight/BioMod.pkl \
|
| 74 |
+
--biomod_data_dir model_dependencies/biomod_data_all \
|
| 75 |
+
--gene2vec_path model_dependencies/selected_gene2vec_27k.npy \
|
| 76 |
+
--gene_mapping_path model_dependencies/gene2ens.csv \
|
| 77 |
+
--scfm_genes_file model_dependencies/selected_genes_27k.txt \
|
| 78 |
+
--n_cells all --batch_size 1 --pool_method max --metrics_mode scgpt \
|
| 79 |
+
--min_genes_per_cell 0 --min_cells_per_gene 0 \
|
| 80 |
+
--output_dir tutorial_runs/zero_shot_bmmc
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
### 3. Kim Lung: Malignant Cells Retained
|
| 84 |
+
|
| 85 |
+
All 32,493 cells receive embeddings. The file has 10 observed cell-type labels
|
| 86 |
+
and 2,021 unlabeled cells. The evaluator excludes cells with missing labels from
|
| 87 |
+
metrics, so 30,472 cells remain for labeled evaluation. This metadata exclusion
|
| 88 |
+
does not remove rows from the input file or the saved embedding array.
|
| 89 |
+
|
| 90 |
+
```bash
|
| 91 |
+
python BioMod/zero_shot_batch/evaluate.py \
|
| 92 |
+
--data_path data/downstream/final_data/Kim2020_Lung.h5ad \
|
| 93 |
+
--dataset_preset auto --gene_col gene_name --batch_key sample --label_key cell_type \
|
| 94 |
+
--scfm_ckpt_path weight/BioMod.pth --scfm_hyper_params_path weight/BioMod.pkl \
|
| 95 |
+
--biomod_data_dir model_dependencies/biomod_data_all \
|
| 96 |
+
--gene2vec_path model_dependencies/selected_gene2vec_27k.npy \
|
| 97 |
+
--gene_mapping_path model_dependencies/gene2ens.csv \
|
| 98 |
+
--scfm_genes_file model_dependencies/selected_genes_27k.txt \
|
| 99 |
+
--n_cells all --batch_size 1 --pool_method max --metrics_mode scgpt \
|
| 100 |
+
--min_genes_per_cell 0 --min_cells_per_gene 0 \
|
| 101 |
+
--output_dir tutorial_runs/zero_shot_kim_lung
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
### 4. Kim Lung: Malignant Cells Removed
|
| 105 |
+
|
| 106 |
+
Use the existing 21,955-cell file with malignant cells already excluded. It
|
| 107 |
+
retains nine observed cell-type labels and the same 2,021 unlabeled cells, giving
|
| 108 |
+
19,934 cells for labeled evaluation. The command does not modify or regenerate
|
| 109 |
+
either lung file.
|
| 110 |
+
|
| 111 |
+
```bash
|
| 112 |
+
python BioMod/zero_shot_batch/evaluate.py \
|
| 113 |
+
--data_path data/downstream/final_data/Kim2020_Lung_noMalignant.h5ad \
|
| 114 |
+
--dataset_preset auto --gene_col gene_name --batch_key sample --label_key cell_type \
|
| 115 |
+
--scfm_ckpt_path weight/BioMod.pth --scfm_hyper_params_path weight/BioMod.pkl \
|
| 116 |
+
--biomod_data_dir model_dependencies/biomod_data_all \
|
| 117 |
+
--gene2vec_path model_dependencies/selected_gene2vec_27k.npy \
|
| 118 |
+
--gene_mapping_path model_dependencies/gene2ens.csv \
|
| 119 |
+
--scfm_genes_file model_dependencies/selected_genes_27k.txt \
|
| 120 |
+
--n_cells all --batch_size 1 --pool_method max --metrics_mode scgpt \
|
| 121 |
+
--min_genes_per_cell 0 --min_cells_per_gene 0 \
|
| 122 |
+
--output_dir tutorial_runs/zero_shot_kim_lung_no_malignant
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
## Notebook
|
| 126 |
+
|
| 127 |
+
See the [task notebook](tutorial.ipynb) for a step-by-step workflow.
|
| 128 |
+
|
| 129 |
+
## Files
|
| 130 |
+
|
| 131 |
+
| File or directory | Purpose |
|
| 132 |
+
| --- | --- |
|
| 133 |
+
| [README.md](README.md) | File guide, evaluation commands, arguments, and output descriptions. |
|
| 134 |
+
| [tutorial.ipynb](tutorial.ipynb) | Task configuration, execution, and result review in a Jupyter notebook. |
|
| 135 |
+
| [evaluate.py](evaluate.py) | Extract BioMod cell embeddings and evaluate cell-type and batch-effect metrics. |
|
| 136 |
+
| [tools/](tools/) | Optional visualization and sequencing-depth analysis helpers. |
|
| 137 |
+
| [tools/visualize_results.py](tools/visualize_results.py) | Plot saved embeddings and compare batch ASW metrics. |
|
| 138 |
+
| [tools/sequencing_depth/](tools/sequencing_depth/) | Generate reduced-depth inputs and compare zero-shot evaluation results. |
|
| 139 |
+
| [tools/sequencing_depth/make_low_depth_h5ad.py](tools/sequencing_depth/make_low_depth_h5ad.py) | Create reduced-depth h5ad datasets by thinning raw integer counts. |
|
| 140 |
+
| [tools/sequencing_depth/run_zero_shot_low_depth.py](tools/sequencing_depth/run_zero_shot_low_depth.py) | Run evaluation over multiple input datasets and summarize the results. |
|
| 141 |
+
| [tools/sequencing_depth/README.md](tools/sequencing_depth/README.md) | Commands for the sequencing-depth evaluation workflow. |
|
| 142 |
+
|
| 143 |
+
## Outputs and Metric Definitions
|
| 144 |
+
|
| 145 |
+
Each output directory contains:
|
| 146 |
+
|
| 147 |
+
- `sclong_module_batch_cell_emb_mode.csv`: metrics with `metric`, `label` and
|
| 148 |
+
`value` columns.
|
| 149 |
+
- `sclong_module_batch_cell_emb_mode_ce.npy`: one embedding row per processed
|
| 150 |
+
input cell, before the metric-only removal of missing batch/label values.
|
| 151 |
+
|
| 152 |
+
With `--metrics_mode scgpt`, the script reports individual scIB metrics plus:
|
| 153 |
+
|
| 154 |
+
- `avg_bio = (NMI_cluster/label + ARI_cluster/label + ASW_label) / 3`.
|
| 155 |
+
- `avg_batch = (graph_conn + ASW_label/batch) / 2`.
|
| 156 |
+
|
| 157 |
+
The manuscript defines `avg_score = 0.6 * avg_bio + 0.4 * avg_batch`, but the
|
| 158 |
+
current entry point does not write an `avg_score` row. Compute that aggregate
|
| 159 |
+
from the two reported values when needed; do not mistake `ASW_label/batch`
|
| 160 |
+
alone for the overall score. `--metrics_mode simple` computes only the batch
|
| 161 |
+
silhouette metric and is not the manuscript's complete metric bundle.
|
| 162 |
+
|
| 163 |
+
The manuscript reports five runs with seeds 0–4. This entry point has no general
|
| 164 |
+
`--seed` argument or five-run driver. The existing `--shuffle_seed` controls an
|
| 165 |
+
optional gene-to-module reshuffling experiment; it is not an evaluation seed
|
| 166 |
+
and must not be used as a substitute. Reproducing the reported run-to-run
|
| 167 |
+
variation requires the original randomization protocol.
|
| 168 |
+
|
| 169 |
+
## Gene Alignment and Optional Workflows
|
| 170 |
+
|
| 171 |
+
The gene column is mapped to the model vocabulary, with unavailable model genes
|
| 172 |
+
filled with zero. `--gene_col` takes an actual `adata.var` column name; to use
|
| 173 |
+
`var.index`, omit this argument with `--dataset_preset auto`. The optional
|
| 174 |
+
`lung` preset supplies `gene_name`, `sample` and `cell_type`, while the examples
|
| 175 |
+
above make every field explicit.
|
| 176 |
+
|
| 177 |
+
Keep saved embedding rows aligned with the original input when plotting.
|
| 178 |
+
The [task notebook](tutorial.ipynb) provides result-review cells, and
|
| 179 |
+
[tools/](tools/) contains standalone plotting and sequencing-depth workflows.
|
| 180 |
+
Reduced-depth evaluation is an additional analysis, not a fifth integration
|
| 181 |
+
condition in the manuscript. The supplied counts layers and any source file
|
| 182 |
+
must remain unchanged unless a separate preprocessing task is explicitly chosen.
|
| 183 |
+
|
| 184 |
+
The remaining bundled H5AD files serve the documented
|
| 185 |
+
[annotation benchmarks](../cell_annotation/README.md#dataset-commands) and
|
| 186 |
+
[gene perturbation task](../gene_perturbation/README.md); their presence does not
|
| 187 |
+
establish additional manuscript integration benchmarks.
|
README.md
CHANGED
|
@@ -101,6 +101,36 @@ to end with the bundled checkpoint.
|
|
| 101 |
| Drug-pair synergy classification | [Training script](BioMod/drug_combination/train.py) | [Notebook](BioMod/drug_combination/tutorial.ipynb) |
|
| 102 |
| Gene perturbation response prediction | [Training script](BioMod/gene_perturbation/train.py) | [Notebook](BioMod/gene_perturbation/tutorial.ipynb) |
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
### Pretraining
|
| 105 |
|
| 106 |
The repository also supports pretraining and continued pretraining.
|
|
|
|
| 101 |
| Drug-pair synergy classification | [Training script](BioMod/drug_combination/train.py) | [Notebook](BioMod/drug_combination/tutorial.ipynb) |
|
| 102 |
| Gene perturbation response prediction | [Training script](BioMod/gene_perturbation/train.py) | [Notebook](BioMod/gene_perturbation/tutorial.ipynb) |
|
| 103 |
|
| 104 |
+
### Commands by dataset
|
| 105 |
+
|
| 106 |
+
Each row below links to a separate, complete launch command for that task and
|
| 107 |
+
dataset or condition. Commands specify the input paths and output directory;
|
| 108 |
+
you do not need to adapt a command from another dataset. Run them in Bash from
|
| 109 |
+
the outer repository root after activating the environment. Read any
|
| 110 |
+
dataset-specific input caveats before launching.
|
| 111 |
+
|
| 112 |
+
| Task | Dataset or condition | Launch command |
|
| 113 |
+
| --- | --- | --- |
|
| 114 |
+
| Cell annotation | Kim Lung | [Complete command](BioMod/cell_annotation/README.md#1-kim-lung) |
|
| 115 |
+
| Cell annotation | Immune | [Complete command](BioMod/cell_annotation/README.md#2-immune) |
|
| 116 |
+
| Cell annotation | Liver | [Complete command](BioMod/cell_annotation/README.md#3-liver) |
|
| 117 |
+
| Cell annotation | MS (paired train/test files) | [Complete command](BioMod/cell_annotation/README.md#4-ms) |
|
| 118 |
+
| Cell annotation | hPancreas (hp14 paired files) | [Complete command](BioMod/cell_annotation/README.md#5-hpancreas) |
|
| 119 |
+
| Cell annotation | Zheng68K | [Complete command](BioMod/cell_annotation/README.md#6-zheng68k) |
|
| 120 |
+
| Cell annotation | Myeloid (reference/query files) | [Complete command](BioMod/cell_annotation/README.md#7-myeloid) |
|
| 121 |
+
| Zero-shot evaluation | hPNC | [Complete command](BioMod/zero_shot_batch/README.md#1-hpnc) |
|
| 122 |
+
| Zero-shot evaluation | BMMC | [Complete command](BioMod/zero_shot_batch/README.md#2-bmmc) |
|
| 123 |
+
| Zero-shot evaluation | Kim Lung: malignant cells retained | [Complete command](BioMod/zero_shot_batch/README.md#3-kim-lung-malignant-cells-retained) |
|
| 124 |
+
| Zero-shot evaluation | Kim Lung: malignant cells removed | [Complete command](BioMod/zero_shot_batch/README.md#4-kim-lung-malignant-cells-removed) |
|
| 125 |
+
| Single-drug response | GDSC-CCLE joint inputs | [Complete command](BioMod/drug_response/README.md#run-the-bundled-gdsc-ccle-collection) |
|
| 126 |
+
| Drug-combination synergy | Bundled training and validation collection | [Complete command](BioMod/drug_combination/README.md#run-the-bundled-training-and-validation-collection) |
|
| 127 |
+
| Gene perturbation | Norman | [Complete command](BioMod/gene_perturbation/README.md#2-run-the-bundled-norman-simulation-split) |
|
| 128 |
+
|
| 129 |
+
Paired training/test files and complementary drug/cell inputs belong to one
|
| 130 |
+
run configuration. Historical reference copies do not add datasets. The
|
| 131 |
+
[optional drug-combination cross-validation command](BioMod/drug_combination/README.md#optional-five-fold-cross-validation-on-the-same-collection)
|
| 132 |
+
uses the same collection under a different validation protocol.
|
| 133 |
+
|
| 134 |
### Pretraining
|
| 135 |
|
| 136 |
The repository also supports pretraining and continued pretraining.
|