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;
}
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();
}
}
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;
}
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;
}
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);
}
Aggregations