From 25996f351364a5728686f4af18f79225002602f2 Mon Sep 17 00:00:00 2001 From: dpryan79 Date: Tue, 16 Feb 2016 11:15:12 +0100 Subject: [PATCH 1/2] Handle labels and comment lines in BED files better --- deeptools/heatmapper.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/deeptools/heatmapper.py b/deeptools/heatmapper.py index 159f4b33d..5410ece28 100644 --- a/deeptools/heatmapper.py +++ b/deeptools/heatmapper.py @@ -786,16 +786,23 @@ 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('#') and totalintervals == 0: + 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: @@ -815,6 +822,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 \ @@ -832,6 +840,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) @@ -844,8 +853,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: From 1c0e6d1dbbb97f811f9220ed420c38bb2ca47af3 Mon Sep 17 00:00:00 2001 From: dpryan79 Date: Tue, 16 Feb 2016 11:54:18 +0100 Subject: [PATCH 2/2] Remove unneeded test --- deeptools/heatmapper.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/deeptools/heatmapper.py b/deeptools/heatmapper.py index 5410ece28..fb9b9139c 100644 --- a/deeptools/heatmapper.py +++ b/deeptools/heatmapper.py @@ -794,8 +794,6 @@ def get_regions_and_groups(regions_file, onlyMultiplesOf=1, for ginterval in bed_file: if ginterval.line.startswith("track") or ginterval.line.startswith("browser"): continue - if ginterval.line.startswith('#') and totalintervals == 0: - continue if ginterval.line.startswith('#'): # check for labels with no associated entries