| 1 |
|
package jalview.util; |
| 2 |
|
|
| 3 |
|
import jalview.datamodel.AlignmentAnnotation; |
| 4 |
|
import jalview.datamodel.HiddenMarkovModel; |
| 5 |
|
import jalview.datamodel.SequenceI; |
| 6 |
|
import jalview.io.DataSourceType; |
| 7 |
|
import jalview.io.FileParse; |
| 8 |
|
import jalview.io.HMMFile; |
| 9 |
|
import jalview.io.StockholmFile; |
| 10 |
|
import jalview.schemes.ResidueProperties; |
| 11 |
|
|
| 12 |
|
import java.io.BufferedReader; |
| 13 |
|
import java.io.File; |
| 14 |
|
import java.io.FileNotFoundException; |
| 15 |
|
import java.io.FileOutputStream; |
| 16 |
|
import java.io.FileReader; |
| 17 |
|
import java.io.IOException; |
| 18 |
|
import java.io.InputStreamReader; |
| 19 |
|
import java.io.PrintWriter; |
| 20 |
|
import java.util.ArrayList; |
| 21 |
|
import java.util.HashMap; |
| 22 |
|
import java.util.List; |
| 23 |
|
import java.util.Map; |
| 24 |
|
import java.util.Random; |
| 25 |
|
import java.util.Scanner; |
| 26 |
|
import java.util.Vector; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
@author |
| 34 |
|
|
| 35 |
|
|
| |
|
| 0% |
Uncovered Elements: 532 (532) |
Complexity: 103 |
Complexity Density: 0.27 |
|
| 36 |
|
public class HMMProbabilityDistributionAnalyser |
| 37 |
|
{ |
| 38 |
|
AlignmentAnnotation reference = null; |
| 39 |
|
|
| 40 |
|
Vector<SequenceI> sequences; |
| 41 |
|
|
| 42 |
|
HiddenMarkovModel hmm; |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
List<ArrayList<Double>> raw = new ArrayList<>(); |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
Map<String, Double> binned = new HashMap<>(); |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
String families = "/media/sf_Shared_Folder/PFAM/Family/SeedFamilies.seed"; |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
final static String FAMILIESTOCLAN = "/media/sf_Shared_Folder/PFAM/Family/Clanlinks.dat"; |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
String hmms = "/media/sf_Shared_Folder/PFAM/HMMs/Pfam-A.hmm"; |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
final static String RAW = "/Raw.csv"; |
| 61 |
|
|
| 62 |
|
|
| 63 |
|
final static String BINNED = "/Binned.csv"; |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
final static double SCALE = 1; |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
int currentFilePosition = 0; |
| 70 |
|
|
| 71 |
|
final static String NL = "\n"; |
| 72 |
|
|
| 73 |
|
Random generator = new Random(); |
| 74 |
|
|
| 75 |
|
|
| 76 |
|
String currentFolder; |
| 77 |
|
|
| 78 |
|
boolean keepRaw = false; |
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
@param |
| 84 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 85 |
0 |
public void setFolder(String path)... |
| 86 |
|
{ |
| 87 |
0 |
currentFolder = path; |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
@param |
| 95 |
|
|
| 96 |
|
@param |
| 97 |
|
@throws |
| 98 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 99 |
0 |
public void moveLocationBy(int index, BufferedReader br)... |
| 100 |
|
throws IOException |
| 101 |
|
{ |
| 102 |
0 |
for (int i = 0; i < index; i++) |
| 103 |
|
{ |
| 104 |
0 |
String line = br.readLine(); |
| 105 |
0 |
while (!"//".equals(line)) |
| 106 |
|
{ |
| 107 |
0 |
line = br.readLine(); |
| 108 |
|
|
| 109 |
|
} |
| 110 |
|
} |
| 111 |
|
|
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
|
| 120 |
|
@param |
| 121 |
|
|
| 122 |
|
@throws |
| 123 |
|
|
| |
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 3 |
Complexity Density: 0.1 |
|
| 124 |
0 |
public void run(int increments, boolean keepRawData) throws IOException... |
| 125 |
|
{ |
| 126 |
0 |
keepRaw = keepRawData; |
| 127 |
0 |
try |
| 128 |
|
{ |
| 129 |
0 |
readPreviousData(currentFolder); |
| 130 |
0 |
BufferedReader posReader = new BufferedReader( |
| 131 |
|
new FileReader(currentFolder + "/CurrentPosition.txt")); |
| 132 |
|
|
| 133 |
0 |
String line = posReader.readLine(); |
| 134 |
0 |
posReader.close(); |
| 135 |
0 |
currentFilePosition = Integer.parseInt(line); |
| 136 |
|
} catch (Exception e) |
| 137 |
|
{ |
| 138 |
0 |
System.out.println("No previous data found"); |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
|
| 142 |
|
|
| 143 |
0 |
BufferedReader inputSTO = new BufferedReader(new FileReader(families)); |
| 144 |
0 |
BufferedReader inputHMM = new BufferedReader(new FileReader(hmms)); |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
0 |
moveLocationBy(currentFilePosition, inputHMM); |
| 149 |
0 |
moveLocationBy(currentFilePosition, inputSTO); |
| 150 |
|
|
| 151 |
0 |
int filesRead = 0; |
| 152 |
0 |
int i = 0; |
| 153 |
0 |
while (filesRead < increments) |
| 154 |
|
{ |
| 155 |
|
|
| 156 |
0 |
readStockholm(inputSTO); |
| 157 |
|
|
| 158 |
0 |
readHMM(inputHMM); |
| 159 |
|
|
| 160 |
0 |
int count = countValidResidues(); |
| 161 |
0 |
processData(count); |
| 162 |
0 |
filesRead++; |
| 163 |
|
|
| 164 |
0 |
currentFilePosition++; |
| 165 |
0 |
System.out.println(i); |
| 166 |
0 |
i++; |
| 167 |
|
} |
| 168 |
|
|
| 169 |
0 |
PrintWriter p = new PrintWriter( |
| 170 |
|
new File(currentFolder + "/CurrentPosition.txt")); |
| 171 |
0 |
p.print(currentFilePosition); |
| 172 |
0 |
p.close(); |
| 173 |
0 |
exportData(currentFolder); |
| 174 |
0 |
raw.clear(); |
| 175 |
0 |
binned.clear(); |
| 176 |
|
|
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
|
| 180 |
|
|
| 181 |
|
|
| 182 |
|
|
| 183 |
|
|
| 184 |
|
@param |
| 185 |
|
|
| 186 |
|
@throws |
| 187 |
|
|
| |
|
| 0% |
Uncovered Elements: 57 (57) |
Complexity: 11 |
Complexity Density: 0.27 |
|
| 188 |
0 |
public void runToEnd(int minCount, int maxCount, boolean keepRawData,... |
| 189 |
|
boolean forClans) |
| 190 |
|
throws IOException |
| 191 |
|
{ |
| 192 |
0 |
keepRaw = keepRawData; |
| 193 |
0 |
BufferedReader inputSTO = null; |
| 194 |
0 |
BufferedReader inputHMM = null; |
| 195 |
0 |
int size = 0; |
| 196 |
0 |
int files = 1; |
| 197 |
0 |
try |
| 198 |
|
{ |
| 199 |
0 |
if (forClans) |
| 200 |
|
{ |
| 201 |
0 |
files = 603; |
| 202 |
|
} |
| 203 |
0 |
int filesRead = 0; |
| 204 |
0 |
for (int clan = 0; clan < files; clan++) |
| 205 |
|
{ |
| 206 |
0 |
System.out.println(clan); |
| 207 |
0 |
String clanPath = ""; |
| 208 |
0 |
int numberOfFamilies = 0; |
| 209 |
0 |
if (forClans) |
| 210 |
|
{ |
| 211 |
0 |
clanPath = currentFolder + "/Clan" + clan; |
| 212 |
0 |
if (!new File(clanPath).exists()) |
| 213 |
|
{ |
| 214 |
0 |
continue; |
| 215 |
|
} |
| 216 |
0 |
BufferedReader famCountReader = new BufferedReader( |
| 217 |
|
new FileReader(clanPath + "/NumberOfFamilies.txt")); |
| 218 |
0 |
numberOfFamilies = Integer.parseInt(famCountReader.readLine()); |
| 219 |
|
} |
| 220 |
|
else |
| 221 |
|
{ |
| 222 |
0 |
numberOfFamilies = 1; |
| 223 |
|
} |
| 224 |
|
|
| 225 |
0 |
for (int fam = 0; fam < numberOfFamilies; fam++) |
| 226 |
|
{ |
| 227 |
0 |
if (forClans) |
| 228 |
|
{ |
| 229 |
0 |
families = clanPath + "/Families/Fam" + fam + ".sto"; |
| 230 |
0 |
hmms = clanPath + "/HMMs/HMM" + fam + ".hmm"; |
| 231 |
|
} |
| 232 |
|
|
| 233 |
0 |
inputSTO = new BufferedReader(new FileReader(families)); |
| 234 |
0 |
inputHMM = new BufferedReader(new FileReader(hmms)); |
| 235 |
|
|
| 236 |
|
|
| 237 |
0 |
int i = 0; |
| 238 |
0 |
boolean endReached = atEnd(inputSTO); |
| 239 |
0 |
while (!endReached) |
| 240 |
|
{ |
| 241 |
0 |
readStockholm(inputSTO); |
| 242 |
0 |
readHMM(inputHMM); |
| 243 |
|
|
| 244 |
0 |
int count = countValidResidues(); |
| 245 |
0 |
if (count >= minCount && count < maxCount) |
| 246 |
|
{ |
| 247 |
0 |
processData(count); |
| 248 |
|
} |
| 249 |
0 |
filesRead++; |
| 250 |
0 |
System.out.println(filesRead); |
| 251 |
0 |
endReached = atEnd(inputSTO); |
| 252 |
|
} |
| 253 |
|
} |
| 254 |
|
} |
| 255 |
|
} catch (Exception e) |
| 256 |
|
{ |
| 257 |
0 |
e.printStackTrace(); |
| 258 |
|
} finally |
| 259 |
|
{ |
| 260 |
0 |
exportData(currentFolder); |
| 261 |
0 |
raw.clear(); |
| 262 |
0 |
binned.clear(); |
| 263 |
|
} |
| 264 |
|
} |
| 265 |
|
|
| 266 |
|
|
| 267 |
|
|
| 268 |
|
|
| 269 |
|
@param |
| 270 |
|
@throws |
| 271 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 272 |
0 |
public void readPreviousData(String source) throws IOException... |
| 273 |
|
{ |
| 274 |
0 |
readBinned(source); |
| 275 |
0 |
if (keepRaw) |
| 276 |
|
{ |
| 277 |
0 |
readRaw(source); |
| 278 |
|
} |
| 279 |
|
} |
| 280 |
|
|
| 281 |
|
|
| 282 |
|
|
| 283 |
|
|
| 284 |
|
@param |
| 285 |
|
@throws |
| 286 |
|
|
| |
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.25 |
|
| 287 |
0 |
public void readBinned(String source) throws IOException... |
| 288 |
|
{ |
| 289 |
0 |
BufferedReader input = new BufferedReader( |
| 290 |
|
new FileReader(source + BINNED)); |
| 291 |
0 |
String line = input.readLine(); |
| 292 |
0 |
binned = new HashMap<>(); |
| 293 |
0 |
while (!("".equals(line) || line == null)) |
| 294 |
|
{ |
| 295 |
0 |
Scanner scanner = new Scanner(line); |
| 296 |
0 |
scanner.useDelimiter(","); |
| 297 |
0 |
String key = scanner.next(); |
| 298 |
0 |
String value = scanner.next(); |
| 299 |
0 |
binned.put(key, Double.valueOf(value)); |
| 300 |
0 |
scanner.close(); |
| 301 |
0 |
line = input.readLine(); |
| 302 |
|
} |
| 303 |
|
|
| 304 |
0 |
input.close(); |
| 305 |
|
} |
| 306 |
|
|
| 307 |
|
|
| 308 |
|
|
| 309 |
|
|
| 310 |
|
@param |
| 311 |
|
@throws |
| 312 |
|
|
| |
|
| 0% |
Uncovered Elements: 37 (37) |
Complexity: 7 |
Complexity Density: 0.26 |
|
| 313 |
0 |
public void readRaw(String source) throws IOException... |
| 314 |
|
{ |
| 315 |
0 |
BufferedReader input = new BufferedReader(new FileReader(source + RAW)); |
| 316 |
0 |
String line = input.readLine(); |
| 317 |
0 |
if (line == null) |
| 318 |
|
{ |
| 319 |
0 |
input.close(); |
| 320 |
0 |
return; |
| 321 |
|
} |
| 322 |
0 |
Scanner numberScanner = new Scanner(line); |
| 323 |
0 |
numberScanner.useDelimiter(","); |
| 324 |
0 |
raw = new ArrayList<>(); |
| 325 |
0 |
while (numberScanner.hasNext()) |
| 326 |
|
{ |
| 327 |
0 |
numberScanner.next(); |
| 328 |
0 |
raw.add(new ArrayList<Double>()); |
| 329 |
|
} |
| 330 |
0 |
numberScanner.close(); |
| 331 |
|
|
| 332 |
0 |
line = input.readLine(); |
| 333 |
0 |
while (!("".equals(line) || line == null)) |
| 334 |
|
{ |
| 335 |
0 |
Scanner scanner = new Scanner(line); |
| 336 |
0 |
scanner.useDelimiter(","); |
| 337 |
|
|
| 338 |
0 |
int i = 0; |
| 339 |
0 |
while (scanner.hasNext()) |
| 340 |
|
{ |
| 341 |
0 |
String value; |
| 342 |
0 |
value = scanner.next(); |
| 343 |
0 |
if (!value.equals("EMPTY")) |
| 344 |
|
{ |
| 345 |
0 |
raw.get(i).add(Double.parseDouble(value)); |
| 346 |
|
} |
| 347 |
|
else |
| 348 |
|
{ |
| 349 |
0 |
raw.get(i).add(null); |
| 350 |
|
} |
| 351 |
|
|
| 352 |
0 |
i++; |
| 353 |
|
} |
| 354 |
0 |
scanner.close(); |
| 355 |
0 |
line = input.readLine(); |
| 356 |
|
} |
| 357 |
|
|
| 358 |
0 |
input.close(); |
| 359 |
|
} |
| 360 |
|
|
| 361 |
|
|
| 362 |
|
|
| 363 |
|
|
| 364 |
|
@return |
| 365 |
|
|
| |
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
| 366 |
0 |
public int countValidResidues()... |
| 367 |
|
{ |
| 368 |
0 |
int count = 0; |
| 369 |
|
|
| 370 |
0 |
for (int width = 0; width < sequences.size(); width++) |
| 371 |
|
{ |
| 372 |
0 |
for (int length = 1; length < hmm.getLength() + 1; length++) |
| 373 |
|
{ |
| 374 |
0 |
char symbol; |
| 375 |
0 |
int alignPos; |
| 376 |
0 |
alignPos = hmm.getNodeMapPosition(length); |
| 377 |
|
|
| 378 |
0 |
symbol = sequences.get(width).getCharAt(alignPos); |
| 379 |
0 |
if (ResidueProperties.backgroundFrequencies.get("amino") |
| 380 |
|
.containsKey(symbol)) |
| 381 |
|
{ |
| 382 |
0 |
count++; |
| 383 |
|
} |
| 384 |
|
} |
| 385 |
|
} |
| 386 |
|
|
| 387 |
0 |
return count; |
| 388 |
|
} |
| 389 |
|
|
| 390 |
|
|
| 391 |
|
|
| 392 |
|
|
| 393 |
|
@param |
| 394 |
|
|
| |
|
| 0% |
Uncovered Elements: 49 (49) |
Complexity: 10 |
Complexity Density: 0.3 |
|
| 395 |
0 |
public void processData(int count)... |
| 396 |
|
{ |
| 397 |
0 |
int rawPos = 0; |
| 398 |
0 |
if (keepRaw) |
| 399 |
|
{ |
| 400 |
0 |
raw.add(new ArrayList<Double>()); |
| 401 |
0 |
rawPos = raw.size() - 1; |
| 402 |
|
} |
| 403 |
0 |
Double total = 0d; |
| 404 |
0 |
for (int width = 0; width < sequences.size(); width++) |
| 405 |
|
{ |
| 406 |
0 |
for (int length = 1; length < hmm.getLength() + 1; length++) |
| 407 |
|
{ |
| 408 |
0 |
char symbol; |
| 409 |
0 |
int alignPos; |
| 410 |
0 |
alignPos = hmm.getNodeMapPosition(length); |
| 411 |
|
|
| 412 |
0 |
symbol = sequences.get(width).getCharAt(alignPos); |
| 413 |
0 |
if (ResidueProperties.backgroundFrequencies.get("amino") |
| 414 |
|
.containsKey(symbol)) |
| 415 |
|
{ |
| 416 |
0 |
Double prob; |
| 417 |
0 |
Float bfreq; |
| 418 |
0 |
Double llr; |
| 419 |
0 |
prob = hmm.getMatchEmissionProbability(alignPos, symbol); |
| 420 |
0 |
bfreq = ResidueProperties.backgroundFrequencies.get("amino") |
| 421 |
|
.get(symbol); |
| 422 |
0 |
if (prob == 0 || bfreq == 0) |
| 423 |
|
{ |
| 424 |
0 |
System.out.println("error"); |
| 425 |
|
} |
| 426 |
0 |
llr = Math.log(prob / bfreq); |
| 427 |
0 |
if (keepRaw) |
| 428 |
|
{ |
| 429 |
0 |
raw.get(rawPos).add(llr); |
| 430 |
|
} |
| 431 |
|
|
| 432 |
0 |
String output; |
| 433 |
0 |
output = String.format("%.1f", llr); |
| 434 |
0 |
total += Double.parseDouble(output); |
| 435 |
0 |
if ("-0.0".equals(output)) |
| 436 |
|
{ |
| 437 |
0 |
output = "0.0"; |
| 438 |
|
} |
| 439 |
0 |
if (binned.containsKey(output)) |
| 440 |
|
{ |
| 441 |
0 |
double prev = binned.get(output); |
| 442 |
0 |
prev += (SCALE / count); |
| 443 |
0 |
binned.put(output, prev); |
| 444 |
|
|
| 445 |
|
} |
| 446 |
|
else |
| 447 |
|
{ |
| 448 |
0 |
binned.put(output, SCALE / count); |
| 449 |
|
} |
| 450 |
|
} |
| 451 |
|
} |
| 452 |
|
} |
| 453 |
0 |
System.out.println(total / count); |
| 454 |
|
} |
| 455 |
|
|
| 456 |
|
|
| 457 |
|
|
| 458 |
|
|
| 459 |
|
|
| 460 |
|
@param |
| 461 |
|
@throws |
| 462 |
|
|
| |
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 463 |
0 |
public void readStockholm(BufferedReader inputSTO) throws IOException... |
| 464 |
|
{ |
| 465 |
0 |
FileParse parserSTO = new FileParse(inputSTO, "", DataSourceType.FILE); |
| 466 |
0 |
StockholmFile file = new StockholmFile(parserSTO); |
| 467 |
0 |
Vector<AlignmentAnnotation> annots = file.getAnnotations(); |
| 468 |
|
|
| 469 |
0 |
for (AlignmentAnnotation annot : annots) |
| 470 |
|
{ |
| 471 |
0 |
if (annot.label.contains("Reference")) |
| 472 |
|
{ |
| 473 |
0 |
reference = annot; |
| 474 |
|
} |
| 475 |
|
} |
| 476 |
0 |
sequences = file.getSeqs(); |
| 477 |
|
} |
| 478 |
|
|
| 479 |
|
|
| 480 |
|
|
| 481 |
|
|
| 482 |
|
@param |
| 483 |
|
@throws |
| 484 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 485 |
0 |
public void readHMM(BufferedReader inputHMM) throws IOException... |
| 486 |
|
{ |
| 487 |
0 |
FileParse parserHMM = new FileParse(inputHMM, "", DataSourceType.FILE); |
| 488 |
0 |
HMMFile file = new HMMFile(parserHMM); |
| 489 |
0 |
hmm = file.getHMM(); |
| 490 |
|
|
| 491 |
|
|
| 492 |
|
} |
| 493 |
|
|
| 494 |
|
|
| 495 |
|
|
| 496 |
|
|
| 497 |
|
@param |
| 498 |
|
@throws |
| 499 |
|
|
| |
|
| 0% |
Uncovered Elements: 33 (33) |
Complexity: 6 |
Complexity Density: 0.26 |
|
| 500 |
0 |
public void exportData(String location) throws FileNotFoundException... |
| 501 |
|
{ |
| 502 |
0 |
PrintWriter writerBin = new PrintWriter(new File(location + BINNED)); |
| 503 |
0 |
for (Map.Entry<String, Double> entry : binned.entrySet()) |
| 504 |
|
{ |
| 505 |
0 |
writerBin.println(entry.getKey() + "," + entry.getValue()); |
| 506 |
|
} |
| 507 |
0 |
writerBin.close(); |
| 508 |
0 |
if (keepRaw) |
| 509 |
|
{ |
| 510 |
|
|
| 511 |
0 |
PrintWriter writerRaw = new PrintWriter(new File(location + RAW)); |
| 512 |
|
|
| 513 |
0 |
StringBuilder identifier = new StringBuilder(); |
| 514 |
|
|
| 515 |
0 |
for (int i = 1; i < raw.size() + 1; i++) |
| 516 |
|
{ |
| 517 |
0 |
identifier.append("Fam " + i + ","); |
| 518 |
|
} |
| 519 |
|
|
| 520 |
0 |
writerRaw.println(identifier); |
| 521 |
|
|
| 522 |
0 |
boolean rowIsEmpty = false; |
| 523 |
0 |
int row = 0; |
| 524 |
0 |
while (!rowIsEmpty) |
| 525 |
|
{ |
| 526 |
0 |
rowIsEmpty = true; |
| 527 |
0 |
StringBuilder string = new StringBuilder(); |
| 528 |
0 |
for (int column = 0; column < raw.size(); column++) |
| 529 |
|
{ |
| 530 |
0 |
if (raw.get(column).size() <= row) |
| 531 |
|
{ |
| 532 |
0 |
string.append("EMPTY,"); |
| 533 |
|
} |
| 534 |
|
else |
| 535 |
|
{ |
| 536 |
0 |
string.append(raw.get(column).get(row) + ","); |
| 537 |
0 |
rowIsEmpty = false; |
| 538 |
|
} |
| 539 |
|
} |
| 540 |
0 |
row++; |
| 541 |
0 |
writerRaw.println(string); |
| 542 |
|
} |
| 543 |
0 |
writerRaw.close(); |
| 544 |
|
|
| 545 |
|
} |
| 546 |
|
|
| 547 |
|
} |
| 548 |
|
|
| 549 |
|
|
| 550 |
|
|
| 551 |
|
|
| 552 |
|
@param |
| 553 |
|
@throws |
| 554 |
|
|
| |
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 555 |
0 |
public void printFam(int index) throws IOException... |
| 556 |
|
{ |
| 557 |
0 |
BufferedReader br = new BufferedReader(new FileReader(families)); |
| 558 |
|
|
| 559 |
0 |
moveLocationBy(index, br); |
| 560 |
|
|
| 561 |
0 |
String line = br.readLine(); |
| 562 |
|
|
| 563 |
0 |
while (!"//".equals(line)) |
| 564 |
|
{ |
| 565 |
0 |
System.out.println(line); |
| 566 |
0 |
line = br.readLine(); |
| 567 |
|
} |
| 568 |
0 |
System.out.println(line); |
| 569 |
0 |
br.close(); |
| 570 |
|
|
| 571 |
|
} |
| 572 |
|
|
| 573 |
|
|
| 574 |
|
|
| 575 |
|
|
| 576 |
|
@param |
| 577 |
|
@throws |
| 578 |
|
|
| |
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 579 |
0 |
public void printHMM(int index) throws IOException... |
| 580 |
|
{ |
| 581 |
0 |
BufferedReader br = new BufferedReader(new FileReader(hmms)); |
| 582 |
|
|
| 583 |
0 |
moveLocationBy(index, br); |
| 584 |
|
|
| 585 |
0 |
String line = br.readLine(); |
| 586 |
|
|
| 587 |
0 |
while (!"//".equals(line)) |
| 588 |
|
{ |
| 589 |
0 |
System.out.println(line); |
| 590 |
0 |
line = br.readLine(); |
| 591 |
|
} |
| 592 |
0 |
System.out.println(line); |
| 593 |
0 |
br.close(); |
| 594 |
|
|
| 595 |
|
} |
| 596 |
|
|
| 597 |
|
|
| 598 |
|
|
| 599 |
|
|
| 600 |
|
@param |
| 601 |
|
@throws |
| 602 |
|
|
| |
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
| 603 |
0 |
public void exportFam(int index, String location) throws IOException... |
| 604 |
|
{ |
| 605 |
0 |
BufferedReader br = new BufferedReader(new FileReader(families)); |
| 606 |
|
|
| 607 |
0 |
moveLocationBy(index, br); |
| 608 |
|
|
| 609 |
0 |
String line = br.readLine(); |
| 610 |
0 |
PrintWriter writer = new PrintWriter( |
| 611 |
|
new FileOutputStream(new File(location), true)); |
| 612 |
0 |
while (!"//".equals(line)) |
| 613 |
|
{ |
| 614 |
0 |
writer.println(line); |
| 615 |
0 |
line = br.readLine(); |
| 616 |
|
} |
| 617 |
0 |
writer.println(line); |
| 618 |
0 |
writer.close(); |
| 619 |
0 |
br.close(); |
| 620 |
|
|
| 621 |
|
} |
| 622 |
|
|
| |
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 623 |
0 |
public void exportFile(BufferedReader br, String location, boolean append)... |
| 624 |
|
throws IOException |
| 625 |
|
{ |
| 626 |
0 |
String line = br.readLine(); |
| 627 |
0 |
PrintWriter writer = new PrintWriter( |
| 628 |
|
new FileOutputStream(location, append)); |
| 629 |
0 |
while (!"//".equals(line)) |
| 630 |
|
{ |
| 631 |
0 |
writer.println(line); |
| 632 |
0 |
line = br.readLine(); |
| 633 |
|
} |
| 634 |
0 |
writer.println(line); |
| 635 |
0 |
writer.close(); |
| 636 |
|
|
| 637 |
|
|
| 638 |
|
} |
| 639 |
|
|
| |
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
| 640 |
0 |
public String getHMMName(int index) throws IOException... |
| 641 |
|
{ |
| 642 |
0 |
String name; |
| 643 |
|
|
| 644 |
0 |
BufferedReader nameFinder = new BufferedReader(new FileReader(hmms)); |
| 645 |
|
|
| 646 |
0 |
moveLocationBy(index, nameFinder); |
| 647 |
|
|
| 648 |
0 |
nameFinder.readLine(); |
| 649 |
|
|
| 650 |
0 |
Scanner scanner = new Scanner(nameFinder.readLine()); |
| 651 |
0 |
name = scanner.next(); |
| 652 |
0 |
name = scanner.next(); |
| 653 |
0 |
scanner.close(); |
| 654 |
0 |
return name; |
| 655 |
|
} |
| 656 |
|
|
| |
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
| 657 |
0 |
public String getFamilyName(int index) throws IOException... |
| 658 |
|
{ |
| 659 |
0 |
String name; |
| 660 |
|
|
| 661 |
0 |
BufferedReader nameFinder = new BufferedReader( |
| 662 |
|
new FileReader(families)); |
| 663 |
|
|
| 664 |
0 |
moveLocationBy(index, nameFinder); |
| 665 |
|
|
| 666 |
0 |
nameFinder.readLine(); |
| 667 |
|
|
| 668 |
0 |
Scanner scanner = new Scanner(nameFinder.readLine()); |
| 669 |
0 |
name = scanner.next(); |
| 670 |
0 |
name = scanner.next(); |
| 671 |
0 |
name = scanner.next(); |
| 672 |
0 |
scanner.close(); |
| 673 |
0 |
return name; |
| 674 |
|
} |
| 675 |
|
|
| 676 |
|
|
| 677 |
|
|
| 678 |
|
|
| 679 |
|
@param |
| 680 |
|
@throws |
| 681 |
|
|
| |
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
| 682 |
0 |
public void exportHMM(int index, String location) throws IOException... |
| 683 |
|
{ |
| 684 |
|
|
| 685 |
|
|
| 686 |
0 |
BufferedReader br = new BufferedReader(new FileReader(hmms)); |
| 687 |
|
|
| 688 |
0 |
moveLocationBy(index, br); |
| 689 |
|
|
| 690 |
0 |
String line = br.readLine(); |
| 691 |
|
|
| 692 |
0 |
PrintWriter writer = new PrintWriter( |
| 693 |
|
new FileOutputStream(new File(location), true)); |
| 694 |
0 |
while (!"//".equals(line)) |
| 695 |
|
{ |
| 696 |
0 |
writer.println(line); |
| 697 |
0 |
line = br.readLine(); |
| 698 |
|
} |
| 699 |
0 |
writer.println(line); |
| 700 |
0 |
writer.close(); |
| 701 |
0 |
br.close(); |
| 702 |
|
|
| 703 |
|
} |
| 704 |
|
|
| 705 |
|
|
| 706 |
|
|
| 707 |
|
|
| 708 |
|
@throws |
| 709 |
|
|
| |
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
| 710 |
0 |
public void clear() throws FileNotFoundException... |
| 711 |
|
{ |
| 712 |
0 |
PrintWriter pos = new PrintWriter( |
| 713 |
|
currentFolder + "/CurrentPosition.txt"); |
| 714 |
0 |
pos.println("0"); |
| 715 |
|
|
| 716 |
0 |
PrintWriter raw = new PrintWriter(currentFolder + RAW); |
| 717 |
|
|
| 718 |
0 |
PrintWriter bin = new PrintWriter(currentFolder + BINNED); |
| 719 |
|
|
| 720 |
0 |
pos.close(); |
| 721 |
0 |
bin.close(); |
| 722 |
0 |
raw.close(); |
| 723 |
|
} |
| 724 |
|
|
| |
|
| 0% |
Uncovered Elements: 60 (60) |
Complexity: 9 |
Complexity Density: 0.19 |
|
| 725 |
0 |
public void sortIntoClans(String directory) throws IOException... |
| 726 |
|
{ |
| 727 |
0 |
BufferedReader clanFinder = new BufferedReader(new FileReader(FAMILIESTOCLAN)); |
| 728 |
0 |
BufferedReader familyReader = new BufferedReader( |
| 729 |
|
new FileReader(families)); |
| 730 |
0 |
BufferedReader hmmReader = new BufferedReader(new FileReader(hmms)); |
| 731 |
0 |
int families = 0; |
| 732 |
|
|
| 733 |
|
|
| 734 |
|
|
| 735 |
0 |
HashMap<String, Integer> clanIndexes = new HashMap<>(); |
| 736 |
0 |
ArrayList<Integer> familyCounts = new ArrayList<>(); |
| 737 |
0 |
int filePos = 0; |
| 738 |
0 |
int clanCount = 0; |
| 739 |
0 |
String line; |
| 740 |
0 |
line = clanFinder.readLine(); |
| 741 |
|
|
| 742 |
0 |
while (!"".equals(line) && !" ".equals(line) && line != null) |
| 743 |
|
{ |
| 744 |
0 |
String clanName; |
| 745 |
0 |
boolean inClan = false; |
| 746 |
0 |
while (!(line.indexOf("//") > -1)) |
| 747 |
|
{ |
| 748 |
|
|
| 749 |
0 |
if (line.indexOf("#=GF CL") > -1) |
| 750 |
|
{ |
| 751 |
0 |
families++; |
| 752 |
0 |
System.out.println(families); |
| 753 |
0 |
inClan = true; |
| 754 |
0 |
Scanner scanner = new Scanner(line); |
| 755 |
0 |
scanner.next(); |
| 756 |
0 |
scanner.next(); |
| 757 |
0 |
clanName = scanner.next(); |
| 758 |
0 |
scanner.close(); |
| 759 |
|
|
| 760 |
0 |
if (!clanIndexes.containsKey(clanName)) |
| 761 |
|
{ |
| 762 |
0 |
clanIndexes.put(clanName, clanCount); |
| 763 |
0 |
clanCount++; |
| 764 |
0 |
familyCounts.add(0); |
| 765 |
|
} |
| 766 |
|
|
| 767 |
|
|
| 768 |
0 |
Integer clanI = clanIndexes.get(clanName); |
| 769 |
0 |
String clanPath = directory + "/Clan" + clanI.toString(); |
| 770 |
0 |
createFolders(clanPath); |
| 771 |
|
|
| 772 |
0 |
int index = clanIndexes.get(clanName); |
| 773 |
0 |
exportFile(familyReader, |
| 774 |
|
clanPath + "/Families/Fam" + familyCounts.get(index) |
| 775 |
|
+ ".sto", |
| 776 |
|
false); |
| 777 |
0 |
exportFile(hmmReader, |
| 778 |
|
clanPath + "/HMMs/HMM" + familyCounts.get(index) + ".hmm", |
| 779 |
|
false); |
| 780 |
|
|
| 781 |
0 |
int count = familyCounts.get(index); |
| 782 |
0 |
count++; |
| 783 |
0 |
familyCounts.set(index, count); |
| 784 |
|
} |
| 785 |
0 |
line = clanFinder.readLine(); |
| 786 |
|
|
| 787 |
|
} |
| 788 |
0 |
if (!inClan) |
| 789 |
|
{ |
| 790 |
0 |
moveLocationBy(1, familyReader); |
| 791 |
0 |
moveLocationBy(1, hmmReader); |
| 792 |
|
} |
| 793 |
0 |
filePos++; |
| 794 |
|
|
| 795 |
0 |
line = clanFinder.readLine(); |
| 796 |
|
|
| 797 |
|
} |
| 798 |
0 |
clanFinder.close(); |
| 799 |
|
|
| 800 |
0 |
for (int clan = 0; clan < clanCount; clan++) |
| 801 |
|
{ |
| 802 |
0 |
PrintWriter writer = new PrintWriter( |
| 803 |
|
directory + "/Clan" + clan + "/NumberOfFamilies.txt"); |
| 804 |
0 |
int count = familyCounts.get(clan); |
| 805 |
0 |
writer.print(count); |
| 806 |
0 |
writer.close(); |
| 807 |
|
} |
| 808 |
|
|
| 809 |
|
} |
| 810 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 811 |
0 |
public String getFamilies()... |
| 812 |
|
{ |
| 813 |
0 |
return families; |
| 814 |
|
} |
| 815 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 816 |
0 |
public void setFamilies(String families)... |
| 817 |
|
{ |
| 818 |
0 |
this.families = currentFolder + families; |
| 819 |
|
} |
| 820 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 821 |
0 |
public String getHmms()... |
| 822 |
|
{ |
| 823 |
0 |
return hmms; |
| 824 |
|
} |
| 825 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 826 |
0 |
public void setHmms(String hmms)... |
| 827 |
|
{ |
| 828 |
0 |
this.hmms = currentFolder + hmms; |
| 829 |
|
} |
| 830 |
|
|
| |
|
| 0% |
Uncovered Elements: 46 (46) |
Complexity: 6 |
Complexity Density: 0.17 |
|
| 831 |
0 |
public void alignWithinClan(String exportLocation, String clansLocation)... |
| 832 |
|
throws IOException, InterruptedException |
| 833 |
|
{ |
| 834 |
0 |
int alignmentsExported = 0; |
| 835 |
0 |
for (int clan = 0; clan < 604; clan++) |
| 836 |
|
{ |
| 837 |
0 |
System.out.println(clan); |
| 838 |
0 |
int famCount = 0; |
| 839 |
0 |
String clanPath = clansLocation + "/Clan" + clan; |
| 840 |
0 |
int numberOfFamilies; |
| 841 |
0 |
BufferedReader br = new BufferedReader( |
| 842 |
|
new FileReader(clanPath + "/NumberOfFamilies.txt")); |
| 843 |
0 |
String line = br.readLine(); |
| 844 |
0 |
numberOfFamilies = Integer.parseInt(line); |
| 845 |
0 |
br.close(); |
| 846 |
0 |
if (numberOfFamilies == 1) |
| 847 |
|
{ |
| 848 |
0 |
continue; |
| 849 |
|
} |
| 850 |
0 |
final String commandExportLocation = exportLocation + "/Clan" + clan; |
| 851 |
0 |
createFolders(commandExportLocation); |
| 852 |
0 |
for (int family = 0; family < numberOfFamilies; family++) |
| 853 |
|
{ |
| 854 |
0 |
famCount++; |
| 855 |
0 |
ArrayList<Integer> indexes = new ArrayList<>(); |
| 856 |
0 |
for (int i = 0; i < numberOfFamilies; i++) |
| 857 |
|
{ |
| 858 |
0 |
if (i != family) |
| 859 |
|
{ |
| 860 |
0 |
indexes.add(i); |
| 861 |
|
} |
| 862 |
|
} |
| 863 |
|
|
| 864 |
0 |
int hmmIndex = getRandom(indexes); |
| 865 |
0 |
String famPath = clanPath + "/Families/Fam" + family + ".sto"; |
| 866 |
0 |
String hmmPath = clanPath + "/HMMs/HMM" + hmmIndex + ".hmm"; |
| 867 |
0 |
String command = "/media/sf_Shared_Folder/hmmer/binaries/hmmalign --mapali " |
| 868 |
|
+ clanPath + "/Families/Fam" + hmmIndex + ".sto" |
| 869 |
|
+ " --trim "; |
| 870 |
0 |
command += hmmPath + " "; |
| 871 |
0 |
command += famPath; |
| 872 |
0 |
final int familyIndex = family; |
| 873 |
0 |
final Process p = Runtime.getRuntime().exec(command); |
| 874 |
|
|
| 875 |
0 |
new Thread(new Runnable() |
| 876 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 10 |
Complexity Density: 0.67 |
|
| 877 |
0 |
@Override... |
| 878 |
|
public void run() |
| 879 |
|
{ |
| 880 |
0 |
BufferedReader input = new BufferedReader( |
| 881 |
|
new InputStreamReader(p.getInputStream())); |
| 882 |
0 |
String line = null; |
| 883 |
|
|
| 884 |
0 |
try |
| 885 |
|
{ |
| 886 |
0 |
PrintWriter writer = new PrintWriter(commandExportLocation |
| 887 |
|
+ "/Families/Fam" + familyIndex + ".sto"); |
| 888 |
0 |
String lastLine = ""; |
| 889 |
0 |
boolean dataFound = false; |
| 890 |
0 |
while ((line = input.readLine()) != null) |
| 891 |
|
{ |
| 892 |
0 |
if (line.contains("#=GR") && !dataFound) |
| 893 |
|
{ |
| 894 |
0 |
writer.println(lastLine); |
| 895 |
0 |
dataFound = true; |
| 896 |
|
} |
| 897 |
0 |
if (line.contains("#") || dataFound || " ".equals(line) |
| 898 |
|
|| "".equals(line) || "//".equals(line)) |
| 899 |
|
{ |
| 900 |
0 |
writer.println(line); |
| 901 |
|
} |
| 902 |
0 |
lastLine = line; |
| 903 |
|
} |
| 904 |
0 |
writer.close(); |
| 905 |
|
} catch (IOException e) |
| 906 |
|
{ |
| 907 |
0 |
e.printStackTrace(); |
| 908 |
|
} |
| 909 |
|
} |
| 910 |
|
}).start(); |
| 911 |
|
|
| 912 |
0 |
p.waitFor(); |
| 913 |
|
|
| 914 |
0 |
BufferedReader hmmExporter = new BufferedReader( |
| 915 |
|
new FileReader(hmmPath)); |
| 916 |
|
|
| 917 |
0 |
exportFile(hmmExporter, |
| 918 |
|
commandExportLocation + "/HMMs/HMM" + family + ".hmm", |
| 919 |
|
false); |
| 920 |
|
|
| 921 |
0 |
alignmentsExported++; |
| 922 |
|
|
| 923 |
|
|
| 924 |
|
} |
| 925 |
0 |
PrintWriter writer = new PrintWriter( |
| 926 |
|
commandExportLocation + "/NumberOfFamilies.txt"); |
| 927 |
0 |
writer.print(famCount); |
| 928 |
0 |
writer.close(); |
| 929 |
|
} |
| 930 |
|
|
| 931 |
|
} |
| 932 |
|
|
| |
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 933 |
0 |
public boolean atEnd(BufferedReader br) throws IOException... |
| 934 |
|
{ |
| 935 |
0 |
boolean end = false; |
| 936 |
0 |
br.mark(80); |
| 937 |
0 |
String line = br.readLine(); |
| 938 |
0 |
if ("".equals(line) || line == null) |
| 939 |
|
{ |
| 940 |
0 |
end = true; |
| 941 |
|
} |
| 942 |
0 |
br.reset(); |
| 943 |
0 |
return end; |
| 944 |
|
} |
| 945 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 946 |
0 |
public int getRandom(ArrayList<Integer> list)... |
| 947 |
|
{ |
| 948 |
0 |
if (!(list.size() > 0)) |
| 949 |
|
{ |
| 950 |
0 |
System.out.println("Error - size = " + list.size()); |
| 951 |
|
} |
| 952 |
0 |
int index = generator.nextInt(list.size()); |
| 953 |
0 |
int value = list.get(index); |
| 954 |
0 |
list.remove(index); |
| 955 |
0 |
return value; |
| 956 |
|
} |
| 957 |
|
|
| |
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 958 |
0 |
public void createFolders(String clanPath)... |
| 959 |
|
{ |
| 960 |
0 |
File clanFolder = new File(clanPath); |
| 961 |
0 |
if (!clanFolder.exists()) |
| 962 |
|
{ |
| 963 |
0 |
clanFolder.mkdir(); |
| 964 |
|
} |
| 965 |
|
|
| 966 |
0 |
File famFolder = new File(clanPath + "/Families"); |
| 967 |
0 |
File hmmFolder = new File(clanPath + "/HMMs"); |
| 968 |
0 |
if (!famFolder.exists()) |
| 969 |
|
{ |
| 970 |
0 |
famFolder.mkdir(); |
| 971 |
0 |
hmmFolder.mkdir(); |
| 972 |
|
} |
| 973 |
|
} |
| 974 |
|
} |
| 975 |
|
|
| 976 |
|
|
| 977 |
|
|
| 978 |
|
|