当前位置: 首页>>代码示例>>Python>>正文


Python intervaltree.Interval方法代码示例

本文整理汇总了Python中intervaltree.Interval方法的典型用法代码示例。如果您正苦于以下问题:Python intervaltree.Interval方法的具体用法?Python intervaltree.Interval怎么用?Python intervaltree.Interval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在intervaltree的用法示例。


在下文中一共展示了intervaltree.Interval方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: intervalListToIntervalTree

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import Interval [as 别名]
def intervalListToIntervalTree(interval_list):
    r"""
    given a dictionary containing tuples of chrom, start, end,
    this is transformed to an interval trees. To each
    interval an id is assigned, this id corresponds to the
    position of the interval in the given array of tuples
    and if needed can be used to identify
    the index of a row/colum in the hic matrix.

    >>> bin_list = [('chrX', 0, 50000), ('chrX', 50000, 100000)]
    >>> res = intervalListToIntervalTree(bin_list)
    >>> sorted(res['chrX'])
    [Interval(0, 50000, 0), Interval(50000, 100000, 1)]
    """
    bin_int_tree = {}

    for intval_id, intval in enumerate(interval_list):
        chrom, start, end = intval[0:3]
        if chrom not in bin_int_tree:
            bin_int_tree[chrom] = IntervalTree()
        bin_int_tree[chrom].add(Interval(start, end, intval_id))

    return bin_int_tree 
开发者ID:deeptools,项目名称:HiCExplorer,代码行数:25,代码来源:hicBuildMatrix.py

示例2: test_str

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import Interval [as 别名]
def test_str():
    iv = Interval(0, 1)
    s = str(iv)
    assert s == 'Interval(0, 1)'
    assert repr(iv) == s

    iv = Interval(0, 1, '[0,1)')
    s = str(iv)
    assert s == "Interval(0, 1, '[0,1)')"
    assert repr(iv) == s

    iv = Interval((1,2), (3,4))
    s = str(iv)
    assert s == 'Interval((1, 2), (3, 4))'
    assert repr(iv) == s

    iv = Interval((1,2), (3,4), (5, 6))
    s = str(iv)
    assert s == 'Interval((1, 2), (3, 4), (5, 6))'
    assert repr(iv) == s 
开发者ID:chaimleib,项目名称:intervaltree,代码行数:22,代码来源:unary_test.py

示例3: test_interval_interval_cmp

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import Interval [as 别名]
def test_interval_interval_cmp():
    """
    Test comparisons with other Intervals using __cmp__()
    """
    iv0 = Interval(0, 10)
    iv1 = Interval(-10, -5)
    iv2 = Interval(-10, 0)
    iv3 = Interval(-10, 5)
    iv4 = Interval(-10, 10)
    iv5 = Interval(-10, 20)
    iv6 = Interval(0, 20)
    iv7 = Interval(5, 20)
    iv8 = Interval(10, 20)
    iv9 = Interval(15, 20)

    assert iv0.__cmp__(iv0) == 0
    assert iv0.__cmp__(iv1) == 1
    assert iv0.__cmp__(iv2) == 1
    assert iv0.__cmp__(iv3) == 1
    assert iv0.__cmp__(iv4) == 1
    assert iv0.__cmp__(iv5) == 1
    assert iv0.__cmp__(iv6) == -1
    assert iv0.__cmp__(iv7) == -1
    assert iv0.__cmp__(iv8) == -1
    assert iv0.__cmp__(iv9) == -1 
开发者ID:chaimleib,项目名称:intervaltree,代码行数:27,代码来源:sorting_test.py

示例4: test_interval_sort_interval

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import Interval [as 别名]
def test_interval_sort_interval():
    base = Interval(0, 10)
    ivs = [
        Interval(-10, -5),
        Interval(-10, 0),
        Interval(-10, 5),
        Interval(-10, 10),
        Interval(-10, 20),
        Interval(0, 20),
        Interval(5, 20),
        Interval(10, 20),
        Interval(15, 20),
    ]

    for iv in ivs:
        sort = sorted([base, iv])
        assert sort[0].__cmp__(sort[1]) in (-1, 0)

        sort = sorted([iv, base])
        assert sort[0].__cmp__(sort[1]) in (-1, 0) 
开发者ID:chaimleib,项目名称:intervaltree,代码行数:22,代码来源:sorting_test.py

示例5: test_insert_to_filled_tree

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import Interval [as 别名]
def test_insert_to_filled_tree():
    t = IntervalTree.from_tuples(data.ivs1.data)
    orig = t.print_structure(True)  # original structure record

    assert match.set_data(t[1]) == set(['[1,2)'])
    t.add(Interval(1, 2, '[1,2)'))  # adding duplicate should do nothing
    assert match.set_data(t[1]) == set(['[1,2)'])
    assert orig == t.print_structure(True)

    t[1:2] = '[1,2)'                # adding duplicate should do nothing
    assert match.set_data(t[1]) == set(['[1,2)'])
    assert orig == t.print_structure(True)

    assert Interval(2, 4, '[2,4)') not in t
    t.add(Interval(2, 4, '[2,4)'))
    assert match.set_data(t[2]) == set(['[2,4)'])
    t.verify()

    t[13:15] = '[13,15)'
    assert match.set_data(t[14]) == set(['[8,15)', '[13,15)', '[14,15)'])
    t.verify() 
开发者ID:chaimleib,项目名称:intervaltree,代码行数:23,代码来源:insert_test.py

示例6: test_removei

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import Interval [as 别名]
def test_removei():
    # Empty tree
    e = IntervalTree()
    with pytest.raises(ValueError):
        e.removei(-1000, -999, "Doesn't exist")
    e.verify()
    assert len(e) == 0

    # Non-existent member should raise ValueError
    t = IntervalTree.from_tuples(data.ivs1.data)
    oldlen = len(t)
    with pytest.raises(ValueError):
        t.removei(-1000, -999, "Doesn't exist")
    t.verify()
    assert len(t) == oldlen

    # Should remove existing member
    assert Interval(1, 2, '[1,2)') in t
    t.removei(1, 2, '[1,2)')
    assert len(t) == oldlen - 1
    assert Interval(1, 2, '[1,2)') not in t 
开发者ID:chaimleib,项目名称:intervaltree,代码行数:23,代码来源:delete_test.py

示例7: test_discardi

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import Interval [as 别名]
def test_discardi():
    # Empty tree
    e = IntervalTree()
    e.discardi(-1000, -999, "Doesn't exist")
    e.verify()
    assert len(e) == 0

    # Non-existent member should do nothing quietly
    t = IntervalTree.from_tuples(data.ivs1.data)
    oldlen = len(t)
    t.discardi(-1000, -999, "Doesn't exist")
    t.verify()
    assert len(t) == oldlen

    # Should discard existing member
    assert Interval(1, 2, '[1,2)') in t
    t.discardi(1, 2, '[1,2)')
    assert len(t) == oldlen - 1
    assert Interval(1, 2, '[1,2)') not in t 
开发者ID:chaimleib,项目名称:intervaltree,代码行数:21,代码来源:delete_test.py

示例8: test_union_operator

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import Interval [as 别名]
def test_union_operator():
    t = IntervalTree()
    interval = Interval(0, 1)
    s = set([interval])

    # currently runs fine
    # with pytest.raises(TypeError):
    #     t | list(s)
    r = t | IntervalTree(s)
    assert len(r) == 1
    assert sorted(r)[0] == interval

    # also currently runs fine
    # with pytest.raises(TypeError):
    #     t |= s
    t |= IntervalTree(s)
    assert len(t) == 1
    assert sorted(t)[0] == interval 
开发者ID:chaimleib,项目名称:intervaltree,代码行数:20,代码来源:setlike_test.py

示例9: test_copy

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import Interval [as 别名]
def test_copy():
    itree = IntervalTree([Interval(0, 1, "x"), Interval(1, 2, ["x"])])
    itree.verify()

    itree2 = IntervalTree(itree)  # Shares Interval objects
    itree2.verify()

    itree3 = itree.copy()         # Shallow copy (same as above, as Intervals are singletons)
    itree3.verify()

    itree4 = pickle.loads(pickle.dumps(itree))  # Deep copy
    itree4.verify()

    list(itree[1])[0].data[0] = "y"
    assert sorted(itree) == [Interval(0, 1, 'x'), Interval(1, 2, ['y'])]
    assert sorted(itree2) == [Interval(0, 1, 'x'), Interval(1, 2, ['y'])]
    assert sorted(itree3) == [Interval(0, 1, 'x'), Interval(1, 2, ['y'])]
    assert sorted(itree4) == [Interval(0, 1, 'x'), Interval(1, 2, ['x'])] 
开发者ID:chaimleib,项目名称:intervaltree,代码行数:20,代码来源:copy_test.py

示例10: test_membership

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import Interval [as 别名]
def test_membership():
    t = IntervalTree.from_tuples(data.ivs1.data)
    assert Interval(1, 2, '[1,2)') in t
    assert t.containsi(1, 2, '[1,2)')
    assert Interval(1, 3, '[1,3)') not in t
    assert not t.containsi(1, 3, '[1,3)')
    assert t.overlaps(4)
    assert t.overlaps(9)
    assert not t.overlaps(15)
    assert t.overlaps(0, 4)
    assert t.overlaps(1, 2)
    assert t.overlaps(1, 3)
    assert t.overlaps(8, 15)
    assert not t.overlaps(15, 16)
    assert not t.overlaps(-1, 0)
    assert not t.overlaps(2, 4) 
开发者ID:chaimleib,项目名称:intervaltree,代码行数:18,代码来源:query_test.py

示例11: test_overlaps_empty

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import Interval [as 别名]
def test_overlaps_empty():
    # Empty tree
    t = IntervalTree()
    assert not t.overlaps(-1)
    assert not t.overlaps(0)

    assert not t.overlaps(-1, 1)
    assert not t.overlaps(-1, 0)
    assert not t.overlaps(0, 0)
    assert not t.overlaps(0, 1)
    assert not t.overlaps(1, 0)
    assert not t.overlaps(1, -1)
    assert not t.overlaps(0, -1)

    assert not t.overlaps(Interval(-1, 1))
    assert not t.overlaps(Interval(-1, 0))
    assert not t.overlaps(Interval(0, 0))
    assert not t.overlaps(Interval(0, 1))
    assert not t.overlaps(Interval(1, 0))
    assert not t.overlaps(Interval(1, -1))
    assert not t.overlaps(Interval(0, -1)) 
开发者ID:chaimleib,项目名称:intervaltree,代码行数:23,代码来源:query_test.py

示例12: test_merge_overlaps_reducer_wo_initializer

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import Interval [as 别名]
def test_merge_overlaps_reducer_wo_initializer():
    def reducer(old, new):
        return "%s, %s" % (old, new)
    # empty tree
    e = IntervalTree()
    e.merge_overlaps(data_reducer=reducer)
    e.verify()
    assert not e

    # One Interval in tree
    o = IntervalTree.from_tuples([(1, 2, 'hello')])
    o.merge_overlaps(data_reducer=reducer)
    o.verify()
    assert len(o) == 1
    assert sorted(o) == [Interval(1, 2, 'hello')]

    # many Intervals in tree, with gap
    t = IntervalTree.from_tuples(data.ivs1.data)
    t.merge_overlaps(data_reducer=reducer)
    t.verify()
    assert len(t) == 2
    assert sorted(t) == [
        Interval(1, 2,'[1,2)'),
        Interval(4, 15, '[4,7), [5,9), [6,10), [8,10), [8,15), [10,12), [12,14), [14,15)')
    ] 
开发者ID:chaimleib,项目名称:intervaltree,代码行数:27,代码来源:restructure_test.py

示例13: test_chop

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import Interval [as 别名]
def test_chop():
    t = IntervalTree([Interval(0, 10)])
    t.chop(3, 7)
    assert len(t) == 2
    assert sorted(t)[0] == Interval(0, 3)
    assert sorted(t)[1] == Interval(7, 10)

    t = IntervalTree([Interval(0, 10)])
    t.chop(0, 7)
    assert len(t) == 1
    assert sorted(t)[0] == Interval(7, 10)

    t = IntervalTree([Interval(0, 10)])
    t.chop(5, 10)
    assert len(t) == 1
    assert sorted(t)[0] == Interval(0, 5)

    t = IntervalTree([Interval(0, 10)])
    t.chop(-5, 15)
    assert len(t) == 0

    t = IntervalTree([Interval(0, 10)])
    t.chop(0, 10)
    assert len(t) == 0 
开发者ID:chaimleib,项目名称:intervaltree,代码行数:26,代码来源:restructure_test.py

示例14: test_slice

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import Interval [as 别名]
def test_slice():
    t = IntervalTree([Interval(5, 15)])
    t.slice(10)
    assert sorted(t)[0] == Interval(5, 10)
    assert sorted(t)[1] == Interval(10, 15)

    t = IntervalTree([Interval(5, 15)])
    t.slice(5)
    assert sorted(t)[0] == Interval(5, 15)

    t.slice(15)
    assert sorted(t)[0] == Interval(5, 15)

    t.slice(0)
    assert sorted(t)[0] == Interval(5, 15)

    t.slice(20)
    assert sorted(t)[0] == Interval(5, 15) 
开发者ID:chaimleib,项目名称:intervaltree,代码行数:20,代码来源:restructure_test.py

示例15: __init__

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import Interval [as 别名]
def __init__(self, interval_tuples):
        '''intervals is like [('22', 12321, 12345, 'APOL1'), ...]'''
        self._its = {}
        self._gene_starts = {}
        self._gene_ends = {}
        for interval_tuple in interval_tuples:
            chrom, pos_start, pos_end, gene_name = interval_tuple
            assert isinstance(pos_start, int)
            assert isinstance(pos_end, int)
            if chrom not in self._its:
                self._its[chrom] = intervaltree.IntervalTree()
                self._gene_starts[chrom] = []
                self._gene_ends[chrom] = []
            self._its[chrom].add(intervaltree.Interval(pos_start, pos_end, gene_name))
            self._gene_starts[chrom].append((pos_start, gene_name))
            self._gene_ends[chrom].append((pos_end, gene_name))
        for chrom in self._its:
            self._gene_starts[chrom] = BisectFinder(self._gene_starts[chrom])
            self._gene_ends[chrom] = BisectFinder(self._gene_ends[chrom]) 
开发者ID:statgen,项目名称:pheweb,代码行数:21,代码来源:add_genes.py


注:本文中的intervaltree.Interval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。