Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce memory footprint by quasi-interning allowed barcodes #428

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading