@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 ..."); }
/** * Writes the row in the main matrix output file for a target and, if requested, the corresponding * row in the row summary output file. * * @param countBuffer the counts for the target. * @param index the index of target within the target collection. */ private void writeOutputRows( final int[] countBuffer, final long[] columnTotals, final int index) { final String countString = IntStream.range(0, countBuffer.length) .mapToObj(i -> transform.apply(countBuffer[i], columnTotals[i])) .collect(Collectors.joining(COLUMN_SEPARATOR)); final String targetInfoString = targetOutInfo.composeTargetOutInfoString(index, targetCollection); outputWriter.println(String.join(COLUMN_SEPARATOR, targetInfoString, countString)); if (rowSummaryOutputWriter != null) { final long sum = MathUtils.sum(countBuffer); final SimpleInterval location = targetCollection.location(index); final int targetSize = location.size(); rowSummaryOutputWriter.println( String.join( COLUMN_SEPARATOR, targetInfoString, Long.toString(sum), String.format( AVERAGE_DOUBLE_FORMAT, sum / ((float) countColumns.columnCount() * targetSize)))); } }