Skip to main content

Algorithms and data structures for my Python projects

Project description

ddalg

Algorithms and data structures for my Python projects.

Build Status

Interval tree

Interval tree is a data structure for holding intervals and to allow efficiently find intervals that overlap with given interval or point. Read more on Wikipedia.

Implementation note

This implementation uses half-open intervals, where begin coordinate is excluded. Half-open intervals are used in e.g. BED genomic format.

The current implementation needs to rebuild the tree after each insert, hence the tree is not efficient for using in read/write fashion.

Usage

  • implement your custom interval object while extending Interval. Two properties need to be overwritten:
    • begin - 0-based (excluded) begin coordinate of the interval
    • end - 0-based (included) end coordinate of the interval
      from ddalg.model import Interval
      
      class YourInterval(Interval):
      
        def __init__(self, begin: int, end: int):
          self._begin = begin
          self._end = end
          # anything else
      
        @property
        def begin(self):
          return self._begin
      
        @property
        def end(self):
          return self._end
      
  • create a collection of your intervals and store them in the interval tree:
    from ddalg.itree import IntervalTree
     
    itree = IntervalTree([YourInterval(0, 3), YourInterval(1, 4)])
    # ... 
    
  • query itree:
    • using 1-based position:
      itree.search(1)
      

      returns (0,3)

    • using half-open interval coordinates:
      itree.get_overlaps(0, 1) 
      

      returns (0,3), effectively the same query as above

    • for intervals with minimal required coverage
      itree.fuzzy_query(0, 1, coverage=.90)
      

      return intervals with >=.9 overlap with respect to query coordinates

    • for intervals with minimal jaccard index
      itree.jaccard_query(0, 1, min_jaccard=.90)
      

      return intervals having jaccard_index>=.9 with respect to query coordinates

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ddalg-0.0.3.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

ddalg-0.0.3-py3.6.egg (27.0 kB view details)

Uploaded Source

File details

Details for the file ddalg-0.0.3.tar.gz.

File metadata

  • Download URL: ddalg-0.0.3.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.1.post20200323 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

File hashes

Hashes for ddalg-0.0.3.tar.gz
Algorithm Hash digest
SHA256 16a942d4f19c86e71de4ba16843f81ccf4a1763db21c68b8651d84386d204e2b
MD5 62ac549e6a43dda61a0636498fe74af4
BLAKE2b-256 eea502718d1074edf29f4cbb671c4b6daa40e682b27fc6f3f2fb5658d1775c93

See more details on using hashes here.

File details

Details for the file ddalg-0.0.3-py3.6.egg.

File metadata

  • Download URL: ddalg-0.0.3-py3.6.egg
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.1.post20200323 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

File hashes

Hashes for ddalg-0.0.3-py3.6.egg
Algorithm Hash digest
SHA256 363610c30129cc7f3805bf172ec6518956fa3a861ce7769c7ab4cf729dd7293b
MD5 81f98f3fb204be3c1d70a2f21ebbd569
BLAKE2b-256 005a412597fc09a8b40e64cbe1ecc1a1d6a733aff1ea293d33cf4a0fc9dc2cab

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page