Refactored/renamed the nested integer array; cleaned up code a bit.

This commit is contained in:
Eric Banks 2012-07-03 00:12:33 -04:00
parent cac72bce91
commit a4670113bd
9 changed files with 207 additions and 186 deletions

View File

@ -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<RecalDatum> qualTable = recalibrationTables.getTable(RecalibrationTables.TableType.QUALITY_SCORE_TABLE); // get the quality score table
final NestedIntegerArray<RecalDatum> qualTable = recalibrationTables.getTable(RecalibrationTables.TableType.QUALITY_SCORE_TABLE); // get the quality score table
for (final RecalDatum value : qualTable.getAllValues()) {
final RecalDatum datum = value;

View File

@ -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<GATKReportTable> generateReportTables(final RecalibrationTables recalibrationTables, final Covariate[] requestedCovariates) {
List<GATKReportTable> result = new LinkedList<GATKReportTable>();
int reportTableIndex = 0;
int rowIndex = 0;
final Map<Covariate, String> covariateNameMap = new HashMap<Covariate, String>(requestedCovariates.length);
for (final Covariate covariate : requestedCovariates)
@ -220,11 +221,11 @@ public class RecalDataManager {
for (int tableIndex = 0; tableIndex < recalibrationTables.numTables(); tableIndex++) {
final ArrayList<Pair<String, String>> columnNames = new ArrayList<Pair<String, String>>(); // initialize the array to hold the column names
final ArrayList<Pair<String, String>> columnNames = new ArrayList<Pair<String, String>>(); // initialize the array to hold the column names
columnNames.add(new Pair<String, String>(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<String, String>(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<String, String> 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<String, String> 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<RecalDatum> table = recalibrationTables.getTable(tableIndex);
for (final IntegerIndexedNestedHashMap.Leaf row : table.getAllLeaves()) {
final NestedIntegerArray<RecalDatum> 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<RecalDatum> 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<RecalDatum> 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<RecalDatum> covTable = recalibrationTables.getTable(i);
for (final IntegerIndexedNestedHashMap.Leaf leaf : covTable.getAllLeaves()) {
final int[] covs = new int[leaf.keys.length-1];
final NestedIntegerArray<RecalDatum> 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
}
}

View File

@ -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<RecalDatum> myTable = recalibrationTables.getTable(type);
final IntegerIndexedNestedHashMap<RecalDatum> otherTable = other.recalibrationTables.getTable(type);
final NestedIntegerArray<RecalDatum> myTable = recalibrationTables.getTable(type);
final NestedIntegerArray<RecalDatum> 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<RecalDatum> qualTable) {
private void parseQualityScoreTable(final GATKReportTable reportTable, final NestedIntegerArray<RecalDatum> 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<RecalDatum> rgTable) {
private void parseReadGroupTable(final GATKReportTable reportTable, final NestedIntegerArray<RecalDatum> 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();
}

View File

@ -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<T> {
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<T> getAllValues() {
final int dataLength = data.length;
final List<T> result = new ArrayList<T>(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<Leaf> getAllLeaves() {
final int dataLength = data.length;
final List<Leaf> result = new ArrayList<Leaf>(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;
}
}

View File

@ -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<T> {
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<T> getAllValues() {
final List<T> result = new ArrayList<T>();
fillAllValues(data, result);
return result;
}
private void fillAllValues(final Object[] array, final List<T> 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<Leaf> getAllLeaves() {
final List<Leaf> result = new ArrayList<Leaf>();
fillAllLeaves(data, new int[0], result);
return result;
}
private void fillAllLeaves(final Object[] array, final int[] path, final List<Leaf> 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;
}
}

View File

@ -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<RecalDatum> table, final int[] key, final EventType errorModel) {
private double calculateGlobalDeltaQ(final NestedIntegerArray<RecalDatum> 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<RecalDatum> table, final int[] key, final EventType errorModel, final double globalDeltaQ, final byte qualFromRead) {
private double calculateDeltaQReported(final NestedIntegerArray<RecalDatum> 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);

View File

@ -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<RecalDatum>(numReadGroups, eventDimension);
tables[TableType.QUALITY_SCORE_TABLE.index] = new IntegerIndexedNestedHashMap<RecalDatum>(numReadGroups, qualDimension, eventDimension);
tables[TableType.READ_GROUP_TABLE.index] = new NestedIntegerArray<RecalDatum>(numReadGroups, eventDimension);
tables[TableType.QUALITY_SCORE_TABLE.index] = new NestedIntegerArray<RecalDatum>(numReadGroups, qualDimension, eventDimension);
for (int i = TableType.OPTIONAL_COVARIATE_TABLES_START.index; i < covariates.length; i++)
tables[i] = new IntegerIndexedNestedHashMap<RecalDatum>(numReadGroups, qualDimension, covariates[i].maximumKeyValue()+1, eventDimension);
tables[i] = new NestedIntegerArray<RecalDatum>(numReadGroups, qualDimension, covariates[i].maximumKeyValue()+1, eventDimension);
}
public IntegerIndexedNestedHashMap<RecalDatum> getTable(final TableType type) {
return (IntegerIndexedNestedHashMap<RecalDatum>)tables[type.index];
public NestedIntegerArray<RecalDatum> getTable(final TableType type) {
return (NestedIntegerArray<RecalDatum>)tables[type.index];
}
public IntegerIndexedNestedHashMap<RecalDatum> getTable(final int index) {
return (IntegerIndexedNestedHashMap<RecalDatum>)tables[index];
public NestedIntegerArray<RecalDatum> getTable(final int index) {
return (NestedIntegerArray<RecalDatum>)tables[index];
}
public int numTables() {

View File

@ -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<RecalDatum> rgTable = recalibrationTables.getTable(RecalibrationTables.TableType.READ_GROUP_TABLE);
final IntegerIndexedNestedHashMap<RecalDatum> qualTable = recalibrationTables.getTable(RecalibrationTables.TableType.QUALITY_SCORE_TABLE);
final NestedIntegerArray<RecalDatum> rgTable = recalibrationTables.getTable(RecalibrationTables.TableType.READ_GROUP_TABLE);
final NestedIntegerArray<RecalDatum> 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<RecalDatum> covTable = recalibrationTables.getTable(RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index + j);
final NestedIntegerArray<RecalDatum> 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++;
}

View File

@ -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<RecalDatum> rgTable = recalibrationTables.getTable(RecalibrationTables.TableType.READ_GROUP_TABLE);
final IntegerIndexedNestedHashMap<RecalDatum> qualTable = recalibrationTables.getTable(RecalibrationTables.TableType.QUALITY_SCORE_TABLE);
final NestedIntegerArray<RecalDatum> rgTable = recalibrationTables.getTable(RecalibrationTables.TableType.READ_GROUP_TABLE);
final NestedIntegerArray<RecalDatum> qualTable = recalibrationTables.getTable(RecalibrationTables.TableType.QUALITY_SCORE_TABLE);
for (int i=0; i<read.getReadLength(); i++) {
final int[] bitKeys = readCovariates.getMismatchesKeySet(i);
@ -95,7 +95,7 @@ public class BaseRecalibrationUnitTest {
rgTable.put(newDatum, bitKeys[0], EventType.BASE_SUBSTITUTION.index);
qualTable.put(newDatum, bitKeys[0], bitKeys[1], EventType.BASE_SUBSTITUTION.index);
for (int j = 0; j < optionalCovariates.size(); j++) {
final IntegerIndexedNestedHashMap<RecalDatum> covTable = recalibrationTables.getTable(RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index + j);
final NestedIntegerArray<RecalDatum> 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);
}
}