From a4670113bd9bd3f036dfa573f0aea90f9cb305c8 Mon Sep 17 00:00:00 2001 From: Eric Banks Date: Tue, 3 Jul 2012 00:12:33 -0400 Subject: [PATCH] Refactored/renamed the nested integer array; cleaned up code a bit. --- .../gatk/walkers/bqsr/QuantizationInfo.java | 4 +- .../gatk/walkers/bqsr/RecalDataManager.java | 65 ++++---- .../walkers/bqsr/RecalibrationReport.java | 14 +- .../IntegerIndexedNestedHashMap.java | 117 -------------- .../utils/collections/NestedIntegerArray.java | 143 ++++++++++++++++++ .../recalibration/BaseRecalibration.java | 14 +- .../recalibration/RecalibrationTables.java | 20 +-- .../bqsr/RecalibrationReportUnitTest.java | 8 +- .../BaseRecalibrationUnitTest.java | 8 +- 9 files changed, 207 insertions(+), 186 deletions(-) delete mode 100755 public/java/src/org/broadinstitute/sting/utils/collections/IntegerIndexedNestedHashMap.java create mode 100755 public/java/src/org/broadinstitute/sting/utils/collections/NestedIntegerArray.java diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/QuantizationInfo.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/QuantizationInfo.java index d2570121f..fb3aef949 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/QuantizationInfo.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/QuantizationInfo.java @@ -3,7 +3,7 @@ package org.broadinstitute.sting.gatk.walkers.bqsr; import org.broadinstitute.sting.gatk.report.GATKReportTable; import org.broadinstitute.sting.utils.MathUtils; import org.broadinstitute.sting.utils.QualityUtils; -import org.broadinstitute.sting.utils.collections.IntegerIndexedNestedHashMap; +import org.broadinstitute.sting.utils.collections.NestedIntegerArray; import org.broadinstitute.sting.utils.recalibration.QualQuantizer; import org.broadinstitute.sting.utils.recalibration.RecalibrationTables; @@ -36,7 +36,7 @@ public class QuantizationInfo { for (int i = 0; i < qualHistogram.length; i++) qualHistogram[i] = 0L; - final IntegerIndexedNestedHashMap qualTable = recalibrationTables.getTable(RecalibrationTables.TableType.QUALITY_SCORE_TABLE); // get the quality score table + final NestedIntegerArray qualTable = recalibrationTables.getTable(RecalibrationTables.TableType.QUALITY_SCORE_TABLE); // get the quality score table for (final RecalDatum value : qualTable.getAllValues()) { final RecalDatum datum = value; 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 aa18eaf79..80e8b574a 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 @@ -32,7 +32,7 @@ import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.R.RScriptExecutor; import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.utils.classloader.PluginManager; -import org.broadinstitute.sting.utils.collections.IntegerIndexedNestedHashMap; +import org.broadinstitute.sting.utils.collections.NestedIntegerArray; import org.broadinstitute.sting.utils.collections.NestedHashMap; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.exceptions.DynamicClassResolutionException; @@ -213,6 +213,7 @@ public class RecalDataManager { private static List generateReportTables(final RecalibrationTables recalibrationTables, final Covariate[] requestedCovariates) { List result = new LinkedList(); int reportTableIndex = 0; + int rowIndex = 0; final Map covariateNameMap = new HashMap(requestedCovariates.length); for (final Covariate covariate : requestedCovariates) @@ -220,11 +221,11 @@ public class RecalDataManager { for (int tableIndex = 0; tableIndex < recalibrationTables.numTables(); tableIndex++) { - final ArrayList> columnNames = new ArrayList>(); // initialize the array to hold the column names + final ArrayList> columnNames = new ArrayList>(); // initialize the array to hold the column names columnNames.add(new Pair(covariateNameMap.get(requestedCovariates[0]), "%s")); // save the required covariate name so we can reference it in the future if (tableIndex != RecalibrationTables.TableType.READ_GROUP_TABLE.index) { columnNames.add(new Pair(covariateNameMap.get(requestedCovariates[1]), "%s")); // save the required covariate name so we can reference it in the future - if (tableIndex == RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index) { + if (tableIndex >= RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index) { columnNames.add(covariateValue); columnNames.add(covariateName); } @@ -237,38 +238,42 @@ public class RecalDataManager { columnNames.add(nObservations); columnNames.add(nErrors); - final GATKReportTable reportTable = new GATKReportTable("RecalTable" + reportTableIndex++, "", columnNames.size()); - for (final Pair columnName : columnNames) - reportTable.addColumn(columnName.getFirst(), columnName.getSecond()); // every table must have the event type + final GATKReportTable reportTable; + if (tableIndex <= RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index) { + reportTable = new GATKReportTable("RecalTable" + reportTableIndex++, "", columnNames.size()); + for (final Pair columnName : columnNames) + reportTable.addColumn(columnName.getFirst(), columnName.getSecond()); + rowIndex = 0; // reset the row index since we're starting with a new table + } else { + reportTable = result.get(RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index); + } - int rowIndex = 0; - - final IntegerIndexedNestedHashMap table = recalibrationTables.getTable(tableIndex); - for (final IntegerIndexedNestedHashMap.Leaf row : table.getAllLeaves()) { + final NestedIntegerArray table = recalibrationTables.getTable(tableIndex); + for (final NestedIntegerArray.Leaf row : table.getAllLeaves()) { final RecalDatum datum = (RecalDatum)row.value; final int[] keys = row.keys; int columnIndex = 0; - setReportTableCell(reportTable, rowIndex, columnNames.get(columnIndex).getFirst(), requestedCovariates[0].formatKey(keys[columnIndex++])); + int keyIndex = 0; + reportTable.set(rowIndex, columnNames.get(columnIndex++).getFirst(), requestedCovariates[0].formatKey(keys[keyIndex++])); if (tableIndex != RecalibrationTables.TableType.READ_GROUP_TABLE.index) { - setReportTableCell(reportTable, rowIndex, columnNames.get(columnIndex).getFirst(), requestedCovariates[1].formatKey(keys[columnIndex++])); + reportTable.set(rowIndex, columnNames.get(columnIndex++).getFirst(), requestedCovariates[1].formatKey(keys[keyIndex++])); if (tableIndex >= RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index) { final Covariate covariate = requestedCovariates[tableIndex]; - final int covariateKey = keys[columnIndex+1]; - setReportTableCell(reportTable, rowIndex, columnNames.get(columnIndex++).getFirst(), covariate.formatKey(covariateKey)); - setReportTableCell(reportTable, rowIndex, columnNames.get(columnIndex++).getFirst(), covariateNameMap.get(covariate)); + reportTable.set(rowIndex, columnNames.get(columnIndex++).getFirst(), covariate.formatKey(keys[keyIndex++])); + reportTable.set(rowIndex, columnNames.get(columnIndex++).getFirst(), covariateNameMap.get(covariate)); } } - final EventType event = EventType.eventFrom(keys[columnIndex]); - setReportTableCell(reportTable, rowIndex, columnNames.get(columnIndex++).getFirst(), event); + final EventType event = EventType.eventFrom(keys[keyIndex]); + reportTable.set(rowIndex, columnNames.get(columnIndex++).getFirst(), event.toString()); - setReportTableCell(reportTable, rowIndex, columnNames.get(columnIndex++).getFirst(), datum.getEmpiricalQuality()); + reportTable.set(rowIndex, columnNames.get(columnIndex++).getFirst(), datum.getEmpiricalQuality()); if (tableIndex == RecalibrationTables.TableType.READ_GROUP_TABLE.index) - setReportTableCell(reportTable, rowIndex, columnNames.get(columnIndex++).getFirst(), datum.getEstimatedQReported()); // we only add the estimated Q reported in the RG table - setReportTableCell(reportTable, rowIndex, columnNames.get(columnIndex++).getFirst(), datum.numObservations); - setReportTableCell(reportTable, rowIndex, columnNames.get(columnIndex).getFirst(), datum.numMismatches); + reportTable.set(rowIndex, columnNames.get(columnIndex++).getFirst(), datum.getEstimatedQReported()); // we only add the estimated Q reported in the RG table + reportTable.set(rowIndex, columnNames.get(columnIndex++).getFirst(), datum.numObservations); + reportTable.set(rowIndex, columnNames.get(columnIndex).getFirst(), datum.numMismatches); rowIndex++; } @@ -282,10 +287,6 @@ public class RecalDataManager { return covariate.getClass().getSimpleName().split("Covariate")[0]; } - private static void setReportTableCell(final GATKReportTable reportTable, final int rowIndex, final String columnName, final Object value) { - reportTable.set(rowIndex, columnName, value.toString()); - } - public static void outputRecalibrationReport(final RecalibrationArgumentCollection RAC, final QuantizationInfo quantizationInfo, final RecalibrationTables recalibrationTables, final Covariate[] requestedCovariates, final PrintStream outputFile) { outputRecalibrationReport(RAC.generateReportTable(), quantizationInfo.generateReportTable(), generateReportTables(recalibrationTables, requestedCovariates), outputFile); } @@ -348,8 +349,8 @@ public class RecalDataManager { final NestedHashMap deltaTable = new NestedHashMap(); // add the quality score table to the delta table - final IntegerIndexedNestedHashMap qualTable = recalibrationTables.getTable(RecalibrationTables.TableType.QUALITY_SCORE_TABLE); - for (final IntegerIndexedNestedHashMap.Leaf leaf : qualTable.getAllLeaves()) { // go through every element in the covariates table to create the delta table + final NestedIntegerArray qualTable = recalibrationTables.getTable(RecalibrationTables.TableType.QUALITY_SCORE_TABLE); + for (final NestedIntegerArray.Leaf leaf : qualTable.getAllLeaves()) { // go through every element in the covariates table to create the delta table final int[] newCovs = new int[4]; newCovs[0] = leaf.keys[0]; newCovs[1] = requestedCovariates.length; // replace the covariate name with an arbitrary (unused) index for QualityScore @@ -360,14 +361,14 @@ public class RecalDataManager { // add the optional covariates to the delta table for (int i = RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index; i < requestedCovariates.length; i++) { - final IntegerIndexedNestedHashMap covTable = recalibrationTables.getTable(i); - for (final IntegerIndexedNestedHashMap.Leaf leaf : covTable.getAllLeaves()) { - final int[] covs = new int[leaf.keys.length-1]; + final NestedIntegerArray covTable = recalibrationTables.getTable(i); + for (final NestedIntegerArray.Leaf leaf : covTable.getAllLeaves()) { + final int[] covs = new int[4]; covs[0] = leaf.keys[0]; - covs[1] = i; // reset the quality score covariate to 0 from the keyset (so we aggregate all rows regardless of QS) + covs[1] = i; // reset the quality score covariate to 0 from the keyset (so we aggregate all rows regardless of QS) covs[2] = leaf.keys[2]; covs[3] = leaf.keys[3]; - addToDeltaTable(deltaTable, covs, (RecalDatum) leaf.value); // add this covariate to the delta table + addToDeltaTable(deltaTable, covs, (RecalDatum) leaf.value); // add this covariate to the delta table } } 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 c084038a2..05e24e98a 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 @@ -3,7 +3,7 @@ package org.broadinstitute.sting.gatk.walkers.bqsr; import org.broadinstitute.sting.gatk.report.GATKReport; import org.broadinstitute.sting.gatk.report.GATKReportTable; import org.broadinstitute.sting.utils.QualityUtils; -import org.broadinstitute.sting.utils.collections.IntegerIndexedNestedHashMap; +import org.broadinstitute.sting.utils.collections.NestedIntegerArray; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.recalibration.RecalibrationTables; @@ -106,10 +106,10 @@ public class RecalibrationReport { public void combine(final RecalibrationReport other) { for (RecalibrationTables.TableType type : RecalibrationTables.TableType.values()) { - final IntegerIndexedNestedHashMap myTable = recalibrationTables.getTable(type); - final IntegerIndexedNestedHashMap otherTable = other.recalibrationTables.getTable(type); + final NestedIntegerArray myTable = recalibrationTables.getTable(type); + final NestedIntegerArray otherTable = other.recalibrationTables.getTable(type); - for (final IntegerIndexedNestedHashMap.Leaf row : otherTable.getAllLeaves()) { + for (final NestedIntegerArray.Leaf row : otherTable.getAllLeaves()) { final RecalDatum myDatum = myTable.get(row.keys); if (myDatum == null) @@ -163,7 +163,7 @@ public class RecalibrationReport { * @param reportTable the GATKReport table containing data for this table * @param qualTable the map representing this table */ - private void parseQualityScoreTable(final GATKReportTable reportTable, final IntegerIndexedNestedHashMap qualTable) { + private void parseQualityScoreTable(final GATKReportTable reportTable, final NestedIntegerArray qualTable) { for ( int i = 0; i < reportTable.getNumRows(); i++ ) { final Object rg = reportTable.get(i, RecalDataManager.READGROUP_COLUMN_NAME); tempQUALarray[0] = requestedCovariates[0].keyFromValue(rg); @@ -182,7 +182,7 @@ public class RecalibrationReport { * @param reportTable the GATKReport table containing data for this table * @param rgTable the map representing this table */ - private void parseReadGroupTable(final GATKReportTable reportTable, final IntegerIndexedNestedHashMap rgTable) { + private void parseReadGroupTable(final GATKReportTable reportTable, final NestedIntegerArray rgTable) { for ( int i = 0; i < reportTable.getNumRows(); i++ ) { final Object rg = reportTable.get(i, RecalDataManager.READGROUP_COLUMN_NAME); tempRGarray[0] = requestedCovariates[0].keyFromValue(rg); @@ -299,7 +299,7 @@ public class RecalibrationReport { */ public void calculateEmpiricalAndQuantizedQualities() { for (RecalibrationTables.TableType type : RecalibrationTables.TableType.values()) { - final IntegerIndexedNestedHashMap table = recalibrationTables.getTable(type); + final NestedIntegerArray table = recalibrationTables.getTable(type); for (final Object value : table.getAllValues()) { ((RecalDatum)value).calcCombinedEmpiricalQuality(); } diff --git a/public/java/src/org/broadinstitute/sting/utils/collections/IntegerIndexedNestedHashMap.java b/public/java/src/org/broadinstitute/sting/utils/collections/IntegerIndexedNestedHashMap.java deleted file mode 100755 index 116ae1b12..000000000 --- a/public/java/src/org/broadinstitute/sting/utils/collections/IntegerIndexedNestedHashMap.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2010 The Broad Institute - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.broadinstitute.sting.utils.collections; - -import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created by IntelliJ IDEA. - * User: ebanks - * Date: July 1, 2012 - */ - -public class IntegerIndexedNestedHashMap { - - protected final Object[] data; - - protected final int numDimensions; - protected final int[] indexFactors; - - public IntegerIndexedNestedHashMap(final int... dimensions) { - numDimensions = dimensions.length; - if ( numDimensions == 0 ) - throw new ReviewedStingException("There must be at least one dimension to an IntegerIndexedNestedHashMap"); - - indexFactors = new int[numDimensions]; - indexFactors[0] = 1; - int totalSize = dimensions[0]; - for ( int i = 1; i < numDimensions; i++ ) { - indexFactors[i] = indexFactors[i-1] * dimensions[i-1]; - totalSize *= dimensions[i]; - } - data = new Object[totalSize]; - } - - public T get(final int... keys) { - return (T)data[calculateIndex(keys)]; - } - - public synchronized void put(final T value, final int... keys) { // WARNING! value comes before the keys! - data[calculateIndex(keys)] = value; - } - - protected int calculateIndex(final int... keys) { - int index = keys[0]; - for ( int i = 1; i < numDimensions; i++ ) - index += keys[i] * indexFactors[i]; - return index; - } - - public List getAllValues() { - final int dataLength = data.length; - final List result = new ArrayList(dataLength); - for ( int i = 0; i < dataLength; i++ ) { - final Object value = data[i]; - if ( value != null ) - result.add((T)value); - } - return result; - } - - public static class Leaf { - public final int[] keys; - public final Object value; - - public Leaf(final int[] keys, final Object value) { - this.keys = keys; - this.value = value; - } - } - - public List getAllLeaves() { - final int dataLength = data.length; - final List result = new ArrayList(dataLength); - for ( int i = 0; i < dataLength; i++ ) { - final Object value = data[i]; - if ( value != null ) - result.add(new Leaf(reverseEngineerIndex(i), value)); - } - return result; - } - - private int[] reverseEngineerIndex(int index) { - final int[] keys = new int[numDimensions]; - for ( int i = numDimensions - 1; i >= 0; i-- ) { - final int key = index / indexFactors[i]; - index -= (key * indexFactors[i]); - keys[i] = key; - } - return keys; - } -} diff --git a/public/java/src/org/broadinstitute/sting/utils/collections/NestedIntegerArray.java b/public/java/src/org/broadinstitute/sting/utils/collections/NestedIntegerArray.java new file mode 100755 index 000000000..31d316555 --- /dev/null +++ b/public/java/src/org/broadinstitute/sting/utils/collections/NestedIntegerArray.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2010 The Broad Institute + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package org.broadinstitute.sting.utils.collections; + +import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by IntelliJ IDEA. + * User: ebanks + * Date: July 1, 2012 + */ + +public class NestedIntegerArray { + + protected final Object[] data; + + protected final int numDimensions; + protected final int[] dimensions; + + public NestedIntegerArray(final int... dimensions) { + numDimensions = dimensions.length; + if ( numDimensions == 0 ) + throw new ReviewedStingException("There must be at least one dimension to an NestedIntegerArray"); + this.dimensions = dimensions.clone(); + + data = new Object[dimensions[0]]; + } + + public T get(final int... keys) { + final int numNestedDimensions = numDimensions - 1; + Object[] myData = data; + + for( int i = 0; i < numNestedDimensions; i++ ) { + if ( keys[i] >= dimensions[i] ) + return null; + myData = (Object[])myData[keys[i]]; + if ( myData == null ) + return null; + } + return (T)myData[keys[numNestedDimensions]]; + } + + public synchronized void put(final T value, final int... keys) { // WARNING! value comes before the keys! + if ( keys.length != numDimensions ) + throw new ReviewedStingException("Exactly " + numDimensions + " keys should be passed to this NestedIntegerArray but " + keys.length + " were provided"); + + final int numNestedDimensions = numDimensions - 1; + Object[] myData = data; + for ( int i = 0; i < numNestedDimensions; i++ ) { + if ( keys[i] >= dimensions[i] ) + throw new ReviewedStingException("Key " + keys[i] + " is too large for dimension " + i + " (max is " + (dimensions[i]-1) + ")"); + Object[] temp = (Object[])myData[keys[i]]; + if ( temp == null ) { + temp = new Object[dimensions[i+1]]; + myData[keys[i]] = temp; + } + myData = temp; + } + + myData[keys[numNestedDimensions]] = value; + } + + public List getAllValues() { + final List result = new ArrayList(); + fillAllValues(data, result); + return result; + } + + private void fillAllValues(final Object[] array, final List result) { + for ( Object value : array ) { + if ( value == null ) + continue; + if ( value instanceof Object[] ) + fillAllValues((Object[])value, result); + else + result.add((T)value); + } + } + + public static class Leaf { + public final int[] keys; + public final Object value; + + public Leaf(final int[] keys, final Object value) { + this.keys = keys; + this.value = value; + } + } + + public List getAllLeaves() { + final List result = new ArrayList(); + fillAllLeaves(data, new int[0], result); + return result; + } + + private void fillAllLeaves(final Object[] array, final int[] path, final List result) { + for ( int key = 0; key < array.length; key++ ) { + final Object value = array[key]; + if ( value == null ) + continue; + final int[] newPath = appendToPath(path, key); + if ( value instanceof Object[] ) { + fillAllLeaves((Object[]) value, newPath, result); + } else { + result.add(new Leaf(newPath, value)); + } + } + } + + private int[] appendToPath(final int[] path, final int newKey) { + final int[] newPath = new int[path.length + 1]; + for ( int i = 0; i < path.length; i++ ) + newPath[i] = path[i]; + newPath[path.length] = newKey; + return newPath; + } +} 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 79ec48022..713c601fa 100644 --- a/public/java/src/org/broadinstitute/sting/utils/recalibration/BaseRecalibration.java +++ b/public/java/src/org/broadinstitute/sting/utils/recalibration/BaseRecalibration.java @@ -28,7 +28,7 @@ package org.broadinstitute.sting.utils.recalibration; import org.broadinstitute.sting.gatk.walkers.bqsr.*; import org.broadinstitute.sting.utils.MathUtils; import org.broadinstitute.sting.utils.QualityUtils; -import org.broadinstitute.sting.utils.collections.IntegerIndexedNestedHashMap; +import org.broadinstitute.sting.utils.collections.NestedIntegerArray; import org.broadinstitute.sting.utils.collections.NestedHashMap; import org.broadinstitute.sting.utils.sam.GATKSAMRecord; @@ -109,13 +109,7 @@ public class BaseRecalibration { if (originalQualityScore >= QualityUtils.MIN_USABLE_Q_SCORE) { // only recalibrate usable qualities (the original quality will come from the instrument -- reported quality) final int[] keySet = fullReadKeySet[offset]; // get the keyset for this base using the error model - final Byte recalibratedQualityScore = performSequentialQualityCalculation(keySet, errorModel); // recalibrate the base - //Byte recalibratedQualityScore = (Byte) qualityScoreByFullCovariateKey[errorModel.index].get(keySet); - //Byte recalibratedQualityScore = null; - //if (recalibratedQualityScore == null) { - // recalibratedQualityScore = performSequentialQualityCalculation(keySet, errorModel); // recalibrate the base - // qualityScoreByFullCovariateKey[errorModel.index].put(recalibratedQualityScore, keySet); - //} + final byte recalibratedQualityScore = performSequentialQualityCalculation(keySet, errorModel); // recalibrate the base quals[offset] = recalibratedQualityScore; } } @@ -153,7 +147,7 @@ public class BaseRecalibration { return quantizationInfo.getQuantizedQuals().get((int) recalibratedQual); // return the quantized version of the recalibrated quality } - private double calculateGlobalDeltaQ(final IntegerIndexedNestedHashMap table, final int[] key, final EventType errorModel) { + private double calculateGlobalDeltaQ(final NestedIntegerArray table, final int[] key, final EventType errorModel) { double result = 0.0; final RecalDatum empiricalQualRG = table.get(key[0], errorModel.index); @@ -166,7 +160,7 @@ public class BaseRecalibration { return result; } - private double calculateDeltaQReported(final IntegerIndexedNestedHashMap table, final int[] key, final EventType errorModel, final double globalDeltaQ, final byte qualFromRead) { + private double calculateDeltaQReported(final NestedIntegerArray table, final int[] key, final EventType errorModel, final double globalDeltaQ, final byte qualFromRead) { double result = 0.0; final RecalDatum empiricalQualQS = table.get(key[0], key[1], errorModel.index); diff --git a/public/java/src/org/broadinstitute/sting/utils/recalibration/RecalibrationTables.java b/public/java/src/org/broadinstitute/sting/utils/recalibration/RecalibrationTables.java index 008d6ec69..0416b5eb9 100644 --- a/public/java/src/org/broadinstitute/sting/utils/recalibration/RecalibrationTables.java +++ b/public/java/src/org/broadinstitute/sting/utils/recalibration/RecalibrationTables.java @@ -28,7 +28,7 @@ package org.broadinstitute.sting.utils.recalibration; import org.broadinstitute.sting.gatk.walkers.bqsr.Covariate; import org.broadinstitute.sting.gatk.walkers.bqsr.EventType; import org.broadinstitute.sting.gatk.walkers.bqsr.RecalDatum; -import org.broadinstitute.sting.utils.collections.IntegerIndexedNestedHashMap; +import org.broadinstitute.sting.utils.collections.NestedIntegerArray; /** * Utility class to facilitate on-the-fly base quality score recalibration. @@ -51,30 +51,30 @@ public class RecalibrationTables { } } - private final IntegerIndexedNestedHashMap[] tables; + private final NestedIntegerArray[] tables; public RecalibrationTables(final Covariate[] covariates) { this(covariates, covariates[TableType.READ_GROUP_TABLE.index].maximumKeyValue() + 1); } public RecalibrationTables(final Covariate[] covariates, final int numReadGroups) { - tables = new IntegerIndexedNestedHashMap[covariates.length]; + tables = new NestedIntegerArray[covariates.length]; final int qualDimension = covariates[TableType.QUALITY_SCORE_TABLE.index].maximumKeyValue() + 1; final int eventDimension = EventType.values().length; - tables[TableType.READ_GROUP_TABLE.index] = new IntegerIndexedNestedHashMap(numReadGroups, eventDimension); - tables[TableType.QUALITY_SCORE_TABLE.index] = new IntegerIndexedNestedHashMap(numReadGroups, qualDimension, eventDimension); + tables[TableType.READ_GROUP_TABLE.index] = new NestedIntegerArray(numReadGroups, eventDimension); + tables[TableType.QUALITY_SCORE_TABLE.index] = new NestedIntegerArray(numReadGroups, qualDimension, eventDimension); for (int i = TableType.OPTIONAL_COVARIATE_TABLES_START.index; i < covariates.length; i++) - tables[i] = new IntegerIndexedNestedHashMap(numReadGroups, qualDimension, covariates[i].maximumKeyValue()+1, eventDimension); + tables[i] = new NestedIntegerArray(numReadGroups, qualDimension, covariates[i].maximumKeyValue()+1, eventDimension); } - public IntegerIndexedNestedHashMap getTable(final TableType type) { - return (IntegerIndexedNestedHashMap)tables[type.index]; + public NestedIntegerArray getTable(final TableType type) { + return (NestedIntegerArray)tables[type.index]; } - public IntegerIndexedNestedHashMap getTable(final int index) { - return (IntegerIndexedNestedHashMap)tables[index]; + public NestedIntegerArray getTable(final int index) { + return (NestedIntegerArray)tables[index]; } public int numTables() { diff --git a/public/java/test/org/broadinstitute/sting/gatk/walkers/bqsr/RecalibrationReportUnitTest.java b/public/java/test/org/broadinstitute/sting/gatk/walkers/bqsr/RecalibrationReportUnitTest.java index b063a640f..e4a77c016 100644 --- a/public/java/test/org/broadinstitute/sting/gatk/walkers/bqsr/RecalibrationReportUnitTest.java +++ b/public/java/test/org/broadinstitute/sting/gatk/walkers/bqsr/RecalibrationReportUnitTest.java @@ -1,7 +1,7 @@ package org.broadinstitute.sting.gatk.walkers.bqsr; import org.broadinstitute.sting.utils.QualityUtils; -import org.broadinstitute.sting.utils.collections.IntegerIndexedNestedHashMap; +import org.broadinstitute.sting.utils.collections.NestedIntegerArray; import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; import org.broadinstitute.sting.utils.recalibration.RecalibrationTables; import org.broadinstitute.sting.utils.sam.GATKSAMReadGroupRecord; @@ -75,8 +75,8 @@ public class RecalibrationReportUnitTest { final ReadCovariates rc = RecalDataManager.computeCovariates(read, requestedCovariates); final RecalibrationTables recalibrationTables = new RecalibrationTables(requestedCovariates); - final IntegerIndexedNestedHashMap rgTable = recalibrationTables.getTable(RecalibrationTables.TableType.READ_GROUP_TABLE); - final IntegerIndexedNestedHashMap qualTable = recalibrationTables.getTable(RecalibrationTables.TableType.QUALITY_SCORE_TABLE); + final NestedIntegerArray rgTable = recalibrationTables.getTable(RecalibrationTables.TableType.READ_GROUP_TABLE); + final NestedIntegerArray qualTable = recalibrationTables.getTable(RecalibrationTables.TableType.QUALITY_SCORE_TABLE); for (int offset = 0; offset < length; offset++) { @@ -89,7 +89,7 @@ public class RecalibrationReportUnitTest { qualTable.put(RecalDatum.createRandomRecalDatum(randomMax, 10), covariates[0], covariates[1], errorMode.index); nKeys += 2; for (int j = 0; j < optionalCovariates.size(); j++) { - final IntegerIndexedNestedHashMap covTable = recalibrationTables.getTable(RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index + j); + final NestedIntegerArray covTable = recalibrationTables.getTable(RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index + j); covTable.put(RecalDatum.createRandomRecalDatum(randomMax, 10), covariates[0], covariates[1], j, covariates[RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index + j], errorMode.index); nKeys++; } 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 99249f529..df4c351d6 100644 --- a/public/java/test/org/broadinstitute/sting/utils/recalibration/BaseRecalibrationUnitTest.java +++ b/public/java/test/org/broadinstitute/sting/utils/recalibration/BaseRecalibrationUnitTest.java @@ -2,7 +2,7 @@ package org.broadinstitute.sting.utils.recalibration; import org.broadinstitute.sting.gatk.walkers.bqsr.*; import org.broadinstitute.sting.utils.QualityUtils; -import org.broadinstitute.sting.utils.collections.IntegerIndexedNestedHashMap; +import org.broadinstitute.sting.utils.collections.NestedIntegerArray; import org.broadinstitute.sting.utils.sam.GATKSAMReadGroupRecord; import org.broadinstitute.sting.utils.sam.GATKSAMRecord; import org.broadinstitute.sting.utils.sam.ReadUtils; @@ -74,8 +74,8 @@ public class BaseRecalibrationUnitTest { readCovariates = RecalDataManager.computeCovariates(read, requestedCovariates); RecalibrationTables recalibrationTables = new RecalibrationTables(requestedCovariates); - final IntegerIndexedNestedHashMap rgTable = recalibrationTables.getTable(RecalibrationTables.TableType.READ_GROUP_TABLE); - final IntegerIndexedNestedHashMap qualTable = recalibrationTables.getTable(RecalibrationTables.TableType.QUALITY_SCORE_TABLE); + final NestedIntegerArray rgTable = recalibrationTables.getTable(RecalibrationTables.TableType.READ_GROUP_TABLE); + final NestedIntegerArray qualTable = recalibrationTables.getTable(RecalibrationTables.TableType.QUALITY_SCORE_TABLE); for (int i=0; i covTable = recalibrationTables.getTable(RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index + j); + final NestedIntegerArray covTable = recalibrationTables.getTable(RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index + j); covTable.put(newDatum, bitKeys[0], bitKeys[1], j, bitKeys[RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index + j], EventType.BASE_SUBSTITUTION.index); } }