/** * Copyright Copyright 2010-17 Simon Andrews * * This file is part of FastQC. * * FastQC is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * FastQC is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with FastQC; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ package uk.ac.babraham.FastQC.Modules; import java.io.IOException; import javax.swing.JPanel; import javax.xml.stream.XMLStreamException; import uk.ac.babraham.FastQC.Graphs.BaseGroup; import uk.ac.babraham.FastQC.Graphs.QualityBoxPlot; import uk.ac.babraham.FastQC.Report.HTMLReportArchive; import uk.ac.babraham.FastQC.Sequence.Sequence; import uk.ac.babraham.FastQC.Sequence.QualityEncoding.PhredEncoding; import uk.ac.babraham.FastQC.Utilities.QualityCount; public class PerBaseQualityScores extends AbstractQCModule { public QualityCount [] qualityCounts = new QualityCount[0]; double [] means = null; double [] medians = null; double [] lowerQuartile = null; double [] upperQuartile = null; double [] lowest = null; double [] highest = null; String [] xLabels; int low = 0; int high = 0; PhredEncoding encodingScheme; private boolean calculated = false; public JPanel getResultsPanel() { if (!calculated) getPercentages(); return new QualityBoxPlot(means,medians,lowest,highest,lowerQuartile,upperQuartile, low, high, 2d, xLabels, "Quality scores across all bases ("+encodingScheme+" encoding)"); } public boolean ignoreFilteredSequences() { return true; } public boolean ignoreInReport () { // We don't show this if there is no quality data. if (ModuleConfig.getParam("quality_base", "ignore") > 0 || qualityCounts.length == 0) { return true; } return false; } private synchronized void getPercentages () { char [] range = calculateOffsets(); encodingScheme = PhredEncoding.getFastQEncodingOffset(range[0]); low = 0; high = range[1] - encodingScheme.offset(); if (high < 35) { high = 35; } BaseGroup [] groups = BaseGroup.makeBaseGroups(qualityCounts.length); means = new double[groups.length]; medians = new double[groups.length]; lowest = new double[groups.length]; highest = new double[groups.length]; lowerQuartile = new double[groups.length]; upperQuartile = new double[groups.length]; xLabels = new String[groups.length]; for (int i=0;i maxChar) { maxChar = qualityCounts[q].getMaxChar(); } } } return new char[] {minChar,maxChar}; } public void processSequence(Sequence sequence) { calculated = false; char [] qual = sequence.getQualityString().toCharArray(); if (qualityCounts.length < qual.length) { QualityCount [] qualityCountsNew = new QualityCount[qual.length]; for (int i=0;i 100) { count++; total += qualityCounts[i].getPercentile(offset, percentile); } } if (count > 0) { return total/count; } return Double.NaN; } private double getMean (int minbp, int maxbp, int offset) { int count = 0; double total = 0; for (int i=minbp-1;i 0) { count++; total += qualityCounts[i].getMean(offset); } } if (count > 0) { return total/count; } return 0; } }