question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'IntervalTree' object has no attribute 'merge_neighbors'

See original GitHub issue

I am attempting to call merge_neighbors() on an IntervalTree instance, but I am running into the following error:

% ../test.py
IntervalTree([Interval(50, 80, {'chrom': 'chr1', 'id': 'F'}), Interval(100, 120, {'chrom': 'chr1', 'id': 'D'}), Interval(100, 140, {'chrom': 'chr1', 'id': 'C'}), Interval(120, 200, {'chrom': 'chr1', 'id': 'A'}), Interval(199, 260, {'chrom': 'chr1', 'id': 'B'})])
None
Traceback (most recent call last):
  ...
  File "../test.py", line 44, in main
    mn_tree = tree.copy().merge_neighbors()
AttributeError: 'IntervalTree' object has no attribute 'merge_neighbors'

Here is the minimal reproducible example script test.py:

#!/usr/bin/env python

import sys
import io
import intervaltree

test_intervals_str = '''chr1	50	80	F
chr1	100	120	D
chr1	100	140	C
chr1	120	200	A
chr1	199	260	B
'''

def main():
    # build tree
    tree = intervaltree.IntervalTree()
    intervals = io.StringIO(test_intervals_str)
    for interval in intervals:
        (chrom, start, stop, id) = interval.rstrip().split('\t')
        tree[int(start):int(stop)] = { 'chrom' : chrom, 'id' : id }
    print(tree)
    mo_tree = tree.copy().merge_overlaps()
    print(mo_tree)
    mn_tree = tree.copy().merge_neighbors()
    print(mn_tree)

if __name__ == '__main__':
    main()

It looks like merged_neighbors is in the version I am using (v3.1.0):

https://github.com/chaimleib/intervaltree/blob/328d6db96596a0b7180dd3ad3fae4f6ff7301e01/intervaltree/intervaltree.py#L770-L776

Here is my install log:

% git clone https://github.com/chaimleib/intervaltree.git
% cd intervaltree 
% python ./setup.py install
!!!>>> This is a RELEASE version <<<!!!

Version: 3.1.0
running install
running bdist_egg
running egg_info
writing intervaltree.egg-info/PKG-INFO
writing dependency_links to intervaltree.egg-info/dependency_links.txt
writing requirements to intervaltree.egg-info/requires.txt
writing top-level names to intervaltree.egg-info/top_level.txt
reading manifest file 'intervaltree.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'intervaltree.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.9-x86_64/egg
running install_lib
running build_py
creating build/bdist.macosx-10.9-x86_64/egg
creating build/bdist.macosx-10.9-x86_64/egg/intervaltree
copying build/lib/intervaltree/intervaltree.py -> build/bdist.macosx-10.9-x86_64/egg/intervaltree
copying build/lib/intervaltree/interval.py -> build/bdist.macosx-10.9-x86_64/egg/intervaltree
copying build/lib/intervaltree/__init__.py -> build/bdist.macosx-10.9-x86_64/egg/intervaltree
copying build/lib/intervaltree/node.py -> build/bdist.macosx-10.9-x86_64/egg/intervaltree
byte-compiling build/bdist.macosx-10.9-x86_64/egg/intervaltree/intervaltree.py to intervaltree.cpython-38.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/intervaltree/interval.py to interval.cpython-38.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/intervaltree/__init__.py to __init__.cpython-38.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/intervaltree/node.py to node.cpython-38.pyc
creating build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying intervaltree.egg-info/PKG-INFO -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying intervaltree.egg-info/SOURCES.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying intervaltree.egg-info/dependency_links.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying intervaltree.egg-info/requires.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying intervaltree.egg-info/top_level.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying intervaltree.egg-info/zip-safe -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
creating 'dist/intervaltree-3.1.0-py3.8.egg' and adding 'build/bdist.macosx-10.9-x86_64/egg' to it
removing 'build/bdist.macosx-10.9-x86_64/egg' (and everything under it)
Processing intervaltree-3.1.0-py3.8.egg
Removing /Users/areynolds/miniconda3/lib/python3.8/site-packages/intervaltree-3.1.0-py3.8.egg
Copying intervaltree-3.1.0-py3.8.egg to /Users/areynolds/miniconda3/lib/python3.8/site-packages
intervaltree 3.1.0 is already the active version in easy-install.pth

Installed /Users/areynolds/miniconda3/lib/python3.8/site-packages/intervaltree-3.1.0-py3.8.egg
Processing dependencies for intervaltree==3.1.0
Searching for sortedcontainers==2.4.0
Best match: sortedcontainers 2.4.0
Adding sortedcontainers 2.4.0 to easy-install.pth file

Using /Users/areynolds/miniconda3/lib/python3.8/site-packages
Finished processing dependencies for intervaltree==3.1.0

Am I not using merge_neighbors correctly, or is there some other issue? Thanks!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
leifwalshcommented, Sep 13, 2021

Could we get a new release that includes merge_neighbors?

0reactions
afparsonscommented, Mar 14, 2022

> It looks like merged_neighbors is in the version I am using (v3.1.0):

@alexpreynolds: I believe merge_neighbors(...) was added in my pull request, #105. @chaimleib has not yet pushed the latest code to PyPI.

You could install from GitHub in the meanwhile.

Edit: Oops, I misread this thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

intervaltree - PyPI
intervaltree. A mutable, self-balancing interval tree for Python 2 and 3. Queries may be by point, by range overlap, or by range envelopment....
Read more >
Fully Explained and Clean Interval Tree for Facebook Follow-Up
The reason is that we can use merge-sort technique to query the merged intervals result when the left subtree does not overlap with...
Read more >
C++ - interval tree implementation - Stack Overflow
I have been looking at fork-event-join models with id,event pairing. Can you elaborate how did you come up with those numbers - 60,80,etc...
Read more >
IntervalTree (Time4J 5.9.1 API)
Obtains a list of all stored intervals which intersect given point in time. boolean. isEmpty(). Checks if this tree contains no intervals.
Read more >
bx.intervals.intersection module - bx-python - Read the Docs
If the object has start and end attributes (like the Interval class) there is are some shortcuts: >>> intersecter = IntervalTree() > ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found