Long -> long conversions in BQSR

This commit is contained in:
Eric Banks 2012-06-14 09:07:02 -04:00
parent 29a74908bb
commit 5c3c6cbc40
4 changed files with 18 additions and 15 deletions

View File

@ -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<Object> keySetFrom(final Long master) {
public List<Object> keySetFrom(final long master) {
final List<Object> objectKeys = new ArrayList<Object>();
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

View File

@ -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<Object> 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;

View File

@ -113,7 +113,7 @@ public class RecalibrationReport {
final Long otherBitKey = otherTableEntry.getKey();
final List<Object> 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);

View File

@ -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();