/**
  * Combines two recalibration reports by adding all observations and errors
  *
  * <p>Note: This method DOES NOT recalculate the empirical qualities and quantized qualities. You
  * have to recalculate them after combining. The reason for not calculating it is because this
  * function is intended for combining a series of recalibration reports, and it only makes sense
  * to calculate the empirical qualities and quantized qualities after all the recalibration
  * reports have been combined. Having the user recalculate when appropriate, makes this method
  * faster
  *
  * <p>Note2: The empirical quality reported, however, is recalculated given its simplicity.
  *
  * @param other the recalibration report to combine with this one
  */
 public void combine(final RecalibrationReport other) {
   for (int tableIndex = 0; tableIndex < recalibrationTables.numTables(); tableIndex++) {
     final NestedIntegerArray<RecalDatum> myTable = recalibrationTables.getTable(tableIndex);
     final NestedIntegerArray<RecalDatum> otherTable =
         other.recalibrationTables.getTable(tableIndex);
     RecalUtils.combineTables(myTable, otherTable);
   }
 }
  public RecalibrationReport(final File recalFile, final SortedSet<String> allReadGroups) {
    final GATKReport report = new GATKReport(recalFile);

    argumentTable = report.getTable(RecalUtils.ARGUMENT_REPORT_TABLE_TITLE);
    RAC = initializeArgumentCollectionTable(argumentTable);

    GATKReportTable quantizedTable = report.getTable(RecalUtils.QUANTIZED_REPORT_TABLE_TITLE);
    quantizationInfo = initializeQuantizationTable(quantizedTable);

    Pair<ArrayList<Covariate>, ArrayList<Covariate>> covariates =
        RecalUtils.initializeCovariates(RAC); // initialize the required and optional covariates
    ArrayList<Covariate> requiredCovariates = covariates.getFirst();
    ArrayList<Covariate> optionalCovariates = covariates.getSecond();
    requestedCovariates = new Covariate[requiredCovariates.size() + optionalCovariates.size()];
    optionalCovariateIndexes = new HashMap<String, Integer>(optionalCovariates.size());
    int covariateIndex = 0;
    for (final Covariate covariate : requiredCovariates)
      requestedCovariates[covariateIndex++] = covariate;
    for (final Covariate covariate : optionalCovariates) {
      requestedCovariates[covariateIndex] = covariate;
      final String covariateName =
          covariate
              .getClass()
              .getSimpleName()
              .split("Covariate")[
              0]; // get the name of the covariate (without the "covariate" part of it) so we can
                  // match with the GATKReport
      optionalCovariateIndexes.put(covariateName, covariateIndex - 2);
      covariateIndex++;
    }

    for (Covariate cov : requestedCovariates)
      cov.initialize(
          RAC); // initialize any covariate member variables using the shared argument collection

    recalibrationTables = new RecalibrationTables(requestedCovariates, allReadGroups.size());

    initializeReadGroupCovariates(allReadGroups);

    parseReadGroupTable(
        report.getTable(RecalUtils.READGROUP_REPORT_TABLE_TITLE),
        recalibrationTables.getReadGroupTable());

    parseQualityScoreTable(
        report.getTable(RecalUtils.QUALITY_SCORE_REPORT_TABLE_TITLE),
        recalibrationTables.getQualityScoreTable());

    parseAllCovariatesTable(
        report.getTable(RecalUtils.ALL_COVARIATES_REPORT_TABLE_TITLE), recalibrationTables);
  }
  /**
   * 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);
    }
  }
 /** @return true if the report has no data */
 public boolean isEmpty() {
   return recalibrationTables.isEmpty();
 }