pertlens 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pertlens-0.1.0/PKG-INFO +123 -0
- pertlens-0.1.0/README.md +105 -0
- pertlens-0.1.0/pertlens/__init__.py +67 -0
- pertlens-0.1.0/pertlens/api.py +515 -0
- pertlens-0.1.0/pertlens/data.py +211 -0
- pertlens-0.1.0/pertlens/engine.py +199 -0
- pertlens-0.1.0/pertlens/evaluation.py +323 -0
- pertlens-0.1.0/pertlens/kre.py +153 -0
- pertlens-0.1.0/pertlens/losses.py +117 -0
- pertlens-0.1.0/pertlens/masking.py +33 -0
- pertlens-0.1.0/pertlens/mce.py +186 -0
- pertlens-0.1.0/pertlens/pipeline.py +249 -0
- pertlens-0.1.0/pertlens/utils.py +89 -0
- pertlens-0.1.0/pertlens.egg-info/PKG-INFO +123 -0
- pertlens-0.1.0/pertlens.egg-info/SOURCES.txt +18 -0
- pertlens-0.1.0/pertlens.egg-info/dependency_links.txt +1 -0
- pertlens-0.1.0/pertlens.egg-info/requires.txt +9 -0
- pertlens-0.1.0/pertlens.egg-info/top_level.txt +1 -0
- pertlens-0.1.0/pyproject.toml +28 -0
- pertlens-0.1.0/setup.cfg +4 -0
pertlens-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pertlens
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Generalizable transcriptional response prediction with PertLens
|
|
5
|
+
Project-URL: Repository, https://github.com/yongzhuangliulab/PertLens
|
|
6
|
+
Project-URL: Data, https://doi.org/10.5281/zenodo.24596160
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: torch==2.11.0
|
|
10
|
+
Requires-Dist: numpy==2.2.6
|
|
11
|
+
Requires-Dist: scipy==1.15.3
|
|
12
|
+
Requires-Dist: pandas==2.3.3
|
|
13
|
+
Requires-Dist: scikit-learn==1.7.2
|
|
14
|
+
Requires-Dist: scanpy==1.11.5
|
|
15
|
+
Requires-Dist: anndata==0.11.4
|
|
16
|
+
Requires-Dist: h5py==3.16.0
|
|
17
|
+
Requires-Dist: tqdm==4.67.3
|
|
18
|
+
|
|
19
|
+
# PertLens
|
|
20
|
+
|
|
21
|
+
## ⚙️ Installation
|
|
22
|
+
|
|
23
|
+
Clone the repository:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
git clone https://github.com/yongzhuangliulab/PertLens.git
|
|
27
|
+
cd PertLens
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 🧩 Core API Interface
|
|
31
|
+
|
|
32
|
+
You can use PertLens as follows:
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from pertlens import PertLens
|
|
36
|
+
|
|
37
|
+
model = PertLens(device="cuda")
|
|
38
|
+
model.fit(
|
|
39
|
+
x_ctrl_train=x_ctrl_train,
|
|
40
|
+
perturbations_train=pert_train,
|
|
41
|
+
x_true_train=x_true_train,
|
|
42
|
+
save_dir="save_models/example",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
x_pred = model.predict(x_ctrl=x_ctrl_test, perturbations=pert_test)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
## 🗂️ Repository structure
|
|
50
|
+
|
|
51
|
+
| Directory | Contents |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| `pertlens/` | Core implementation |
|
|
54
|
+
| `scripts/` | Experiment, ablation, and visualization scripts |
|
|
55
|
+
| `data/` | Input datasets |
|
|
56
|
+
| `anndata/` | Prediction outputs |
|
|
57
|
+
| `results/` | Evaluation results |
|
|
58
|
+
| `save_models/` | Trained models |
|
|
59
|
+
| `figures/` | Generated figures |
|
|
60
|
+
|
|
61
|
+
## 🧬 Data
|
|
62
|
+
|
|
63
|
+
Download data.zip from https://doi.org/10.5281/zenodo.24596160 and extract it into the repository root. The archive contains the three datasets used in the PertLens experiments: Adamson, sci-Plex3, and PBMC.
|
|
64
|
+
|
|
65
|
+
- **Adamson:** Originally introduced by [Adamson et al. (2016)](https://doi.org/10.1016/j.cell.2016.11.048); processed data and associated files are from [biolord](https://doi.org/10.1038/s41587-023-02079-x) and [GEARS](https://doi.org/10.1038/s41587-023-01905-6).
|
|
66
|
+
- **sci-Plex3:** Originally introduced by [Srivatsan et al. (2020)](https://doi.org/10.1126/science.aax6234); the processed data are from [biolord](https://doi.org/10.1038/s41587-023-02079-x).
|
|
67
|
+
- **PBMC:** Originally introduced by [Kang et al. (2018)](https://doi.org/10.1038/nbt.4042); the data follow the version used by [scGen](https://doi.org/10.1038/s41592-019-0494-8).
|
|
68
|
+
|
|
69
|
+
## 🔬 Demos
|
|
70
|
+
|
|
71
|
+
Run experiment scripts from the `scripts/` directory. Baseline methods may require additional environments, external repositories, or pretrained models. Experiment outputs are saved under `anndata/`, `results/`, and `save_models/`; existing files at the same paths may be overwritten.
|
|
72
|
+
|
|
73
|
+
### Adamson
|
|
74
|
+
|
|
75
|
+
| Name | Description |
|
|
76
|
+
| --- | --- |
|
|
77
|
+
| [PertLens](scripts/adamson_run_PertLens.py) | Training and evaluation. |
|
|
78
|
+
| [Perturbed Mean](scripts/adamson_run_PerturbedMean.py) | Baseline evaluation. |
|
|
79
|
+
| [PCA-LM](scripts/adamson_run_AhlmannLinear.py) | Baseline fitting and evaluation. |
|
|
80
|
+
| [GEARS](scripts/adamson_run_GEARS.py) | Training and evaluation. |
|
|
81
|
+
| [biolord](scripts/adamson_run_Biolord.py) | Training and evaluation. |
|
|
82
|
+
| [scGPT](scripts/adamson_run_scGPT.py) | Fine-tuning and evaluation. |
|
|
83
|
+
| [Doloris](scripts/adamson_run_Doloris.py) | Training and evaluation. |
|
|
84
|
+
|
|
85
|
+
### sci-Plex3
|
|
86
|
+
|
|
87
|
+
| Name | Description |
|
|
88
|
+
| --- | --- |
|
|
89
|
+
| [PertLens](scripts/sciplex3_run_PertLens.py) | Training and evaluation. |
|
|
90
|
+
| [Perturbed Mean](scripts/sciplex3_run_PerturbedMean.py) | Baseline evaluation. |
|
|
91
|
+
| [chemCPA](scripts/sciplex3_run_chemCPA.py) | Training and evaluation. |
|
|
92
|
+
| [biolord](scripts/sciplex3_run_Biolord.py) | Training and evaluation. |
|
|
93
|
+
| [CellFlow](scripts/sciplex3_run_CellFlow.py) | Training and evaluation. |
|
|
94
|
+
| [Doloris](scripts/sciplex3_run_Doloris.py) | Training and evaluation. |
|
|
95
|
+
|
|
96
|
+
### PBMC
|
|
97
|
+
|
|
98
|
+
| Name | Description |
|
|
99
|
+
| --- | --- |
|
|
100
|
+
| [PertLens](scripts/pbmc_run_PertLens.py) | Training and evaluation. |
|
|
101
|
+
| [Identity](scripts/pbmc_run_Identity.py) | Baseline evaluation. |
|
|
102
|
+
| [MeanDelta](scripts/pbmc_run_MeanDelta.py) | Baseline evaluation. |
|
|
103
|
+
| [scGen](scripts/pbmc_run_scGen.py) | Training and evaluation. |
|
|
104
|
+
| [biolord](scripts/pbmc_run_Biolord.py) | Training and evaluation. |
|
|
105
|
+
| [PrePR-CT](scripts/pbmc_run_PrePRCT.py) | Training and evaluation. |
|
|
106
|
+
|
|
107
|
+
### Ablation studies
|
|
108
|
+
|
|
109
|
+
| Name | Description |
|
|
110
|
+
| --- | --- |
|
|
111
|
+
| [Encoder and estimator](scripts/ablation_encoder_head.py) | Encoder and estimator variants across datasets. |
|
|
112
|
+
| [Dose encoding](scripts/ablation_dose_encoding.py) | Dose-encoding variants on sci-Plex3. |
|
|
113
|
+
| [RKGM](scripts/ablation_rkgm.py) | RKGM variants across datasets. |
|
|
114
|
+
| [Representation geometry](scripts/ablation_rkgm_geometry.py) | sci-Plex3 representations with and without RKGM. |
|
|
115
|
+
|
|
116
|
+
### Visualization
|
|
117
|
+
|
|
118
|
+
| Name | Description |
|
|
119
|
+
| --- | --- |
|
|
120
|
+
| [Adamson plots](scripts/adamson_plot.ipynb) | Visualize Adamson results. |
|
|
121
|
+
| [sci-Plex3 plots](scripts/sciplex3_plot.ipynb) | Visualize sci-Plex3 results. |
|
|
122
|
+
| [PBMC plots](scripts/pbmc_plot.ipynb) | Visualize PBMC results. |
|
|
123
|
+
|
pertlens-0.1.0/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# PertLens
|
|
2
|
+
|
|
3
|
+
## ⚙️ Installation
|
|
4
|
+
|
|
5
|
+
Clone the repository:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://github.com/yongzhuangliulab/PertLens.git
|
|
9
|
+
cd PertLens
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 🧩 Core API Interface
|
|
13
|
+
|
|
14
|
+
You can use PertLens as follows:
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
from pertlens import PertLens
|
|
18
|
+
|
|
19
|
+
model = PertLens(device="cuda")
|
|
20
|
+
model.fit(
|
|
21
|
+
x_ctrl_train=x_ctrl_train,
|
|
22
|
+
perturbations_train=pert_train,
|
|
23
|
+
x_true_train=x_true_train,
|
|
24
|
+
save_dir="save_models/example",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
x_pred = model.predict(x_ctrl=x_ctrl_test, perturbations=pert_test)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
## 🗂️ Repository structure
|
|
32
|
+
|
|
33
|
+
| Directory | Contents |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| `pertlens/` | Core implementation |
|
|
36
|
+
| `scripts/` | Experiment, ablation, and visualization scripts |
|
|
37
|
+
| `data/` | Input datasets |
|
|
38
|
+
| `anndata/` | Prediction outputs |
|
|
39
|
+
| `results/` | Evaluation results |
|
|
40
|
+
| `save_models/` | Trained models |
|
|
41
|
+
| `figures/` | Generated figures |
|
|
42
|
+
|
|
43
|
+
## 🧬 Data
|
|
44
|
+
|
|
45
|
+
Download data.zip from https://doi.org/10.5281/zenodo.24596160 and extract it into the repository root. The archive contains the three datasets used in the PertLens experiments: Adamson, sci-Plex3, and PBMC.
|
|
46
|
+
|
|
47
|
+
- **Adamson:** Originally introduced by [Adamson et al. (2016)](https://doi.org/10.1016/j.cell.2016.11.048); processed data and associated files are from [biolord](https://doi.org/10.1038/s41587-023-02079-x) and [GEARS](https://doi.org/10.1038/s41587-023-01905-6).
|
|
48
|
+
- **sci-Plex3:** Originally introduced by [Srivatsan et al. (2020)](https://doi.org/10.1126/science.aax6234); the processed data are from [biolord](https://doi.org/10.1038/s41587-023-02079-x).
|
|
49
|
+
- **PBMC:** Originally introduced by [Kang et al. (2018)](https://doi.org/10.1038/nbt.4042); the data follow the version used by [scGen](https://doi.org/10.1038/s41592-019-0494-8).
|
|
50
|
+
|
|
51
|
+
## 🔬 Demos
|
|
52
|
+
|
|
53
|
+
Run experiment scripts from the `scripts/` directory. Baseline methods may require additional environments, external repositories, or pretrained models. Experiment outputs are saved under `anndata/`, `results/`, and `save_models/`; existing files at the same paths may be overwritten.
|
|
54
|
+
|
|
55
|
+
### Adamson
|
|
56
|
+
|
|
57
|
+
| Name | Description |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| [PertLens](scripts/adamson_run_PertLens.py) | Training and evaluation. |
|
|
60
|
+
| [Perturbed Mean](scripts/adamson_run_PerturbedMean.py) | Baseline evaluation. |
|
|
61
|
+
| [PCA-LM](scripts/adamson_run_AhlmannLinear.py) | Baseline fitting and evaluation. |
|
|
62
|
+
| [GEARS](scripts/adamson_run_GEARS.py) | Training and evaluation. |
|
|
63
|
+
| [biolord](scripts/adamson_run_Biolord.py) | Training and evaluation. |
|
|
64
|
+
| [scGPT](scripts/adamson_run_scGPT.py) | Fine-tuning and evaluation. |
|
|
65
|
+
| [Doloris](scripts/adamson_run_Doloris.py) | Training and evaluation. |
|
|
66
|
+
|
|
67
|
+
### sci-Plex3
|
|
68
|
+
|
|
69
|
+
| Name | Description |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| [PertLens](scripts/sciplex3_run_PertLens.py) | Training and evaluation. |
|
|
72
|
+
| [Perturbed Mean](scripts/sciplex3_run_PerturbedMean.py) | Baseline evaluation. |
|
|
73
|
+
| [chemCPA](scripts/sciplex3_run_chemCPA.py) | Training and evaluation. |
|
|
74
|
+
| [biolord](scripts/sciplex3_run_Biolord.py) | Training and evaluation. |
|
|
75
|
+
| [CellFlow](scripts/sciplex3_run_CellFlow.py) | Training and evaluation. |
|
|
76
|
+
| [Doloris](scripts/sciplex3_run_Doloris.py) | Training and evaluation. |
|
|
77
|
+
|
|
78
|
+
### PBMC
|
|
79
|
+
|
|
80
|
+
| Name | Description |
|
|
81
|
+
| --- | --- |
|
|
82
|
+
| [PertLens](scripts/pbmc_run_PertLens.py) | Training and evaluation. |
|
|
83
|
+
| [Identity](scripts/pbmc_run_Identity.py) | Baseline evaluation. |
|
|
84
|
+
| [MeanDelta](scripts/pbmc_run_MeanDelta.py) | Baseline evaluation. |
|
|
85
|
+
| [scGen](scripts/pbmc_run_scGen.py) | Training and evaluation. |
|
|
86
|
+
| [biolord](scripts/pbmc_run_Biolord.py) | Training and evaluation. |
|
|
87
|
+
| [PrePR-CT](scripts/pbmc_run_PrePRCT.py) | Training and evaluation. |
|
|
88
|
+
|
|
89
|
+
### Ablation studies
|
|
90
|
+
|
|
91
|
+
| Name | Description |
|
|
92
|
+
| --- | --- |
|
|
93
|
+
| [Encoder and estimator](scripts/ablation_encoder_head.py) | Encoder and estimator variants across datasets. |
|
|
94
|
+
| [Dose encoding](scripts/ablation_dose_encoding.py) | Dose-encoding variants on sci-Plex3. |
|
|
95
|
+
| [RKGM](scripts/ablation_rkgm.py) | RKGM variants across datasets. |
|
|
96
|
+
| [Representation geometry](scripts/ablation_rkgm_geometry.py) | sci-Plex3 representations with and without RKGM. |
|
|
97
|
+
|
|
98
|
+
### Visualization
|
|
99
|
+
|
|
100
|
+
| Name | Description |
|
|
101
|
+
| --- | --- |
|
|
102
|
+
| [Adamson plots](scripts/adamson_plot.ipynb) | Visualize Adamson results. |
|
|
103
|
+
| [sci-Plex3 plots](scripts/sciplex3_plot.ipynb) | Visualize sci-Plex3 results. |
|
|
104
|
+
| [PBMC plots](scripts/pbmc_plot.ipynb) | Visualize PBMC results. |
|
|
105
|
+
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from .mce import MaskedContextEncoder, ScalarEncoder, DoseEncoder
|
|
2
|
+
from .data import (
|
|
3
|
+
PertLensDataset,
|
|
4
|
+
build_pertlens_loader,
|
|
5
|
+
split_train_val_arrays,
|
|
6
|
+
make_pert_labels,
|
|
7
|
+
normalize_perturbations,
|
|
8
|
+
)
|
|
9
|
+
from .kre import (
|
|
10
|
+
gaussian_kernel,
|
|
11
|
+
kernel_ridge_regression,
|
|
12
|
+
kernel_ridge_regression_eq,
|
|
13
|
+
predict_krr,
|
|
14
|
+
fit_kre_per_gene,
|
|
15
|
+
predict_kre_per_gene,
|
|
16
|
+
)
|
|
17
|
+
from .api import (
|
|
18
|
+
train_mce,
|
|
19
|
+
fit_kre,
|
|
20
|
+
predict_pertlens,
|
|
21
|
+
load_mce,
|
|
22
|
+
)
|
|
23
|
+
from .pipeline import PertLens
|
|
24
|
+
from .losses import compute_mce_loss, response_kernel_geometry_matching_loss
|
|
25
|
+
from .evaluation import (
|
|
26
|
+
compute_metrics_adamson,
|
|
27
|
+
convert_to_serializable,
|
|
28
|
+
mean_expr_to_torch,
|
|
29
|
+
compute_metrics_sciplex3,
|
|
30
|
+
compute_metrics_pbmc,
|
|
31
|
+
)
|
|
32
|
+
from .utils import compress_by_perturbation
|
|
33
|
+
|
|
34
|
+
__all__ = [
|
|
35
|
+
# MCE
|
|
36
|
+
"MaskedContextEncoder",
|
|
37
|
+
"ScalarEncoder",
|
|
38
|
+
"DoseEncoder",
|
|
39
|
+
"PertLens",
|
|
40
|
+
# data
|
|
41
|
+
"PertLensDataset",
|
|
42
|
+
"build_pertlens_loader",
|
|
43
|
+
"split_train_val_arrays",
|
|
44
|
+
"make_pert_labels",
|
|
45
|
+
"normalize_perturbations",
|
|
46
|
+
"compress_by_perturbation",
|
|
47
|
+
# KRE
|
|
48
|
+
"gaussian_kernel",
|
|
49
|
+
"kernel_ridge_regression",
|
|
50
|
+
"kernel_ridge_regression_eq",
|
|
51
|
+
"predict_krr",
|
|
52
|
+
"fit_kre_per_gene",
|
|
53
|
+
"predict_kre_per_gene",
|
|
54
|
+
# end-to-end API
|
|
55
|
+
"train_mce",
|
|
56
|
+
"fit_kre",
|
|
57
|
+
"predict_pertlens",
|
|
58
|
+
"load_mce",
|
|
59
|
+
"compute_mce_loss",
|
|
60
|
+
"response_kernel_geometry_matching_loss",
|
|
61
|
+
# evaluation
|
|
62
|
+
"compute_metrics_adamson",
|
|
63
|
+
"convert_to_serializable",
|
|
64
|
+
"mean_expr_to_torch",
|
|
65
|
+
"compute_metrics_sciplex3",
|
|
66
|
+
"compute_metrics_pbmc",
|
|
67
|
+
]
|