Example usage for com.google.common.collect TreeRangeMap subRangeMap

List of usage examples for com.google.common.collect TreeRangeMap subRangeMap

Introduction

In this page you can find the example usage for com.google.common.collect TreeRangeMap subRangeMap.

Prototype

@Override
    public RangeMap<K, V> subRangeMap(Range<K> subRange) 

Source Link

Usage

From source file:org.mskcc.juber.intervals.IntervalNameMap.java

public List<String> getIntersecting(String contig, int start, int end) {
    List<String> nameList = new ArrayList<String>();
    Range<Integer> range = Range.closed(start, end);

    // get the contig-specific list of range maps
    List<TreeRangeMap<Integer, String>> contigRanges = contigIntervals.get(contig);

    if (contigRanges == null) {
        return nameList;
    }/*from   w  w  w.  java2 s .co  m*/

    // check each map in the list for intersection
    for (int i = 0; i < contigRanges.size(); i++) {
        TreeRangeMap<Integer, String> map = contigRanges.get(i);
        Map<Range<Integer>, String> intersecting = map.subRangeMap(range).asMapOfRanges();

        // add all intersecting ranges from the current map to the return
        // list
        for (Range<Integer> key : intersecting.keySet()) {
            nameList.add(intersecting.get(key));
        }
    }

    return nameList;
}

From source file:org.mskcc.juber.intervals.IntervalNameMap.java

private void add(List<TreeRangeMap<Integer, String>> contigRanges, Range<Integer> range, String name) {
    TreeRangeMap<Integer, String> map = null;

    // find the first tree range map that has no range conflicting
    // with the given range
    // this is because Guava range maps don't accommodate intersecting
    // ranges/* ww  w .  j av  a 2 s  .  c om*/
    int index = 0;
    for (; index < contigRanges.size(); index++) {
        map = contigRanges.get(index);
        if (map.subRangeMap(range).asMapOfRanges().size() == 0) {
            break;
        }
    }

    // did not break, requires adding new map
    if (index == contigRanges.size()) {
        map = TreeRangeMap.create();
        contigRanges.add(map);
    }

    // add the current range to the selected map
    map.put(range, name);
}