Debian Codegraph @

uk/ac/babraham/FastQC/Utilities/QualityCount.java

raw symbols SCIP
1 /**
2 * Copyright Copyright 2013-17 Simon Andrews
3 *
4 * This file is part of FastQC.
5 *
6 * Conclave is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * SeqMonk is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Conclave; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 package uk.ac.babraham.FastQC.Utilities;
22
23 public class QualityCount {
24
25 /*
26 * So I'm on my third go at writing this. I've now tried an all
27 * primitive version of this class so that we don't have to do
28 * hash lookups which require a conversion from chr to Character.
29 * We should also be safe with 150 slots which will give us up to
30 * Phred 86 with a 64 offset, which should be plenty.
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 }