diff --git a/render-ws-java-client/src/main/java/org/janelia/render/client/CopyMatchClient.java b/render-ws-java-client/src/main/java/org/janelia/render/client/CopyMatchClient.java index fdc4ae9f2..6d468545d 100644 --- a/render-ws-java-client/src/main/java/org/janelia/render/client/CopyMatchClient.java +++ b/render-ws-java-client/src/main/java/org/janelia/render/client/CopyMatchClient.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; import org.janelia.alignment.match.CanvasMatches; import org.janelia.alignment.match.MatchAggregator; @@ -57,7 +58,7 @@ private void copyMatches(final Parameters parameters) final RenderDataClient sourceMatchClient = parameters.matchClient.getDataClient(); final RenderDataClient targetMatchClient = parameters.matchCopy.buildTargetMatchClient(sourceMatchClient); final List pGroupIds; - if ((parameters.matchCopy.pGroupIds == null) || (parameters.matchCopy.pGroupIds.size() == 0)) { + if ((parameters.matchCopy.pGroupIds == null) || parameters.matchCopy.pGroupIds.isEmpty()) { pGroupIds = sourceMatchClient.getMatchPGroupIds(); } else { pGroupIds = parameters.matchCopy.pGroupIds; @@ -73,15 +74,31 @@ public static void copyMatches(final RenderDataClient sourceMatchClient, final String pGroupId, final MatchCopyParameters matchCopy) throws Exception { - final List groupMatches = - sourceMatchClient.getMatchesWithPGroupId(pGroupId, false); + List groupMatches = sourceMatchClient.getMatchesWithPGroupId(pGroupId, false); - if (groupMatches.size() > 0) { + if (! groupMatches.isEmpty()) { if (matchCopy.removeExisting) { targetMatchClient.deleteMatchesWithPGroupId(pGroupId); } + if (matchCopy.excludePairsWithTileIdPattern != null) { + final Pattern excludePattern = Pattern.compile(matchCopy.excludePairsWithTileIdPattern); + final List matchesToKeep = new ArrayList<>(groupMatches.size()); + final long originalPairCount = groupMatches.size(); + for (final CanvasMatches match : groupMatches) { + final String pTileId = match.getpId(); + final String qTileId = match.getqId(); + if (! excludePattern.matcher(pTileId).matches() && ! excludePattern.matcher(qTileId).matches()) { + matchesToKeep.add(match); + } + } + groupMatches = matchesToKeep; + + LOG.info("copyMatches: reduced {} to {} pairs that do not include a tileId with the pattern {}", + originalPairCount, groupMatches.size(), matchCopy.excludePairsWithTileIdPattern); + } + if (matchCopy.isAggregationRequested()) { final long originalMatchCount = countMatches(groupMatches); aggregateMatches(groupMatches, matchCopy); diff --git a/render-ws-java-client/src/main/java/org/janelia/render/client/parameter/MatchCopyParameters.java b/render-ws-java-client/src/main/java/org/janelia/render/client/parameter/MatchCopyParameters.java index 00bf36c02..d09d0fd74 100644 --- a/render-ws-java-client/src/main/java/org/janelia/render/client/parameter/MatchCopyParameters.java +++ b/render-ws-java-client/src/main/java/org/janelia/render/client/parameter/MatchCopyParameters.java @@ -68,6 +68,13 @@ public class MatchCopyParameters description = "Pixel radius for cross layer match filtering") public Double matchAggregationRadiusCross; + @Parameter( + names = "--excludePairsWithTileIdPattern", + description = "Do not copy match pairs that include at least one tile with an ID matching this pattern, " + + "e.g. .*_0000(01|02|03|04|07|08|12|13|16|17|18|19)_.*", + variableArity = true) + public String excludePairsWithTileIdPattern; + public MatchCopyParameters() { }