Skip to content

Commit

Permalink
Reduce memory footprint by quasi-interning allowed barcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
alecw committed Jun 10, 2024
1 parent f475449 commit c466a5c
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.broadinstitute.dropseqrna.utils.AbstractSplitBamClp;
import org.broadinstitute.dropseqrna.utils.BaseRange;
import org.broadinstitute.dropseqrna.utils.PairedSamRecordIterator;
import org.broadinstitute.dropseqrna.utils.StringInterner;
import org.broadinstitute.dropseqrna.utils.readpairs.ReadPair;
import picard.cmdline.StandardOptionDefinitions;

Expand Down Expand Up @@ -79,6 +80,8 @@ public class CorrectAndSplitScrnaReadPairs
public String BARCODE_QUALS_TAG;

private Map<String, Double> allowedBarcodeNormalizedOccurences;
// Don't store many copies of the same allowed barcode in ed1MatchCache
private final StringInterner allowedBarcodeInterner = new StringInterner();

private final ResourceLimitedMap<String, List<String>> ed1MatchCache =
new ResourceLimitedMap<>(
Expand Down Expand Up @@ -145,7 +148,7 @@ private Map<String, Double> getNormalizedAllowedBarcodes() {
double allowedBarcodeOccurenceCount = allowedBarcodeHistogram.getSumOfValues();
final Map<String, Double> ret = new HashMap<>(allowedBarcodeHistogram.size());
for (final String allowedBarcode: allowedBarcodeHistogram.keySet()) {
ret.put(allowedBarcode, allowedBarcodeHistogram.get(allowedBarcode).getValue()/allowedBarcodeOccurenceCount);
ret.put(allowedBarcodeInterner.intern(allowedBarcode), allowedBarcodeHistogram.get(allowedBarcode).getValue()/allowedBarcodeOccurenceCount);
}
return ret;
}
Expand Down Expand Up @@ -230,7 +233,7 @@ private List<String> getEd1Matches(final String cellBarcode) {
cellBarcodeBytes[i] = b;
final String candidate = StringUtil.bytesToString(cellBarcodeBytes);
if (allowedBarcodeNormalizedOccurences.containsKey(candidate)) {
ret.add(candidate);
ret.add(allowedBarcodeInterner.intern(candidate));
}
}
cellBarcodeBytes[i] = original;
Expand Down

0 comments on commit c466a5c

Please sign in to comment.