Find clusters

Analysis › Regions · version 3 · can follow the ROI

Finds clusters – by DBSCAN, Voronoi density, HDBSCAN or local maxima

What it does

Finds clusters – places where localizations lie closer together than elsewhere – and names them. Nothing has to be said about how many clusters there are; a cluster may have any shape, and what is not crowded belongs to none. Four algorithms, each with its own settings, of which the form shows only the chosen one's:

Frame analysis, a tick for every algorithm, drops the clusters whose localizations bunch in time. A DNA-PAINT site is visited by imager strands at random throughout the acquisition; an imager that sticks to the glass, or dirt, gives a cloud of localizations that all come in one stretch of time, and looks like a site in the picture.

What it gives is a name for every cluster, written onto the table: cluster_id (1 for the largest cluster, 2 for the next, ..., 0 for a localization in no cluster) and n_in_cluster (how many localizations its cluster has). With them

It clusters the localizations of the layer as it is shown: its filter (the lowest and highest values of attributes a localization must lie between), its ROI and, on a layer that merges blinks, its blinks – merge blinks, also called grouping or linking, combines the localizations in consecutive frames that come from one blinking event into one. Use it on structures that are separate from each other – pores, clusters of a receptor, vesicles. On a continuous structure (a filament network) every localization is crowded and it joins everything into one.

How it works

DBSCAN

1. Neighbours. For every localization the others within the radius (called eps) are counted. One with at least neighbours (called k) others that close is a core point: it sits inside a cluster.

2. Clusters. Core points within the radius of each other belong to the same cluster, and so do their core neighbours, and theirs: a cluster is every core point that can be reached from another in steps no longer than the radius. Its shape does not matter.

3. Edges and noise. A localization that is not a core point but lies within the radius of one is on a cluster's edge (a border point) and joins the cluster of the nearest core point. The rest are noise: cluster_id -1, in no cluster.

4. Names. The clusters are numbered by size, the largest 1. n_in_cluster is written beside cluster_id; both are kept when blinks are merged, a blink taking its cluster.

Several files or colours. A run writes cluster_id afresh only in the files and channels its layer shows. The others keep their clusters, and the new ones are numbered after the largest kept number. So two files, or two colours of one file, on two layers are clustered one after the other: run it on the first layer, then on the second, and both keep their clusters. Inside a file and channel the layer shows, a localization its filter or ROI leaves out gets -1, never an old number: a field of view never holds clusters of two runs. A kept cluster keeps its number, so results measured per cluster and ROIs made from the clusters still point to it.

141 simulated nuclear pores (left; a colour per pore) and the clusters DBSCAN finds with a 50 nm radius and 10 neighbours (right; a colour per cluster, noise grey): every cluster holds one pore, and one pore came out as two clusters.

Voronoi

1. Cells. The plane is divided into one cell per localization, the part of it nearer that localization than any other. Where localizations crowd, the cells are small. Localizations at exactly the same position share a cell.

2. Dense cells. A cell's density is the localizations in it over its area. It is dense when that is above density factor times the field's mean density: all the localizations over the area of the smallest convex outline around them. A cell at the edge of the field is open, has no area, and is never dense.

3. Clusters. Dense cells that share an edge are one cluster. A cluster with fewer than minimum size localizations is dropped.

The same pores with 2000 scattered localizations added. Each localization coloured by the density of its cell over the field's mean (left): the pores' cells are far denser than the mean, the scattered ones below it. With a density factor of 2 and a minimum size of 10 (right), the pores come out as clusters without a radius having been chosen, and the scattered localizations as none.

Local maxima

1. Neighbours. For every localization the others within the radius are counted, as for DBSCAN.

2. Centres. A localization with more than minimum size neighbours (itself included) and no neighbour with more is a local maximum: the middle of a site's cloud.

3. Clusters. The local maxima, those with most neighbours first, each take their neighbours that no other has taken yet. A local maximum that an earlier one has already taken gives its free neighbours to that cluster: two maxima closer than the radius are one cluster. A cluster with fewer than minimum size localizations is dropped.

Unlike DBSCAN, nothing chains: a cluster reaches at most one radius from its centre, so two sites 20 nm apart stay two clusters with a radius of 8 nm, where DBSCAN joins them through the localizations between them.

Pairs of DNA-PAINT sites 20 nm apart (3 nm localization precision; a colour per true site, left). Local maxima with an 8 nm radius finds every site (middle); DBSCAN with the same radius joins many pairs (right).

Frame analysis

With frame analysis ticked, each cluster is looked at in time, on its localizations even on a layer that merges blinks. Each localization's place in the acquisition is a fraction from 0 (the first frame) to 1 (the last). A cluster is dropped – its localizations get cluster_id -1 – when

The remaining clusters are numbered again, without gaps. These are the numbers that Binding kinetics gives each region (mean_frame_rel, peak_window_fraction), so a cluster dropped here would fail there too.

HDBSCAN

1. Core distances. For every localization, the distance to its neighbours-th nearest neighbour: small inside a cluster, large in the background.

2. A tree of clusters. Two localizations are as far apart as the larger of their distance and their core distances (the mutual reachability). Joining the localizations from the closest pair on gives a tree: at every radius, the clusters DBSCAN would find with it.

3. The lasting clusters. Of the clusters in that tree with at least minimum size localizations, those that persist over the widest range of radii are kept; the rest of the localizations are noise. The hdbscan package does all three.

In detail

DBSCAN

Core. With the number of localizations within of localization , itself included, is a core point when

The automatic radius. A radius of 0 asks for SMAP's: the radius of a ball that would hold localizations at the mean density of the field,

with the volume (area in 2D) of the localizations' bounding box, their number and the dimension. It is fair for a field evenly covered; for a cell in a mostly empty field it is far too large.

3D. With in 3D ticked and z_nm in the table, distances are measured in x, y and z.

How it is computed. The localizations are sorted into square cells wide, so each one looks for its neighbours only in the nine cells around it, on every processor core – the search of Neighbourhood. Core points within of each other are joined into clusters while the cells are scanned again, without listing the pairs first. Two million localizations take about 2 s. Each file of the session is clustered on its own, and the numbers of the second file's clusters follow the first's. The panel shows the percentage done, and Stop ends the run and leaves the table as it was.

Voronoi

With the area of cell , the localizations in it and the localizations of the file over the area of their convex hull, cell is dense when

the density factor. Cells vary in size even where nothing is clustered: in a uniform field a factor of 1 calls 56% of the cells dense, 2 calls 16% and 3 calls 6%, and those cells, where they touch, make small clusters of the background – which is what minimum size is for. Cells touch when they share an edge – when their localizations are neighbours in the Delaunay triangulation, which is how the touching cells are found. The triangulation is computed in tiles on every core and checked to be the one of the whole field, as in Neighbourhood; it takes about 20 µs a localization, so a run of more than about a million asks first.

The mean density is that of the convex hull of the localizations, so a field with large empty parts (outside a cell) has a low mean, and more of it is dense than in a field evenly covered. An ROI around the cell, or a higher factor, corrects for it. SR-Tesseler, where this criterion comes from, uses the same multiple of the mean density; ClusterViSu (the clustering of SharpViSu, Andronov et al. 2016) sets the threshold instead where the data's distribution of cell areas crosses that of a random one, from simulations, which is not done here.

Local maxima

With the localizations within of , itself included, is a local maximum when

the minimum size. Ties are allowed, so a site whose densest point is shared by several localizations has several maxima; they are within of each other and come out as one cluster.

Order. Picasso takes the maxima in the order of the table. Here they are taken most neighbours first, ties in the order of the cell search, so the answer does not depend on how the table is sorted. The clusters are the same as Picasso's in number and members; a localization between two maxima may go to the other one (fewer than 1 in 100 on pairs of sites 20 nm apart).

3D. With in 3D ticked and z_nm in the table, z is scaled by radius / z radius before the search, so the neighbourhood is an ellipsoid radius wide and z radius high – Picasso's anisotropic radius, for z measured less precisely than x and y.

How it is computed. The counts are DBSCAN's cell search; the neighbours of the localizations that may be maxima are listed by the same search, in chunks of 200,000. 3.7 million localizations take about 9 s.

Frame analysis

For localization of a file whose acquisition runs from frame to , its place is

A cluster is dropped when

with its localizations and those with in the twentieth , . The acquisition is the file's recorded number of frames where a file has one (a simulation records it), else its first and last localization. Picasso uses the frames of the table it was given and the frame numbers as they are; the difference is half a frame.

HDBSCAN

The clusters are the hdbscan package's (McInnes et al. 2017), with minimum size as its min_cluster_size and neighbours as its min_samples (auto: the same as the minimum size), on x and y, or x, y and z with in 3D. Its labels are renumbered by size like the others'.

The tree of step 2 is a minimum spanning tree of the mutual reachability. The package builds it by Borůvka's algorithm on a k-d tree, which looks only at nearby localizations: 2.5 s for 100,000 localizations and about a minute for a million. scikit-learn's HDBSCAN builds it by Prim's algorithm, every localization against every other: 48 s for 100,000 and hours for a million, which is why it is not used. The exact tree is asked for (approx_min_span_tree=False, no slower here). Many mutual reachabilities are equal, so several trees are equally minimal, and the two libraries break the ties differently: on the same data their clusters agree almost but not quite (an adjusted Rand index of 0.99).

It is one computation that Stop cannot end early, and a run expected to take more than 20 s – about 400,000 localizations – asks first. Merge blinks, or run it in an ROI, for a shorter run.

When to prefer HDBSCAN. When the clusters in one field have very different densities – a tight cluster beside a loose one – no single DBSCAN radius fits both, and HDBSCAN finds each. It also needs no radius when nothing is known about the clusters' size. When not. When a cluster is defined physically – localizations within a known distance, such as one protein complex – DBSCAN's radius says exactly that, and HDBSCAN's answer depends on what else is in the field. HDBSCAN also tends to give scattered localizations near a cluster to it: in a test with two clusters and 60 scattered localizations it put about a quarter of the scattered ones into the clusters.

Parameters

settingdefaultwhat it does
algorithm
algorithm
DBSCANDBSCAN: a radius and a count; Voronoi: dense cells that touch; HDBSCAN: no radius; local maxima: one cluster per DNA-PAINT site. Choices: DBSCAN; Voronoi; HDBSCAN; local maxima
DBSCAN
   radius
   dbscan.radius_nm
50 nmEps: how close a neighbour is; 0: chosen from the density, as SMAP does.

About the distance between neighbouring localizations inside a structure, not its size: a few times the localization precision (also called the CRLB: how far a fitted position may lie from the true one), 30 to 80 nm for typical data. Too small and clusters break into pieces; too large and neighbouring structures merge.

   neighbours
   dbscan.neighbours
10K: the neighbours within the radius that make a core point.

Larger values ask for denser clusters and leave more of a cluster's edge as noise. Raise it with the number of localizations per structure; 5 to 20 is usual.

at least 1
   in 3D
   dbscan.use_z
onCluster in x, y and z when the table has z_nm.

Off clusters by x and y only, which joins structures that are above each other.

Voronoi
   density factor
   voronoi.factor
2Dense: a Voronoi density above this many times the field's mean.

Lower finds fainter clusters and calls more of the background dense, where random crowding of the background then forms clusters of a few localizations; minimum size removes those. Higher keeps only the cores of the clusters. 2 to 3 suits clusters that stand well out of a background.

   minimum size
   voronoi.min_size
10Localizations in a cluster; smaller ones are none.

Above the number of localizations random crowding of the background gathers – with merged blinks 5 to 10, without them higher, since one molecule's repeated localizations are dense among themselves.

at least 1
HDBSCAN
   minimum size
   hdbscan.min_cluster_size
10The fewest localizations a cluster has.

The smallest structure worth calling a cluster, in localizations. It is also the main control of how finely HDBSCAN divides: larger merges neighbouring clusters.

at least 2
   neighbours
   hdbscan.min_samples
autoAuto: the minimum size; more is more conservative, with more noise.

How dense a neighbourhood must be to start a cluster. Larger values leave more localizations as noise and keep only well-defined clusters.

at least 1
   in 3D
   hdbscan.use_z
onCluster in x, y and z when the table has z_nm.

As for DBSCAN.

local maxima
   radius
   local_maxima.radius_nm
10 nmA site's localizations lie within it; about twice the precision (NeNA).

About twice the localization precision, as Picasso advises – twice the NeNA value of Localization Precision. Too large and neighbouring sites merge; too small and the sites' edges are left out, and a dim site has too few neighbours to be a maximum.

at least 0.1 nm
   minimum size
   local_maxima.min_points
10Localizations a cluster has at least.

Below the localizations a site gives over the acquisition and above what the background gathers within one radius. Picasso's default is 10; with long acquisitions sites give hundreds, and a higher value keeps out unspecific binding.

at least 1
   in 3D
   local_maxima.use_z
onCluster in x, y and z when the table has z_nm.

As for DBSCAN.

   z radius
   local_maxima.z_radius_nm
20 nmThe neighbourhood's half height in z.

Twice the precision in z, which in astigmatic 3D is about two to three times that in x and y.

at least 0.1 nm
frame analysis
frame_analysis
offNo cluster where its localizations bunch in time: a sticky imager.

Tick it for DNA-PAINT, where Picasso's SMLM clusterer has it on. Leave it off for dyes that bleach – in STORM or PALM most localizations come early, and every cluster would fail – and for acquisitions shorter than a few hundred frames, where a twentieth holds only a few frames.

Output

Differences from SMAP

DBSCAN is based on SMAP's Analyze/cluster/DBSCAN_cluster (Ries 2020), which runs the MIiSR version of DBSCAN (Caetano et al. 2015).

References