use of ij.plugin.PlugIn in project GDSC-SMLM by aherbert.
the class TraceExporter method export.
private void export(MemoryPeakResults results) {
// Copy to allow manipulation
results = results.copy();
// Strip results with no trace Id
results.removeIf(result -> result.getId() <= 0);
// Sort by ID then time
results.sort(IdFramePeakResultComparator.INSTANCE);
// Split traces with big jumps and long tracks into smaller tracks
results = splitTraces(results);
results = splitLongTraces(results);
// Count each ID and remove short traces
int id = 0;
int count = 0;
int tracks = 0;
int maxLength = 0;
final TIntHashSet remove = new TIntHashSet();
for (int i = 0, size = results.size(); i < size; i++) {
final PeakResult result = results.get(i);
if (result.getId() != id) {
if (count < settings.minLength) {
remove.add(id);
} else {
tracks++;
maxLength = Math.max(maxLength, count);
}
count = 0;
id = result.getId();
}
count += getLength(result);
}
// Final ID
if (count < settings.minLength) {
remove.add(id);
} else {
tracks++;
maxLength = Math.max(maxLength, count);
}
if (!remove.isEmpty()) {
results.removeIf(result -> remove.contains(result.getId()));
results.sort(IdFramePeakResultComparator.INSTANCE);
}
if (settings.wobble > 0) {
// Just leave any exceptions to trickle up and kill the plugin
final TypeConverter<DistanceUnit> c = results.getDistanceConverter(DistanceUnit.NM);
final double w = c.convertBack(settings.wobble);
final UniformRandomProvider rng = UniformRandomProviders.create();
final NormalizedGaussianSampler gauss = SamplerUtils.createNormalizedGaussianSampler(rng);
final boolean is3D = results.is3D();
results.forEach((PeakResultProcedure) peakResult -> {
peakResult.setXPosition((float) (peakResult.getXPosition() + w * gauss.sample()));
peakResult.setYPosition((float) (peakResult.getYPosition() + w * gauss.sample()));
if (is3D) {
peakResult.setZPosition((float) (peakResult.getZPosition() + w * gauss.sample()));
}
});
}
if (settings.format == 2) {
exportVbSpt(results);
} else if (settings.format == 1) {
exportAnaDda(results);
} else {
exportSpotOn(results);
}
ImageJUtils.log("Exported %s: %s in %s", results.getName(), TextUtils.pleural(results.size(), "localisation"), TextUtils.pleural(tracks, "track"));
if (settings.showTraceLengths) {
// We store and index (count-1)
final int[] h = new int[maxLength];
id = 0;
for (int i = 0, size = results.size(); i < size; i++) {
final PeakResult result = results.get(i);
if (result.getId() != id) {
h[count - 1]++;
count = 0;
id = result.getId();
}
count += getLength(result);
}
h[count - 1]++;
final String title = TITLE + ": " + results.getName();
final Plot plot = new Plot(title, "Length", "Frequency");
plot.addPoints(SimpleArrayUtils.newArray(h.length, 1, 1.0f), SimpleArrayUtils.toFloat(h), Plot.BAR);
plot.setLimits(SimpleArrayUtils.findIndex(h, i -> i != 0), maxLength + 1, 0, Double.NaN);
ImageJUtils.display(title, plot);
}
}
Aggregations