@param pafPath input PAF file @param targets set of target names @param tolerance minimum extension required for bridging partners @return map of targets and their read counts @throws IOException
(String pafPath, Set<String> targets, int tolerance)
| 385 | * @throws IOException |
| 386 | */ |
| 387 | public static HashMap<String, Float> getReadCounts(String pafPath, Set<String> targets, int tolerance) throws IOException { |
| 388 | HashMap<String, Float> counts = new HashMap<>(targets.size()); |
| 389 | |
| 390 | PafReader reader = new PafReader(pafPath); |
| 391 | |
| 392 | String prevName = null; |
| 393 | int largestOverlapSize = 0; |
| 394 | Interval largestOverlap = null; |
| 395 | String bestTarget = null; |
| 396 | HashMap<String, Interval> targetNameQueryIntervalMap = new HashMap<>(); |
| 397 | for (PafRecord r = new PafRecord(); reader.hasNext();) { |
| 398 | reader.next(r); |
| 399 | |
| 400 | if (targets.contains(r.tName)) { |
| 401 | if (!r.qName.equals(prevName)) { |
| 402 | if (prevName != null) { |
| 403 | float increment = 1f; |
| 404 | targetNameQueryIntervalMap.remove(bestTarget); |
| 405 | |
| 406 | String partner = getBestPartner(targetNameQueryIntervalMap, largestOverlap, tolerance); |
| 407 | if (partner != null) { |
| 408 | increment = 0.5f; |
| 409 | |
| 410 | // TODO: Store number of reads bridging two targets |
| 411 | if (counts.containsKey(partner)) { |
| 412 | float c = counts.get(partner); |
| 413 | counts.put(partner, c + increment); |
| 414 | } |
| 415 | else { |
| 416 | counts.put(partner, increment); |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | if (counts.containsKey(bestTarget)) { |
| 421 | float c = counts.get(bestTarget); |
| 422 | counts.put(bestTarget, c + increment); |
| 423 | } |
| 424 | else { |
| 425 | counts.put(bestTarget, increment); |
| 426 | } |
| 427 | |
| 428 | targetNameQueryIntervalMap.clear(); |
| 429 | } |
| 430 | |
| 431 | prevName = r.qName; |
| 432 | largestOverlapSize = 0; |
| 433 | bestTarget = null; |
| 434 | } |
| 435 | |
| 436 | Interval i = new Interval(r.qStart, r.qEnd); |
| 437 | targetNameQueryIntervalMap.put(r.tName, i); |
| 438 | |
| 439 | int overlapSize = r.qEnd - r.qStart; |
| 440 | if (overlapSize > largestOverlapSize) { |
| 441 | largestOverlapSize = overlapSize; |
| 442 | bestTarget = r.tName; |
| 443 | largestOverlap = i; |
| 444 | } |