| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
package uk.ac.babraham.FastQC.Utilities; |
| 22 |
|
| 23 |
public class QualityCount { |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
private long [] actualCounts = new long[150]; |
| 34 |
|
| 35 |
private long totalCounts = 0; |
| 36 |
|
| 37 |
public void addValue(char c) { |
| 38 |
totalCounts++; |
| 39 |
|
| 40 |
if ((int)c >= actualCounts.length) { |
| 41 |
throw new IllegalArgumentException("Got character "+c+" as a quality value which has ASCII"+((int)c)+" which is higher than we can cope with"); |
| 42 |
} |
| 43 |
actualCounts[(int)c]++; |
| 44 |
} |
| 45 |
|
| 46 |
public long getTotalCount () { |
| 47 |
return totalCounts; |
| 48 |
} |
| 49 |
|
| 50 |
public char getMinChar () { |
| 51 |
|
| 52 |
for (int i=0;i<actualCounts.length;i++) { |
| 53 |
if (actualCounts[i]>0) return (char)i; |
| 54 |
} |
| 55 |
|
| 56 |
return (char)1000; |
| 57 |
} |
| 58 |
|
| 59 |
public char getMaxChar () { |
| 60 |
for (int i=actualCounts.length-1;i>=0;i--) { |
| 61 |
if (actualCounts[i]>0) return (char)i; |
| 62 |
} |
| 63 |
|
| 64 |
return (char)1000; |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
public double getMean (int offset) { |
| 69 |
long total = 0; |
| 70 |
long count = 0; |
| 71 |
|
| 72 |
for (int i=offset;i<actualCounts.length;i++) { |
| 73 |
total += actualCounts[i]*(i-offset); |
| 74 |
count += actualCounts[i]; |
| 75 |
} |
| 76 |
|
| 77 |
return ((double)total)/count; |
| 78 |
} |
| 79 |
|
| 80 |
public double getPercentile (int offset, int percentile) { |
| 81 |
|
| 82 |
long total = totalCounts; |
| 83 |
|
| 84 |
total *= percentile; |
| 85 |
total /= 100; |
| 86 |
|
| 87 |
long count = 0; |
| 88 |
for (int i=offset;i<actualCounts.length;i++) { |
| 89 |
count += actualCounts[i]; |
| 90 |
if (count >=total) { |
| 91 |
return((char)(i-offset)); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
return -1; |
| 96 |
|
| 97 |
} |
| 98 |
|
| 99 |
} |