| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
package uk.ac.babraham.FastQC.Modules; |
| 21 |
|
| 22 |
import java.io.IOException; |
| 23 |
|
| 24 |
import javax.swing.JPanel; |
| 25 |
import javax.xml.stream.XMLStreamException; |
| 26 |
|
| 27 |
import uk.ac.babraham.FastQC.Graphs.BaseGroup; |
| 28 |
import uk.ac.babraham.FastQC.Graphs.LineGraph; |
| 29 |
import uk.ac.babraham.FastQC.Report.HTMLReportArchive; |
| 30 |
import uk.ac.babraham.FastQC.Sequence.Sequence; |
| 31 |
|
| 32 |
public class NContent extends AbstractQCModule { |
| 33 |
|
| 34 |
public long [] nCounts = new long [0]; |
| 35 |
public long [] notNCounts = new long [0]; |
| 36 |
public boolean calculated = false; |
| 37 |
public double [] percentages = null; |
| 38 |
public String [] xCategories = new String[0]; |
| 39 |
|
| 40 |
public JPanel getResultsPanel() { |
| 41 |
|
| 42 |
if (!calculated) getPercentages(); |
| 43 |
return new LineGraph(new double [][] {percentages}, 0d, 100d, "Position in read (bp)",new String [] {"%N"}, xCategories, "N content across all bases"); |
| 44 |
} |
| 45 |
|
| 46 |
public boolean ignoreFilteredSequences() { |
| 47 |
return true; |
| 48 |
} |
| 49 |
|
| 50 |
public boolean ignoreInReport () { |
| 51 |
if (ModuleConfig.getParam("n_content", "ignore") > 0) { |
| 52 |
return true; |
| 53 |
} |
| 54 |
return false; |
| 55 |
} |
| 56 |
|
| 57 |
private synchronized void getPercentages () { |
| 58 |
|
| 59 |
BaseGroup [] groups = BaseGroup.makeBaseGroups(nCounts.length); |
| 60 |
|
| 61 |
xCategories = new String[groups.length]; |
| 62 |
|
| 63 |
percentages = new double [groups.length]; |
| 64 |
|
| 65 |
long total; |
| 66 |
long nCount; |
| 67 |
|
| 68 |
for (int i=0;i<groups.length;i++) { |
| 69 |
|
| 70 |
xCategories[i] = groups[i].toString(); |
| 71 |
|
| 72 |
nCount = 0; |
| 73 |
total = 0; |
| 74 |
|
| 75 |
for (int bp=groups[i].lowerCount()-1;bp<groups[i].upperCount();bp++) { |
| 76 |
nCount += nCounts[bp]; |
| 77 |
total += nCounts[bp]; |
| 78 |
total += notNCounts[bp]; |
| 79 |
} |
| 80 |
|
| 81 |
percentages[i] = 100*(nCount/(double)total); |
| 82 |
} |
| 83 |
|
| 84 |
calculated = true; |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
public void processSequence(Sequence sequence) { |
| 89 |
calculated = false; |
| 90 |
char [] seq = sequence.getSequence().toCharArray(); |
| 91 |
if (nCounts.length < seq.length) { |
| 92 |
|
| 93 |
|
| 94 |
long [] nCountsNew = new long [seq.length]; |
| 95 |
long [] notNCountsNew = new long [seq.length]; |
| 96 |
|
| 97 |
for (int i=0;i<nCounts.length;i++) { |
| 98 |
nCountsNew[i] = nCounts[i]; |
| 99 |
notNCountsNew[i] = notNCounts[i]; |
| 100 |
} |
| 101 |
|
| 102 |
nCounts = nCountsNew; |
| 103 |
notNCounts = notNCountsNew; |
| 104 |
} |
| 105 |
|
| 106 |
for (int i=0;i<seq.length;i++) { |
| 107 |
if (seq[i] == 'N') { |
| 108 |
++nCounts[i]; |
| 109 |
} |
| 110 |
else { |
| 111 |
++notNCounts[i]; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
} |
| 116 |
|
| 117 |
public void reset () { |
| 118 |
nCounts = new long[0]; |
| 119 |
notNCounts = new long[0]; |
| 120 |
} |
| 121 |
|
| 122 |
public String description() { |
| 123 |
return "Shows the percentage of bases at each position which are not being called"; |
| 124 |
} |
| 125 |
|
| 126 |
public String name() { |
| 127 |
return "Per base N content"; |
| 128 |
} |
| 129 |
|
| 130 |
public boolean raisesError() { |
| 131 |
if (!calculated) getPercentages(); |
| 132 |
for (int i=0;i<percentages.length;i++) { |
| 133 |
if (percentages[i] > ModuleConfig.getParam("n_content", "error")) { |
| 134 |
return true; |
| 135 |
} |
| 136 |
} |
| 137 |
return false; |
| 138 |
} |
| 139 |
|
| 140 |
public boolean raisesWarning() { |
| 141 |
if (!calculated) getPercentages(); |
| 142 |
for (int i=0;i<percentages.length;i++) { |
| 143 |
if (percentages[i] > ModuleConfig.getParam("n_content", "warn")) { |
| 144 |
return true; |
| 145 |
} |
| 146 |
} |
| 147 |
return false; |
| 148 |
} |
| 149 |
|
| 150 |
public void makeReport(HTMLReportArchive report) throws XMLStreamException,IOException { |
| 151 |
if (!calculated) getPercentages(); |
| 152 |
|
| 153 |
writeDefaultImage(report, "per_base_n_content.png", "N content graph", Math.max(800, percentages.length*15), 600); |
| 154 |
|
| 155 |
StringBuffer sb = report.dataDocument(); |
| 156 |
sb.append("#Base\tN-Count\n"); |
| 157 |
for (int i=0;i<xCategories.length;i++) { |
| 158 |
sb.append(xCategories[i]); |
| 159 |
sb.append("\t"); |
| 160 |
sb.append(percentages[i]); |
| 161 |
sb.append("\n"); |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
} |