Program: 50479
Project: 50479
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());
  writer.printf("String_Node_Str",basename);
  final AlignmentReader reader=new AlignmentReader(basename);
  reader.readHeader();
  writer.println("String_Node_Str");
  writer.printf("String_Node_Str",reader.getNumberOfTargets());
  final int[] targetLength=reader.getTargetLength();
  writer.printf("String_Node_Str",ArrayUtils.getLength(reader.getTargetLength()));
  final SummaryStatistics targetLengthStats=new SummaryStatistics();
  if (targetLength != null) {
    for (    final double d : targetLength) {
      targetLengthStats.addValue(d);
    }
  }
  writer.printf("String_Node_Str",(int)targetLengthStats.getMin());
  writer.printf("String_Node_Str",(int)targetLengthStats.getMax());
  writer.printf("String_Node_Str",targetLengthStats.getMean());
  writer.println();
  writer.printf("String_Node_Str",reader.getNumberOfQueries());
  final int[] queryLength=reader.getQueryLengths();
  writer.printf("String_Node_Str",ArrayUtils.getLength(queryLength));
  final SummaryStatistics queryLengthStats=new SummaryStatistics();
  if (queryLength != null) {
    for (    final double d : queryLength) {
      queryLengthStats.addValue(d);
    }
  }
  writer.printf("String_Node_Str",(int)queryLengthStats.getMin());
  writer.printf("String_Node_Str",(int)queryLengthStats.getMax());
  writer.printf("String_Node_Str",queryLengthStats.getMean());
  writer.println("String_Node_Str" + reader.isConstantQueryLengths());
  writer.printf("String_Node_Str",reader.getQueryIdentifiers() != null && !reader.getTargetIdentifiers().isEmpty());
  writer.printf("String_Node_Str",reader.getTargetIdentifiers() != null && !reader.getTargetIdentifiers().isEmpty());
  writer.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());
  }
  avgScore/=(double)numLogicalAlignmentEntries;
  final int numQuerySequences=maxQueryIndex + 1;
  writer.printf("String_Node_Str",numQuerySequences);
  final int numTargetSequences=maxTargetIndex + 1;
  final double avgNumVariationsPerQuery=((double)sumNumVariations) / (double)numQuerySequences;
  writer.printf("String_Node_Str",numTargetSequences);
  writer.printf("String_Node_Str",numLogicalAlignmentEntries);
  writer.printf("String_Node_Str",alignedQueryIndices.size());
  writer.printf("String_Node_Str",(double)alignedQueryIndices.size() / (double)(long)numQuerySequences * 100.0d);
  writer.printf("String_Node_Str",numEntries > 0 ? total / numEntries : -1);
  writer.printf("String_Node_Str",avgScore);
  writer.printf("String_Node_Str",avgNumVariationsPerQuery);
  final long size=file.length();
  writer.printf("String_Node_Str",divide(size,numLogicalAlignmentEntries));
}

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());
  writer.printf("String_Node_Str",basename);
  final AlignmentReader reader=new AlignmentReader(basename);
  reader.readHeader();
  writer.println("String_Node_Str");
  writer.printf("String_Node_Str",reader.getNumberOfTargets());
  final int[] targetLength=reader.getTargetLength();
  writer.printf("String_Node_Str",ArrayUtils.getLength(reader.getTargetLength()));
  final SummaryStatistics targetLengthStats=new SummaryStatistics();
  if (targetLength != null) {
    for (    final double d : targetLength) {
      targetLengthStats.addValue(d);
    }
  }
  writer.printf("String_Node_Str",(int)targetLengthStats.getMin());
  writer.printf("String_Node_Str",(int)targetLengthStats.getMax());
  writer.printf("String_Node_Str",targetLengthStats.getMean());
  writer.println();
  writer.printf("String_Node_Str",reader.getNumberOfQueries());
  final int[] queryLength=reader.getQueryLengths();
  writer.printf("String_Node_Str",ArrayUtils.getLength(queryLength));
  final SummaryStatistics queryLengthStats=new SummaryStatistics();
  if (queryLength != null) {
    for (    final double d : queryLength) {
      queryLengthStats.addValue(d);
    }
  }
  writer.printf("String_Node_Str",(int)queryLengthStats.getMin());
  writer.printf("String_Node_Str",(int)queryLengthStats.getMax());
  writer.printf("String_Node_Str",queryLengthStats.getMean());
  writer.println("String_Node_Str" + reader.isConstantQueryLengths());
  writer.printf("String_Node_Str",reader.getQueryIdentifiers() != null && !reader.getQueryIdentifiers().isEmpty());
  writer.printf("String_Node_Str",reader.getTargetIdentifiers() != null && !reader.getTargetIdentifiers().isEmpty());
  writer.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());
  }
  avgScore/=(double)numLogicalAlignmentEntries;
  final int numQuerySequences=maxQueryIndex + 1;
  writer.printf("String_Node_Str",numQuerySequences);
  final int numTargetSequences=maxTargetIndex + 1;
  final double avgNumVariationsPerQuery=((double)sumNumVariations) / (double)numQuerySequences;
  writer.printf("String_Node_Str",numTargetSequences);
  writer.printf("String_Node_Str",numLogicalAlignmentEntries);
  writer.printf("String_Node_Str",alignedQueryIndices.size());
  writer.printf("String_Node_Str",(double)alignedQueryIndices.size() / (double)(long)numQuerySequences * 100.0d);
  writer.printf("String_Node_Str",numEntries > 0 ? total / numEntries : -1);
  writer.printf("String_Node_Str",avgScore);
  writer.printf("String_Node_Str",avgNumVariationsPerQuery);
  final long size=file.length();
  writer.printf("String_Node_Str",divide(size,numLogicalAlignmentEntries));
}