@Override public boolean put( final T value, final int... keys ) { StringBuilder logEntry = new StringBuilder(); logEntry.append(logEntryLabel); logEntry.append("\t"); logEntry.append(NestedIntegerArrayOperation.PUT); logEntry.append("\t"); logEntry.append(value); for ( int key : keys ) { logEntry.append("\t"); logEntry.append(key); } // PrintStream methods all use synchronized blocks internally, so our logging is thread-safe log.println(logEntry.toString()); return super.put(value, keys); } }
/** * Updates the current RecalDatum element in the delta table. * * If it doesn't have an element yet, it creates an RecalDatum element and adds it to the delta table. * * @param deltaTable the delta table * @param deltaKey the key to the table * @param recalDatum the recal datum to combine with the accuracyDatum element in the table */ private static void addToDeltaTable(final NestedIntegerArray<RecalDatum> deltaTable, final int[] deltaKey, final RecalDatum recalDatum) { final RecalDatum deltaDatum = deltaTable.get(deltaKey); // check if we already have a RecalDatum for this key if (deltaDatum == null) // if we don't have a key yet, create a new one with the same values as the current datum deltaTable.put(new RecalDatum(recalDatum), deltaKey); else // if we do have a datum, combine it with this one deltaDatum.combine(recalDatum); }
/** * Combines the recalibration data for table1 and table2 into table1 * * Note that table1 is the destination, so it is modified * * @param table1 the destination table to merge table2 into * @param table2 the source table to merge into table1 */ public static void combineTables(final NestedIntegerArray<RecalDatum> table1, final NestedIntegerArray<RecalDatum> table2) { if ( table1 == null ) throw new IllegalArgumentException("table1 cannot be null"); if ( table2 == null ) throw new IllegalArgumentException("table2 cannot be null"); if ( ! Arrays.equals(table1.getDimensions(), table2.getDimensions())) throw new IllegalArgumentException("Table1 " + Utils.join(",", table1.getDimensions()) + " not equal to " + Utils.join(",", table2.getDimensions())); for (final NestedIntegerArray.Leaf<RecalDatum> row : table2.getAllLeaves()) { final RecalDatum myDatum = table1.get(row.keys); if (myDatum == null) table1.put(row.value, row.keys); else myDatum.combine(row.value); } }
public NestedIntegerArray<RecalDatum> makeTable(final List<Row> rows) { final NestedIntegerArray<RecalDatum> x = new NestedIntegerArray<RecalDatum>(3, 3); for ( final Row r : rows ) x.put(new RecalDatum((long)r.no, (double)r.ne, (byte)10), r.rg, r.qual); return x; } }
/** * Increments the RecalDatum at the specified position in the specified table, or put a new item there * if there isn't already one. * * Does this in a thread-safe way WITHOUT being synchronized: relies on the behavior of NestedIntegerArray.put() * to return false if another thread inserts a new item at our position in the middle of our put operation. * * @param table the table that holds/will hold our item * @param qual qual for this event * @param isError error value for this event * @param keys location in table of our item */ public static void incrementDatumOrPutIfNecessary( final NestedIntegerArray<RecalDatum> table, final byte qual, final double isError, final int... keys ) { final RecalDatum existingDatum = table.get(keys); if ( existingDatum == null ) { // No existing item, try to put a new one if ( ! table.put(createDatumObject(qual, isError), keys) ) { // Failed to put a new item because another thread came along and put an item here first. // Get the newly-put item and increment it (item is guaranteed to exist at this point) table.get(keys).increment(1L, isError); } } else { // Easy case: already an item here, so increment it existingDatum.increment(1L, isError); } }
/** * Finalize, if appropriate, all derived data in recalibrationTables. * * Called once after all calls to updateDataForRead have been issued. * * Assumes that all of the principal tables (by quality score) have been completely updated, * and walks over this data to create summary data tables like by read group table. */ public void finalizeData() { if ( finalized ) throw new IllegalStateException("FinalizeData() has already been called"); // merge all of the thread-local tables finalRecalibrationTables = mergeThreadLocalRecalibrationTables(); final NestedIntegerArray<RecalDatum> byReadGroupTable = finalRecalibrationTables.getReadGroupTable(); final NestedIntegerArray<RecalDatum> byQualTable = finalRecalibrationTables.getQualityScoreTable(); // iterate over all values in the qual table for ( final NestedIntegerArray.Leaf<RecalDatum> leaf : byQualTable.getAllLeaves() ) { final int rgKey = leaf.keys[0]; final int eventIndex = leaf.keys[2]; final RecalDatum rgDatum = byReadGroupTable.get(rgKey, eventIndex); final RecalDatum qualDatum = leaf.value; if ( rgDatum == null ) { // create a copy of qualDatum, and initialize byReadGroup table with it byReadGroupTable.put(new RecalDatum(qualDatum), rgKey, eventIndex); } else { // combine the qual datum with the existing datum in the byReadGroup table rgDatum.combine(qualDatum); } } finalized = true; }
/** * Compiles the list of keys for the ReadGroup table and uses the shared parsing utility to produce the actual table * * @param reportTable the GATKReport table containing data for this table * @param rgTable the map representing this table */ private void parseReadGroupTable(final GATKReportTable reportTable, final NestedIntegerArray<RecalDatum> rgTable) { for ( int i = 0; i < reportTable.getNumRows(); i++ ) { final Object rg = reportTable.get(i, RecalUtils.READGROUP_COLUMN_NAME); tempRGarray[0] = requestedCovariates[0].keyFromValue(rg); final EventType event = EventType.eventFrom((String)reportTable.get(i, RecalUtils.EVENT_TYPE_COLUMN_NAME)); tempRGarray[1] = event.ordinal(); rgTable.put(getRecalDatum(reportTable, i, true), tempRGarray); } }
/** * * Compiles the list of keys for the QualityScore table and uses the shared parsing utility to produce the actual table * @param reportTable the GATKReport table containing data for this table * @param qualTable the map representing this table */ private void parseQualityScoreTable(final GATKReportTable reportTable, final NestedIntegerArray<RecalDatum> qualTable) { for ( int i = 0; i < reportTable.getNumRows(); i++ ) { final Object rg = reportTable.get(i, RecalUtils.READGROUP_COLUMN_NAME); tempQUALarray[0] = requestedCovariates[0].keyFromValue(rg); final Object qual = reportTable.get(i, RecalUtils.QUALITY_SCORE_COLUMN_NAME); tempQUALarray[1] = requestedCovariates[1].keyFromValue(qual); final EventType event = EventType.eventFrom((String)reportTable.get(i, RecalUtils.EVENT_TYPE_COLUMN_NAME)); tempQUALarray[2] = event.ordinal(); qualTable.put(getRecalDatum(reportTable, i, false), tempQUALarray); } }
/** * Compiles the list of keys for the Covariates table and uses the shared parsing utility to produce the actual table * * @param reportTable the GATKReport table containing data for this table * @param recalibrationTables the recalibration tables \ */ private void parseAllCovariatesTable(final GATKReportTable reportTable, final RecalibrationTables recalibrationTables) { for ( int i = 0; i < reportTable.getNumRows(); i++ ) { final Object rg = reportTable.get(i, RecalUtils.READGROUP_COLUMN_NAME); tempCOVarray[0] = requestedCovariates[0].keyFromValue(rg); final Object qual = reportTable.get(i, RecalUtils.QUALITY_SCORE_COLUMN_NAME); tempCOVarray[1] = requestedCovariates[1].keyFromValue(qual); final String covName = (String)reportTable.get(i, RecalUtils.COVARIATE_NAME_COLUMN_NAME); final int covIndex = optionalCovariateIndexes.get(covName); final Object covValue = reportTable.get(i, RecalUtils.COVARIATE_VALUE_COLUMN_NAME); tempCOVarray[2] = requestedCovariates[RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.ordinal() + covIndex].keyFromValue(covValue); final EventType event = EventType.eventFrom((String)reportTable.get(i, RecalUtils.EVENT_TYPE_COLUMN_NAME)); tempCOVarray[3] = event.ordinal(); recalibrationTables.getTable(RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.ordinal() + covIndex).put(getRecalDatum(reportTable, i, false), tempCOVarray); } }
final int randomMax = errorMode == EventType.BASE_SUBSTITUTION ? 10000 : 100000; rgTable.put(createRandomRecalDatum(randomMax, 10), covariates[0], errorMode.ordinal()); qualTable.put(createRandomRecalDatum(randomMax, 10), covariates[0], covariates[1], errorMode.ordinal()); nKeys += 2; for (int j = 0; j < optionalCovariates.size(); j++) { final int covValue = covariates[RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.ordinal() + j]; if ( covValue >= 0 ) { covTable.put(createRandomRecalDatum(randomMax, 10), covariates[0], covariates[1], covValue, errorMode.ordinal()); nKeys++;