コード例 #1
0
def test_union_of_overlapping():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    second = IntervalSet((i.open(8, 21), i.closed(22, 23)))
    expected = IntervalSet((i.open(1, 5), i.closedopen(7,
                                                       21), i.closed(22, 23)))
    result = first.union(second)
    assert result == expected
コード例 #2
0
def test_union_of_disjoint():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    second = IntervalSet((i.open(12, 21), i.closed(22, 23)))
    expected = IntervalSet(
        (i.open(1, 5), i.closed(7, 10), i.open(12, 21), i.closed(22, 23)))
    result = first.union(second)
    assert result == expected
コード例 #3
0
def test_overlaps_corner_case_closed():
    one = i.closed(1, 5)
    two = i.closed(5, 10)
    assert one.overlaps(two)
    assert two.overlaps(one)
    assert one.overlaps(one)
    assert two.overlaps(two)
コード例 #4
0
ファイル: test_interval.py プロジェクト: intiocean/pyinter
def test_subtract_empty_types():
    left = i.closed(datetime(2015, 1, 1), datetime(2020, 1, 1))
    right = i.closed(datetime(2010, 1, 1), datetime(2100, 1, 1))
    result = left - right
    assert result.empty()
    assert isinstance(result.lower_value, datetime)
    assert isinstance(result.upper_value, datetime)
コード例 #5
0
ファイル: test_interval.py プロジェクト: isabella232/pyinter
def test_subtract_empty_types():
    left = i.closed(datetime(2015, 1, 1), datetime(2020, 1, 1))
    right = i.closed(datetime(2010, 1, 1), datetime(2100, 1, 1))
    result = left - right
    assert result.empty()
    assert isinstance(result.lower_value, datetime)
    assert isinstance(result.upper_value, datetime)
コード例 #6
0
def test_overlaps_corner_case_closed():
    one = i.closed(1, 5)
    two = i.closed(5, 10)
    assert one.overlaps(two)
    assert two.overlaps(one)
    assert one.overlaps(one)
    assert two.overlaps(two)
    
コード例 #7
0
def test_values_in():
    one = i.open(1, 5)
    two = i.closed(7, 10)
    ivset = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    assert 1 not in ivset
    assert 1.00000001 in ivset
    assert 3 in ivset
    assert 7 in ivset
    assert 8 in ivset
    assert 10.0001 not in ivset
    assert one in ivset
    assert two in ivset
コード例 #8
0
ファイル: test_interval_set.py プロジェクト: dimonb/pyinter
def test_values_in():
    one = i.open(1, 5)
    two = i.closed(7, 10)
    ivset = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    assert 1 not in ivset
    assert 1.00000001 in ivset
    assert 3 in ivset
    assert 7 in ivset
    assert 8 in ivset
    assert 10.0001 not in ivset
    assert one in ivset
    assert two in ivset
コード例 #9
0
def test_contains():
    small = i.closed(1, 5)
    medium = i.closedopen(3, 10)
    assert small.lower_value in small
    assert small._upper_value in small
    assert medium.lower_value in medium
    assert medium._upper_value not in medium
コード例 #10
0
def test_contains():
    small = i.closed(1, 5)
    medium = i.closedopen(3, 10)
    assert small.lower_value in small
    assert small._upper_value in small
    assert medium.lower_value in medium
    assert medium._upper_value not in medium
コード例 #11
0
ファイル: test_interval.py プロジェクト: pombredanne/pyinter
def test_complement_closed():
    unit = i.closed(0, 1)
    complement = unit.complement()
    (lower_interval,
     upper_interval) = sorted(complement)  # an IntervalSet is not sorted
    assert lower_interval == i.open(i.NEGATIVE_INFINITY, 0)
    assert upper_interval == i.open(1, i.INFINITY)
コード例 #12
0
def test_non_equality():
    small, medium = get_intervals()[:2]
    assert small != medium
    assert small != i.openclosed(1, 5)
    assert small != i.closedopen(1, 5)
    assert small != i.closed(1, 5)
    assert small != i.Interval(i.Interval.OPEN, 1, 7, i.Interval.OPEN)
    assert small != i.open(100, 288)
コード例 #13
0
def test_non_equality():
    small, medium = get_intervals()[:2]
    assert small != medium
    assert small != i.openclosed(1,5)
    assert small != i.closedopen(1,5)
    assert small != i.closed(1,5)
    assert small != i.Interval(i.Interval.OPEN, 1, 7, i.Interval.OPEN)
    assert small != i.open(100, 288)
コード例 #14
0
def test_complement():
    one = i.open(3, 6)
    two = i.open(7, 10)
    intervals = IntervalSet([one, two])
    complement = intervals.complement()
    (lower, middle, upper) = sorted(complement)  # an IntervalSet is not sorted

    assert lower == i.openclosed(i.NEGATIVE_INFINITY, 3)
    assert middle == i.closed(6, 7)
    assert upper == i.closedopen(10, i.INFINITY)
コード例 #15
0
def test_closed_interval_construction_using_helper():
    expected_lower = i.Interval.CLOSED
    expectedlower_value = 10
    expected_upper_value = 100
    expected_upper = i.Interval.CLOSED
    result = i.closed(10, 100)
    assert result.lower == expected_lower
    assert result.lower_value == expectedlower_value
    assert result.upper_value == expected_upper_value
    assert result.upper == expected_upper
コード例 #16
0
ファイル: test_interval_set.py プロジェクト: Shopify/pyinter
def test_complement():
    one = i.open(3, 6)
    two = i.open(7, 10)
    intervals = IntervalSet([one, two])
    complement = intervals.complement()
    (lower, middle, upper) = sorted(complement)  # an IntervalSet is not sorted

    assert lower == i.openclosed(i.NEGATIVE_INFINITY, 3)
    assert middle == i.closed(6, 7)
    assert upper == i.closedopen(10, i.INFINITY)
コード例 #17
0
def test_closed_interval_construction_using_helper():
    expected_lower = i.Interval.CLOSED
    expectedlower_value = 10
    expected_upper_value = 100
    expected_upper = i.Interval.CLOSED
    result = i.closed(10, 100)
    assert result._lower == expected_lower
    assert result.lower_value == expectedlower_value
    assert result._upper_value == expected_upper_value
    assert result._upper == expected_upper
コード例 #18
0
ファイル: test_interval.py プロジェクト: isabella232/pyinter
def test_overlaps_empty():
    assert not i.open(0, 0).overlaps(i.closed(1, 20))
    assert not i.open(1, 1).overlaps(i.closed(1, 20))
    assert not i.open(2, 2).overlaps(i.closed(1, 20))
    assert not i.closed(1, 20).overlaps(i.open(0, 0))
    assert not i.closed(1, 20).overlaps(i.open(1, 1))
    assert not i.closed(1, 20).overlaps(i.open(2, 2))
コード例 #19
0
ファイル: test_interval.py プロジェクト: intiocean/pyinter
def test_overlaps_empty():
    assert not i.open(0, 0).overlaps(i.closed(1, 20))
    assert not i.open(1, 1).overlaps(i.closed(1, 20))
    assert not i.open(2, 2).overlaps(i.closed(1, 20))
    assert not i.closed(1, 20).overlaps(i.open(0, 0))
    assert not i.closed(1, 20).overlaps(i.open(1, 1))
    assert not i.closed(1, 20).overlaps(i.open(2, 2))
コード例 #20
0
    for line in sys.stdin:
        line = line.strip()
        if line:
            ss = line.split()
            exonStart = ss[1].strip(',').split(',')
            exonEnd = ss[2].strip(',').split(',')

            name = ss[0] + ss[3]
            if name not in dataMap:
                dataMap[name] = (ss[0], ss[3], interval_set.IntervalSet())

            for s, e in zip(exonStart, exonEnd):
                s = int(s) -1 - padding # bed file 0 based.
                if s < 0:
                    s = 0
                e = int(e) + padding # end not include, therefore do not need -1.
                dataMap[name][2].add(interval.closed(s, e)) #auto aggregate overlap.

    #output results.
    for _,v in dataMap.items():
        index = 0
        for i in v[2]:
            index += 1
            sys.stdout.write('%s\t%d\t%d\t%s+%d\n'%(v[0], i.lower_value, i.upper_value, v[1], index))

sys.stdout.flush()
sys.stdout.close()
sys.stderr.flush()
sys.stderr.close()
コード例 #21
0
def test_intersection_of_almost_overlapping():
    first = IntervalSet((i.open(1, 5), i.closedopen(7, 10)))
    second = IntervalSet((i.open(1, 5), i.closed(7, 23)))
    expected = IntervalSet((i.open(1, 5), i.closedopen(7, 10)))
    result = first.intersection(second)
    assert result == expected
コード例 #22
0
ファイル: test_interval.py プロジェクト: intiocean/pyinter
def test_interval_copy():
    assert i.open(1, 4).copy() == i.open(1, 4)
    assert i.openclosed(1, 4).copy() == i.openclosed(1, 4)
    assert i.closedopen(1, 4).copy() == i.closedopen(1, 4)
    assert i.closed(1, 4).copy() == i.closed(1, 4)
コード例 #23
0
ファイル: test_interval.py プロジェクト: intiocean/pyinter
def test_overlaps_touching():
    assert not i.openclosed(1, 4).overlaps(i.openclosed(4, 5))
    assert not i.closedopen(1, 4).overlaps(i.closedopen(4, 5))
    assert not i.open(1, 4).overlaps(i.open(4, 5))
    assert i.closed(1, 4).overlaps(i.closed(4, 5))
コード例 #24
0
ファイル: test_interval.py プロジェクト: intiocean/pyinter
def test_complement_closed():
    unit = i.closed(0, 1)
    complement = unit.complement()
    (lower_interval, upper_interval) = sorted(complement)  # an IntervalSet is not sorted
    assert lower_interval == i.open(i.NEGATIVE_INFINITY, 0)
    assert upper_interval == i.open(1, i.INFINITY)
コード例 #25
0
ファイル: test_interval.py プロジェクト: intiocean/pyinter
def test_subtract_almost_complete_overlap():
    left = i.closed(1, 2)
    right = i.open(1, 5)
    expected = i.closed(1, 1)
    assert left - right == expected
コード例 #26
0
ファイル: test_interval.py プロジェクト: intiocean/pyinter
def test_subtract_exact_overlap():
    left = i.closed(1, 2)
    right = i.closed(1, 2)
    assert (left - right).empty()
コード例 #27
0
ファイル: test_interval_set.py プロジェクト: dimonb/pyinter
def test_union_of_disjoint():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    second = IntervalSet((i.open(12, 21), i.closed(22,23)))
    expected = IntervalSet((i.open(1, 5), i.closed(7, 10), i.open(12, 21), i.closed(22, 23)))
    result = first.union(second)
    assert result == expected
コード例 #28
0
ファイル: test_interval_set.py プロジェクト: dimonb/pyinter
def test_intersection_of_almost_overlapping():
    first = IntervalSet((i.open(1, 5), i.closedopen(7, 10)))
    second = IntervalSet((i.open(1, 5), i.closed(7,23)))
    expected = IntervalSet((i.open(1, 5), i.closedopen(7, 10)))
    result = first.intersection(second)
    assert result == expected
コード例 #29
0
def test_equality_of_not_equal():
    one = IntervalSet([i.open(1, 10)])
    two = IntervalSet([i.closed(1, 10)])
    assert one != two
コード例 #30
0
ファイル: test_interval.py プロジェクト: isabella232/pyinter
def test_subtract_exact_overlap():
    left = i.closed(1, 2)
    right = i.closed(1, 2)
    assert (left - right).empty()
コード例 #31
0
def test_contains_self_closed_open():
    small = i.closedopen(1, 5)
    medium = i.closed(7, 10)
    assert small in small
    assert small not in medium
    assert medium not in small
コード例 #32
0
def test_contains_fully_overlapping():
    small = i.closed(7, 10)
    medium = i.closedopen(7, 21)
    assert small in medium
コード例 #33
0
def test_intersection_of_equal():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    result = first.intersection(first)
    assert result == first
コード例 #34
0
ファイル: test_interval_set.py プロジェクト: Shopify/pyinter
def test_initialising_with_generator_does_not_consume_generator_before_storing_items():
    generator = (el for el in (i.open(1, 5), i.closed(7, 10)))
    assert len(IntervalSet(generator)) == 2
コード例 #35
0
def test_len_works_as_expected():
    assert len(IntervalSet((i.open(1, 5), i.closed(7, 10)))) == 2
コード例 #36
0
def test_contains_fully_overlapping():
    small = i.closed(7, 10)
    medium = i.closedopen(7, 21)
    assert small in medium
コード例 #37
0
def test_contains_self_closed_open():
    small = i.closedopen(1, 5)
    medium = i.closed(7, 10)
    assert small in small
    assert small not in medium
    assert medium not in small
コード例 #38
0
ファイル: test_interval_set.py プロジェクト: dimonb/pyinter
def test_length_of_unioned():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    second = IntervalSet((i.open(8, 21), i.closed(22,23)))
    # This is of length 3 as 2 of the intervals overlap and therefore join together
    assert len(first.union(second)) == 3
コード例 #39
0
ファイル: test_interval.py プロジェクト: intiocean/pyinter
def test_subtract_complete_overlap_returns_an_empty_interval():
    left = i.closed(1, 2)
    right = i.closed(1, 2)
    assert (left - right).empty()
コード例 #40
0
def test_initialising_with_generator_does_not_consume_generator_before_storing_items(
):
    generator = (el for el in (i.open(1, 5), i.closed(7, 10)))
    assert len(IntervalSet(generator)) == 2
コード例 #41
0
ファイル: test_interval.py プロジェクト: intiocean/pyinter
def test_repr():
    assert repr(i.open(1, 2)) == '(1, 2)'
    assert repr(i.openclosed(1, 2)) == '(1, 2]'
    assert repr(i.closed(1, 2)) == '[1, 2]'
    assert repr(i.closedopen(1, 2)) == '[1, 2)'
コード例 #42
0
            ss = line.split()
            exonStart = ss[1].strip(',').split(',')
            exonEnd = ss[2].strip(',').split(',')

            name = ss[0] + ss[3]
            if name not in dataMap:
                dataMap[name] = (ss[0], ss[3], interval_set.IntervalSet())

            for s, e in zip(exonStart, exonEnd):
                s = int(s) - 1 - padding  # bed file 0 based.
                if s < 0:
                    s = 0
                e = int(
                    e) + padding  # end not include, therefore do not need -1.
                #automatic merge overlapped interval.
                dataMap[name][2].add(interval.closed(
                    s, e))  #auto aggregate overlap.

    #output results.
    for _, v in dataMap.items():
        index = 0
        for i in v[2]:
            index += 1
            sys.stdout.write('%s\t%d\t%d\t%s+%d\n' %
                             (v[0], i.lower_value, i.upper_value, v[1], index))

sys.stdout.flush()
sys.stdout.close()
sys.stderr.flush()
sys.stderr.close()
コード例 #43
0
def test_length_of_unioned():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    second = IntervalSet((i.open(8, 21), i.closed(22, 23)))
    # This is of length 3 as 2 of the intervals overlap and therefore join together
    assert len(first.union(second)) == 3
コード例 #44
0
ファイル: test_interval.py プロジェクト: pombredanne/pyinter
def test_repr():
    assert repr(i.open(1, 2)) == '(1, 2)'
    assert repr(i.openclosed(1, 2)) == '(1, 2]'
    assert repr(i.closed(1, 2)) == '[1, 2]'
    assert repr(i.closedopen(1, 2)) == '[1, 2)'
コード例 #45
0
ファイル: test_interval_set.py プロジェクト: dimonb/pyinter
def test_len_works_as_expected():
    assert len(IntervalSet((i.open(1, 5), i.closed(7, 10)))) == 2
コード例 #46
0
def test_intersection_of_disjoint_is_empty():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    second = IntervalSet((i.open(20, 21), i.closed(22, 23)))
    expected = IntervalSet()
    result = first.intersection(second)
    assert result == expected
コード例 #47
0
ファイル: test_interval_set.py プロジェクト: dimonb/pyinter
def test_equality_of_not_equal():
    one = IntervalSet([i.open(1, 10)])
    two = IntervalSet([i.closed(1, 10)])
    assert one != two
コード例 #48
0
ファイル: test_interval.py プロジェクト: isabella232/pyinter
def test_interval_copy():
    assert i.open(1, 4).copy() == i.open(1, 4)
    assert i.openclosed(1, 4).copy() == i.openclosed(1, 4)
    assert i.closedopen(1, 4).copy() == i.closedopen(1, 4)
    assert i.closed(1, 4).copy() == i.closed(1, 4)
コード例 #49
0
ファイル: test_interval_set.py プロジェクト: dimonb/pyinter
def test_intersection_of_disjoint_is_empty():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    second = IntervalSet((i.open(20,21), i.closed(22,23)))
    expected = IntervalSet()
    result = first.intersection(second)
    assert result == expected
コード例 #50
0
ファイル: test_interval.py プロジェクト: isabella232/pyinter
def test_subtract_almost_complete_overlap():
    left = i.closed(1, 2)
    right = i.open(1, 5)
    expected = i.closed(1, 1)
    assert left - right == expected
コード例 #51
0
ファイル: test_interval_set.py プロジェクト: dimonb/pyinter
def test_union_of_overlapping():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    second = IntervalSet((i.open(8, 21), i.closed(22,23)))
    expected = IntervalSet((i.open(1, 5), i.closedopen(7, 21), i.closed(22, 23)))
    result = first.union(second)
    assert result == expected
コード例 #52
0
ファイル: test_interval.py プロジェクト: isabella232/pyinter
def test_subtract_complete_overlap_returns_an_empty_interval():
    left = i.closed(1, 2)
    right = i.closed(1, 2)
    assert (left - right).empty()
コード例 #53
0
ファイル: test_interval_set.py プロジェクト: dimonb/pyinter
def test_union_of_equal():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    result = first.union(first)
    assert result == first
コード例 #54
0
ファイル: test_interval.py プロジェクト: isabella232/pyinter
def test_overlaps_touching():
    assert not i.openclosed(1, 4).overlaps(i.openclosed(4, 5))
    assert not i.closedopen(1, 4).overlaps(i.closedopen(4, 5))
    assert not i.open(1, 4).overlaps(i.open(4, 5))
    assert i.closed(1, 4).overlaps(i.closed(4, 5))