Search in sources :

Example 1 with ClusterPoint

use of 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
    ArrayList<ClusterPoint> points = new ArrayList<ClusterPoint>(molecules.size());
    for (Molecule m : molecules) // Precision was used to store the molecule ID
    points.add(ClusterPoint.newClusterPoint((int) m.precision, m.x, m.y, m.photons));
    ClusteringEngine engine = new ClusteringEngine(Prefs.getThreads(), ClusteringAlgorithm.PARTICLE_SINGLE_LINKAGE, new IJTrackProgress());
    IJ.showStatus("Clustering to check inter-molecule distances");
    engine.setTrackJoins(true);
    ArrayList<Cluster> clusters = engine.findClusters(points, intraHist[0][p99]);
    IJ.showStatus("");
    if (clusters != null) {
        double[] intraIdDistances = engine.getIntraIdDistances();
        double[] interIdDistances = engine.getInterIdDistances();
        int all = interIdDistances.length + intraIdDistances.length;
        log("  * Fraction of inter-molecule particle linkage @ %s nm = %s %%", Utils.rounded(intraHist[0][p99], 4), (all > 0) ? Utils.rounded(100.0 * interIdDistances.length / all, 4) : "0");
        // Show a double cumulative histogram plot
        double[][] intraIdHist = Maths.cumulativeHistogram(intraIdDistances, false);
        double[][] interIdHist = Maths.cumulativeHistogram(interIdDistances, false);
        // Plot
        String title = TITLE + " molecule linkage distance";
        Plot2 plot = new Plot2(title, "Distance", "Frequency", intraIdHist[0], intraIdHist[1]);
        double max = (intraIdHist[1].length > 0) ? intraIdHist[1][intraIdHist[1].length - 1] : 0;
        if (interIdHist[1].length > 0)
            max = FastMath.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], Plot2.LINE);
        plot.setColor(Color.black);
        Utils.display(title, plot);
    } else {
        log("Aborted clustering to check inter-molecule distances");
    }
}
Also used : TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) ArrayList(java.util.ArrayList) IJTrackProgress(gdsc.core.ij.IJTrackProgress) Cluster(gdsc.core.clustering.Cluster) Plot2(ij.gui.Plot2) WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint) ClusterPoint(gdsc.core.clustering.ClusterPoint) ClusteringEngine(gdsc.core.clustering.ClusteringEngine) ClusterPoint(gdsc.core.clustering.ClusterPoint)

Example 2 with ClusterPoint

use of gdsc.core.clustering.ClusterPoint in project GDSC-SMLM by aherbert.

the class PCPALMClusters method convertToPoint.

/**
	 * Convert molecules for clustering
	 * 
	 * @param molecules
	 * @return
	 */
private List<ClusterPoint> convertToPoint(ArrayList<Molecule> molecules) {
    ArrayList<ClusterPoint> points = new ArrayList<ClusterPoint>(molecules.size());
    int id = 0;
    for (Molecule m : molecules) {
        points.add(ClusterPoint.newClusterPoint(id++, m.x, m.y, (weightedClustering) ? m.photons : 1));
    }
    return points;
}
Also used : ArrayList(java.util.ArrayList) ClusterPoint(gdsc.core.clustering.ClusterPoint) ClusterPoint(gdsc.core.clustering.ClusterPoint)

Example 3 with ClusterPoint

use of 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 peakResults
	 * @return
	 */
public static List<ClusterPoint> convertToClusterPoints(List<PeakResult> peakResults) {
    ArrayList<ClusterPoint> points = new ArrayList<ClusterPoint>(peakResults.size());
    int id = 0;
    for (PeakResult p : peakResults) points.add(ClusterPoint.newTimeClusterPoint(id++, p.getXPosition(), p.getYPosition(), p.getSignal(), p.getFrame(), p.getEndFrame()));
    return points;
}
Also used : ArrayList(java.util.ArrayList) ClusterPoint(gdsc.core.clustering.ClusterPoint) PeakResult(gdsc.smlm.results.PeakResult) ClusterPoint(gdsc.core.clustering.ClusterPoint)

Example 4 with ClusterPoint

use of 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 peakResults
	 * @param clusters
	 * @return
	 */
public static Trace[] convertToTraces(List<PeakResult> peakResults, ArrayList<Cluster> clusters) {
    Trace[] traces = new Trace[clusters.size()];
    int i = 0;
    for (Cluster cluster : clusters) {
        Trace trace = new Trace();
        trace.setId(i + 1);
        for (ClusterPoint point = cluster.head; point != null; point = point.next) {
            // The point Id was the position in the original results array
            trace.add(peakResults.get(point.id));
        }
        traces[i++] = trace;
    }
    return traces;
}
Also used : Trace(gdsc.smlm.results.Trace) Cluster(gdsc.core.clustering.Cluster) ClusterPoint(gdsc.core.clustering.ClusterPoint) ClusterPoint(gdsc.core.clustering.ClusterPoint)

Aggregations

ClusterPoint (gdsc.core.clustering.ClusterPoint)4 ArrayList (java.util.ArrayList)3 Cluster (gdsc.core.clustering.Cluster)2 ClusteringEngine (gdsc.core.clustering.ClusteringEngine)1 IJTrackProgress (gdsc.core.ij.IJTrackProgress)1 PeakResult (gdsc.smlm.results.PeakResult)1 Trace (gdsc.smlm.results.Trace)1 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)1 Plot2 (ij.gui.Plot2)1 WeightedObservedPoint (org.apache.commons.math3.fitting.WeightedObservedPoint)1