Skip to content

Commit

Permalink
Merge pull request #290 from fidelram/fix288
Browse files Browse the repository at this point in the history
Handle labels and comment lines in BED files better
  • Loading branch information
dpryan79 committed Feb 16, 2016
2 parents 9f1ba16 + 1c0e6d1 commit 2a52d6e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions deeptools/heatmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,16 +786,21 @@ def get_regions_and_groups(regions_file, onlyMultiplesOf=1,
previnterval = None
duplicates = 0
totalintervals = 0
groupintervals = 0
includedintervals = 0
group_labels = []
group_idx = 0
bed_file = deeptools.readBed.ReadBed(regions_file)
for ginterval in bed_file:
totalintervals += 1
if ginterval.line.startswith("track") or ginterval.line.startswith("browser"):
continue

if ginterval.line.startswith('#'):
# check for labels with no associated entries
if groupintervals == 0:
continue
else:
groupintervals = 0
group_idx += 1
label = ginterval.line[1:].strip()
if label in group_labels:
Expand All @@ -815,6 +820,7 @@ def get_regions_and_groups(regions_file, onlyMultiplesOf=1,
# continue
# check for regions that have the same position as the previous.
# This assumes that the regions file given is sorted
totalintervals += 1
if previnterval is not None:
if previnterval.chrom == ginterval.chrom and \
previnterval.start == ginterval.start and \
Expand All @@ -832,6 +838,7 @@ def get_regions_and_groups(regions_file, onlyMultiplesOf=1,
ginterval.end))
duplicates += 1

groupintervals += 1
previnterval = ginterval
ginterval.group_idx = group_idx
regions.append(ginterval)
Expand All @@ -844,8 +851,10 @@ def get_regions_and_groups(regions_file, onlyMultiplesOf=1,
if not group_labels:
group_labels.append(default_group_name)
using_default_group_name = True
groupintervals = 0

if len(group_labels) < group_idx - 1:
# If there are any remaining intervals with no group label then add a fake one
if groupintervals > 0:
# There was a missing "#" at the end
label = default_group_name
if label in group_labels:
Expand Down

0 comments on commit 2a52d6e

Please sign in to comment.