Search in sources :

Example 1 with MalkFilePeakResults

use of uk.ac.sussex.gdsc.smlm.results.MalkFilePeakResults 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 MalkFilePeakResults

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

the class ResultsManager method save.

private static boolean save(ResultsFileSettings resultsSettings, MemoryPeakResults source) {
    // Assume the directory exists
    String resultsFilename;
    try {
        resultsFilename = new File(resultsSettings.getResultsDirectory(), source.getName() + ".results." + ResultsProtosHelper.getExtension(resultsSettings.getFileFormat())).getCanonicalPath();
    } catch (final IOException ex) {
        return false;
    }
    PeakResults results;
    switch(resultsSettings.getFileFormat()) {
        case BINARY:
            results = new BinaryFilePeakResults(resultsFilename, source.hasDeviations(), source.hasEndFrame(), source.hasId(), resultsSettings.getShowPrecision());
            break;
        case TEXT:
            final TextFilePeakResults f = new TextFilePeakResults(resultsFilename, source.hasDeviations(), source.hasEndFrame(), source.hasId(), resultsSettings.getShowPrecision());
            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());
    }
    results.copySettings(source);
    results.begin();
    results.addAll(source.toArray());
    results.end();
    ImageJUtils.log("Saved %s to %s", source.getName(), resultsFilename);
    return true;
}
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) IOException(java.io.IOException) File(java.io.File) TextFilePeakResults(uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults)

Aggregations

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 TextFilePeakResults (uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults)2 TsfPeakResultsWriter (uk.ac.sussex.gdsc.smlm.results.TsfPeakResultsWriter)2 IOException (java.io.IOException)1