From 5c3c6cbc40dd7da0bf53cbf04688d211d6a9f4db Mon Sep 17 00:00:00 2001 From: Eric Banks Date: Thu, 14 Jun 2012 09:07:02 -0400 Subject: [PATCH] Long -> long conversions in BQSR --- .../gatk/walkers/bqsr/BQSRKeyManager.java | 23 ++++++++++--------- .../gatk/walkers/bqsr/RecalDataManager.java | 4 ++-- .../walkers/bqsr/RecalibrationReport.java | 4 ++-- .../recalibration/BaseRecalibration.java | 2 ++ 4 files changed, 18 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 9efb5a86f..29eecfbb1 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 @@ -88,7 +88,7 @@ public class BQSRKeyManager { final int totalNumberOfBits = optionalCovariateIDOffset + nOptionalIDBits; // total number of bits used in the final key if ( totalNumberOfBits > 64 ) - throw new UserException.BadInput("The total number of bits used for the master BQSR key is greater than 64 and cannot be represented in a Long"); + throw new UserException.BadInput("The total number of bits used for the master BQSR key is greater than 64 and cannot be represented in a long"); } /** @@ -98,7 +98,7 @@ public class BQSRKeyManager { * * @param allKeys The keys in long representation for each covariate (includes all optional covariates, not just the one requested) * @param eventType The type of event described by this keyset (e.g. mismatches, insertions, deletions) - * @return one key in long representation + * @return one key in long representation (non-negative) or -1 for a bad key */ public long createMasterKey(final long[] allKeys, final EventType eventType, final int optionalCovariateIndex) { @@ -111,11 +111,12 @@ public class BQSRKeyManager { masterKey |= (eventKey << nRequiredBits); if (optionalCovariateIndex >= 0 && optionalCovariateIndex < optionalCovariates.length) { - final Long covariateKey = allKeys[keyIndex + optionalCovariateIndex]; - if (covariateKey != null) { // do not add nulls to the final set of keys - masterKey |= (covariateKey << optionalCovariateOffset); - masterKey |= (optionalCovariatesInfo[optionalCovariateIndex].covariateID << optionalCovariateIDOffset); - } + final long covariateKey = allKeys[keyIndex + optionalCovariateIndex]; + if (covariateKey < 0) // do not add "nulls" to the final set of keys + return -1; + + masterKey |= (covariateKey << optionalCovariateOffset); + masterKey |= (optionalCovariatesInfo[optionalCovariateIndex].covariateID << optionalCovariateIDOffset); } return masterKey; @@ -133,7 +134,7 @@ public class BQSRKeyManager { * @param key list of objects produced by the required covariates followed by one or zero optional covariates. * @return a key representing these objects. */ - public Long longFromKey(Object[] key) { + public long longFromKey(Object[] key) { int requiredCovariate = 0; long masterKey = 0L; // This will be a master key holding all the required keys, to replicate later on for (RequiredCovariateInfo infoRequired : requiredCovariatesInfo) @@ -176,15 +177,15 @@ public class BQSRKeyManager { * @param master the master representation of the keys * @return an object array with the values for each key */ - public List keySetFrom(final Long master) { + public List keySetFrom(final long master) { final List objectKeys = new ArrayList(); for (RequiredCovariateInfo info : requiredCovariatesInfo) { - final Long covariateKey = extractKeyFromMaster(master, info.mask, info.offset); // get the covariate's key + final long covariateKey = extractKeyFromMaster(master, info.mask, info.offset); // get the covariate's key objectKeys.add(info.covariate.formatKey(covariateKey)); // convert the key to object using covariate's interface } if (optionalCovariatesInfo.length > 0) { - final Long covKey = extractKeyFromMaster(master, optionalCovariateMask, optionalCovariateOffset); // get the covariate's key + final long covKey = extractKeyFromMaster(master, optionalCovariateMask, optionalCovariateOffset); // get the covariate's key final int covIDKey = (int)extractKeyFromMaster(master, optionalCovariateIDMask, optionalCovariateIDOffset); // get the covariate's id (to identify which covariate this is) Covariate covariate = optionalCovariatesInfo[(short)covIDKey].covariate; // get the corresponding optional covariate object objectKeys.add(covariate.formatKey(covKey)); // add the optional covariate key to the key set diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/RecalDataManager.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/RecalDataManager.java index 98cf587de..63ea2d677 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/RecalDataManager.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/RecalDataManager.java @@ -392,7 +392,7 @@ public class RecalDataManager { newCovs.add(1, covs.get(1)); newCovs.add(2, "QualityScore"); // replace the covariate name with QualityScore (for the QualityScore covariate) newCovs.add(3, covs.get(2)); - final Long deltaKey = deltaKeyManager.longFromKey(newCovs.toArray()); // create a new bitset key for the delta table + final long deltaKey = deltaKeyManager.longFromKey(newCovs.toArray()); // create a new bitset key for the delta table addToDeltaTable(deltaTable, deltaKey, recalDatum); // add this covariate to the delta table } } @@ -406,7 +406,7 @@ public class RecalDataManager { final List covs = keyManager.keySetFrom(entry.getKey()); // extract the key objects from the bitset key covs.remove(QUALITY_SCORE_COVARIATE_INDEX); // reset the quality score covariate to 0 from the keyset (so we aggregate all rows regardless of QS) - final Long deltaKey = deltaKeyManager.longFromKey(covs.toArray()); // create a new bitset key for the delta table + final long deltaKey = deltaKeyManager.longFromKey(covs.toArray()); // create a new bitset key for the delta table addToDeltaTable(deltaTable, deltaKey, recalDatum); // add this covariate to the delta table } readyToPrint = true; diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/RecalibrationReport.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/RecalibrationReport.java index da21d566c..ed1864bba 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/RecalibrationReport.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/RecalibrationReport.java @@ -113,7 +113,7 @@ public class RecalibrationReport { final Long otherBitKey = otherTableEntry.getKey(); final List otherObjectKey = otherKeyManager.keySetFrom(otherBitKey); - final Long thisKey = thisKeyManager.longFromKey(otherObjectKey.toArray()); + final long thisKey = thisKeyManager.longFromKey(otherObjectKey.toArray()); final RecalDatum thisDatum = thisTable.get(thisKey); if (thisDatum == null) @@ -199,7 +199,7 @@ public class RecalibrationReport { for (int j = 0; j < nKeys; j++) keySet[j] = reportTable.get(i, columnNamesOrderedList.get(j)); // all these objects are okay in String format, the key manager will handle them correctly (except for the event type (see below) keySet[keySet.length-1] = EventType.eventFrom((String) keySet[keySet.length-1]); // the last key is always the event type. We convert the string ("M", "I" or "D") to an enum object (necessary for the key manager). - final Long bitKey = keyManager.longFromKey(keySet); + final long bitKey = keyManager.longFromKey(keySet); final long nObservations = (Long) reportTable.get(i, RecalDataManager.NUMBER_OBSERVATIONS_COLUMN_NAME); final long nErrors = (Long) reportTable.get(i, RecalDataManager.NUMBER_ERRORS_COLUMN_NAME); 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 da5558a9e..2f292dbf8 100644 --- a/public/java/src/org/broadinstitute/sting/utils/recalibration/BaseRecalibration.java +++ b/public/java/src/org/broadinstitute/sting/utils/recalibration/BaseRecalibration.java @@ -165,6 +165,8 @@ public class BaseRecalibration { else { // this is the table with all the covariates for (int i = 0; i < numOptionalCovariates; i++) { masterKey = keyManager.createMasterKey(key, errorModel, i); + if (masterKey < 0) + continue; final RecalDatum empiricalQualCO = table.get(masterKey); if (empiricalQualCO != null) { final double deltaQCovariateEmpirical = empiricalQualCO.getEmpiricalQuality();