/** * 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 java.text.DecimalFormat; import java.util.HashMap; import java.util.Iterator; import javax.swing.JPanel; import javax.xml.stream.XMLStreamException; import uk.ac.babraham.FastQC.Graphs.LineGraph; import uk.ac.babraham.FastQC.Report.HTMLReportArchive; import uk.ac.babraham.FastQC.Sequence.Sequence; public class DuplicationLevel extends AbstractQCModule { private OverRepresentedSeqs overrepresentedModule; private double [] totalPercentages = null; private double maxCount = 100; private double percentDifferentSeqs = 0; private String [] labels; private static final DecimalFormat df = new DecimalFormat("#.##"); protected DuplicationLevel (OverRepresentedSeqs overrepresentedModule) { this.overrepresentedModule = overrepresentedModule; } public String description() { return "Plots the number of sequences which are duplicated to different levels"; } public boolean ignoreFilteredSequences() { if (ModuleConfig.getParam("duplication", "ignore") > 0) { return true; } return false; } public boolean ignoreInReport () { if (ModuleConfig.getParam("duplication", "ignore") > 0) { return true; } return false; } protected synchronized void calculateLevels () { if (totalPercentages != null) return; totalPercentages = new double[16]; HashMap collatedCounts = new HashMap(); Iterator it = overrepresentedModule.sequences.keySet().iterator(); while (it.hasNext()) { int thisCount = overrepresentedModule.sequences.get(it.next()); if (collatedCounts.containsKey(thisCount)) { collatedCounts.put(thisCount,collatedCounts.get(thisCount)+1); } else { collatedCounts.put(thisCount,1); } } // Now we can correct each of these HashMap correctedCounts = new HashMap(); Iterator itr = collatedCounts.keySet().iterator(); while (itr.hasNext()) { int dupLevel = itr.next(); int count = collatedCounts.get(dupLevel); correctedCounts.put(dupLevel,getCorrectedCount(overrepresentedModule.countAtUniqueLimit, overrepresentedModule.count, dupLevel, count)); } // From the corrected counts we can now work out the raw and deduplicated proportions double dedupTotal = 0; double rawTotal = 0; Iterator itc = correctedCounts.keySet().iterator(); while (itc.hasNext()) { int dupLevel = itc.next(); double count = correctedCounts.get(dupLevel); dedupTotal += count; rawTotal += count * dupLevel; int dupSlot = dupLevel - 1; // The dupSlot < 0 is a kludge to fix a problem we see if we have // a duplication level > 2^31. It it gets bigger than 2^64 then // we're really stuffed but I think this will work for all practical // purposes and this is a really corner case anyway. if (dupSlot > 9999 || dupSlot < 0) dupSlot = 15; else if (dupSlot > 4999) dupSlot = 14; else if (dupSlot > 999) dupSlot = 13; else if (dupSlot > 499) dupSlot = 12; else if (dupSlot > 99) dupSlot = 11; else if (dupSlot > 49) dupSlot = 10; else if (dupSlot > 9) dupSlot = 9; totalPercentages[dupSlot] += count * dupLevel; } // System.err.println("True total = "+overrepresentedModule.count+" inferred total is "+rawTotal+" dedup total is "+dedupTotal); labels = new String [16]; for (int i=0;i