From 0f79adb2aa1c13ec6eb5f00ecb7f57c9d4608e51 Mon Sep 17 00:00:00 2001 From: Eric Banks Date: Tue, 12 Jun 2012 15:41:01 -0400 Subject: [PATCH] Changing more Java Lists to native arrays in BQSR for performance optimization. --- .../sting/gatk/walkers/bqsr/BQSRKeyManager.java | 12 ++++++------ .../sting/utils/recalibration/BaseRecalibration.java | 10 +++++----- .../gatk/walkers/bqsr/BQSRKeyManagerUnitTest.java | 2 +- .../recalibration/BaseRecalibrationUnitTest.java | 4 +--- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/BQSRKeyManager.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/BQSRKeyManager.java index 389863620..9880af405 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/BQSRKeyManager.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/BQSRKeyManager.java @@ -109,8 +109,8 @@ public class BQSRKeyManager { * @param eventType The type of event described by this keyset (e.g. mismatches, insertions, deletions) * @return one key in long representation per covariate */ - public List longsFromAllKeys(final Long[] allKeys, final EventType eventType) { - final List allFinalKeys = new ArrayList(); // Generate one key per optional covariate + public Long[] longsFromAllKeys(final Long[] allKeys, final EventType eventType) { + final Long[] allFinalKeys = new Long[optionalCovariatesInfo.length > 0 ? optionalCovariatesInfo.length : 1]; // Generate one key per optional covariate int covariateIndex = 0; long masterKey = 0L; // This will be a master key holding all the required keys, to replicate later on @@ -120,19 +120,19 @@ public class BQSRKeyManager { final long eventKey = keyFromEvent(eventType); // create a key for the event type masterKey |= (eventKey << nRequiredBits); - for (OptionalCovariateInfo infoOptional : optionalCovariatesInfo) { + for (int i = 0; i < optionalCovariatesInfo.length; i++) { final Long covariateKey = allKeys[covariateIndex++]; if (covariateKey == null) continue; // do not add nulls to the final set of keys. long newKey = masterKey | (covariateKey << optionalCovariateOffset); - newKey |= (infoOptional.covariateID << optionalCovariateIDOffset); + newKey |= (optionalCovariatesInfo[i].covariateID << optionalCovariateIDOffset); - allFinalKeys.add(newKey); // add this key to the list of keys + allFinalKeys[i] = newKey; // add this key to the list of keys } if (optionalCovariatesInfo.length == 0) // special case when we have no optional covariates - allFinalKeys.add(masterKey); + allFinalKeys[0] = masterKey; return allFinalKeys; } diff --git a/public/java/src/org/broadinstitute/sting/utils/recalibration/BaseRecalibration.java b/public/java/src/org/broadinstitute/sting/utils/recalibration/BaseRecalibration.java index fc5d5117c..45b814c17 100644 --- a/public/java/src/org/broadinstitute/sting/utils/recalibration/BaseRecalibration.java +++ b/public/java/src/org/broadinstitute/sting/utils/recalibration/BaseRecalibration.java @@ -135,13 +135,13 @@ public class BaseRecalibration { final BQSRKeyManager keyManager = mapEntry.getKey(); final Map table = mapEntry.getValue(); - final List bitKeys = keyManager.longsFromAllKeys(key, errorModel); // calculate the shift in quality due to the read group + final Long[] bitKeys = keyManager.longsFromAllKeys(key, errorModel); // calculate the shift in quality due to the read group switch(keyManager.getNumRequiredCovariates()) { case 1: // this is the ReadGroup table - if (bitKeys.size() > 1) + if (bitKeys.length > 1) throw new ReviewedStingException(TOO_MANY_KEYS_EXCEPTION); - final RecalDatum empiricalQualRG = table.get(bitKeys.get(0)); + final RecalDatum empiricalQualRG = table.get(bitKeys[0]); if (empiricalQualRG != null) { final double globalDeltaQEmpirical = empiricalQualRG.getEmpiricalQuality(); final double aggregrateQReported = empiricalQualRG.getEstimatedQReported(); @@ -150,10 +150,10 @@ public class BaseRecalibration { break; case 2: if (keyManager.getNumOptionalCovariates() == 0) { // this is the QualityScore table - if (bitKeys.size() > 1) + if (bitKeys.length > 1) throw new ReviewedStingException(TOO_MANY_KEYS_EXCEPTION); - final RecalDatum empiricalQualQS = table.get(bitKeys.get(0)); + final RecalDatum empiricalQualQS = table.get(bitKeys[0]); if (empiricalQualQS != null) { final double deltaQReportedEmpirical = empiricalQualQS.getEmpiricalQuality(); deltaQReported = deltaQReportedEmpirical - qualFromRead - globalDeltaQ; diff --git a/public/java/test/org/broadinstitute/sting/gatk/walkers/bqsr/BQSRKeyManagerUnitTest.java b/public/java/test/org/broadinstitute/sting/gatk/walkers/bqsr/BQSRKeyManagerUnitTest.java index c7591eb25..33ce22c66 100644 --- a/public/java/test/org/broadinstitute/sting/gatk/walkers/bqsr/BQSRKeyManagerUnitTest.java +++ b/public/java/test/org/broadinstitute/sting/gatk/walkers/bqsr/BQSRKeyManagerUnitTest.java @@ -116,7 +116,7 @@ public class BQSRKeyManagerUnitTest { expectedCovariate[j - nRequired] = covariateList.get(j).formatKey(keySet[j]); } - List hashKeys = keyManager.longsFromAllKeys(keySet, EventType.eventFrom(eventType)); + Long[] hashKeys = keyManager.longsFromAllKeys(keySet, EventType.eventFrom(eventType)); short cov = 0; for (Long key : hashKeys) { Object[] actual = keyManager.keySetFrom(key).toArray(); diff --git a/public/java/test/org/broadinstitute/sting/utils/recalibration/BaseRecalibrationUnitTest.java b/public/java/test/org/broadinstitute/sting/utils/recalibration/BaseRecalibrationUnitTest.java index 277e55885..96dc0ec36 100644 --- a/public/java/test/org/broadinstitute/sting/utils/recalibration/BaseRecalibrationUnitTest.java +++ b/public/java/test/org/broadinstitute/sting/utils/recalibration/BaseRecalibrationUnitTest.java @@ -74,7 +74,6 @@ public class BaseRecalibrationUnitTest { BQSRKeyManager cvKeyManager = new BQSRKeyManager(requiredCovariates, optionalCovariates); keysAndTablesMap.put(cvKeyManager, new HashMap()); - for (Covariate cov : requiredCovariates) requestedCovariates.add(cov); for (Covariate cov : optionalCovariates) @@ -85,7 +84,6 @@ public class BaseRecalibrationUnitTest { for (int i=0; i> mapEntry : keysAndTablesMap.entrySet()) { - List keys = mapEntry.getKey().longsFromAllKeys(bitKeys, EventType.BASE_SUBSTITUTION); + Long[] keys = mapEntry.getKey().longsFromAllKeys(bitKeys, EventType.BASE_SUBSTITUTION); for (Long key : keys) updateCovariateWithKeySet(mapEntry.getValue(), key, newDatum); }