Program: 37717
Project: 37717
Buggy source:
public static List<ChangePoint> identifyConstrainedNegativeBinomialPoints(String[] ids,SAMFileReader[] sfrs,Strandedness[] strandednesses,String chr,int start,int end,int maxBins,int binSize,int minCP,boolean isNegativeStrand,double alpha_0,double beta_0,int nb_r,int r,double p,boolean constrain_decreasing,double min_fold,int confidence_interval){
  int l=end - start + 1;
  int nBins=(l + binSize - 1) / binSize;
  char strand=isNegativeStrand ? '-' : '+';
  if (nBins > maxBins) {
    nBins=maxBins;
    binSize=(l + maxBins - 1) / maxBins;
    logger.info("String_Node_Str",chr,start,end,strand,binSize);
  }
  List<ChangePoint> changePoints=new ArrayList<ChangePoint>();
  double[][] y=new double[sfrs.length][];
  for (int i=0; i < sfrs.length; i++) {
    int[] cov=BAMTools.binnedMaxEndCoverage(sfrs[i],chr,start,nBins,binSize,false,true,strandednesses[i],isNegativeStrand);
    y[i]=new double[nBins];
    for (int j=0; j < nBins; j++) {
      y[i][j]=cov[j];
    }
  }
  JointSegmentationResult segmentation=IdentifyConstrainedChangePoints.doubly_constrained_multi_segmentation(y,alpha_0,beta_0,nb_r,r,p,constrain_decreasing,min_fold);
  PrefixSuffixResult prefix_suffix=IdentifyConstrainedChangePoints.prefix_suffix(y,alpha_0,beta_0,nb_r,r,p);
  ConfidenceCalculator cc=new ConfidenceCalculator(prefix_suffix);
  if (segmentation.n_segments > 1) {
    double[][] segment_mle=segmentation.segment_mle;
    int[] changepoints=segmentation.change_point;
    List<Integer> positions=new ArrayList<Integer>(segmentation.n_segments);
    List<double[]> before_mles=new ArrayList<double[]>(segmentation.n_segments);
    List<double[]> after_mles=new ArrayList<double[]>(segmentation.n_segments);
    List<Double> confidences=new ArrayList<Double>();
    List<Double> l_odds=new ArrayList<Double>();
    StrandedGenomicIntervalTree<Map<String,Object>> segments=new StrandedGenomicIntervalTree<Map<String,Object>>();
    segments.add(chr,start,end,strand);
    for (int i=0; i < changepoints.length; i++) {
      int changepoint_i=changepoints[i];
      if (changepoints[i] > minCP && changepoints[i] < nBins - minCP - 1) {
        int position=start + (changepoint_i * binSize) + (binSize / 2);
        if (position >= start && position <= end) {
          positions.add(position);
          before_mles.add(segment_mle[i]);
          after_mles.add(segment_mle[i + 1]);
          ConfidenceResult cr=cc.calculateConfidence(Math.max(changepoint_i - confidence_interval,0),Math.min(changepoint_i + 1 + confidence_interval,prefix_suffix.l - 2));
          confidences.add(Math.exp(cr.log_confidence));
          l_odds.add(cr.log_odds);
          SegmentFragmenter.fragment(segments,chr,position,strand,isNegativeStrand);
        }
      }
    }
    List<AnnotatedRegion> slist=new ArrayList<AnnotatedRegion>();
    for (    AnnotatedRegion s : segments) {
      slist.add(s);
    }
    for (int i=0; i < positions.size(); i++) {
      AnnotatedRegion before=slist.get(i);
      AnnotatedRegion after=slist.get(i + 1);
      AnnotatedRegion pos=new AnnotatedRegion("String_Node_Str",chr,positions.get(i),positions.get(i),strand);
      double[] before_mle=before_mles.get(i);
      double[] after_mle=after_mles.get(i);
      double confidence=confidences.get(i);
      double log_odds=l_odds.get(i);
      changePoints.add(new ChangePoint(pos,isNegativeStrand ? after : before,!isNegativeStrand ? after : before,ids,isNegativeStrand ? after_mle : before_mle,!isNegativeStrand ? after_mle : before_mle,confidence,log_odds));
    }
  }
  return changePoints;
}

Fixed version (ground truth):
public static List<ChangePoint> identifyConstrainedNegativeBinomialPoints(String[] ids,SAMFileReader[] sfrs,Strandedness[] strandednesses,String chr,int start,int end,int maxBins,int binSize,int minCP,boolean isNegativeStrand,double alpha_0,double beta_0,int nb_r,int r,double p,boolean constrain_decreasing,double min_fold){
  int l=end - start + 1;
  int nBins=(l + binSize - 1) / binSize;
  char strand=isNegativeStrand ? '-' : '+';
  if (nBins > maxBins) {
    nBins=maxBins;
    binSize=(l + maxBins - 1) / maxBins;
    logger.info("String_Node_Str",chr,start,end,strand,binSize);
  }
  List<ChangePoint> changePoints=new ArrayList<ChangePoint>();
  double[][] y=new double[sfrs.length][];
  for (int i=0; i < sfrs.length; i++) {
    int[] cov=BAMTools.binnedMaxEndCoverage(sfrs[i],chr,start,nBins,binSize,false,true,strandednesses[i],isNegativeStrand);
    y[i]=new double[nBins];
    for (int j=0; j < nBins; j++) {
      y[i][j]=cov[j];
    }
  }
  JointSegmentationResult segmentation=IdentifyConstrainedChangePoints.doubly_constrained_multi_segmentation(y,alpha_0,beta_0,nb_r,r,p,constrain_decreasing,min_fold);
  PrefixSuffixResult prefix_suffix=IdentifyConstrainedChangePoints.prefix_suffix(y,alpha_0,beta_0,nb_r,r,p);
  ConfidenceCalculator cc=new ConfidenceCalculator(prefix_suffix);
  if (segmentation.n_segments > 1) {
    double[][] segment_mle=segmentation.segment_mle;
    int[] changepoints=segmentation.change_point;
    List<Integer> positions=new ArrayList<Integer>(segmentation.n_segments);
    List<double[]> before_mles=new ArrayList<double[]>(segmentation.n_segments);
    List<double[]> after_mles=new ArrayList<double[]>(segmentation.n_segments);
    List<Double> confidences=new ArrayList<Double>();
    List<Double> l_odds=new ArrayList<Double>();
    StrandedGenomicIntervalTree<Map<String,Object>> segments=new StrandedGenomicIntervalTree<Map<String,Object>>();
    segments.add(chr,start,end,strand);
    for (int i=0; i < changepoints.length; i++) {
      int changepoint_i=changepoints[i];
      if (changepoints[i] > minCP && changepoints[i] < nBins - minCP - 1) {
        int position=start + (changepoint_i * binSize) + (binSize / 2);
        if (position >= start && position <= end) {
          positions.add(position);
          before_mles.add(segment_mle[i]);
          after_mles.add(segment_mle[i + 1]);
          ConfidenceResult cr=cc.calculateConfidence(changepoints[i]);
          confidences.add(Math.exp(cr.log_confidence));
          l_odds.add(cr.log_odds);
          SegmentFragmenter.fragment(segments,chr,position,strand,isNegativeStrand);
        }
      }
    }
    List<AnnotatedRegion> slist=new ArrayList<AnnotatedRegion>();
    for (    AnnotatedRegion s : segments) {
      slist.add(s);
    }
    for (int i=0; i < positions.size(); i++) {
      AnnotatedRegion before=slist.get(i);
      AnnotatedRegion after=slist.get(i + 1);
      AnnotatedRegion pos=new AnnotatedRegion("String_Node_Str",chr,positions.get(i),positions.get(i),strand);
      double[] before_mle=before_mles.get(i);
      double[] after_mle=after_mles.get(i);
      double confidence=confidences.get(i);
      double log_odds=l_odds.get(i);
      changePoints.add(new ChangePoint(pos,isNegativeStrand ? after : before,!isNegativeStrand ? after : before,ids,isNegativeStrand ? after_mle : before_mle,!isNegativeStrand ? after_mle : before_mle,confidence,log_odds));
    }
  }
  return changePoints;
}