use of uk.ac.sussex.gdsc.core.clustering.ClusterPoint in project GDSC-SMLM by aherbert.
the class PcPalmClusters method convertToPoint.
/**
* Convert molecules for clustering.
*
* @param molecules the molecules
* @return the list of cluster points
*/
private List<ClusterPoint> convertToPoint(List<Molecule> molecules) {
final ArrayList<ClusterPoint> points = new ArrayList<>(molecules.size());
int id = 0;
for (final Molecule m : molecules) {
points.add(ClusterPoint.newClusterPoint(id++, m.x, m.y, (weightedClustering) ? m.photons : 1));
}
return points;
}
use of uk.ac.sussex.gdsc.core.clustering.ClusterPoint in project GDSC-SMLM by aherbert.
the class TraceMolecules method convertToTraces.
/**
* Convert the clusters from the clustering engine into traces composed of the original list of
* peak results.
*
* @param results the results
* @param clusters the clusters
* @return the traces
*/
public static Trace[] convertToTraces(MemoryPeakResults results, List<Cluster> clusters) {
final Trace[] traces = new Trace[clusters.size()];
int index = 0;
for (final Cluster cluster : clusters) {
final Trace trace = new Trace();
trace.setId(index + 1);
for (ClusterPoint point = cluster.getHeadClusterPoint(); point != null; point = point.getNext()) {
// The point Id was the position in the original results array
trace.add(results.get(point.getId()));
}
trace.sort();
traces[index++] = trace;
}
return traces;
}
use of uk.ac.sussex.gdsc.core.clustering.ClusterPoint in project GDSC-SMLM by aherbert.
the class TraceMolecules method convertToClusterPoints.
/**
* Convert a list of peak results into points for the clustering engine.
*
* @param results the results
* @return the list of clusters
*/
public static List<ClusterPoint> convertToClusterPoints(MemoryPeakResults results) {
final ArrayList<ClusterPoint> points = new ArrayList<>(results.size());
final Counter counter = new Counter();
results.forEach((PeakResultProcedure) result -> points.add(ClusterPoint.newTimeClusterPoint(counter.getAndIncrement(), result.getXPosition(), result.getYPosition(), result.getIntensity(), result.getFrame(), result.getEndFrame())));
return points;
}
use of uk.ac.sussex.gdsc.core.clustering.ClusterPoint in project GDSC-SMLM by aherbert.
the class PcPalmMolecules method performDistanceAnalysis.
private void performDistanceAnalysis(double[][] intraHist, int p99) {
// We want to know the fraction of distances between molecules at the 99th percentile
// that are intra- rather than inter-molecule.
// Do single linkage clustering of closest pair at this distance and count the number of
// links that are inter and intra.
// Convert molecules for clustering
final ArrayList<ClusterPoint> points = new ArrayList<>(settings.molecules.size());
for (final Molecule m : settings.molecules) {
// Precision was used to store the molecule ID
points.add(ClusterPoint.newClusterPoint((int) m.precision, m.x, m.y, m.photons));
}
final ClusteringEngine engine = new ClusteringEngine(Prefs.getThreads(), ClusteringAlgorithm.PARTICLE_SINGLE_LINKAGE, SimpleImageJTrackProgress.getInstance());
IJ.showStatus("Clustering to check inter-molecule distances");
engine.setTrackJoins(true);
final List<Cluster> clusters = engine.findClusters(points, intraHist[0][p99]);
IJ.showStatus("");
if (clusters != null) {
final double[] intraIdDistances = engine.getIntraIdDistances();
final double[] interIdDistances = engine.getInterIdDistances();
final int all = interIdDistances.length + intraIdDistances.length;
log(" * Fraction of inter-molecule particle linkage @ %s nm = %s %%", MathUtils.rounded(intraHist[0][p99], 4), (all > 0) ? MathUtils.rounded(100.0 * interIdDistances.length / all, 4) : "0");
// Show a double cumulative histogram plot
final double[][] intraIdHist = MathUtils.cumulativeHistogram(intraIdDistances, false);
final double[][] interIdHist = MathUtils.cumulativeHistogram(interIdDistances, false);
// Plot
final String title = TITLE + " molecule linkage distance";
final Plot plot = new Plot(title, "Distance", "Frequency");
plot.addPoints(intraIdHist[0], intraIdHist[1], Plot.LINE);
double max = (intraIdHist[1].length > 0) ? intraIdHist[1][intraIdHist[1].length - 1] : 0;
if (interIdHist[1].length > 0) {
max = Math.max(max, interIdHist[1][interIdHist[1].length - 1]);
}
plot.setLimits(0, intraIdHist[0][intraIdHist[0].length - 1], 0, max);
plot.setColor(Color.blue);
plot.addPoints(interIdHist[0], interIdHist[1], Plot.LINE);
plot.setColor(Color.black);
plot.addLegend("Intra-molecule\nInter-molecule");
ImageJUtils.display(title, plot);
} else {
log("Aborted clustering to check inter-molecule distances");
}
}
Aggregations