/* (non-Javadoc)
   * @see edu.usc.epigenome.genomeLibs.MethylDb.CpgWalker.CpgWalker#processWindow(java.util.List)
   */
  @Override
  protected void processWindow(List<Cpg> inWindow) {
    checkWriter();
    super.processWindow(inWindow);

    int windMidpoint =
        (int)
            Math.round(
                ((double) (CpgWalker.windEnd(inWindow) + CpgWalker.windStart(inWindow))) / 2.0);
    double meth = this.methSummarizer.get(0).getValMean(true);
    int winds = CpgWalker.windStart(inWindow);
    int winde = CpgWalker.windEnd(inWindow);
    //		System.err.printf("Processing window CpgWalkerWigWriter: %s\tmeth=%.2f\n",
    // CpgWalker.windStr(inWindow), meth);

    // First wig writer
    wigWriter.printf("%d\t%d\n", windMidpoint, (int) Math.round(100.0 * meth));

    // Then bedgraph
    if (bedgraphWriter != null) {
      int midpointMidpoint =
          (int) Math.floor(((double) lastWindMidpoint + (double) windMidpoint) / 2.0);
      int spanStart = lastSpanEnd + 1;
      int spanEnd =
          (this.lastWindMidpoint > 0) ? midpointMidpoint : -1; // This isn't really correct

      // Don't do it if we're on the first one of the chromosome.
      if (this.lastSpanEnd > 0) {
        if (this.csvMode) {
          bedgraphWriter.printf(
              "%d,%d,%d,%d,%d\n",
              this.curChrNum, winds, winde, (int) Math.round(100.0 * lastMeth), inWindow.size());
        } else {
          bedgraphWriter.printf(
              "%s\t%d\t%d\t%d\n",
              this.curChr, spanStart, spanEnd, (int) Math.round(100.0 * lastMeth));
        }
      }
      //			System.err.printf("\t%s\t%d\t%d\t%d\t%d\n",this.curChr, winds, winde,
      // (int)Math.round(100.0*lastMeth), winde-winds);

      this.lastSpanEnd = spanEnd;
      this.lastWindMidpoint = windMidpoint;
      this.lastMeth = meth;
    }
  }
  /* (non-Javadoc)
   * @see edu.usc.epigenome.genomeLibs.MethylDb.CpgWalker.CpgWalker#init()
   */
  @Override
  protected void init() {
    super.init();

    try {
      System.err.printf("Initializing CpgWalkerWigWriter: %s\n", this.walkParams.toString());
    } catch (Exception e) {
    }
  }
 /* (non-Javadoc)
  * @see edu.usc.epigenome.genomeLibs.MethylDb.CpgWalker.CpgWalker#alertNewChrom()
  */
 @Override
 protected void alertNewChrom() {
   super.alertNewChrom();
   this.curChrNum = (new ChromFeatures()).chrom_from_public_str(this.curChr);
   System.err.printf("New chrom: %s\n", this.curChr);
   checkWriter();
   wigWriter.printf("variableStep chrom=%s\n", this.curChr);
   lastWindMidpoint = -1;
   lastSpanEnd = -1;
   lastMeth = -1.0;
 }
 /* (non-Javadoc)
  * @see edu.usc.epigenome.genomeLibs.MethylDb.CpgWalker.CpgWalker#finishChr()
  */
 @Override
 public void finishChr() {
   super.finishChr();
   checkWriter();
 }