From ff96b368d82f889b34a78b58af0af5d6aad2d31d Mon Sep 17 00:00:00 2001 From: Cristian Goina Date: Wed, 11 Sep 2024 09:59:57 -0400 Subject: [PATCH] replaced explicit CDMatchEntity mask and target types with generics - in order to allow running flywire vs hemibrain which is EM vs EM --- .../cmd/CalculateGradientScoresCmd.java | 40 +++++++++---------- .../cmd/NormalizeGradientScoresCmd.java | 8 ++-- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/colormipsearch-tools/src/main/java/org/janelia/colormipsearch/cmd/CalculateGradientScoresCmd.java b/colormipsearch-tools/src/main/java/org/janelia/colormipsearch/cmd/CalculateGradientScoresCmd.java index 7e8cbba4..6d066502 100644 --- a/colormipsearch-tools/src/main/java/org/janelia/colormipsearch/cmd/CalculateGradientScoresCmd.java +++ b/colormipsearch-tools/src/main/java/org/janelia/colormipsearch/cmd/CalculateGradientScoresCmd.java @@ -51,9 +51,7 @@ import org.janelia.colormipsearch.model.AbstractNeuronEntity; import org.janelia.colormipsearch.model.CDMatchEntity; import org.janelia.colormipsearch.model.ComputeFileType; -import org.janelia.colormipsearch.model.EMNeuronEntity; import org.janelia.colormipsearch.model.FileData; -import org.janelia.colormipsearch.model.LMNeuronEntity; import org.janelia.colormipsearch.model.ProcessingType; import org.janelia.colormipsearch.results.GroupedMatchedEntities; import org.janelia.colormipsearch.results.ItemsHandling; @@ -125,7 +123,7 @@ void execute() { calculateAllGradientScores(); } - private void calculateAllGradientScores() { + private void calculateAllGradientScores() { long startTime = System.currentTimeMillis(); ImageRegionDefinition excludedRegions = args.getRegionGeneratorForTextLabels(); ColorDepthSearchAlgorithmProvider gradScoreAlgorithmProvider = ColorDepthSearchAlgorithmProviderFactory.createShapeMatchCDSAlgorithmProvider( @@ -135,8 +133,8 @@ private void calculateAllGradientScores() { loadQueryROIMask(args.queryROIMaskName), excludedRegions ); - NeuronMatchesReader> cdMatchesReader = getCDMatchesReader(); - NeuronMatchesWriter> cdMatchesWriter = getCDMatchesWriter(); + NeuronMatchesReader> cdMatchesReader = getCDMatchesReader(); + NeuronMatchesWriter> cdMatchesWriter = getCDMatchesWriter(); CDMIPsWriter cdmipsWriter = getCDMipsWriter(); Collection matchesMasksToProcess = cdMatchesReader.listMatchesLocations( args.masksLibraries.stream() @@ -186,13 +184,13 @@ private void calculateAllGradientScores() { (Runtime.getRuntime().totalMemory() / _1M)); } - private void processMasks(List masksIds, - NeuronMatchesReader> cdMatchesReader, - NeuronMatchesWriter> cdMatchesWriter, - CDMIPsWriter cdmipsWriter, - ColorDepthSearchAlgorithmProvider gradScoreAlgorithmProvider, - Executor executor, - String processingContext) { + private void processMasks(List masksIds, + NeuronMatchesReader> cdMatchesReader, + NeuronMatchesWriter> cdMatchesWriter, + CDMIPsWriter cdmipsWriter, + ColorDepthSearchAlgorithmProvider gradScoreAlgorithmProvider, + Executor executor, + String processingContext) { LOG.info("Start {} - process {} masks", processingContext, masksIds.size()); long startProcessingPartitionTime = System.currentTimeMillis(); long updatedMatches = 0; @@ -208,15 +206,15 @@ private void processMasks(List masksIds, (Runtime.getRuntime().totalMemory() / _1M)); } - private long processMask(String maskId, - NeuronMatchesReader> cdMatchesReader, - NeuronMatchesWriter> cdMatchesWriter, + private long processMask(String maskId, + NeuronMatchesReader> cdMatchesReader, + NeuronMatchesWriter> cdMatchesWriter, CDMIPsWriter cdmipsWriter, ColorDepthSearchAlgorithmProvider gradScoreAlgorithmProvider, Executor executor, String processingContext) { // read all matches for the current mask - List> cdMatchesForMask = getCDMatchesForMask(cdMatchesReader, maskId); + List> cdMatchesForMask = getCDMatchesForMask(cdMatchesReader, maskId); long nPublishedNames = cdMatchesForMask.stream() .map(cdm -> cdm.getMatchedImage().getPublishedName()) .distinct() @@ -234,7 +232,7 @@ private long processMask(String maskId, maskId, (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / _1M + 1, // round up (Runtime.getRuntime().totalMemory() / _1M)); - List> cdMatchesWithGradScores = calculateGradientScores( + List> cdMatchesWithGradScores = calculateGradientScores( gradScoreAlgorithmProvider, cdMatchesForMask, args.gradScoreParallelism, @@ -437,10 +435,10 @@ List> getCDMatchesForMask(NeuronMatchesReader List>>> startGradScoreComputations(M mask, - List> selectedMatches, - ColorDepthSearchAlgorithmProvider gradScoreAlgorithmProvider, - int gradScoreParallelism, - Executor executor) { + List> selectedMatches, + ColorDepthSearchAlgorithmProvider gradScoreAlgorithmProvider, + int gradScoreParallelism, + Executor executor) { if (CollectionUtils.isEmpty(selectedMatches)) { LOG.error("No matches were selected for {}", mask); return Collections.emptyList(); diff --git a/colormipsearch-tools/src/main/java/org/janelia/colormipsearch/cmd/NormalizeGradientScoresCmd.java b/colormipsearch-tools/src/main/java/org/janelia/colormipsearch/cmd/NormalizeGradientScoresCmd.java index 04c5b690..b13047d1 100644 --- a/colormipsearch-tools/src/main/java/org/janelia/colormipsearch/cmd/NormalizeGradientScoresCmd.java +++ b/colormipsearch-tools/src/main/java/org/janelia/colormipsearch/cmd/NormalizeGradientScoresCmd.java @@ -44,8 +44,6 @@ import org.janelia.colormipsearch.model.AbstractNeuronEntity; import org.janelia.colormipsearch.model.CDMatchEntity; import org.janelia.colormipsearch.model.ComputeFileType; -import org.janelia.colormipsearch.model.EMNeuronEntity; -import org.janelia.colormipsearch.model.LMNeuronEntity; import org.janelia.colormipsearch.model.ProcessingType; import org.janelia.colormipsearch.results.ItemsHandling; import org.slf4j.Logger; @@ -89,9 +87,9 @@ void execute() { normalizeAllGradientScores(); } - private void normalizeAllGradientScores() { + private void normalizeAllGradientScores() { long startTime = System.currentTimeMillis(); - NeuronMatchesReader> cdMatchesReader = getCDMatchesReader(); + NeuronMatchesReader> cdMatchesReader = getCDMatchesReader(); Collection matchesMasksToProcess = cdMatchesReader.listMatchesLocations( args.masksLibraries.stream() .map(larg -> new DataSourceParam() @@ -115,7 +113,7 @@ private void normalizeAllGradientScores() { // process each item from the current partition sequentially indexedPartition.getValue().forEach(maskIdToProcess -> { // read all matches for the current mask - List> cdMatchesForMask = getCDMatchesForMask(cdMatchesReader, maskIdToProcess); + List> cdMatchesForMask = getCDMatchesForMask(cdMatchesReader, maskIdToProcess); // normalize the grad scores LOG.info("Normalize grad scores for {} matches of {}", cdMatchesForMask.size(), maskIdToProcess); updateNormalizedScores(cdMatchesForMask);