From f807b29168110c628ff2e409eca01538a81a4ab1 Mon Sep 17 00:00:00 2001 From: Khalid Shakir Date: Sun, 9 Jun 2024 16:39:54 -0400 Subject: [PATCH] Use an LRU cache with CorrectAndSplitScrnaReadPairs to reduce mem --- gradle/wrapper/gradle-wrapper.properties | 2 +- .../CorrectAndSplitScrnaReadPairs.java | 28 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3fa8f862..a4413138 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/java/org/broadinstitute/dropseqrna/beadsynthesis/CorrectAndSplitScrnaReadPairs.java b/src/java/org/broadinstitute/dropseqrna/beadsynthesis/CorrectAndSplitScrnaReadPairs.java index edfb06e3..1e420373 100644 --- a/src/java/org/broadinstitute/dropseqrna/beadsynthesis/CorrectAndSplitScrnaReadPairs.java +++ b/src/java/org/broadinstitute/dropseqrna/beadsynthesis/CorrectAndSplitScrnaReadPairs.java @@ -79,11 +79,26 @@ public class CorrectAndSplitScrnaReadPairs public String BARCODE_QUALS_TAG; private Map allowedBarcodeNormalizedOccurences; - private final Map> ed1MatchCache = new HashMap<>(); + + private final ResourceLimitedMap> ed1MatchCache = + new ResourceLimitedMap<>( + 1_000_000, + new ResourceLimitedMapFunctor<>() { + @Override + public List makeValue(final String key) { + return CorrectAndSplitScrnaReadPairs.this.getEd1Matches(key); + } + + @Override + public void finalizeValue(final String key, final List strings) { + } + } + ); + private List baseRanges; - private BarcodeCorrectionMetrics metrics = new BarcodeCorrectionMetrics(); - private Histogram numCandidatesHist = new Histogram<>("NUM_ED1_CANDIDATES", "NUM_READS"); + private final BarcodeCorrectionMetrics metrics = new BarcodeCorrectionMetrics(); + private final Histogram numCandidatesHist = new Histogram<>("NUM_ED1_CANDIDATES", "NUM_READS"); @Override protected void splitBAMs() { @@ -146,7 +161,7 @@ private String getCorrectedCellBarcode(final SAMRecord readWithBarcode) { exactMatchBarcodes.add(cellBarcode); return cellBarcode; } else { - List ed1Matches = ed1MatchCache.computeIfAbsent(cellBarcode, this::getEd1Matches); + List ed1Matches = ed1MatchCache.get(cellBarcode); if (ed1Matches.isEmpty()) { if (VERBOSITY == Log.LogLevel.DEBUG && metrics.NUM_READS_UNCORRECTABLE_NO_ED1_BARCODES == 0) { log.debug("UNCORRECTABLE_NO_ED1 " + readWithBarcode); @@ -267,4 +282,9 @@ public static class BarcodeCorrectionMetrics extends MetricBase { public long NUM_BARCODES_UNCORRECTABLE_NO_ED1_BARCODES; public long NUM_BARCODES_UNCORRECTED_AMBIGUOUS; } + + /** Stock main method. */ + public static void main(final String[] args) { + System.exit(new CorrectAndSplitScrnaReadPairs().instanceMain(args)); + } }