Repository navigation
VLab4Mic 1.1.0: revision release - #171
Open
brunomsaraiva wants to merge 245 commits into
Open
brunomsaraiva wants to merge 245 commits into
brunomsaraiva wants to merge 245 commits into
Conversation
Each epitope, visited in random order, is first tested for binding with probability p (labelling efficiency) and only then checked for steric hindrance against probes that are already bound. Previously the first epitope in the random order was always bound, so p=0 still produced one label and the bound count was biased upwards by about (1-p). Also vectorise the distance check, return early when no minimum distance is set, and fix boolean_epitope_selection raising UnboundLocalError when no epitope has been selected yet. Add tests for the sampling model: p=0 binds nothing, the bound count is Binomial(N, p) without hindrance, bound epitopes respect the minimum distance, unbound epitopes do not block neighbours, and results are reproducible with a fixed seed.
A guard added to avoid an indexing error with an empty emitter list returned the input unfiltered whenever there was at most one emitter, so a single emitter outside the ROI was still imaged. Handle the empty case explicitly (return an empty Nx3 array), reshape a single emitter to 2D, and always apply the ROI filter. Add tests for one emitter inside and outside the ROI, several emitters, and no emitters.
create_parameters_iterables set random_orientations to [False] whenever no plane-wise orientations were given, overriding the experiment setting and any user sweep over random_orientations. It also raised AttributeError when set_sweep_parameters had not been called, because enable_random_orientations was only defined there. Initialise enable_random_orientations in __init__, keep it enabled across calls to set_sweep_parameters once plane-wise orientations are given, and only set random_orientations to [True] in that case.
test_sweep_based_on_image took about 190 s, used an unseeded random mask and had no assertions. Use a fixed 8x8 mask with three positive pixels, one modality, one repetition and a random seed, and check that one particle is placed per positive pixel, the sample is sized to the image, the image is used as reference, and metrics are computed for each labelling efficiency. The test now runs in about 3 s.
normals_by_scaling returns the direction from the centroid of the target sites. This is the surface normal only on convex shapes: on a flat lattice it lies in the plane, so probes were oriented sideways. Add normals_by_local_plane, which takes for each site the direction of least variance among its nearest sites, and orients normals consistently by propagating the side along a minimum spanning tree of neighbouring sites. The side of each patch is set away from the centroid where that is defined, and towards a reference vector on flat surfaces (the structure axis, unless normal_vector is given). Expose it as normals mode "local_plane" in assign_normals2targets and set_structure_normal_params (with n_neighbours). The default mode stays "scaling", so existing outputs are unchanged. Also fix assign_normals2targets raising NameError for the "global" and "structure_axis" modes when a single target is given, by computing the normals for one or all targets through the same helper.
When rendering SMLM localisations, photons per frame were computed with equal=100, which replaced the fluorophore photon rate with 100 and the exposure time with 1. Fluorophore brightness and exposure time therefore had no effect on SMLM images. Remove the override (and the now unused equal argument), so each localisation emits photons_per_second * exp_time photons per frame, as for the other constant-emission modalities. With AF647 (1e5 photons/s) at the default 1 ms exposure the result is unchanged. Add a test that SMLM intensity scales tenfold with tenfold exposure time and with tenfold brightness.
Localisation precision for SMLM was a fixed value set in the modality, independent of how many photons each localisation collects. Add a precision_model option to the modality emitters: - "fixed" (default): use lateral_precision and axial_precision as before. - "photon_limited": derive the lateral precision from the photons per localisation (fluorophore photons_per_second x exp_time) with the Mortensen et al. (2010) expression, using the detection PSF width, camera pixel size, background photons per pixel and camera excess noise factor. The axial precision is the lateral precision times axial_precision_ratio. The parameters are documented in SMLM.yaml and can be set through update_modality. Default outputs are unchanged.
Add numpydoc docstrings to boolean_epitope_selection and binomial_epitope_sampling, and complete the docstring of sample_epitopes_sterically with its parameters, return value and use of the global random state.
Describe the parameter groups it builds, the default labelling efficiency sweep, and when random_orientations is set.
Add numpydoc docstrings to normals_by_scaling, global_normal_direction, coordinates_scaling and _compute_target_normals, convert the normals_by_local_plane docstring to numpydoc with a reference, and describe the modes and when normals are computed in set_structure_normal_params.
Replace the development notes in the generate_imaging docstring with a description of the simulation steps, parameters and return values. Describe the constant and blinking emission models in calculate_photons_per_frame, and document the two emission helpers. Note that the blinking model currently raises NameError because its trace simulation functions are not defined in vlab4mic.
Convert the photon_limited_lateral_precision docstring to numpydoc with the formula, units, errors and reference. Add parameters, return values and errors to get_localisation_precision and _set_emitter_params, document generate_localisations_with_noise, describe the precision model step in generate_imaging, and add the missing depth_of_field_nm, lateral_precision, axial_precision, nlocalisations and simulate_localistations parameters to update_modality.
Document the parameters added for image-based sweeps (reference_image, reference_image_parameters, image4vsample, image4vsample_parameters, xy/xz/yz_orientations and capture_outputs) and the undocumented na_as_zero, custom_metrics, default_metrics, plot_parameters and random_seed in run_parameter_sweep. Correct the tuple format of swept values, documented as (start, stop, num) but used as (start, stop, step), with stop included for numeric parameters and excluded for integer ones. Add docstrings to set_sweep_parameters, load_reference_image, virtual_sample_from_image, use_default_metrics and generate_random_orientations, document capture_outputs in generate_acquisitions and run_analysis, and fix the parameter names in add_custom_analysis_metrics.
Make the image-based sweep test fast, seeded and asserting
…ency Apply labelling efficiency to every epitope before steric check
Filter single emitters by ROI in get_emitters_in_ROI
Do not force random_orientations in parameter sweeps
…lane Add local_plane normals for flat and non-convex surfaces
Use fluorophore brightness and exposure time for SMLM localisations
Document image-based sweep parameters and fix sweep docstrings
…ecision Add opt-in photon-limited localisation precision for SMLM (re-target of #148)
Every virtual sample build reused the experiment seed, so repeated realisations and sweep conditions drew identical orientations, rotations and unconstrained positions, while placement with a minimal distance (the normal case for particles) and axial offsets (issue #135) ignored the seed entirely. Within a field, positions, orientations and rotations also restarted the same random stream. The experiment now draws a child seed for every field build from a generator seeded with random_seed, and each field keeps one generator (set_random_seed) for all of its draws, including minimal-distance placement, axial offsets and uniform orientations. A fixed seed reproduces the whole sequence of realisations; successive builds differ. Closes #135.
After displacing each localisation by the localisation precision, the
SMLM path still convolved the localisations with the modality PSF
(8 nm in SMLM.yaml), so the effective blur was about 9.4 nm instead of
the 5 nm precision, contrary to the manuscript ("rendered without
further blur"; the localisation precision enters once).
Localisations are now rendered with a separate lateral Gaussian,
rendering_kernel_nm (SMLM.yaml, update_modality), and summed over the
depth-of-field window. The default of 0 renders a histogram. The
emitter path (no localisations) is unchanged. Rendering skips the 3D
FFT convolution, which also reduces memory use for SMLM.
construct_label replaced binding.wobble_range.theta with None unless a wobble_theta override was passed, so the wobble defined in the probe templates was never applied: every simulation without probe_wobble_theta ran with no wobble, contrary to Supp. Table S1. The template value is now kept unless wobble_theta is given (0 or None disables wobble). Template values follow Table S1: 10 degrees for the antibody, nanobody, GFP-nanobody and anti-p24 antibody templates; direct and fluorescent-protein/tag templates have no wobble.
- singlecluster_verification returned the subunits to remove when the remainder was one cluster, but the subunits to keep when it was split, while the caller always removed the returned IDs. With a split remainder the removed patch was kept and the rest dropped. It now always returns the subunits to remove: the proposal plus every remaining cluster except the largest (not "cluster 0", which is the cluster of the first point). - A breaking point with no neighbour within the large-cluster distance raised ValueError; it now removes only that subunit. - If no pattern within 5% of the requested fraction is found in 50 trials, the closest pattern is used with a warning instead of silently returning an empty particle.
gen_targets_by_sequence joined all peptide fragments of a chain into one string, mapped string positions back through the chain residues, and averaged len(motif) + 1 residues. Internal motifs therefore included the next residue, matches could span chain breaks, the mapping shifted when a chain contained residues outside the fragments, and only the first match per chain was kept. The motif is now searched in each fragment separately, residues are taken from the fragment itself, exactly len(motif) residues are averaged, and every match is a target site, as described in Supp. Note 1 and Fig. S8b. C-terminal motifs such as EQATETQ and ATETQ are unaffected.
The "estimate" steric distance was the largest distance between the points of the labelling entity (anchor, axis point and every candidate conjugation site), e.g. 14.4 nm for the antibody instead of its 17.1 nm extent, and 6.4 nm instead of 7.1 nm for the GFP-nanobody. The manuscript defines the exclusion sphere by the largest dimension of the probe model. estimate_probe_size now uses the largest distance between any two atoms of the probe model (via its convex hull), and falls back to the entity points for probes without an atomic model. probe_steric_hindrance still overrides the estimate.
- Swept acquisition parameters without a "channels" key were replaced by
{"channels": ["ch0"]}, so swept exp_time values were dropped and every
condition used the default exposure. They are now kept, with ch0
added; a user-given channel no longer raises NameError.
- save_images wrote the reference image under the last condition's name,
overwriting that condition. It is now saved as reference.tiff.
- Tuple ranges (start, stop, step) used int((stop - start) / step) + 1
points, which dropped the last value and changed the step for e.g.
(0, 0.3, 0.1), and were ignored for every parameter not listed in
parameter_settings.yaml (all optical parameters, DoL, steric
hindrance...). values_from_range now expands any tuple, stop included.
- run_parameter_sweep(particle_positions=...) also registered the
positions as a sweep axis, which passed particle_positions twice and
raised TypeError. They are now a fixed setting; swept positions take
precedence over reused ones in the sweep loop.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #171 +/- ##
==========================================
- Coverage 73.27% 71.75% -1.53%
==========================================
Files 31 31
Lines 5737 6543 +806
==========================================
+ Hits 4204 4695 +491
- Misses 1533 1848 +315 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Revision release, 1.1.0. It brings the model corrections, the new analyses and the article figure scripts from the manuscript revision into
main. The full list is in the[1.1.0]section ofCHANGELOG.md.Highlights
vlab4mic.analysis.distinguishability) scores how well two structures can be told apart. The score is a cross-validated ROC AUC with bootstrap intervals, a permutation p-value and a null control. It can score results fromrun_replicatesor a parameter sweep.vlab4mic.analysis.particle_measures) cover ring radius and width, corner detection, breaks, resolved sites and filament width.examples/article_figures, named by figure and panel; the folder'sREADME.mdmaps figures to scripts.generate_figures.pyruns them all into one output folder, which can also be set with the newVLAB4MIC_OUTPUT_DIRenvironment variable.VLab4Mic_distinguishability.ipynb; thenotebooksextra now requiresvlab4micjupyter>=0.2.1.Before merging
revisions_updatewere cancelled or stuck in the queue; the last completed run passed.v1.1.0, which triggers the PyPI upload. Set the[1.1.0]date inCHANGELOG.mdat release.vlab4mic>=1.1from PyPI, so it will fail until 1.1.0 is published.