/**
   * Handle writing the {@link PerSequenceQualityScores} to the database.
   *
   * @param scores the {@link PerSequenceQualityScores} computed by fastqc.
   * @param analysis the {@link AnalysisFastQCBuilder} to update.
   */
  private void handlePerSequenceQualityScores(
      PerSequenceQualityScores scores, AnalysisFastQCBuilder analysis) throws IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    LineGraph lg = (LineGraph) scores.getResultsPanel();
    BufferedImage b = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB);
    Graphics g = b.getGraphics();
    lg.paint(g, b.getWidth(), b.getHeight());

    ImageIO.write(b, "PNG", os);
    byte[] image = os.toByteArray();
    analysis.perSequenceQualityScoreChart(image);
  }
  /**
   * Handle writing the {@link DuplicationLevel} to the database.
   *
   * @param duplicationLevel the {@link DuplicationLevel} calculated by fastqc.
   * @param analysis the {@link AnalysisFastQCBuilder} to update.
   */
  private void handleDuplicationLevel(
      DuplicationLevel duplicationLevel, AnalysisFastQCBuilder analysis) throws IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    LineGraph lg = (LineGraph) duplicationLevel.getResultsPanel();
    BufferedImage b = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB);
    Graphics g = b.getGraphics();
    lg.paint(g, b.getWidth(), b.getHeight());

    ImageIO.write(b, "PNG", os);
    byte[] image = os.toByteArray();
    analysis.duplicationLevelChart(image);
  }
 /**
  * Handle writing the {@link BasicStats} to the database.
  *
  * @param stats the {@link BasicStats} computed by fastqc.
  * @param analysis the {@link AnalysisFastQCBuilder} to update.
  */
 private void handleBasicStats(BasicStats stats, AnalysisFastQCBuilder analysis) {
   analysis.fileType(stats.getFileType());
   analysis.encoding(PhredEncoding.getFastQEncodingOffset(stats.getLowestChar()).name());
   analysis.minLength(stats.getMinLength());
   analysis.maxLength(stats.getMaxLength());
   analysis.totalSequences(stats.getActualCount());
   analysis.filteredSequences(stats.getFilteredCount());
   analysis.gcContent(stats.getGCContent());
   analysis.totalBases(
       stats.getACount()
           + stats.getGCount()
           + stats.getCCount()
           + stats.getTCount()
           + stats.getNCount());
 }