File size: 12,380 Bytes
27f8132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# CLI Commands

All RECOVAR commands follow the pattern `recovar <command> [arguments]`.

Project mode is the standard workflow: pass `--project <dir>` (or run from inside a project), let RECOVAR place outputs in stable numbered directories such as `Pipeline/job_0001/`, and use project metadata for readable names in the CLI and GUI. Standalone explicit paths remain supported.

## Main workflow

| Command | Description |
|---------|-------------|
| `pipeline` | Run the full heterogeneity analysis pipeline |
| `analyze` | Post-pipeline analysis (k-means, volumes, UMAP) |
| `gui` | Launch the web GUI (default: `http://localhost:8080`) |
| `quickstart` | Interactive wizard for pipeline setup |
| `init_project` | Initialize a project directory with auto-numbered jobs |
| `project_status` | Show status of all jobs in a project |
| `downsample` | Pre-downsample images to disk |
| `parse_relion5_tomo` | Convert RELION5 tilt-series data to 2D tilt format |

## Volume generation

| Command | Description |
|---------|-------------|
| `compute_state` | Generate volumes at specific latent coordinates |
| `compute_trajectory` | Compute trajectories and generate volume series |

## Particle selection

| Command | Description |
|---------|-------------|
| `extract_image_subset` | Extract particles based on volume features |
| `extract_image_subset_from_kmeans` | Extract particles from k-means clusters |

## Density estimation

| Command | Description |
|---------|-------------|
| `estimate_conformational_density` | Estimate probability density in latent space |
| `estimate_stable_states` | Identify stable conformational states |

## Quality control

| Command | Description |
|---------|-------------|
| `outlier_detection` | Detect outlier particles |
| `junk_particle_detection` | Detect junk particles |
| `pipeline_with_outliers` | Combined pipeline + outlier detection |

## Advanced

| Command | Description |
|---------|-------------|
| `reconstruct_from_external_embedding` | Volume generation from external latent spaces |
| `postprocess` | Post-processing and output refinement |

## Diagnostics

| Command | Description |
|---------|-------------|
| `check_paths` | Preview how image paths resolve without running the pipeline |
| `build_custom_cuda` | Pre-build the custom CUDA backproject/project extension |

## Testing

| Command | Description |
|---------|-------------|
| `run_test_dataset` | Quick pipeline test on synthetic data |
| `run_test_all_metrics` | Comprehensive metric testing |
| `make_test_dataset` | Generate synthetic test datasets |

## Getting help

For any command:

```bash
recovar <command> -h
```

---

## `pipeline`

Run the full heterogeneity analysis pipeline.

```bash
recovar pipeline particles.star --mask mask.mrc --project .
# or: recovar pipeline particles.star -o output --mask mask.mrc [options]
```

See [Running the Pipeline](../guide/pipeline.md) for full documentation.

---

## `analyze`

Post-pipeline analysis: k-means clustering, volume generation, UMAP, trajectories.

```bash
recovar analyze --zdim=10 --project .
# or: recovar analyze result_dir --zdim=10 [options]
```

| Flag | Default | Description |
|------|---------|-------------|
| `--zdim` | Required | Latent dimension (single integer) |
| `-o` | Auto | Output directory |
| `--n-clusters` | 20 | Number of k-means clusters |
| `--n-trajectories` | 0 | Trajectories between cluster pairs |
| `--n-vols-along-path` | 6 | Volumes per trajectory |
| `--density` | None | Density `.pkl` file for trajectory guidance |
| `--Bfactor` | 0 | B-factor sharpening |
| `--n-bins` | 50 | Bins for kernel regression |
| `--maskrad-fraction` | 20 | Kernel radius = `grid_size / value` |
| `--skip-umap` | False | Skip UMAP (recommended for >200k particles) |
| `--skip-centers` | False | Skip cluster center volumes |
| `--normalize-kmeans` | False | Normalize z before k-means |
| `--no-z-regularization` | False | Use unregularized z |
| `--lazy` | False | Lazy loading |
| `--particles` | Same | Higher-resolution particle stack (overrides pipeline stack) |
| `--datadir` | Same | Path prefix for particle paths |
| `--strip-prefix` | None | Strip prefix from paths in star file |
| `--apply-global-filtering` | False | Apply global FSC filtering to half-maps |

---

## `downsample`

Pre-downsample particle images to disk via Fourier cropping.

```bash
recovar downsample particles.star -D 128 --project . --output-name particles_d128
# or: recovar downsample particles.star -D 128 -o downsampled/ [options]
```

| Flag | Default | Description |
|------|---------|-------------|
| `-D`, `--target-D` | Required | Target box size (even integer) |
| `-o`, `--outdir` | Auto in project mode | Output directory |
| `--datadir` | None | Base directory for image paths |
| `--strip-prefix` | None | Strip prefix from paths |
| `--batch-size` | 1000 | Images per batch |
| `--chunk-size` | None | Accepted but not yet wired up — output is always a single stack |

See [Downsampling](../guide/downsampling.md) for details.

---

## `compute_state`

Generate volumes at specific latent space coordinates.

```bash
recovar compute_state result_dir -o volumes --latent-points coords.txt [options]
```

| Flag | Default | Description |
|------|---------|-------------|
| `--latent-points` | Required | Coordinates file (`.txt`) |
| `-o`, `--outdir` | Auto (project mode) | Output directory; auto-numbered when a project is active |
| `--Bfactor` | 0 | B-factor sharpening |
| `--n-bins` | 50 | Bins for kernel regression |
| `--maskrad-fraction` | 20 | Kernel radius = `grid_size / value` |
| `--n-min-particles` | None (100 internally) | Minimum particles for regression |
| `--particles` | Same | Higher-resolution particle stack |
| `--datadir` | Same | Path prefix for particles |
| `--zdim1` | False | Enable for 1D latent space |

---

## `compute_trajectory`

Compute high-density trajectories through latent space with volume series.

```bash
recovar compute_trajectory result_dir -o trajectory --zdim=10 \
    --endpts centers.txt --ind 0,1 [options]
```

### Endpoint specification (one required)

| Flags | Description |
|-------|-------------|
| `--endpts FILE --ind 0,1` | Lines from coordinate file |
| `--endpts FILE` | First two lines of file |
| `--z_st FILE --z_end FILE` | Separate start/end files |

### Options

| Flag | Default | Description |
|------|---------|-------------|
| `--zdim` | Auto | Latent dimension; inferred if only one is available, otherwise pass it explicitly |
| `-o`, `--outdir` | Auto (project mode) | Output directory; auto-numbered when a project is active |
| `--density` | None | Density file for high-density path |
| `--n-vols-along-path` | 6 | Volumes along the path |
| `--Bfactor` | 0 | B-factor sharpening |
| `--n-bins` | 50 | Bins for kernel regression |
| `--maskrad-fraction` | 20 | Kernel radius parameter |

---

## `estimate_conformational_density`

Estimate probability density in latent space using deconvolution.

```bash
recovar estimate_conformational_density result_dir [options]
```

| Flag | Default | Description |
|------|---------|-------------|
| `--pca_dim` | 4 | PCA dimensions for density estimation |
| `--z_dim_used` | Auto | Latent dimension to use (smallest zdim >= pca_dim) |
| `--output_dir` | Auto | Output directory |
| `--percentile_reject` | 10 | Reject % of data with large covariance |
| `--num_disc_points` | Auto | Grid points per dimension (50 for dim>3, 100 for dim=3, 200 for dim=2) |
| `--alphas` | Auto | Regularization values (space-separated) |

!!! note
    Runtime scales exponentially with `--pca_dim`. Keep it at 4 or below.

---

## `extract_image_subset`

Extract particles that produced a specific volume feature.

```bash
recovar extract_image_subset vol_dir --output indices.pkl [selection]
```

Selection (one required):

| Flag | Description |
|------|-------------|
| `--mask mask.mrc` | Select by mask center of mass |
| `--coordinate x,y,z` | Select by pixel coordinates |
| `--subvol-idx N` | Select by subvolume index |

---

## `extract_image_subset_from_kmeans`

Extract particles from k-means clusters.

```bash
recovar extract_image_subset_from_kmeans kmeans_result.pkl subset.pkl 0,1,2 [-i]
```

The positional order is `<centers.pkl> <output.pkl> <indices>`. The output path **must end in `.pkl`**.

| Argument | Description |
|----------|-------------|
| `kmeans_result.pkl` | Path to `data/kmeans_result.pkl` from analyze |
| `output.pkl` | Output `.pkl` file for the selected indices. In project mode, pass `--project` and the file is auto-placed as `indices.pkl` in a numbered job directory |
| `indices` | Comma-separated cluster indices (e.g. `0,1,2`) |
| `-i`, `--inverse` | Invert selection (keep clusters *not* listed) |

---

## `parse_relion5_tomo`

Convert RELION5 tilt-series data to RECOVAR's 2D tilt format.

```bash
recovar parse_relion5_tomo \
    -t Polish/job249/tomograms.star \
    -p Extract/job260/particles.star \
    -o particles_2d.star
```

| Flag | Default | Description |
|------|---------|-------------|
| `-t`, `--tomograms` | Required | RELION5 `tomograms.star` (from Polish or Tomograms job) |
| `-p`, `--particles` | Required | RELION5 `particles.star` (from Extract or Refine job) |
| `-o`, `--output` | `particles_2d.star` | Output 2D STAR file |
| `-v`, `--verbose` | False | Enable verbose logging |

Tilt image dimensions and pixel size are read from the optics table in `particles.star` — there is no flag to set them.

See [Cryo-ET](../guide/cryo-et.md#importing-from-relion5) for usage details.

---

## `gui`

Launch the web GUI for interactive job management and result exploration.

```bash
recovar gui [options]
```

| Flag | Default | Description |
|------|---------|-------------|
| `--port` | 8080 | Port to bind to (the next free port is used if it is busy) |
| `--host` | 127.0.0.1 | Bind address (`0.0.0.0` for remote access) |
| `--reload` | False | Auto-reload for development |
| `--no-browser` | False | Do not auto-open a browser on launch |
| `--check` | False | Diagnose GUI dependencies, GPU, and SLURM availability, then exit |

See the [GUI Guide](../guide/gui.md) for full documentation.

---

## `init_project`

Initialize a new project directory with auto-numbered job tracking.

```bash
recovar init_project [directory] [--name "Project Name"]
```

| Argument | Default | Description |
|----------|---------|-------------|
| `directory` | `.` | Directory to initialize (created if needed) |
| `--name` | Directory name | Human-readable project name |

Creates a `project.json` index file in the directory. Subsequent commands using `--project` will auto-generate numbered job directories (e.g. `Pipeline/job_0001/`, `Analyze/job_0001/`). (When you open the same directory in the web GUI, the GUI additionally maintains its own `recovar_project.db`.)

---

## `project_status`

Show status of all jobs in a project.

```bash
recovar project_status [directory] [--tree]
```

| Argument | Default | Description |
|----------|---------|-------------|
| `directory` | `.` | Project directory |
| `--tree` | False | Show job dependency tree instead of table |

---

## Common flag: `--project`

All commands that produce output accept `--project <dir>` to enable project mode. This is the recommended way to run RECOVAR. When active, output directories are auto-generated, downstream commands may omit `result_dir` to use the latest completed Pipeline job, and RECOVAR stores human-readable job names alongside the numbered directories. If you run from within a project directory (containing `project.json`), it is auto-detected without needing the flag.

Each job creates `job.json`, `command.txt`, `run.log`, and `README.txt` metadata files.

### Project directory naming

| CLI command | Directory name | Example |
|-------------|----------------|---------|
| `pipeline` | `Pipeline/` | `Pipeline/job_0001/` (alias shown separately in CLI/GUI) |
| `analyze` | `Analyze/` | `Analyze/job_0001/` |
| `compute_state` | `ReconstructState/` | `ReconstructState/job_0001/` |
| `compute_trajectory` | `ReconstructTrajectory/` | `ReconstructTrajectory/job_0001/` |
| `estimate_conformational_density` | `Density/` | `Density/job_0001/` |
| `junk_particle_detection` | `JunkDetection/` | `JunkDetection/job_0001/` |
| `outlier_detection` | `OutlierDetection/` | `OutlierDetection/job_0001/` |