File size: 6,343 Bytes
1078b52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6dd9839
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
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
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
---
license: other
library_name: pytorch
tags:
  - biology
  - rna
  - protein
  - rbp
  - protein-rna-interaction
  - generative-model
  - classification
datasets:
  - sunlab-ai/ProRiboGen-dataset
---

# ProRiboGen β€” Inference Package

Inference-only package for a website / API backend. **No training or test CSVs.**

**ProRiboGen** has two modules:

1. **Generation** β€” protein amino-acid sequence β†’ RNA FASTA + motifs (+ optional logos)
2. **Classification** β€” protein + RNA β†’ binding probability `binding_prob ∈ (0, 1)`

Protein conditioning uses **VESM-3B** (weights live on your GPU server; not shipped here).

Package size β‰ˆ **2.8 GB** (three checkpoints).

---

## Layout

```
ProRiboGen_code/
β”œβ”€β”€ README.md                 # this file
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ configs/
β”‚   β”œβ”€β”€ paths.env.example     # copy β†’ paths.env and edit VESM paths
β”‚   β”œβ”€β”€ sample_fixed80bp.json
β”‚   └── model.json            # classifier backbone / data config
β”œβ”€β”€ checkpoints/
β”‚   β”œβ”€β”€ generator.pt          # ~1.2G  RNA generation module
β”‚   β”œβ”€β”€ backbone.pt           # ~1.2G  MLM backbone for classification
β”‚   └── classifier.pt         # ~477M  binding classifier head + fusion
β”œβ”€β”€ generator/                # Generation module (sample.py + src/ + tokenizer/)
β”œβ”€β”€ classifier/               # Classification module (RnaRealismClassifierV3)
β”œβ”€β”€ protein_encoder/          # AA sequence β†’ VESM H5
β”œβ”€β”€ motif/                    # MEME, HOMER conversion, logo PNGs
β”œβ”€β”€ api/                      # CLI + FastAPI
β”œβ”€β”€ examples/                 # demo protein FASTA
β”œβ”€β”€ scripts/                  # smoke tests
└── workspace/                # runtime outputs (created on demand)
```

### Checkpoint roles

| File | Role |
|------|------|
| `generator.pt` | **Generation only** β€” MaskGIT+ sampling |
| `backbone.pt` | **Classification** β€” build ESM MLM, then load classifier weights |
| `classifier.pt` | **Classification** β€” binding / realism score |

Do **not** use `backbone.pt` for generation. Do **not** use `generator.pt` as the classifier backbone (the classifier was trained on the backbone run).

---

## Setup (another server)

### 1. Dependencies

```bash
cd ProRiboGen_code
python3 -m venv .venv && source .venv/bin/activate   # optional
pip install -r requirements.txt
# Motif discovery needs MEME Suite on PATH (`meme` command).
# Logos need: pip install logomaker matplotlib pandas
```

### 2. Configure VESM

```bash
cp configs/paths.env.example configs/paths.env
# edit configs/paths.env
```

Either:

```bash
# A) Standard 17-VESM3 tree
VESM_ROOT=/path/to/17-VESM3
# expects:
#   $VESM_ROOT/models/base/facebook_esm2_t36_3B_UR50D
#   $VESM_ROOT/models/weights/VESM_3B.pth
```

or:

```bash
# B) Explicit paths (overrides A)
VESM_BASE_MODEL_DIR=/path/to/facebook_esm2_t36_3B_UR50D
VESM_WEIGHTS=/path/to/VESM_3B.pth
DEVICE=cuda:0
```

Checkpoint / tokenizer relative paths in `paths.env` usually need no change.

### 3. Smoke tests

```bash
bash scripts/demo_generate.sh
bash scripts/demo_score.sh

# With a real protein FASTA from this package:
python api/generate_rna_and_motif.py \
  --protein @examples/HS90A_HUMAN_P07900.fasta \
  --num-sequences 32 --length-bp 80

python api/score_binding.py \
  --protein @examples/HS90A_HUMAN_P07900.fasta \
  --rna AUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGC
```

---

## Module 1 β€” Generation (RNA + motifs)

```bash
python api/generate_rna_and_motif.py \
  --protein "MSKSLYVR..." \
  --p-id DemoRBP \
  --num-sequences 64 \
  --length-bp 80
```

Or:

```bash
python api/generate_rna_and_motif.py --protein @/path/to/protein.fasta --num-sequences 64
```

Outputs under `workspace/job_<p_id>/`:

| Path | Meaning |
|------|---------|
| `*_vesm3b.h5` | VESM token embeddings |
| `generated/*.fasta` | Generated RNA |
| `motifs/*/meme.txt` | MEME raw output |
| `homer_motif_matrix/*.motif` | HOMER PWMs |
| `homer_motif_logo/*.png` | Sequence logos (ACGU colors below) |

Skip MEME/logos: `--skip-motif`.

**Logo colors** (same as internal `create_motif_logo.ipynb`):

| Base | Hex |
|------|-----|
| A | `#65a455` |
| C | `#2e45a4` |
| G | `#fda562` |
| U | `#d54f3f` |

Standalone logos:

```bash
python motif/plot_homer_logos.py workspace/job_DemoRBP/homer_motif_matrix workspace/job_DemoRBP/homer_motif_logo
```

Website tip: use `num_sequences=64–256` for latency; paper-style runs use `2048`.

---

## Module 2 β€” Classification (binding probability)

```bash
python api/score_binding.py \
  --protein "MSKSLYVR..." \
  --rna "UGCAUGCGAU..." \
  --p-id DemoRBP
```

Example JSON:

```json
{
  "p_id": "DemoRBP",
  "rna": "UGCAUGCGAU...",
  "rna_len": 80,
  "logit": 1.23,
  "binding_prob": 0.77
}
```

Default decision threshold: `binding_prob >= 0.5` (same as training eval). Reuse a cached H5 with `--protein-h5` to skip re-encoding.

---

## HTTP API

```bash
uvicorn api.app:app --host 0.0.0.0 --port 8000
```

```bash
curl http://127.0.0.1:8000/health

curl -X POST http://127.0.0.1:8000/v1/generate \
  -H 'Content-Type: application/json' \
  -d '{"protein":"MSK...","p_id":"Demo","num_sequences":32,"run_motif":true}'

curl -X POST http://127.0.0.1:8000/v1/score \
  -H 'Content-Type: application/json' \
  -d '{"protein":"MSK...","rna":"UGCA...","p_id":"Demo"}'
```

Frontend only needs these two endpoints; GPU work stays on this service.

---

## Pipeline

```
AA sequence
    β”‚
    β”œβ”€ VESM-3B ─► H5 [L, 2560]
    β”‚
    β”œβ”€ generator.pt (generation) ─► FASTA ─► MEME ─► HOMER ─► PNG logos
    β”‚
    └─ backbone.pt + classifier.pt + RNA ─► binding_prob (classification)
```

No pretrained 337-protein H5 is required; each request encodes VESM on the fly.

---

## Copy to another machine

```bash
rsync -avP ProRiboGen_code/ user@host:/path/ProRiboGen_code/
# or
tar -cf ProRiboGen_code.tar ProRiboGen_code
```

On the new host: install deps β†’ edit `configs/paths.env` β†’ run the smoke scripts.

---

## Hardware / notes

1. Prefer GPU β‰₯ 24 GB (VESM-3B + 12-layer ProRiboGen). Encode then generate/score can be split across steps.
2. Without MEME, use `--skip-motif` (sequences only).
3. `paths.env` is gitignored; ship `paths.env.example` only.
4. Python β‰₯ 3.10 recommended (`list[str]` typing in scripts).