Search in sources :

Example 1 with TextFilePeakResults

use of uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults in project GDSC-SMLM by aherbert.

the class ResultsManager method addFileResults.

/**
 * Adds the file results.
 *
 * @param resultsList the results list
 * @param resultsSettings the results settings
 * @param resultsFilename the results filename
 * @param showDeviations the show deviations
 * @param showEndFrame the show end frame
 * @param showId the show id
 * @param showCategory the show category
 * @return the peak results
 */
public static PeakResults addFileResults(PeakResultsList resultsList, ResultsFileSettings resultsSettings, String resultsFilename, boolean showDeviations, boolean showEndFrame, boolean showId, boolean showCategory) {
    if (resultsSettings.getFileFormatValue() > 0 && resultsFilename != null) {
        final File file = new File(resultsFilename);
        final File parent = file.getParentFile();
        if (parent != null && parent.exists()) {
            PeakResults results;
            switch(resultsSettings.getFileFormat()) {
                case BINARY:
                    results = new BinaryFilePeakResults(resultsFilename, showDeviations, showEndFrame, showId, resultsSettings.getShowPrecision(), showCategory);
                    break;
                case TEXT:
                    final TextFilePeakResults f = new TextFilePeakResults(resultsFilename, showDeviations, showEndFrame, showId, resultsSettings.getShowPrecision(), showCategory);
                    f.setDistanceUnit(resultsSettings.getDistanceUnit());
                    f.setIntensityUnit(resultsSettings.getIntensityUnit());
                    f.setAngleUnit(resultsSettings.getAngleUnit());
                    f.setComputePrecision(true);
                    results = f;
                    break;
                case MALK:
                    results = new MalkFilePeakResults(resultsFilename);
                    break;
                case TSF:
                    results = new TsfPeakResultsWriter(resultsFilename);
                    break;
                default:
                    throw new IllegalArgumentException("Unsupported file format: " + resultsSettings.getFileFormat());
            }
            resultsList.addOutput(results);
            return results;
        }
    }
    return null;
}
Also used : BinaryFilePeakResults(uk.ac.sussex.gdsc.smlm.results.BinaryFilePeakResults) MalkFilePeakResults(uk.ac.sussex.gdsc.smlm.results.MalkFilePeakResults) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) ImageJImagePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults) PeakResults(uk.ac.sussex.gdsc.smlm.results.PeakResults) BinaryFilePeakResults(uk.ac.sussex.gdsc.smlm.results.BinaryFilePeakResults) MalkFilePeakResults(uk.ac.sussex.gdsc.smlm.results.MalkFilePeakResults) ImageJTablePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJTablePeakResults) TextFilePeakResults(uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults) TsfPeakResultsWriter(uk.ac.sussex.gdsc.smlm.results.TsfPeakResultsWriter) File(java.io.File) TextFilePeakResults(uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults)

Example 2 with TextFilePeakResults

use of uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults in project GDSC-SMLM by aherbert.

the class NeighbourAnalysis method saveTraces.

private void saveTraces(Trace[] traces) {
    final String[] path = ImageJUtils.decodePath(settings.filename);
    final OpenDialog chooser = new OpenDialog("Traces_File", path[0], path[1]);
    if (chooser.getFileName() != null) {
        settings.filename = chooser.getDirectory() + chooser.getFileName();
        // Remove extension and replace with .xls
        final int index = settings.filename.lastIndexOf('.');
        if (index > 0) {
            settings.filename = settings.filename.substring(0, index);
        }
        settings.filename += ".xls";
        final boolean showDeviations = results.hasDeviations();
        final TextFilePeakResults traceResults = new TextFilePeakResults(settings.filename, showDeviations);
        traceResults.copySettings(results);
        traceResults.begin();
        if (!traceResults.isActive()) {
            IJ.error(TITLE, "Failed to write to file: " + settings.filename);
            return;
        }
        traceResults.addComment(createSettingsComment());
        for (final Trace trace : traces) {
            // addTrace(...) does a sort on the results
            traceResults.addCluster(trace);
        }
        traceResults.end();
    }
}
Also used : Trace(uk.ac.sussex.gdsc.smlm.results.Trace) TextFilePeakResults(uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults) OpenDialog(ij.io.OpenDialog)

Example 3 with TextFilePeakResults

use of uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults in project GDSC-SMLM by aherbert.

the class ResultsMatchCalculator method createFilePeakResults.

private TextFilePeakResults createFilePeakResults(String directory, int set, MemoryPeakResults results, double distanceLow, double distanceHigh) {
    final String filename = directory + String.format("Match%d_%s_%s_%s.txt", set, results.getName(), rounder.toString(distanceLow), rounder.toString(distanceHigh));
    final TextFilePeakResults r = new TextFilePeakResults(filename, false, outputEndFrame(results));
    r.copySettings(results);
    r.begin();
    return r;
}
Also used : TextFilePeakResults(uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults)

Example 4 with TextFilePeakResults

use of uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults in project GDSC-SMLM by aherbert.

the class TraceMolecules method saveTraces.

/**
 * Save the traces to the file. A File open dialog is presented and the selected filename
 * returned.
 *
 * <p>If the id is above zero then the file open dialog title will have the id appended and the
 * filename is searched for .[0-9]+. and it is replaced with .id.
 *
 * @param sourceResults the source results
 * @param traces the traces
 * @param comment the comment
 * @param filename The initial filename
 * @param id The traces id (used if above 0)
 * @return The select filename (or null)
 */
static String saveTraces(MemoryPeakResults sourceResults, Trace[] traces, String comment, String filename, int id) {
    IJ.showStatus("Saving traces");
    String title = "Traces_File";
    if (id > 0) {
        title += id;
        final String regex = "\\.[0-9]+\\.";
        if (filename.matches(regex)) {
            filename = filename.replaceAll(regex, "." + (id) + ".");
        } else {
            filename = FileUtils.replaceExtension(filename, id + ".xls");
        }
    }
    filename = ImageJUtils.getFilename(title, filename);
    if (filename != null) {
        filename = FileUtils.replaceExtension(filename, "xls");
        final boolean showDeviations = sourceResults.hasDeviations();
        // Assume that are results are from a single frame but store the trace ID
        final TextFilePeakResults traceResults = new TextFilePeakResults(filename, showDeviations, false, true);
        traceResults.copySettings(sourceResults);
        traceResults.begin();
        if (!traceResults.isActive()) {
            IJ.error("Failed to write to file: " + filename);
        } else {
            traceResults.addComment(comment);
            for (final Trace trace : traces) {
                traceResults.addTrace(trace);
            }
            traceResults.end();
        }
    }
    IJ.showStatus("");
    return filename;
}
Also used : Trace(uk.ac.sussex.gdsc.smlm.results.Trace) TextFilePeakResults(uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults)

Example 5 with TextFilePeakResults

use of uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults in project GDSC-SMLM by aherbert.

the class ResultsMatchCalculator method runCompareCoordinates.

@SuppressWarnings("null")
private void runCompareCoordinates(MemoryPeakResults results1, MemoryPeakResults results2) {
    final boolean requirePairs = settings.showPairs || settings.isSaveClassifications();
    final boolean saveMatched = settings.isSaveMatched();
    final boolean saveUnmatched = settings.isSaveUnmatched();
    final TextFilePeakResults fileResults = createFilePeakResults(results2);
    final List<PointPair> allMatches = new LinkedList<>();
    final List<PointPair> pairs = (requirePairs) ? new LinkedList<>() : null;
    final double maxDistance = settings.distanceThreshold + settings.increments * settings.delta;
    // Divide the results into time points
    final TIntObjectHashMap<List<Coordinate>> actualCoordinates = getCoordinates(results1, settings.coordinateMethod1);
    final TIntObjectHashMap<List<Coordinate>> predictedCoordinates = getCoordinates(results2, settings.coordinateMethod2);
    int n1 = 0;
    int n2 = 0;
    // Process each time point
    for (final int t : getTimepoints(actualCoordinates, predictedCoordinates)) {
        final Coordinate[] actual = getCoordinates(actualCoordinates, t);
        final Coordinate[] predicted = getCoordinates(predictedCoordinates, t);
        final List<Coordinate> tp = null;
        List<Coordinate> fp = null;
        List<Coordinate> fn = null;
        final List<PointPair> matches = new LinkedList<>();
        if (requirePairs) {
            fp = new LinkedList<>();
            fn = new LinkedList<>();
        }
        MatchCalculator.analyseResults2D(actual, predicted, maxDistance, tp, fp, fn, matches);
        // Aggregate
        n1 += actual.length;
        n2 += predicted.length;
        allMatches.addAll(matches);
        if (settings.showPairs) {
            pairs.addAll(matches);
            for (final Coordinate c : fn) {
                pairs.add(new PointPair(c, null));
            }
            for (final Coordinate c : fp) {
                pairs.add(new PointPair(null, c));
            }
        }
        if (fileResults != null) {
            // Matches are marked in the original value with 1 for true, 0 for false
            if (saveMatched) {
                for (final PointPair pair : matches) {
                    PeakResult result = ((PeakResultPoint) pair.getPoint2()).getPeakResult();
                    result = result.copy();
                    result.setOrigValue(1);
                    fileResults.add(result);
                }
            }
            if (saveUnmatched) {
                for (final Coordinate c : fp) {
                    PeakResult result = ((PeakResultPoint) c).getPeakResult();
                    result = result.copy();
                    result.setOrigValue(0);
                    fileResults.add(result);
                }
            }
        }
    }
    if (fileResults != null) {
        fileResults.end();
    }
    final boolean doIdAnalysis1 = settings.idAnalysis && haveIds(results1);
    final boolean doIdAnalysis2 = settings.idAnalysis && haveIds(results2);
    // Create output.
    // This supports headless mode with just the results table
    // or graphical mode with a results table and pairs window.
    final boolean headless = java.awt.GraphicsEnvironment.isHeadless();
    TextWindow resultsWindow = null;
    if (!headless) {
        resultsWindow = (settings.showTable) ? createResultsWindow(doIdAnalysis1 || doIdAnalysis2) : null;
        showPairs(results1, pairs, resultsWindow);
    }
    showResults(results1, results2, allMatches, n1, n2, doIdAnalysis1, doIdAnalysis2, resultsWindow);
    savePairs(results1, results2, allMatches);
}
Also used : TextFilePeakResults(uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults) LinkedList(java.util.LinkedList) PeakResultPoint(uk.ac.sussex.gdsc.smlm.results.PeakResultPoint) Point(java.awt.Point) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) TextWindow(ij.text.TextWindow) BufferedTextWindow(uk.ac.sussex.gdsc.core.ij.BufferedTextWindow) Coordinate(uk.ac.sussex.gdsc.core.match.Coordinate) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) PointPair(uk.ac.sussex.gdsc.core.match.PointPair) PeakResultPoint(uk.ac.sussex.gdsc.smlm.results.PeakResultPoint)

Aggregations

TextFilePeakResults (uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults)8 OpenDialog (ij.io.OpenDialog)2 File (java.io.File)2 ImageJImagePeakResults (uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults)2 ImageJTablePeakResults (uk.ac.sussex.gdsc.smlm.ij.results.ImageJTablePeakResults)2 BinaryFilePeakResults (uk.ac.sussex.gdsc.smlm.results.BinaryFilePeakResults)2 MalkFilePeakResults (uk.ac.sussex.gdsc.smlm.results.MalkFilePeakResults)2 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)2 PeakResults (uk.ac.sussex.gdsc.smlm.results.PeakResults)2 Trace (uk.ac.sussex.gdsc.smlm.results.Trace)2 TsfPeakResultsWriter (uk.ac.sussex.gdsc.smlm.results.TsfPeakResultsWriter)2 TextWindow (ij.text.TextWindow)1 Point (java.awt.Point)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 BufferedTextWindow (uk.ac.sussex.gdsc.core.ij.BufferedTextWindow)1 Coordinate (uk.ac.sussex.gdsc.core.match.Coordinate)1 PointPair (uk.ac.sussex.gdsc.core.match.PointPair)1