@Override
  public void performOperation() throws OperationFailedException {

    BEDFile intervals = (BEDFile) this.getInputBufferForClass(BEDFile.class);
    BAMFile bam = (BAMFile) this.getInputBufferForClass(BAMFile.class);
    DOCMetrics metrics = (DOCMetrics) getOutputBufferForClass(DOCMetrics.class);

    try {
      intervals.buildIntervalsMap();

      CoverageCalculator covCalc = new CoverageCalculator(bam.getFile(), intervals, false);
      covCalc.setThreadCount(getPipelineOwner().getThreadCount());

      int[] depthHistogram = covCalc.computeOverallCoverage();

      // The depth histogram is an un-normalized raw counts of the number of bases with a certain
      // read depth
      // for instance, the 10th position in the list of the number of bases found with read depths =
      // 10
      double mean = CoverageCalculator.getMean(depthHistogram);
      double[] covs = CoverageCalculator.convertCountsToProportions(depthHistogram);

      int[] cutoffs = new int[] {1, 10, 15, 20, 25, 50, 100};
      double[] covAboveCutoffs = new double[cutoffs.length];
      for (int i = 0; i < covAboveCutoffs.length; i++) {
        covAboveCutoffs[i] = covs[cutoffs[i]];
      }

      metrics.setMeanCoverage(mean);
      metrics.setCoverageProportions(covs);
      metrics.setCutoffs(cutoffs);
      metrics.setFractionAboveCutoff(covAboveCutoffs);

      Logger.getLogger(Pipeline.primaryLoggerName)
          .info(getObjectLabel() + " Found mean depth : " + mean);

    } catch (IOException e) {
      e.printStackTrace();
      Logger.getLogger(Pipeline.primaryLoggerName)
          .warning(getObjectLabel() + " encountered IO Error : " + e.getLocalizedMessage());
      throw new OperationFailedException(
          "IO Error calculating coverages : " + e.getLocalizedMessage(), this);
    } catch (InterruptedException e) {
      e.printStackTrace();
      Logger.getLogger(Pipeline.primaryLoggerName)
          .warning(getObjectLabel() + " was interrupted: " + e.getLocalizedMessage());
      throw new OperationFailedException(
          "Interrupted calculating coverages : " + e.getLocalizedMessage(), this);
    }
  }