CpGPT 0.0.1__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.
- cpgpt-0.0.1/.project-root +2 -0
- cpgpt-0.0.1/LICENSE +25 -0
- cpgpt-0.0.1/PKG-INFO +31 -0
- cpgpt-0.0.1/README.md +468 -0
- cpgpt-0.0.1/cpgpt/__init__.py +0 -0
- cpgpt-0.0.1/cpgpt/data/__init__.py +17 -0
- cpgpt-0.0.1/cpgpt/data/components/__init__.py +12 -0
- cpgpt-0.0.1/cpgpt/data/components/cpgpt_datasaver.py +742 -0
- cpgpt-0.0.1/cpgpt/data/components/cpgpt_dataset.py +386 -0
- cpgpt-0.0.1/cpgpt/data/components/dna_llm_embedder.py +1023 -0
- cpgpt-0.0.1/cpgpt/data/components/illumina_methylation_prober.py +425 -0
- cpgpt-0.0.1/cpgpt/data/cpgpt_datamodule.py +251 -0
- cpgpt-0.0.1/cpgpt/eval.py +107 -0
- cpgpt-0.0.1/cpgpt/infer/__init__.py +8 -0
- cpgpt-0.0.1/cpgpt/infer/cpgpt_inferencer.py +587 -0
- cpgpt-0.0.1/cpgpt/infer/utils.py +76 -0
- cpgpt-0.0.1/cpgpt/log/__init__.py +6 -0
- cpgpt-0.0.1/cpgpt/log/utils.py +158 -0
- cpgpt-0.0.1/cpgpt/loss/__init__.py +25 -0
- cpgpt-0.0.1/cpgpt/loss/loss.py +585 -0
- cpgpt-0.0.1/cpgpt/model/__init__.py +37 -0
- cpgpt-0.0.1/cpgpt/model/components/__init__.py +21 -0
- cpgpt-0.0.1/cpgpt/model/components/model.py +630 -0
- cpgpt-0.0.1/cpgpt/model/components/modules.py +1095 -0
- cpgpt-0.0.1/cpgpt/model/cpgpt_module.py +1490 -0
- cpgpt-0.0.1/cpgpt/model/cpgpt_module_mortality.py +298 -0
- cpgpt-0.0.1/cpgpt/model/utils.py +219 -0
- cpgpt-0.0.1/cpgpt/train.py +129 -0
- cpgpt-0.0.1/cpgpt/trainer/__init__.py +3 -0
- cpgpt-0.0.1/cpgpt/trainer/cpgpt_trainer.py +198 -0
- cpgpt-0.0.1/cpgpt/utils/__init__.py +24 -0
- cpgpt-0.0.1/cpgpt/utils/instantiators.py +80 -0
- cpgpt-0.0.1/cpgpt/utils/logging_utils.py +110 -0
- cpgpt-0.0.1/cpgpt/utils/pylogger.py +80 -0
- cpgpt-0.0.1/cpgpt/utils/rich_utils.py +299 -0
- cpgpt-0.0.1/cpgpt/utils/utils.py +137 -0
- cpgpt-0.0.1/poetry.lock +8246 -0
- cpgpt-0.0.1/pyproject.toml +123 -0
cpgpt-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
NON-COMMERCIAL LICENSE AGREEMENT
|
|
2
|
+
|
|
3
|
+
CpGPT: A Foundation Model for DNA Methylation
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2024 Lucas Paulo de Lima Camillo and contributors
|
|
6
|
+
|
|
7
|
+
This software and associated documentation files (the "Software") may be used for non-commercial research and educational purposes only. "Non-commercial" means not primarily intended for or directed towards commercial advantage or monetary compensation.
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this Software and associated documentation files, to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, and distribute copies of the Software, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
1. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
2. The Software may not be used for commercial purposes, including but not limited to:
|
|
14
|
+
a. Selling or licensing the Software or derivatives based on the Software
|
|
15
|
+
b. Using the Software to provide services to third parties for monetary compensation
|
|
16
|
+
c. Using the Software in a commercial product or service
|
|
17
|
+
d. Using the model or code to participate in any competition with financial prizes, including but not limited to the Biomarkers of Aging Challenge
|
|
18
|
+
|
|
19
|
+
3. Redistributions in any form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
20
|
+
|
|
21
|
+
4. Publications resulting from the use of this Software must cite the original publication as referenced in the README.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
24
|
+
|
|
25
|
+
For commercial use, please contact Lucas Paulo de Lima Camillo for licensing options.
|
cpgpt-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: CpGPT
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: CpGPT: A Foundation Model for DNA Methylation
|
|
5
|
+
License: Non-commercial
|
|
6
|
+
Author: Lucas Paulo de Lima Camillo
|
|
7
|
+
Author-email: lucas_camillo@alumni.brown.edu
|
|
8
|
+
Requires-Python: >=3.10,<3.13
|
|
9
|
+
Classifier: License :: Other/Proprietary License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Dist: biopython (>=1.84,<2.0)
|
|
15
|
+
Requires-Dist: fastapi (>=0.112.0,<0.115)
|
|
16
|
+
Requires-Dist: hydra-colorlog (>=1.2.0)
|
|
17
|
+
Requires-Dist: hydra-core (>=1.3.2)
|
|
18
|
+
Requires-Dist: lightning (>=2.5.0)
|
|
19
|
+
Requires-Dist: loguru (>=0.7.2)
|
|
20
|
+
Requires-Dist: pyfaidx (>=0.8.1.2)
|
|
21
|
+
Requires-Dist: rich (>=13.8.1)
|
|
22
|
+
Requires-Dist: rootutils (>=1.0.7,<2.0.0)
|
|
23
|
+
Requires-Dist: schedulefree (>=1.4,<2.0)
|
|
24
|
+
Requires-Dist: sqlitedict (>=2.1.0)
|
|
25
|
+
Requires-Dist: torch (>=2.5.0)
|
|
26
|
+
Requires-Dist: torchmetrics (>=1.5.2)
|
|
27
|
+
Requires-Dist: torchtune (==0.3.1)
|
|
28
|
+
Requires-Dist: torchvision (>=0.20.1)
|
|
29
|
+
Requires-Dist: transformers (>=4.44.2)
|
|
30
|
+
Project-URL: homepage, https://github.com/lcamillo/CpGPT
|
|
31
|
+
Project-URL: repository, https://github.com/lcamillo/CpGPT
|
cpgpt-0.0.1/README.md
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# CpGPT: A Foundation Model for DNA Methylation
|
|
4
|
+
|
|
5
|
+
<img src="cpgpt_logo.svg" width="200px" alt="CpGPT Logo">
|
|
6
|
+
|
|
7
|
+
[](https://www.python.org/downloads/)
|
|
8
|
+
[](https://pytorch.org/get-started/locally/)
|
|
9
|
+
[](https://lightning.ai/)
|
|
10
|
+
[](LICENSE)
|
|
11
|
+
[](https://www.biorxiv.org/content/10.1101/2024.10.24.619766v1)
|
|
12
|
+
|
|
13
|
+
[](https://github.com/lcamillo/CpGPT)
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
## 📋 Table of Contents
|
|
18
|
+
|
|
19
|
+
- [📖 Overview](#-overview)
|
|
20
|
+
- [🚀 Quick Setup](#-quick-setup)
|
|
21
|
+
- [🗄️ CpGCorpus](#%EF%B8%8F-cpgcorpus)
|
|
22
|
+
- [🐘 Model Zoo](#-model-zoo)
|
|
23
|
+
- [🧪 Tutorials](#-tutorials)
|
|
24
|
+
- [🔧 Finetuning](#-finetuning)
|
|
25
|
+
- [❓ FAQ](#-faq)
|
|
26
|
+
- [📚 Citation](#-citation)
|
|
27
|
+
- [📜 License](#-license)
|
|
28
|
+
|
|
29
|
+
## 📖 Overview
|
|
30
|
+
|
|
31
|
+
CpGPT is a foundation model for DNA methylation, trained on genome-wide DNA methylation data. It can generate, impute, and embed methylation profiles, and can be finetuned for various downstream tasks.
|
|
32
|
+
|
|
33
|
+
## 🚀 Quick Setup
|
|
34
|
+
|
|
35
|
+
### Prerequisites
|
|
36
|
+
|
|
37
|
+
- Python 3.10+
|
|
38
|
+
- [Poetry](https://python-poetry.org/docs/#installation)
|
|
39
|
+
- AWS CLI (for downloading dependencies)
|
|
40
|
+
|
|
41
|
+
### Installation Instructions
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# Clone the repository
|
|
45
|
+
git clone https://github.com/lcamillo/CpGPT.git
|
|
46
|
+
cd CpGPT
|
|
47
|
+
|
|
48
|
+
# Install poetry if not available
|
|
49
|
+
pip install poetry
|
|
50
|
+
|
|
51
|
+
# Install dependencies with Poetry
|
|
52
|
+
poetry install
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
### Setting up AWS CLI for Dependencies
|
|
57
|
+
|
|
58
|
+
Our pre-trained models and data are stored in AWS S3. If you do not already have an AWS account setup, follow these steps:
|
|
59
|
+
|
|
60
|
+
<details closed>
|
|
61
|
+
<summary><b>1. Create an AWS Account</b></summary>
|
|
62
|
+
|
|
63
|
+
1. Go to [AWS Console](https://aws.amazon.com/) and click "Create an AWS Account" in the top right
|
|
64
|
+
2. Follow the signup process:
|
|
65
|
+
- Provide email and account name
|
|
66
|
+
- Enter your personal/business information
|
|
67
|
+
- Add payment information (a credit card is required, but the downloads follow free tier limits)
|
|
68
|
+
- Complete identity verification (you'll receive a phone call or text)
|
|
69
|
+
- Select a support plan (Free tier is sufficient)
|
|
70
|
+
|
|
71
|
+
</details>
|
|
72
|
+
|
|
73
|
+
<details closed>
|
|
74
|
+
<summary><b>2. Install the AWS CLI</b></summary>
|
|
75
|
+
|
|
76
|
+
**For Linux/macOS:**
|
|
77
|
+
```bash
|
|
78
|
+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
|
|
79
|
+
unzip awscliv2.zip
|
|
80
|
+
sudo ./aws/install
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**For Windows:**
|
|
84
|
+
- Download the [AWS CLI MSI installer](https://awscli.amazonaws.com/AWSCLIV2.msi)
|
|
85
|
+
- Run the downloaded MSI installer and follow the on-screen instructions
|
|
86
|
+
|
|
87
|
+
**Verify installation:**
|
|
88
|
+
```bash
|
|
89
|
+
aws --version
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
</details>
|
|
93
|
+
|
|
94
|
+
<details closed>
|
|
95
|
+
<summary><b>3. Create Access Keys</b></summary>
|
|
96
|
+
|
|
97
|
+
1. Log in to the [AWS Console](https://console.aws.amazon.com/)
|
|
98
|
+
2. Click on your account name in the top right, then "Security credentials"
|
|
99
|
+
3. Scroll down to "Access keys" and click "Create access key"
|
|
100
|
+
4. Select "Command Line Interface (CLI)" as the use case
|
|
101
|
+
5. Check the "I understand..." acknowledgment and click "Next"
|
|
102
|
+
6. **IMPORTANT**: Download the CSV file or copy both the "Access key ID" and "Secret access key" to a secure location. You will not be able to view the secret access key again.
|
|
103
|
+
|
|
104
|
+
</details>
|
|
105
|
+
|
|
106
|
+
<details closed>
|
|
107
|
+
<summary><b>4. Configure AWS CLI</b></summary>
|
|
108
|
+
|
|
109
|
+
Run the following command and enter your credentials when prompted:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
aws configure
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
You'll need to input:
|
|
116
|
+
- **AWS Access Key ID**: The access key ID from step 3
|
|
117
|
+
- **AWS Secret Access Key**: The secret access key from step 3
|
|
118
|
+
- **Default region name**: Enter `us-east-1` (where our data is hosted)
|
|
119
|
+
- **Default output format**: Enter `json`
|
|
120
|
+
|
|
121
|
+
</details>
|
|
122
|
+
|
|
123
|
+
<details closed>
|
|
124
|
+
<summary><b>5. Test Your Configuration</b></summary>
|
|
125
|
+
|
|
126
|
+
Verify your setup with this command that lists the contents (without downloading):
|
|
127
|
+
```bash
|
|
128
|
+
aws s3 ls s3://cpgpt-lucascamillo-public/data/cpgcorpus/raw/ --requester-payer requester
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
You should see a list of GSE folders if your configuration is correct.
|
|
132
|
+
|
|
133
|
+
</details>
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
## 🗄️ CpGCorpus
|
|
137
|
+
|
|
138
|
+
<details closed>
|
|
139
|
+
<summary><b>Download the Full Corpus</b></summary>
|
|
140
|
+
|
|
141
|
+
To download the entire CpGCorpus from our S3 bucket, run the following command:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
aws s3 sync s3://cpgpt-lucascamillo-public/data/cpgcorpus/raw ./data/cpgcorpus/raw --requester-payer requester
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
</details>
|
|
148
|
+
|
|
149
|
+
<details closed>
|
|
150
|
+
<summary><b>Directory Layout</b></summary>
|
|
151
|
+
|
|
152
|
+
The CpGCorpus is organized in a hierarchical structure by GSE (Gene Series) and further by GPL (Platform). Below is an overview of the directory layout and file contents:
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
cpgcorpus/
|
|
156
|
+
└── raw/
|
|
157
|
+
└── {GSE_ID}/
|
|
158
|
+
└── {GPL_ID}/
|
|
159
|
+
├── betas/
|
|
160
|
+
│ ├── QCDPB.arrow # Processed beta values via the R sesame QCDPB pipeline
|
|
161
|
+
│ └── gse_betas.arrow # Raw beta values downloaded from GEO
|
|
162
|
+
└── metadata/
|
|
163
|
+
└── metadata.arrow # Metadata and sample annotations
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
- The "betas" folder contains one of the two files:
|
|
167
|
+
- QCDPB.arrow: Processed data from the R sesame QCDPB pipeline.
|
|
168
|
+
- gse_betas.arrow: Beta values as originally downloaded from GEO.
|
|
169
|
+
- The "metadata" folder stores the metadata.arrow file that holds supplementary experimental details.
|
|
170
|
+
|
|
171
|
+
</details>
|
|
172
|
+
|
|
173
|
+
<details closed>
|
|
174
|
+
<summary><b>Supported Methylation Platforms</b></summary>
|
|
175
|
+
|
|
176
|
+
The corpus includes multiple platforms:
|
|
177
|
+
|
|
178
|
+
- GPL8490 (27k array)
|
|
179
|
+
- GPL13534 (450k)
|
|
180
|
+
- GPL18809 (450k)
|
|
181
|
+
- GPL21145 (EPIC)
|
|
182
|
+
- GPL23976 (EPIC)
|
|
183
|
+
- GPL29753 (EPIC)
|
|
184
|
+
- GPL33022 (EPICv2)
|
|
185
|
+
- GPL34394 (MSA)
|
|
186
|
+
|
|
187
|
+
</details>
|
|
188
|
+
|
|
189
|
+
<details closed>
|
|
190
|
+
<summary><b>Download a specific sample</b></summary>
|
|
191
|
+
|
|
192
|
+
To download a specific dataset (for example, GSE163839 using platform GPL13534), run:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
aws s3 cp s3://cpgpt-lucascamillo-public/data/cpgcorpus/raw/GSE163839/GPL13534/betas/QCDPB.arrow ./data/GSE163839.arrow --requester-payer requester
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
</details>
|
|
199
|
+
|
|
200
|
+
## 🐘 Model Zoo
|
|
201
|
+
|
|
202
|
+
There are several versions of CpGPT, mainly divided into pretrained and finetuned models. Below, you can find a table with a summary of such versions including the path to the model checkpoint.
|
|
203
|
+
|
|
204
|
+
<details open>
|
|
205
|
+
<summary><b>Pre-trained Models</b></summary>
|
|
206
|
+
|
|
207
|
+
| Model | Size | Parameters | Description | Path |
|
|
208
|
+
| ---------- | ----- | ---------- | --------------------------------------------------------------------------------- | --------------------------------------- |
|
|
209
|
+
| CpGPT-2M | 30MB | ~2.5M | Lightweight model for quick experimentation and resource-constrained environments | `dependencies/model/weights/small.ckpt` |
|
|
210
|
+
| CpGPT-100M | 1.1GB | ~101M | Full-size model for state-of-the-art performance and high accuracy | `dependencies/model/weights/large.ckpt` |
|
|
211
|
+
|
|
212
|
+
</details>
|
|
213
|
+
|
|
214
|
+
<details>
|
|
215
|
+
<summary><b>Fine-tuned Models</b></summary>
|
|
216
|
+
|
|
217
|
+
We provide specialized pre-trained models for common tasks:
|
|
218
|
+
|
|
219
|
+
| Model | Parameters | Description | Output | Path |
|
|
220
|
+
| --------------------------- | ---------- | -------------------------------------------------------- | ---------------------------------------------------------------------- | ----------------------------------------------------- |
|
|
221
|
+
| CpGPT-2M-Age | ~2.9M | Multi-tissue chronological age predictor | Age in years | `dependencies/model/weights/age.ckpt` |
|
|
222
|
+
| CpGPT-2M-AverageAdultWeight | ~2.9M | Multi-tissue, pan-mammalian weight predictor | Log1p of average adult weight in kilograms | `dependencies/model/weights/average_adultweight.ckpt` |
|
|
223
|
+
| CpGPT-100M-BoA | ~101M | EPICv2 blood imputation | No phenotype is predicted | `dependencies/model/weights/boa.ckpt` |
|
|
224
|
+
| CpGPT-2M-Cancer | ~2.9M | Multi-tissue cancer predictor | Logits of cancer status (use sigmoid to get probabilities) | `dependencies/model/weights/cancer.ckpt` |
|
|
225
|
+
| CpGPT-2M-ClockProxies | ~3.1M | Blood proxies of five epigenetic clocks | altumage, dunedinpace (x100), grimage2, hrsinchphenoage, pchorvath2013 | `dependencies/model/weights/clock_proxies.ckpt` |
|
|
226
|
+
| CpGPT-2M-EpicMammal | ~2.5M | Blood EPIC-Mammalian array converter | No phenotype is predicted | `dependencies/model/weights/epicvmammal.ckpt` |
|
|
227
|
+
| CpGPT-100M-Hannum | ~101M | 450k blood imputation | No phenotype is predicted | `dependencies/model/weights/hannum.ckpt` |
|
|
228
|
+
| CpGPT-100M-HumanRRBSAtlas | ~101M | Multi-tissue RRBS imputation | No phenotype is predicted | `dependencies/model/weights/human_rrbs_atlas.ckpt` |
|
|
229
|
+
| CpGPT-100M-Mammalian | ~101M | Multi-tissue, pan-mammalian mammalian array imputation | No phenotype is predicted | `dependencies/model/weights/mammalian.ckpt` |
|
|
230
|
+
| CpGPT-2M-MaxLifespan | ~2.9M | Multi-tissue, pan-mammalian max lifespan predictor | Log1p of max lifespan in years | `dependencies/model/weights/maximum_lifespan.ckpt` |
|
|
231
|
+
| CpGPT-2M-Mortality | ~2.9M | Blood mortality predictor. Please use strict_load=False. | Risk score | `dependencies/model/weights/mortality.ckpt` |
|
|
232
|
+
| CpGPT-2M-RelativeAge | ~2.9M | Multi-tissue, pan-mammalian relative age predictor | Relative age (0 to 1) | `dependencies/model/weights/relative_age.ckpt` |
|
|
233
|
+
| CpGPT-100M-sciMETv3 | ~101M | Brain, single-cell imputation | No phenotype is predicted | `dependencies/model/weights/scimetv3.ckpt` |
|
|
234
|
+
|
|
235
|
+
</details>
|
|
236
|
+
|
|
237
|
+
## 🧪 Tutorials
|
|
238
|
+
|
|
239
|
+
More tutorials will be added soon!
|
|
240
|
+
|
|
241
|
+
<div class="tutorial-cards" style="display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; margin-bottom: 20px;">
|
|
242
|
+
<div style="border: 1px solid #ddd; border-radius: 8px; padding: 15px; width: 250px;">
|
|
243
|
+
<h3>🔬 Quick setup</h3>
|
|
244
|
+
<p>Basic introduction to CpGPT and its capabilities</p>
|
|
245
|
+
<a href="tutorials/quick_setup.ipynb">View Tutorial</a>
|
|
246
|
+
</div>
|
|
247
|
+
</div>
|
|
248
|
+
|
|
249
|
+
## 🔧 Finetuning
|
|
250
|
+
|
|
251
|
+
> ⚠️ **Warning**: Fine-tuning CpGPT models requires a GPU. The training process is computationally intensive and will be extremely slow or may fail entirely without GPU acceleration. We recommend at least 8GB of VRAM for the small model and 24GB+ for the large model.
|
|
252
|
+
|
|
253
|
+
<details closed>
|
|
254
|
+
<summary><b>Getting Started</b></summary>
|
|
255
|
+
|
|
256
|
+
1. **Download dependencies** if you have not already done so by following the steps in the <a href="tutorials/quick_setup.ipynb">quick setup tutorial notebook</a>.
|
|
257
|
+
|
|
258
|
+
2. **Prepare your data** by following the steps in the <a href="tutorials/quick_setup.ipynb">quick setup tutorial notebook</a>.
|
|
259
|
+
|
|
260
|
+
</details>
|
|
261
|
+
|
|
262
|
+
<details closed>
|
|
263
|
+
<summary><b>Configuration</b></summary>
|
|
264
|
+
|
|
265
|
+
1. **Create a configuration file** by modifying template in `configs/experiment/`.
|
|
266
|
+
|
|
267
|
+
2. **Run fine-tuning** with the CLI:
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
cpgpt-train experiment=template
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
3. **Get the best checkpoint** in the logs folders:
|
|
274
|
+
|
|
275
|
+
- **Checkpoint weights**: `logs/experiment/{experiment_name}/checkpoints/{experiment_name}.ckpt`
|
|
276
|
+
- **Model config**: `logs/experiment/{experiment_name}/.hydra/config.yaml`
|
|
277
|
+
|
|
278
|
+
</details>
|
|
279
|
+
|
|
280
|
+
### Configuration Guide
|
|
281
|
+
|
|
282
|
+
<details>
|
|
283
|
+
<summary><b>🔍 Model Configuration</b></summary>
|
|
284
|
+
|
|
285
|
+
CpGPT provides several parameters to customize your model architecture and training process:
|
|
286
|
+
|
|
287
|
+
| Parameter | Description | Examples |
|
|
288
|
+
| ----------------- | ----------------------- | -------------------------------------------------- |
|
|
289
|
+
| `model/net` | Model architecture size | `small.yaml`, `large.yaml` |
|
|
290
|
+
| `model/optimizer` | Optimization algorithm | `adamw.yaml`, `adamwscheduleree.yaml`, `lion.yaml` |
|
|
291
|
+
| `model/scheduler` | Learning rate scheduler | `cosine_warmup.yaml`, `constant.yaml` |
|
|
292
|
+
|
|
293
|
+
</details>
|
|
294
|
+
|
|
295
|
+
<details>
|
|
296
|
+
<summary><b>📊 Task-Specific Settings</b></summary>
|
|
297
|
+
|
|
298
|
+
Modify these parameters in your experiment YAML file to customize the model for different tasks:
|
|
299
|
+
|
|
300
|
+
```yaml
|
|
301
|
+
model:
|
|
302
|
+
training:
|
|
303
|
+
# Type of loss function for condition decoder
|
|
304
|
+
condition_decoder_loss: mae # Options: mae, mse, ce
|
|
305
|
+
|
|
306
|
+
# Weighting for the condition loss vs reconstruction
|
|
307
|
+
loss_weights:
|
|
308
|
+
condition_loss: 0.1
|
|
309
|
+
|
|
310
|
+
optimizer:
|
|
311
|
+
# Learning rate
|
|
312
|
+
lr: 0.0001
|
|
313
|
+
|
|
314
|
+
net:
|
|
315
|
+
# Enable the condition decoder for prediction tasks
|
|
316
|
+
use_condition_decoder: true
|
|
317
|
+
|
|
318
|
+
# Number of target variables to predict
|
|
319
|
+
condition_size: 1 # 1 for regression, can be >1 for multi-target
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
</details>
|
|
323
|
+
|
|
324
|
+
<details>
|
|
325
|
+
<summary><b>⚙️ Training Parameters</b></summary>
|
|
326
|
+
|
|
327
|
+
Control the training process with these settings:
|
|
328
|
+
|
|
329
|
+
```yaml
|
|
330
|
+
trainer:
|
|
331
|
+
# Minimum training steps (for warmup)
|
|
332
|
+
min_steps: 2000
|
|
333
|
+
|
|
334
|
+
# Maximum training steps before stopping
|
|
335
|
+
max_steps: 100000
|
|
336
|
+
|
|
337
|
+
data:
|
|
338
|
+
# Batch size for training
|
|
339
|
+
batch_size: 16 # Reduce for large models or limited GPU memory
|
|
340
|
+
|
|
341
|
+
# Data directories
|
|
342
|
+
train_dir: ${paths.data_dir}/mydata/processed/train
|
|
343
|
+
val_dir: ${paths.data_dir}/mydata/processed/val
|
|
344
|
+
test_dir: ${paths.data_dir}/mydata/processed/test
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
</details>
|
|
348
|
+
|
|
349
|
+
<details>
|
|
350
|
+
<summary><b>💾 Checkpointing</b></summary>
|
|
351
|
+
|
|
352
|
+
Configure model saving behavior:
|
|
353
|
+
|
|
354
|
+
```yaml
|
|
355
|
+
callbacks:
|
|
356
|
+
model_checkpoint:
|
|
357
|
+
# Metric to monitor for saving best model
|
|
358
|
+
monitor: "val/condition_loss" # Options: val/loss, val/condition_loss, etc.
|
|
359
|
+
|
|
360
|
+
# Filename pattern for saved checkpoints
|
|
361
|
+
filename: "${tags[0]}" # Uses the first tag as filename
|
|
362
|
+
|
|
363
|
+
# Save mode
|
|
364
|
+
mode: "min" # min for losses, max for metrics like accuracy
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
</details>
|
|
368
|
+
|
|
369
|
+
<details>
|
|
370
|
+
<summary><b>📝 Logging</b></summary>
|
|
371
|
+
|
|
372
|
+
Configure experiment logging with these options:
|
|
373
|
+
|
|
374
|
+
```yaml
|
|
375
|
+
logger:
|
|
376
|
+
# WandB logging
|
|
377
|
+
wandb:
|
|
378
|
+
project: "cpgpt"
|
|
379
|
+
name: "${tags[0]}"
|
|
380
|
+
tags: ${tags}
|
|
381
|
+
group: "${task_name}"
|
|
382
|
+
|
|
383
|
+
# TensorBoard logging
|
|
384
|
+
tensorboard:
|
|
385
|
+
name: "tensorboard"
|
|
386
|
+
save_dir: "logs/tensorboard/"
|
|
387
|
+
|
|
388
|
+
# CSV logging
|
|
389
|
+
csv:
|
|
390
|
+
name: "csv"
|
|
391
|
+
save_dir: "logs/csv/"
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
Available loggers include:
|
|
395
|
+
|
|
396
|
+
- `wandb.yaml`: Weights & Biases for experiment tracking with visualization
|
|
397
|
+
- `tensorboard.yaml`: TensorBoard for local visualization
|
|
398
|
+
- `csv.yaml`: Simple CSV logging for offline analysis
|
|
399
|
+
- `mlflow.yaml`: MLflow for organization-level experiment tracking
|
|
400
|
+
|
|
401
|
+
</details>
|
|
402
|
+
|
|
403
|
+
## ❓ FAQ
|
|
404
|
+
|
|
405
|
+
<details>
|
|
406
|
+
<summary><b>What methylation array platforms are supported?</b></summary>
|
|
407
|
+
CpGPT was pretrained with bulk data from all of the available Illumina arrays, besides the Horvath Mammalian array, at the time of writing. Nevertheless, CpGPT should be able to generalize to new arrays and unseen genomic loci. For RRBS and other types of sequencing-based methylation measurements, finetuning with at least a subset of the data is highly recommended.
|
|
408
|
+
</details>
|
|
409
|
+
|
|
410
|
+
<details>
|
|
411
|
+
<summary><b>How much data do I need to fine-tune CpGPT?</b></summary>
|
|
412
|
+
CpGPT can be fine-tuned with as few as 50-100 samples for simple tasks. For complex tasks or higher accuracy, we recommend 500+ samples.
|
|
413
|
+
</details>
|
|
414
|
+
|
|
415
|
+
<details>
|
|
416
|
+
<summary><b>Should I filter the CpG sites prior to finetuning?</b></summary>
|
|
417
|
+
That depends on the task and the reason for finetuning. For instance, to finetune for a model that does not predict specific phenotypes and is just used to learn whole-genome methylation profiles, then it is best not to filter any features. However, if there is a specific phenotype to be predicted, then using a ridge regression and picking the top N features can speed up the training time required (see below).
|
|
418
|
+
</details>
|
|
419
|
+
|
|
420
|
+
<details>
|
|
421
|
+
<summary><b>How many steps should I finetune it for?</b></summary>
|
|
422
|
+
That ultimately depends on how many samples and how many features are shown to the model. As a rough guide, showing CpGPT each sample-feature combination 50 times works well. For instance, if there are 100 samples with 10,000 CpG sites each, then with a batch size of 10, 100,000 steps would be ideal.
|
|
423
|
+
</details>
|
|
424
|
+
|
|
425
|
+
<details>
|
|
426
|
+
<summary><b>How can I get the very best possible performance?</b></summary>
|
|
427
|
+
One trick that can increase training time substantially but can lead to some minor performance improvements is to change the following parameter in the `template.yaml` file:
|
|
428
|
+
|
|
429
|
+
```yaml
|
|
430
|
+
model:
|
|
431
|
+
training:
|
|
432
|
+
generative_splits: 5
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
The default for that parameter is 2, which effectively means that generative training is not used.
|
|
436
|
+
|
|
437
|
+
</details>
|
|
438
|
+
|
|
439
|
+
<details>
|
|
440
|
+
<summary><b>Can I use CpGPT for commercial purposes?</b></summary>
|
|
441
|
+
The current release is for non-commercial research purposes only. Please contact us for licensing information for commercial use.
|
|
442
|
+
</details>
|
|
443
|
+
|
|
444
|
+
## 📚 Citation
|
|
445
|
+
|
|
446
|
+
If you use CpGPT in your research, please cite our paper:
|
|
447
|
+
|
|
448
|
+
```bibtex
|
|
449
|
+
@article{camillo2024cpgpt,
|
|
450
|
+
title={CpGPT: A Foundation Model for DNA Methylation},
|
|
451
|
+
author={Camillo, Lucas Paulo de Lima et al.},
|
|
452
|
+
journal={bioRxiv},
|
|
453
|
+
year={2024},
|
|
454
|
+
doi={10.1101/2024.10.24.619766},
|
|
455
|
+
url={https://www.biorxiv.org/content/10.1101/2024.10.24.619766v1}
|
|
456
|
+
}
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
## 📜 License
|
|
460
|
+
|
|
461
|
+
This project is licensed for non-commercial research purposes only. See [LICENSE](LICENSE) for details.
|
|
462
|
+
|
|
463
|
+
______________________________________________________________________
|
|
464
|
+
|
|
465
|
+
<div align="center">
|
|
466
|
+
<p>© 2024 Lucas Paulo de Lima Camillo</p>
|
|
467
|
+
<a href="https://twitter.com/lucascamillomd"><img src="https://img.shields.io/twitter/follow/lucascamillomd?style=social" alt="Twitter Follow"></a>
|
|
468
|
+
</div>
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from .components import (
|
|
2
|
+
CpGPTDataSaver,
|
|
3
|
+
CpGPTDataset,
|
|
4
|
+
DNALLMEmbedder,
|
|
5
|
+
IlluminaMethylationProber,
|
|
6
|
+
cpgpt_data_collate,
|
|
7
|
+
)
|
|
8
|
+
from .cpgpt_datamodule import CpGPTDataModule
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"CpGPTDataModule",
|
|
12
|
+
"CpGPTDataSaver",
|
|
13
|
+
"CpGPTDataset",
|
|
14
|
+
"DNALLMEmbedder",
|
|
15
|
+
"IlluminaMethylationProber",
|
|
16
|
+
"cpgpt_data_collate",
|
|
17
|
+
]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from .cpgpt_datasaver import CpGPTDataSaver
|
|
2
|
+
from .cpgpt_dataset import CpGPTDataset, cpgpt_data_collate
|
|
3
|
+
from .dna_llm_embedder import DNALLMEmbedder
|
|
4
|
+
from .illumina_methylation_prober import IlluminaMethylationProber
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"CpGPTDataSaver",
|
|
8
|
+
"CpGPTDataset",
|
|
9
|
+
"DNALLMEmbedder",
|
|
10
|
+
"IlluminaMethylationProber",
|
|
11
|
+
"cpgpt_data_collate",
|
|
12
|
+
]
|