Changing more Java Lists to native arrays in BQSR for performance optimization.

This commit is contained in:
Eric Banks 2012-06-12 15:41:01 -04:00
parent 1da3e43679
commit 0f79adb2aa
4 changed files with 13 additions and 15 deletions

View File

@ -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<Long> longsFromAllKeys(final Long[] allKeys, final EventType eventType) {
final List<Long> allFinalKeys = new ArrayList<Long>(); // 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;
}

View File

@ -135,13 +135,13 @@ public class BaseRecalibration {
final BQSRKeyManager keyManager = mapEntry.getKey();
final Map<Long, RecalDatum> table = mapEntry.getValue();
final List<Long> 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;

View File

@ -116,7 +116,7 @@ public class BQSRKeyManagerUnitTest {
expectedCovariate[j - nRequired] = covariateList.get(j).formatKey(keySet[j]);
}
List<Long> 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();

View File

@ -74,7 +74,6 @@ public class BaseRecalibrationUnitTest {
BQSRKeyManager cvKeyManager = new BQSRKeyManager(requiredCovariates, optionalCovariates);
keysAndTablesMap.put(cvKeyManager, new HashMap<Long, RecalDatum>());
for (Covariate cov : requiredCovariates)
requestedCovariates.add(cov);
for (Covariate cov : optionalCovariates)
@ -85,7 +84,6 @@ public class BaseRecalibrationUnitTest {
for (int i=0; i<read.getReadLength(); i++) {
Long[] bitKeys = readCovariates.getMismatchesKeySet(i);
Object[] objKey = buildObjectKey(bitKeys);
Random random = new Random();
@ -99,7 +97,7 @@ public class BaseRecalibrationUnitTest {
RecalDatum newDatum = new RecalDatum(nObservations, nErrors, estimatedQReported, empiricalQuality);
for (Map.Entry<BQSRKeyManager, Map<Long, RecalDatum>> mapEntry : keysAndTablesMap.entrySet()) {
List<Long> 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);
}