Search in sources :

Example 1 with ClusterPoint

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;
}
Also used : ArrayList(java.util.ArrayList) ClusterPoint(uk.ac.sussex.gdsc.core.clustering.ClusterPoint) ClusterPoint(uk.ac.sussex.gdsc.core.clustering.ClusterPoint)

Example 2 with ClusterPoint

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;
}
Also used : Trace(uk.ac.sussex.gdsc.smlm.results.Trace) Cluster(uk.ac.sussex.gdsc.core.clustering.Cluster) ClusterPoint(uk.ac.sussex.gdsc.core.clustering.ClusterPoint) ClusterPoint(uk.ac.sussex.gdsc.core.clustering.ClusterPoint)

Example 3 with ClusterPoint

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;
}
Also used : Arrays(java.util.Arrays) ClusteringEngine(uk.ac.sussex.gdsc.core.clustering.ClusteringEngine) UnitConverterUtils(uk.ac.sussex.gdsc.smlm.data.config.UnitConverterUtils) HistogramPlotBuilder(uk.ac.sussex.gdsc.core.ij.HistogramPlot.HistogramPlotBuilder) TextWindow(ij.text.TextWindow) CalibrationOrBuilder(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CalibrationOrBuilder) StoredDataStatistics(uk.ac.sussex.gdsc.core.utils.StoredDataStatistics) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) ClusteringAlgorithm(uk.ac.sussex.gdsc.core.clustering.ClusteringAlgorithm) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) ClusteringSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.ClusteringSettings) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) TraceMode(uk.ac.sussex.gdsc.smlm.results.TraceManager.TraceMode) Logger(java.util.logging.Logger) TIntHashSet(gnu.trove.set.hash.TIntHashSet) CalibrationHelper(uk.ac.sussex.gdsc.smlm.data.config.CalibrationHelper) ImagePlus(ij.ImagePlus) LutLoader(ij.plugin.LutLoader) List(java.util.List) Converter(uk.ac.sussex.gdsc.core.data.utils.Converter) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) FileUtils(uk.ac.sussex.gdsc.core.utils.FileUtils) PlugIn(ij.plugin.PlugIn) TypeConverter(uk.ac.sussex.gdsc.core.data.utils.TypeConverter) Roi(ij.gui.Roi) PrecisionResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PrecisionResultProcedure) SplineInterpolator(org.apache.commons.math3.analysis.interpolation.SplineInterpolator) TraceManager(uk.ac.sussex.gdsc.smlm.results.TraceManager) PolygonRoi(ij.gui.PolygonRoi) PolynomialSplineFunction(org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction) Prefs(ij.Prefs) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WindowManager(ij.WindowManager) WindowOrganiser(uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser) ClusterPoint(uk.ac.sussex.gdsc.core.clustering.ClusterPoint) DmttConfiguration(uk.ac.sussex.gdsc.smlm.results.DynamicMultipleTargetTracing.DmttConfiguration) AtomicReference(java.util.concurrent.atomic.AtomicReference) TextField(java.awt.TextField) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Trace(uk.ac.sussex.gdsc.smlm.results.Trace) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) Statistics(uk.ac.sussex.gdsc.core.utils.Statistics) SimpleImageJTrackProgress(uk.ac.sussex.gdsc.core.ij.SimpleImageJTrackProgress) Files(java.nio.file.Files) Calibration(ij.measure.Calibration) Checkbox(java.awt.Checkbox) BufferedWriter(java.io.BufferedWriter) DynamicMultipleTargetTracing(uk.ac.sussex.gdsc.smlm.results.DynamicMultipleTargetTracing) TimeUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.TimeUnit) Consumer(java.util.function.Consumer) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) FloatProcessor(ij.process.FloatProcessor) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) Paths(java.nio.file.Paths) Cluster(uk.ac.sussex.gdsc.core.clustering.Cluster) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) TextFilePeakResults(uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults) IJ(ij.IJ) Collections(java.util.Collections) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) ArrayList(java.util.ArrayList) ClusterPoint(uk.ac.sussex.gdsc.core.clustering.ClusterPoint)

Example 4 with ClusterPoint

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");
    }
}
Also used : Plot(ij.gui.Plot) HistogramPlot(uk.ac.sussex.gdsc.core.ij.HistogramPlot) TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) ArrayList(java.util.ArrayList) Cluster(uk.ac.sussex.gdsc.core.clustering.Cluster) WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint) ClusterPoint(uk.ac.sussex.gdsc.core.clustering.ClusterPoint) ClusteringEngine(uk.ac.sussex.gdsc.core.clustering.ClusteringEngine) ClusterPoint(uk.ac.sussex.gdsc.core.clustering.ClusterPoint)

Aggregations

ClusterPoint (uk.ac.sussex.gdsc.core.clustering.ClusterPoint)4 ArrayList (java.util.ArrayList)3 Cluster (uk.ac.sussex.gdsc.core.clustering.Cluster)3 ClusteringEngine (uk.ac.sussex.gdsc.core.clustering.ClusteringEngine)2 Trace (uk.ac.sussex.gdsc.smlm.results.Trace)2 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)1 TIntHashSet (gnu.trove.set.hash.TIntHashSet)1 IJ (ij.IJ)1 ImagePlus (ij.ImagePlus)1 Prefs (ij.Prefs)1 WindowManager (ij.WindowManager)1 Plot (ij.gui.Plot)1 PolygonRoi (ij.gui.PolygonRoi)1 Roi (ij.gui.Roi)1 Calibration (ij.measure.Calibration)1 LutLoader (ij.plugin.LutLoader)1 PlugIn (ij.plugin.PlugIn)1 FloatProcessor (ij.process.FloatProcessor)1 TextWindow (ij.text.TextWindow)1 Checkbox (java.awt.Checkbox)1