Program: 50362
Project: 50362
Buggy source:
@Override public void writeRecord(final DiscoverVariantIterateSortedAlignments iterator,final SampleCountInfo[] sampleCounts,final int referenceIndex,int position,final DiscoverVariantPositionData list,final int groupIndexA,final int groupIndexB){
  position=position + 1;
  final char refBase=sampleCounts[0].referenceBase;
  if (refBase != 'C' && refBase != 'G') {
    return;
  }
  fillMethylationCountArrays(sampleCounts,list,position,refBase,mci,readerIndexToGroupIndex);
  if (eventCountAtSite < minimumEventThreshold) {
    return;
  }
  statWriter.setInfo(depthFieldIndex,list.size());
  final CharSequence currentReferenceId=iterator.getReferenceId(referenceIndex);
  statWriter.setChromosome(currentReferenceId);
  statWriter.setPosition(position);
  statWriter.setReferenceAllele(Character.toString(sampleCounts[0].referenceBase));
  final String biomartRegionSpan=String.format("String_Node_Str",currentReferenceId,position,position);
  statWriter.setInfo(biomartFieldIndex,biomartRegionSpan);
  statWriter.setInfo(strandFieldIndex,Character.toString(strandAtSite));
  final String genomicContext=findGenomicContext(referenceIndex,position);
  statWriter.setInfo(genomicContextIndex,genomicContext);
  for (int groupIndex=0; groupIndex < numberOfGroups; groupIndex++) {
    statWriter.setInfo(notMethylatedCCountsIndex[groupIndex],mci.unmethylatedCCountsPerGroup[groupIndex]);
    statWriter.setInfo(methylatedCCountsIndex[groupIndex],mci.methylatedCCountPerGroup[groupIndex]);
  }
  for (int sampleIndex=0; sampleIndex < numberOfSamples; sampleIndex++) {
    final float numerator=mci.methylatedCCountsPerSample[sampleIndex];
    final float denominator=numerator + mci.unmethylatedCCountPerSample[sampleIndex];
    final float methylationRate=numerator * 100 / denominator;
    statWriter.setSampleValue(methylationRateFieldIndex,sampleIndex,Math.round(methylationRate));
    statWriter.setSampleValue(unconvertedCytosineFieldIndex,sampleIndex,mci.methylatedCCountsPerSample[sampleIndex]);
    statWriter.setSampleValue(convertedCytosineFieldIndex,sampleIndex,mci.unmethylatedCCountPerSample[sampleIndex]);
  }
  for (  final GroupComparison comparison : groupComparisons) {
    final int indexGroup1=comparison.indexGroup1;
    final int indexGroup2=comparison.indexGroup2;
    final double denominator=(double)(mci.unmethylatedCCountsPerGroup[indexGroup1]) * (double)(mci.methylatedCCountPerGroup[indexGroup2]);
    final double oddsRatio=denominator == 0 ? Double.NaN : ((double)(mci.unmethylatedCCountsPerGroup[indexGroup2]) * (double)(mci.methylatedCCountPerGroup[indexGroup1])) / denominator;
    final double logOddsRatioSE;
    if (mci.methylatedCCountPerGroup[indexGroup1] < 10 || mci.methylatedCCountPerGroup[indexGroup2] < 10 || mci.unmethylatedCCountsPerGroup[indexGroup1] < 10 || mci.unmethylatedCCountsPerGroup[indexGroup2] < 10) {
      logOddsRatioSE=Double.NaN;
    }
 else {
      logOddsRatioSE=Math.sqrt(1d / mci.unmethylatedCCountsPerGroup[indexGroup2] + 1d / mci.methylatedCCountPerGroup[indexGroup1] + 1d / mci.methylatedCCountPerGroup[indexGroup2] + 1d / mci.unmethylatedCCountsPerGroup[indexGroup1]);
    }
    final double log2OddsRatio=Math.log(oddsRatio) / Math.log(2);
    final double log2OddsRatioZValue=log2OddsRatio / logOddsRatioSE;
    double fisherP=Double.NaN;
    if (eventCountAtSite >= minimumEventThreshold) {
      final boolean ok=checkCounts();
      if (ok) {
        fisherP=fisherRInstalled ? FisherExactRCalculator.getFisherPValue(mci.unmethylatedCCountsPerGroup[indexGroup2],mci.methylatedCCountPerGroup[indexGroup2],mci.unmethylatedCCountsPerGroup[indexGroup1],mci.methylatedCCountPerGroup[indexGroup1]) : Double.NaN;
      }
 else {
        System.err.printf("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str",currentReferenceId,referenceIndex,position,mci.unmethylatedCCountsPerGroup[indexGroup2],mci.methylatedCCountPerGroup[indexGroup2],mci.unmethylatedCCountsPerGroup[indexGroup1],mci.methylatedCCountPerGroup[indexGroup1]);
      }
    }
    final double totalCsObservedgroup1=mci.methylatedCCountPerGroup[indexGroup1] + mci.unmethylatedCCountsPerGroup[indexGroup1];
    final double totalCsObservedgroup2=mci.methylatedCCountPerGroup[indexGroup2] + mci.unmethylatedCCountsPerGroup[indexGroup2];
    double group1MR;
    if (totalCsObservedgroup1 == 0) {
      group1MR=Double.NaN;
    }
 else {
      group1MR=mci.methylatedCCountPerGroup[indexGroup1] * 100 / totalCsObservedgroup1;
    }
    double group2MR;
    if (totalCsObservedgroup2 == 0) {
      group2MR=Double.NaN;
    }
 else {
      group2MR=mci.methylatedCCountPerGroup[indexGroup2] * 100 / totalCsObservedgroup2;
    }
    final int deltaMR=(int)Math.round(Math.abs(group1MR - group2MR));
    statWriter.setInfo(log2OddsRatioColumnIndex[comparison.index],log2OddsRatio);
    statWriter.setInfo(log2OddsRatioStandardErrorColumnIndex[comparison.index],logOddsRatioSE);
    statWriter.setInfo(log2OddsRatioZColumnIndex[comparison.index],log2OddsRatioZValue);
    statWriter.setInfo(fisherExactPValueColumnIndex[comparison.index],fisherP);
    statWriter.setInfo(deltaMRColumnIndex[comparison.index],deltaMR);
  }
  genotypeFormatter.writeGenotypes(statWriter,sampleCounts,position);
  for (int sampleIndex=0; sampleIndex < numberOfSamples; sampleIndex++) {
    final int firstIndex=sampleIndex;
    final int secondIndex=convertIndex(sampleIndex,strandAtSite);
    if (strandAtSite == '+') {
      final int otherIndex=convertIndex(sampleIndex,'-');
      statWriter.setSampleValue(methylationRateFieldIndex,otherIndex,"String_Node_Str");
      statWriter.setSampleValue(convertedCytosineFieldIndex,otherIndex,"String_Node_Str");
      statWriter.setSampleValue(unconvertedCytosineFieldIndex,otherIndex,"String_Node_Str");
      statWriter.setSampleValue(genotypeFormatter.getGenotypeFieldIndex(),otherIndex,"String_Node_Str");
      statWriter.setSampleValue(genotypeFormatter.getBaseCountFieldIndex(),otherIndex,"String_Node_Str");
      statWriter.setSampleValue(genotypeFormatter.getFailBaseCountFieldIndex(),otherIndex,"String_Node_Str");
      statWriter.setSampleValue(genotypeFormatter.getGoodBaseCountFieldIndex(),otherIndex,"String_Node_Str");
    }
 else {
      statWriter.switchSampleValue(methylationRateFieldIndex,firstIndex,secondIndex,"String_Node_Str");
      statWriter.switchSampleValue(convertedCytosineFieldIndex,firstIndex,secondIndex,"String_Node_Str");
      statWriter.switchSampleValue(unconvertedCytosineFieldIndex,firstIndex,secondIndex,"String_Node_Str");
      statWriter.switchSampleValue(genotypeFormatter.getGenotypeFieldIndex(),firstIndex,secondIndex,"String_Node_Str");
      statWriter.switchSampleValue(genotypeFormatter.getBaseCountFieldIndex(),firstIndex,secondIndex,"String_Node_Str");
      statWriter.switchSampleValue(genotypeFormatter.getFailBaseCountFieldIndex(),firstIndex,secondIndex,"String_Node_Str");
      statWriter.switchSampleValue(genotypeFormatter.getGoodBaseCountFieldIndex(),firstIndex,secondIndex,"String_Node_Str");
    }
  }
  statWriter.writeRecord();
}

Fixed version (ground truth):
@Override public void writeRecord(final DiscoverVariantIterateSortedAlignments iterator,final SampleCountInfo[] sampleCounts,final int referenceIndex,int position,final DiscoverVariantPositionData list,final int groupIndexA,final int groupIndexB){
  position=position + 1;
  final char refBase=sampleCounts[0].referenceBase;
  if (refBase != 'C' && refBase != 'G') {
    return;
  }
  fillMethylationCountArrays(sampleCounts,list,position,refBase,mci,readerIndexToGroupIndex);
  if (mci.eventCountAtSite < minimumEventThreshold) {
    return;
  }
  statWriter.setInfo(depthFieldIndex,list.size());
  final CharSequence currentReferenceId=iterator.getReferenceId(referenceIndex);
  statWriter.setChromosome(currentReferenceId);
  statWriter.setPosition(position);
  statWriter.setReferenceAllele(Character.toString(sampleCounts[0].referenceBase));
  final String biomartRegionSpan=String.format("String_Node_Str",currentReferenceId,position,position);
  statWriter.setInfo(biomartFieldIndex,biomartRegionSpan);
  statWriter.setInfo(strandFieldIndex,Character.toString(mci.strandAtSite));
  final String genomicContext=findGenomicContext(referenceIndex,position);
  statWriter.setInfo(genomicContextIndex,genomicContext);
  for (int groupIndex=0; groupIndex < numberOfGroups; groupIndex++) {
    statWriter.setInfo(notMethylatedCCountsIndex[groupIndex],mci.unmethylatedCCountsPerGroup[groupIndex]);
    statWriter.setInfo(methylatedCCountsIndex[groupIndex],mci.methylatedCCountPerGroup[groupIndex]);
  }
  for (int sampleIndex=0; sampleIndex < numberOfSamples; sampleIndex++) {
    final float numerator=mci.methylatedCCountsPerSample[sampleIndex];
    final float denominator=numerator + mci.unmethylatedCCountPerSample[sampleIndex];
    final float methylationRate=numerator * 100 / denominator;
    statWriter.setSampleValue(methylationRateFieldIndex,sampleIndex,Math.round(methylationRate));
    statWriter.setSampleValue(unconvertedCytosineFieldIndex,sampleIndex,mci.methylatedCCountsPerSample[sampleIndex]);
    statWriter.setSampleValue(convertedCytosineFieldIndex,sampleIndex,mci.unmethylatedCCountPerSample[sampleIndex]);
  }
  for (  final GroupComparison comparison : groupComparisons) {
    final int indexGroup1=comparison.indexGroup1;
    final int indexGroup2=comparison.indexGroup2;
    final double denominator=(double)(mci.unmethylatedCCountsPerGroup[indexGroup1]) * (double)(mci.methylatedCCountPerGroup[indexGroup2]);
    final double oddsRatio=denominator == 0 ? Double.NaN : ((double)(mci.unmethylatedCCountsPerGroup[indexGroup2]) * (double)(mci.methylatedCCountPerGroup[indexGroup1])) / denominator;
    final double logOddsRatioSE;
    if (mci.methylatedCCountPerGroup[indexGroup1] < 10 || mci.methylatedCCountPerGroup[indexGroup2] < 10 || mci.unmethylatedCCountsPerGroup[indexGroup1] < 10 || mci.unmethylatedCCountsPerGroup[indexGroup2] < 10) {
      logOddsRatioSE=Double.NaN;
    }
 else {
      logOddsRatioSE=Math.sqrt(1d / mci.unmethylatedCCountsPerGroup[indexGroup2] + 1d / mci.methylatedCCountPerGroup[indexGroup1] + 1d / mci.methylatedCCountPerGroup[indexGroup2] + 1d / mci.unmethylatedCCountsPerGroup[indexGroup1]);
    }
    final double log2OddsRatio=Math.log(oddsRatio) / Math.log(2);
    final double log2OddsRatioZValue=log2OddsRatio / logOddsRatioSE;
    double fisherP=Double.NaN;
    if (mci.eventCountAtSite >= minimumEventThreshold) {
      final boolean ok=checkCounts();
      if (ok) {
        fisherP=fisherRInstalled ? FisherExactRCalculator.getFisherPValue(mci.unmethylatedCCountsPerGroup[indexGroup2],mci.methylatedCCountPerGroup[indexGroup2],mci.unmethylatedCCountsPerGroup[indexGroup1],mci.methylatedCCountPerGroup[indexGroup1]) : Double.NaN;
      }
 else {
        System.err.printf("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str",currentReferenceId,referenceIndex,position,mci.unmethylatedCCountsPerGroup[indexGroup2],mci.methylatedCCountPerGroup[indexGroup2],mci.unmethylatedCCountsPerGroup[indexGroup1],mci.methylatedCCountPerGroup[indexGroup1]);
      }
    }
    final double totalCsObservedgroup1=mci.methylatedCCountPerGroup[indexGroup1] + mci.unmethylatedCCountsPerGroup[indexGroup1];
    final double totalCsObservedgroup2=mci.methylatedCCountPerGroup[indexGroup2] + mci.unmethylatedCCountsPerGroup[indexGroup2];
    double group1MR;
    if (totalCsObservedgroup1 == 0) {
      group1MR=Double.NaN;
    }
 else {
      group1MR=mci.methylatedCCountPerGroup[indexGroup1] * 100 / totalCsObservedgroup1;
    }
    double group2MR;
    if (totalCsObservedgroup2 == 0) {
      group2MR=Double.NaN;
    }
 else {
      group2MR=mci.methylatedCCountPerGroup[indexGroup2] * 100 / totalCsObservedgroup2;
    }
    final int deltaMR=(int)Math.round(Math.abs(group1MR - group2MR));
    statWriter.setInfo(log2OddsRatioColumnIndex[comparison.index],log2OddsRatio);
    statWriter.setInfo(log2OddsRatioStandardErrorColumnIndex[comparison.index],logOddsRatioSE);
    statWriter.setInfo(log2OddsRatioZColumnIndex[comparison.index],log2OddsRatioZValue);
    statWriter.setInfo(fisherExactPValueColumnIndex[comparison.index],fisherP);
    statWriter.setInfo(deltaMRColumnIndex[comparison.index],deltaMR);
  }
  genotypeFormatter.writeGenotypes(statWriter,sampleCounts,position);
  for (int sampleIndex=0; sampleIndex < numberOfSamples; sampleIndex++) {
    final int firstIndex=sampleIndex;
    final int secondIndex=convertIndex(sampleIndex,mci.strandAtSite);
    if (mci.strandAtSite == '+') {
      final int otherIndex=convertIndex(sampleIndex,'-');
      statWriter.setSampleValue(methylationRateFieldIndex,otherIndex,"String_Node_Str");
      statWriter.setSampleValue(convertedCytosineFieldIndex,otherIndex,"String_Node_Str");
      statWriter.setSampleValue(unconvertedCytosineFieldIndex,otherIndex,"String_Node_Str");
      statWriter.setSampleValue(genotypeFormatter.getGenotypeFieldIndex(),otherIndex,"String_Node_Str");
      statWriter.setSampleValue(genotypeFormatter.getBaseCountFieldIndex(),otherIndex,"String_Node_Str");
      statWriter.setSampleValue(genotypeFormatter.getFailBaseCountFieldIndex(),otherIndex,"String_Node_Str");
      statWriter.setSampleValue(genotypeFormatter.getGoodBaseCountFieldIndex(),otherIndex,"String_Node_Str");
    }
 else {
      statWriter.switchSampleValue(methylationRateFieldIndex,firstIndex,secondIndex,"String_Node_Str");
      statWriter.switchSampleValue(convertedCytosineFieldIndex,firstIndex,secondIndex,"String_Node_Str");
      statWriter.switchSampleValue(unconvertedCytosineFieldIndex,firstIndex,secondIndex,"String_Node_Str");
      statWriter.switchSampleValue(genotypeFormatter.getGenotypeFieldIndex(),firstIndex,secondIndex,"String_Node_Str");
      statWriter.switchSampleValue(genotypeFormatter.getBaseCountFieldIndex(),firstIndex,secondIndex,"String_Node_Str");
      statWriter.switchSampleValue(genotypeFormatter.getFailBaseCountFieldIndex(),firstIndex,secondIndex,"String_Node_Str");
      statWriter.switchSampleValue(genotypeFormatter.getGoodBaseCountFieldIndex(),firstIndex,secondIndex,"String_Node_Str");
    }
  }
  statWriter.writeRecord();
}