| 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.Graphs; |
| 21 |
|
| 22 |
import java.util.Vector; |
| 23 |
|
| 24 |
import uk.ac.babraham.FastQC.FastQCConfig; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public class BaseGroup { |
| 34 |
|
| 35 |
private int lowerCount; |
| 36 |
private int upperCount; |
| 37 |
|
| 38 |
public static BaseGroup [] makeBaseGroups (int maxLength) { |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
if (FastQCConfig.getInstance().minLength > maxLength) { |
| 47 |
maxLength = FastQCConfig.getInstance().minLength; |
| 48 |
} |
| 49 |
|
| 50 |
if (FastQCConfig.getInstance().nogroup) { |
| 51 |
return(makeUngroupedGroups(maxLength)); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
if (FastQCConfig.getInstance().nogroup) { |
| 56 |
return(makeUngroupedGroups(maxLength)); |
| 57 |
} |
| 58 |
else if (FastQCConfig.getInstance().expgroup) { |
| 59 |
return(makeExponentialBaseGroups(maxLength)); |
| 60 |
} |
| 61 |
else { |
| 62 |
return(makeLinearBaseGroups(maxLength)); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
public static BaseGroup [] makeUngroupedGroups (int maxLength) { |
| 67 |
|
| 68 |
int startingBase = 1; |
| 69 |
int interval = 1; |
| 70 |
|
| 71 |
Vector<BaseGroup> groups = new Vector<BaseGroup>(); |
| 72 |
|
| 73 |
while (startingBase <= maxLength) { |
| 74 |
|
| 75 |
int endBase = startingBase+(interval-1); |
| 76 |
if (endBase > maxLength) endBase = maxLength; |
| 77 |
|
| 78 |
BaseGroup bg = new BaseGroup(startingBase, endBase); |
| 79 |
groups.add(bg); |
| 80 |
|
| 81 |
startingBase += interval; |
| 82 |
} |
| 83 |
|
| 84 |
return groups.toArray(new BaseGroup[0]); |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
public static BaseGroup [] makeExponentialBaseGroups (int maxLength) { |
| 89 |
|
| 90 |
int startingBase = 1; |
| 91 |
int interval = 1; |
| 92 |
|
| 93 |
Vector<BaseGroup> groups = new Vector<BaseGroup>(); |
| 94 |
|
| 95 |
while (startingBase <= maxLength) { |
| 96 |
|
| 97 |
int endBase = startingBase+(interval-1); |
| 98 |
if (endBase > maxLength) endBase = maxLength; |
| 99 |
|
| 100 |
BaseGroup bg = new BaseGroup(startingBase, endBase); |
| 101 |
groups.add(bg); |
| 102 |
|
| 103 |
startingBase += interval; |
| 104 |
|
| 105 |
|
| 106 |
if (startingBase == 10 && maxLength > 75) { |
| 107 |
interval = 5; |
| 108 |
} |
| 109 |
if (startingBase == 50 && maxLength > 200) { |
| 110 |
interval = 10; |
| 111 |
} |
| 112 |
if (startingBase == 100 && maxLength > 300) { |
| 113 |
interval = 50; |
| 114 |
} |
| 115 |
if (startingBase == 500 && maxLength > 1000) { |
| 116 |
interval = 100; |
| 117 |
} |
| 118 |
if (startingBase == 1000 && maxLength > 2000) { |
| 119 |
interval = 500; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
} |
| 124 |
|
| 125 |
return groups.toArray(new BaseGroup[0]); |
| 126 |
|
| 127 |
} |
| 128 |
|
| 129 |
private static int getLinearInterval (int length) { |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
int [] baseValues = new int [] {2,5,10}; |
| 136 |
int multiplier = 1; |
| 137 |
|
| 138 |
while (true) { |
| 139 |
for (int b=0;b<baseValues.length;b++) { |
| 140 |
int interval = baseValues[b] * multiplier; |
| 141 |
int groupCount = 9 + ((length-9)/interval); |
| 142 |
if ((length-9) % interval != 0) { |
| 143 |
groupCount += 1; |
| 144 |
} |
| 145 |
|
| 146 |
if (groupCount < 75) return interval; |
| 147 |
} |
| 148 |
|
| 149 |
multiplier *= 10; |
| 150 |
|
| 151 |
if (multiplier == 10000000) { |
| 152 |
throw new IllegalStateException("Couldn't find a sensible interval grouping for length '"+length+"'"); |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
} |
| 157 |
|
| 158 |
public static BaseGroup [] makeLinearBaseGroups (int maxLength) { |
| 159 |
|
| 160 |
|
| 161 |
if (maxLength <= 75) return makeUngroupedGroups(maxLength); |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
int interval = getLinearInterval(maxLength); |
| 166 |
|
| 167 |
|
| 168 |
int startingBase = 1; |
| 169 |
|
| 170 |
Vector<BaseGroup> groups = new Vector<BaseGroup>(); |
| 171 |
|
| 172 |
while (startingBase <= maxLength) { |
| 173 |
|
| 174 |
int endBase = startingBase+(interval-1); |
| 175 |
|
| 176 |
if (startingBase < 10) endBase = startingBase; |
| 177 |
|
| 178 |
if (startingBase == 10 && interval > 10) { |
| 179 |
endBase = interval-1; |
| 180 |
} |
| 181 |
|
| 182 |
if (endBase > maxLength) endBase = maxLength; |
| 183 |
|
| 184 |
BaseGroup bg = new BaseGroup(startingBase, endBase); |
| 185 |
groups.add(bg); |
| 186 |
|
| 187 |
if (startingBase < 10) { |
| 188 |
startingBase +=1; |
| 189 |
} |
| 190 |
else if (startingBase == 10 && interval > 10) { |
| 191 |
startingBase = interval; |
| 192 |
} |
| 193 |
else { |
| 194 |
startingBase += interval; |
| 195 |
} |
| 196 |
|
| 197 |
} |
| 198 |
|
| 199 |
return groups.toArray(new BaseGroup[0]); |
| 200 |
|
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
private BaseGroup (int lowerCount, int upperCount) { |
| 211 |
this.lowerCount = lowerCount; |
| 212 |
this.upperCount = upperCount; |
| 213 |
} |
| 214 |
|
| 215 |
public int lowerCount () { |
| 216 |
return lowerCount; |
| 217 |
} |
| 218 |
|
| 219 |
public int upperCount () { |
| 220 |
return upperCount; |
| 221 |
} |
| 222 |
|
| 223 |
public boolean containsValue (int value) { |
| 224 |
return value>=lowerCount && value<=upperCount; |
| 225 |
} |
| 226 |
|
| 227 |
public String toString () { |
| 228 |
if (lowerCount == upperCount) { |
| 229 |
return ""+lowerCount; |
| 230 |
} |
| 231 |
else { |
| 232 |
return ""+lowerCount+"-"+upperCount; |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
} |