本文整理匯總了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
示例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
示例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
示例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)
示例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()
示例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
示例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
示例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
示例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'])]
示例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)
示例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))
示例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)')
]
示例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
示例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)
示例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])