Program: 50459
Project: 50459
Buggy source:
/** 
 * Print statistics about an alignment file in the Goby compact form.
 * @param file The file to display statistics about
 * @throws IOException if the file cannot be read
 */
private void describeCompactAlignment(final File file) throws IOException {
  final String basename=AlignmentReader.getBasename(file.toString());
  stream.printf("String_Node_Str",basename);
  final AlignmentReader reader=new AlignmentReader(basename);
  reader.readHeader();
  stream.println("String_Node_Str");
  stream.printf("String_Node_Str",reader.isSorted());
  stream.printf("String_Node_Str",reader.isIndexed());
  stream.printf("String_Node_Str",reader.getNumberOfTargets());
  final int[] targetLengthsFromHeader=reader.getTargetLength();
  stream.printf("String_Node_Str",ArrayUtils.getLength(reader.getTargetLength()));
  stream.printf("String_Node_Str",reader.getSmallestSplitQueryIndex());
  stream.printf("String_Node_Str",reader.getLargestSplitQueryIndex());
  final SummaryStatistics targetLengthStats=new SummaryStatistics();
  if (targetLengthsFromHeader != null) {
    for (    final double d : targetLengthsFromHeader) {
      targetLengthStats.addValue(d);
    }
  }
  stream.printf("String_Node_Str",(int)targetLengthStats.getMin());
  stream.printf("String_Node_Str",(int)targetLengthStats.getMax());
  stream.printf("String_Node_Str",targetLengthStats.getMean());
  stream.println();
  stream.printf("String_Node_Str",reader.getNumberOfQueries());
  final int[] queryLengthsFromHeader=reader.getQueryLengths();
  stream.printf("String_Node_Str",ArrayUtils.getLength(queryLengthsFromHeader));
  final SummaryStatistics queryLengthStats=new SummaryStatistics();
  if (queryLengthsFromHeader != null) {
    stream.println("String_Node_Str");
  }
  stream.println("String_Node_Str" + reader.isConstantQueryLengths());
  stream.printf("String_Node_Str",reader.getQueryIdentifiers() != null && !reader.getQueryIdentifiers().isEmpty());
  stream.printf("String_Node_Str",reader.getTargetIdentifiers() != null && !reader.getTargetIdentifiers().isEmpty());
  stream.println();
  final IntSet alignedQueryIndices=new IntOpenHashSet();
  describeAmbigousReads(basename,reader.getNumberOfQueries(),alignedQueryIndices);
  int maxQueryIndex=-1;
  int maxTargetIndex=-1;
  int numEntries=0;
  long numLogicalAlignmentEntries=0;
  long total=0;
  double avgScore=0;
  int sumNumVariations=0;
  for (  final Alignments.AlignmentEntry entry : reader) {
    numberOfReads++;
    numEntries++;
    numLogicalAlignmentEntries+=entry.getMultiplicity();
    total+=entry.getQueryAlignedLength();
    avgScore+=entry.getScore();
    maxQueryIndex=Math.max(maxQueryIndex,entry.getQueryIndex());
    maxTargetIndex=Math.max(maxTargetIndex,entry.getTargetIndex());
    cumulativeReadLength+=entry.getQueryAlignedLength();
    minReadLength=Math.min(minReadLength,entry.getQueryAlignedLength());
    maxReadLength=Math.max(maxReadLength,entry.getQueryAlignedLength());
    sumNumVariations+=entry.getSequenceVariationsCount();
    alignedQueryIndices.add(entry.getQueryIndex());
    final double queryLength;
    if (entry.hasQueryLength()) {
      queryLength=entry.getQueryLength();
    }
 else {
      queryLength=reader.getQueryLength(entry.getQueryIndex());
    }
    queryLengthStats.addValue(queryLength);
  }
  avgScore/=(double)numLogicalAlignmentEntries;
  final int numQuerySequences=maxQueryIndex + 1;
  stream.printf("String_Node_Str",numQuerySequences);
  final int numTargetSequences=maxTargetIndex + 1;
  final double avgNumVariationsPerQuery=((double)sumNumVariations) / (double)numQuerySequences;
  stream.printf("String_Node_Str",numTargetSequences);
  stream.printf("String_Node_Str",numLogicalAlignmentEntries);
  stream.printf("String_Node_Str",alignedQueryIndices.size());
  stream.printf("String_Node_Str",(double)alignedQueryIndices.size() / (double)(long)numQuerySequences * 100.0d);
  stream.printf("String_Node_Str",numEntries > 0 ? divide(total,numEntries) : -1);
  stream.printf("String_Node_Str",avgScore);
  stream.printf("String_Node_Str",avgNumVariationsPerQuery);
  final long size=file.length();
  stream.printf("String_Node_Str",divide(size,numLogicalAlignmentEntries));
  stream.printf("String_Node_Str",(int)queryLengthStats.getMin());
  stream.printf("String_Node_Str",(int)queryLengthStats.getMax());
  stream.printf("String_Node_Str",queryLengthStats.getMean());
}

Fixed version (ground truth):
/** 
 * Print statistics about an alignment file in the Goby compact form.
 * @param file The file to display statistics about
 * @throws IOException if the file cannot be read
 */
private void describeCompactAlignment(final File file) throws IOException {
  final String basename=AlignmentReader.getBasename(file.toString());
  stream.printf("String_Node_Str",basename);
  final AlignmentReader reader=new AlignmentReader(basename);
  reader.readHeader();
  stream.println("String_Node_Str");
  stream.printf("String_Node_Str",reader.isSorted());
  stream.printf("String_Node_Str",reader.isIndexed());
  stream.printf("String_Node_Str",reader.getNumberOfTargets());
  final int[] targetLengthsFromHeader=reader.getTargetLength();
  stream.printf("String_Node_Str",ArrayUtils.getLength(reader.getTargetLength()));
  stream.printf("String_Node_Str",reader.getSmallestSplitQueryIndex());
  stream.printf("String_Node_Str",reader.getLargestSplitQueryIndex());
  final SummaryStatistics targetLengthStats=new SummaryStatistics();
  if (targetLengthsFromHeader != null) {
    for (    final double d : targetLengthsFromHeader) {
      targetLengthStats.addValue(d);
    }
  }
  stream.printf("String_Node_Str",(int)targetLengthStats.getMin());
  stream.printf("String_Node_Str",(int)targetLengthStats.getMax());
  stream.printf("String_Node_Str",targetLengthStats.getMean());
  stream.println();
  stream.printf("String_Node_Str",reader.getNumberOfQueries());
  final int[] queryLengthsFromHeader=reader.getQueryLengths();
  stream.printf("String_Node_Str",ArrayUtils.getLength(queryLengthsFromHeader));
  final SummaryStatistics queryLengthStats=new SummaryStatistics();
  if (queryLengthsFromHeader != null) {
    stream.println("String_Node_Str");
  }
  stream.println("String_Node_Str" + reader.isConstantQueryLengths());
  stream.printf("String_Node_Str",reader.getQueryIdentifiers() != null && !reader.getQueryIdentifiers().isEmpty());
  stream.printf("String_Node_Str",reader.getTargetIdentifiers() != null && !reader.getTargetIdentifiers().isEmpty());
  stream.println();
  final IntSet alignedQueryIndices=new IntOpenHashSet();
  describeAmbigousReads(basename,reader.getNumberOfQueries(),alignedQueryIndices);
  int maxQueryIndex=-1;
  int maxTargetIndex=-1;
  int numEntries=0;
  long numLogicalAlignmentEntries=0;
  long total=0;
  double avgScore=0;
  int sumNumVariations=0;
  for (  final Alignments.AlignmentEntry entry : reader) {
    numberOfReads++;
    numEntries++;
    numLogicalAlignmentEntries+=entry.getMultiplicity();
    total+=entry.getQueryAlignedLength();
    avgScore+=entry.getScore();
    maxQueryIndex=Math.max(maxQueryIndex,entry.getQueryIndex());
    maxTargetIndex=Math.max(maxTargetIndex,entry.getTargetIndex());
    cumulativeReadLength+=entry.getQueryAlignedLength();
    minReadLength=Math.min(minReadLength,entry.getQueryAlignedLength());
    maxReadLength=Math.max(maxReadLength,entry.getQueryAlignedLength());
    sumNumVariations+=entry.getSequenceVariationsCount();
    alignedQueryIndices.add(entry.getQueryIndex());
    if (entry.hasQueryLength()) {
      final double queryLength=entry.getQueryLength();
      queryLengthStats.addValue(queryLength);
    }
 else     if (reader.hasQueryLengths() || reader.isConstantQueryLengths()) {
      final double queryLength=reader.getQueryLength(entry.getQueryIndex());
      queryLengthStats.addValue(queryLength);
    }
  }
  avgScore/=(double)numLogicalAlignmentEntries;
  final int numQuerySequences=maxQueryIndex + 1;
  stream.printf("String_Node_Str",numQuerySequences);
  final int numTargetSequences=maxTargetIndex + 1;
  final double avgNumVariationsPerQuery=((double)sumNumVariations) / (double)numQuerySequences;
  stream.printf("String_Node_Str",numTargetSequences);
  stream.printf("String_Node_Str",numLogicalAlignmentEntries);
  stream.printf("String_Node_Str",alignedQueryIndices.size());
  stream.printf("String_Node_Str",(double)alignedQueryIndices.size() / (double)(long)numQuerySequences * 100.0d);
  stream.printf("String_Node_Str",numEntries > 0 ? divide(total,numEntries) : -1);
  stream.printf("String_Node_Str",avgScore);
  stream.printf("String_Node_Str",avgNumVariationsPerQuery);
  final long size=file.length();
  stream.printf("String_Node_Str",divide(size,numLogicalAlignmentEntries));
  stream.printf("String_Node_Str",(int)queryLengthStats.getMin());
  stream.printf("String_Node_Str",(int)queryLengthStats.getMax());
  stream.printf("String_Node_Str",queryLengthStats.getMean());
}