/** Writes the column summary output table. */
  private void writeColumnSummaryOutput() {
    if (columnSummaryOutputWriter == null) {
      return;
    }

    final long totalSize = targetCollection.totalSize();

    final List<String> columnNames = countColumns.columnNames();
    for (int i = 0; i < columnNames.size(); i++) {
      final long sum = IntStream.of(counts[i]).sum();
      columnSummaryOutputWriter.println(
          String.join(
              COLUMN_SEPARATOR,
              columnNames.get(i),
              String.valueOf(sum),
              String.format(AVERAGE_DOUBLE_FORMAT, sum / (double) totalSize)));
    }
  }
  @Override
  public void onTraversalStart() {

    sampleCollection = new SampleCollection(getHeaderForReads());

    logger.log(Level.INFO, "Reading targets locations from intervals...");

    targetCollection = resolveTargetCollection();

    // Initializing count and count column management member fields:
    countColumns = groupBy.countColumns(this);
    final int columnCount = countColumns.columnCount();
    counts = new int[columnCount][targetCollection.targetCount()];

    // Open output files and write headers:
    outputWriter =
        openOutputWriter(
            output,
            composeMatrixOutputHeader(
                getCommandLine(), targetOutInfo, groupBy, countColumns.columnNames()));
    if (columnSummaryOutput != null) {
      columnSummaryOutputWriter =
          openOutputWriter(
              columnSummaryOutput,
              composeColumnSummaryHeader(
                  getCommandLine(),
                  groupBy,
                  targetCollection.targetCount(),
                  targetCollection.totalSize()));
    }
    if (rowSummaryOutput != null) {
      rowSummaryOutputWriter =
          openOutputWriter(
              rowSummaryOutput,
              composeRowOutputHeader(
                  getCommandLine(), targetOutInfo, groupBy, countColumns.columnCount()));
    }

    // Next we start the traversal:
    logger.log(Level.INFO, "Collecting read counts ...");
  }