Created
April 12, 2018 00:02
-
-
Save adamewing/8d1fd11924292422c1be9ff397bc6c12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from collections import defaultdict as dd | |
from bx.intervals.intersection import Intersecter, Interval | |
def interval_forest(bed_file): | |
''' build dictionary of interval trees ''' | |
forest = dd(Intersecter) | |
with open(bed_file, 'r') as bed: | |
for line in bed: | |
chrom, start, end = line.strip().split()[:3] | |
label = '|'.join(line.strip().split()) | |
forest[chrom].add_interval(Interval(int(start), int(end), value=label)) | |
return forest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment