Esempio n. 1
0
  /**
   * Perform a stabbing query on the node
   *
   * @param point the time to query at
   * @return all intervals containing time
   */
  public Markers stab(Integer point) {
    Markers result = new Markers();

    for (Entry<Marker, List<Marker>> entry : intervals.entrySet()) {
      if (entry.getKey().intersects(point)) { //
        for (Marker interval : entry.getValue()) result.add(interval);
      } else if (entry.getKey().getStart() > point) break;
    }

    if (point < center && leftNode != null) result.add(leftNode.stab(point));
    else if (point > center && rightNode != null) result.add(rightNode.stab(point));
    return result;
  }
Esempio n. 2
0
  /**
   * Perform an interval intersection query on the node
   *
   * @param target: the interval to intersect
   * @return all intervals containing 'target'
   */
  public Markers query(Interval target) {
    Markers result = new Markers();

    for (Entry<Marker, List<Marker>> entry : intervals.entrySet()) {
      if (entry.getKey().intersects(target)) {
        for (Marker interval : entry.getValue()) result.add(interval);
      } else if (entry.getKey().getStart() > target.getEnd()) break;
    }

    if (target.getStart() < center && leftNode != null) result.add(leftNode.query(target));
    if (target.getEnd() > center && rightNode != null) result.add(rightNode.query(target));
    return result;
  }
Esempio n. 3
0
  /**
   * Query index to find all VCF entries intersecting 'marker', starting from node 'idx' Store VCF
   * entries in 'results'
   */
  protected void query(Interval queryMarker, int idx, Markers results) {
    // Negative index? Nothing to do
    if (idx < 0) return;

    if (debug)
      Gpr.debug("Node: " + toString(idx) + (results.isEmpty() ? "" : "\n\tResults: " + results));

    // Check all intervals intersecting
    queryIntersects(queryMarker, idx, results);

    // Recurse left or right
    int midPos = mid[idx];
    if ((queryMarker.getEnd() < midPos) && (left[idx] >= 0)) {
      query(queryMarker, left[idx], results);
    }

    if ((midPos < queryMarker.getStart()) && (right[idx] >= 0)) {
      query(queryMarker, right[idx], results);
    }
  }
Esempio n. 4
0
  /** Query VCF entries intersecting 'marker' at node 'idx' */
  protected void queryIntersects(Interval queryMarker, int idx, Markers results) {
    if (intersectFilePosStart[idx] == null) return;
    if (debug) Gpr.debug("queryIntersects\tidx: " + idx);

    // Read entries from disk
    List<VcfEntry> vcfEntries = readEntries(idx);

    // Find matching entries
    for (VcfEntry ve : vcfEntries) {
      // If any variant within the vcfEntry intersects the query
      // marker, we store this VCF entry as a result
      for (Variant var : ve.variants()) {
        if (var.intersects(queryMarker)) {
          if (debug) Gpr.debug("\tAdding matching result: " + ve);
          results.add(ve);
          break; // Store this entry only once
        }
      }

      // Past query's end coordinate? We don't need to look any further
      if (queryMarker.getEnd() < ve.getStart()) return;
    }
  }
Esempio n. 5
0
  public IntervalNodeOri(Markers markers) {
    intervals = new TreeMap<Marker, List<Marker>>();

    SortedSet<Integer> endpoints = new TreeSet<Integer>();

    for (Interval interval : markers) {
      endpoints.add(interval.getStart());
      endpoints.add(interval.getEnd());
    }

    if (endpoints.isEmpty()) {
      center = 0;
      return;
    }

    int median = getMedian(endpoints);
    center = median;

    Markers left = new Markers();
    Markers right = new Markers();

    for (Marker interval : markers) {
      if (interval.getEnd() < median) left.add(interval);
      else if (interval.getStart() > median) right.add(interval);
      else {
        List<Marker> posting = intervals.get(interval);
        if (posting == null) {
          posting = new ArrayList<Marker>();
          intervals.put(interval, posting);
        }
        posting.add(interval);
      }
    }

    if (left.size() > 0) leftNode = new IntervalNodeOri(left);
    if (right.size() > 0) rightNode = new IntervalNodeOri(right);
  }