Analysis and comparison with other programs¶
Here we explain how to compute the k-means loss and produce class average galleries for different methods. In principle this works for any STAR file.
1. Convert the results¶
We provide support for conversion for results obtained with cryoSPARC (.cs files) and Xmipp. Although Xmipp outputs a STAR file, its conventions are slightly different.
python scripts/convert_results.py --particles particles.star --program cryosparc \
--result J12_020_particles.cs --out converted/cryosparc_data.star
converts one result to a data.star in RELION's conventions: rlnImageName, rlnClassNumber
(1-based), rlnAnglePsi and rlnOriginX/YAngst, one row per particle in the order of
--particles (the particle STAR file the program was run on). Run it once per result.
--program is one of:
--program |
--result |
conversion |
|---|---|---|
relion |
a RELION run_itNNN_data.star |
copied |
cryosparc |
a cryoSPARC 2D classification particles.cs |
rlnAnglePsi = alignments2D/pose in degrees; origin = alignments2D/shift × pixel size |
xmipp |
an Xmipp xmipp_alignPCA_2D classes_images.star |
rlnAnglePsi = −anglePsi; origin = R(anglePsi) (shiftX, shiftY) × pixel size |
hr2d's own run_itNNN_data.star files are already in RELION's conventions.
2. Compute the k-means loss¶
As a clarification, this is not exactly the k-means loss, but a version that is adapted to cryo-EM 2D classification, \(L(S, A)\) (defined in The loss): $$ L(S, A) = \sum_{k=1}^{K} \sum_{i \in S_k} \lVert x_i - A_i\, \mu(S_k) \rVert^2 $$
python scripts/kmeans_loss.py --data DATASET_STAR --project PROJECT_DIR \
--method HR2D:runs/hr2d --method RELION:relion_data.star --out loss/ [--box 128]
For each result (an hr2d or RELION run folder, scored at the iterations in --iters, or one
data.star), the script rebuilds the least-squares class means from the result's assignments, in-plane angles and in-plane shifts and evaluates the k-means loss
on the whitened images up to Nyquist (or --radius). It writes kmeans_loss.csv with the loss per
particle (column loss_per_particle) of every result and iteration. Lower is better.
3. Galleries, resolutions and agreement¶
-
scripts/class_gallery.py--data STAR --project DIR --method NAME:DATA.star [...] --out OUT: each method's classes, rebuilt the same way, sorted by size, with half-set FRC resolutions (NAME_classes.png,NAME_class_resolution.csv,summary.csv). Pass--image_sign dark-on-lightfor dark particles. These figures are merely for visualization purposes, resolution might vary as we do not consider a MAP approach like in expectation–maximization. -
scripts/nmi_matrix.py--method NAME:PATH [...] --out OUT: the normalised mutual information between the class assignments of every pair of methods (nmi_matrix.{csv,png,pdf}).
Preparing data for other programs¶
python scripts/downsample_stack.py --particles particles.star --project_dir DIR --out_dir copy/ \
--box 128 [--strip_poses] [--invert_contrast]
writes a Fourier-cropped, normalised copy of a particle set (particles_128.mrcs and
particles_128.star in --out_dir) for programs that cannot crop on the fly. --strip_poses removes any angles and origins
from the STAR file, so that every program starts from scratch.