diff --git a/pygenometracks/tests/test_bed_and_gtf_tracks.py b/pygenometracks/tests/test_bed_and_gtf_tracks.py index aca19e91..99b47c1b 100644 --- a/pygenometracks/tests/test_bed_and_gtf_tracks.py +++ b/pygenometracks/tests/test_bed_and_gtf_tracks.py @@ -1030,6 +1030,19 @@ labels = false height = 1 +[spacer] + +[empty deletion] +file = empty.bed +display = deletions +height = 1 +title = no deletion ovelayed with genes + +[genes] +file = dm3_genes_withrgbandscore.bed.gz +overlay_previous = share-y +display = collapsed + [x-axis] """ with open(os.path.join(ROOT, "bed_deletions.ini"), 'w') as fh: diff --git a/pygenometracks/tests/test_data/bed_deletions.ini b/pygenometracks/tests/test_data/bed_deletions.ini index 5784b022..a43dcdce 100644 --- a/pygenometracks/tests/test_data/bed_deletions.ini +++ b/pygenometracks/tests/test_data/bed_deletions.ini @@ -22,4 +22,17 @@ color = red labels = false height = 1 +[spacer] + +[empty deletion] +file = empty.bed +display = deletions +height = 1 +title = no deletion ovelayed with genes + +[genes] +file = dm3_genes_withrgbandscore.bed.gz +overlay_previous = share-y +display = collapsed + [x-axis] diff --git a/pygenometracks/tests/test_data/master_bed_deletions.png b/pygenometracks/tests/test_data/master_bed_deletions.png index aa973eed..aa30b847 100644 Binary files a/pygenometracks/tests/test_data/master_bed_deletions.png and b/pygenometracks/tests/test_data/master_bed_deletions.png differ diff --git a/pygenometracks/tests/test_data/master_bed_deletions_zoom.png b/pygenometracks/tests/test_data/master_bed_deletions_zoom.png index d3e373a2..b06754d8 100644 Binary files a/pygenometracks/tests/test_data/master_bed_deletions_zoom.png and b/pygenometracks/tests/test_data/master_bed_deletions_zoom.png differ diff --git a/pygenometracks/tests/test_data/master_bed_displays.png b/pygenometracks/tests/test_data/master_bed_displays.png index 1dd8ba7f..b9365bd8 100644 Binary files a/pygenometracks/tests/test_data/master_bed_displays.png and b/pygenometracks/tests/test_data/master_bed_displays.png differ diff --git a/pygenometracks/tracks/BedTrack.py b/pygenometracks/tracks/BedTrack.py index c35b2dcc..93b91718 100644 --- a/pygenometracks/tracks/BedTrack.py +++ b/pygenometracks/tracks/BedTrack.py @@ -18,6 +18,8 @@ DEFAULT_DISPLAY_BED = 'stacked' AROUND_REGION = 100000 +EPSILON = 0.08 + class BedTrack(GenomeTrack): SUPPORTED_ENDINGS = ['bed', 'bed3', 'bed4', 'bed5', 'bed6', 'bed8', @@ -401,13 +403,16 @@ def plot(self, ax, chrom_region, start_region, end_region): chrom_region_before = chrom_region chrom_region = change_chrom_names(chrom_region) if chrom_region not in self.interval_tree.keys(): - self.log.warning("*Warning*\nNo interval was found when " - "overlapping with both " - f"{chrom_region_before}:{start_region - AROUND_REGION}-{end_region + AROUND_REGION}" - f" and {chrom_region}:{start_region - AROUND_REGION}-{end_region + AROUND_REGION}" - " inside the bed file. " - "This will generate an empty track!!\n") - return + if self.properties['display'] != 'deletions': + self.log.warning("*Warning*\nNo interval was found when " + "overlapping with both " + f"{chrom_region_before}:{start_region - AROUND_REGION}-{end_region + AROUND_REGION}" + f" and {chrom_region}:{start_region - AROUND_REGION}-{end_region + AROUND_REGION}" + " inside the bed file. " + "This will generate an empty track!!\n") + return + else: + self.interval_tree[chrom_region] = IntervalTree() genes_overlap = \ sorted(self.interval_tree[chrom_region][start_region:end_region]) @@ -626,8 +631,7 @@ def is_right_to(a, b): " for the interval plotted" f" ({chrom_region}:{start_region}-{end_region}).\n") - epsilon = 0.08 - ymax = - epsilon + ymax = - EPSILON # We set ymin and ymax to have genes centered epsilon from the border @@ -637,21 +641,23 @@ def is_right_to(a, b): elif self.properties['gene_rows'] is not None: max_ypos = self.properties['gene_rows'] * self.row_scale - ymin = max_ypos + (1 + epsilon) + ymin = max_ypos + (1 + EPSILON) self.log.debug(f"ylim {ymin},{ymax}") # the axis is inverted (thus, ymax < ymin) ax.set_ylim(ymin, ymax) if self.properties['display'] == 'interleaved': - ax.set_ylim(2 + epsilon, ymax) + ax.set_ylim(2 + EPSILON, ymax) elif self.properties['display'] == 'collapsed': - ax.set_ylim(1 + epsilon, ymax) + ax.set_ylim(1 + EPSILON, ymax) if self.properties['orientation'] == 'inverted': ylims = ax.get_ylim() ax.set_ylim(ylims[1], ylims[0]) + self.log.debug(f"ylim {ax.get_ylim()}") + def plot_label(self, label_ax, width_dpi, h_align='left'): if h_align == 'left': label_ax.text(0.05, 1, self.properties['title'], @@ -1183,14 +1189,20 @@ def plot_deletions(self, ax, genes_overlap, start_region, end_region): " " " label + genes_overlap can be empty, then it plots + _____________________________ """ valid_regions = 0 back_bone = [] last_plotted = start_region - y1 = 1 - y2 = 0 - y3 = -0.5 + y1 = 0.5 + y2 = -0.5 + y3 = -1 min_y = y2 + x1 = start_region + x2 = start_region + x3 = start_region + for region in genes_overlap: """ x1 x2 x3 @@ -1242,8 +1254,8 @@ def plot_deletions(self, ax, genes_overlap, start_region, end_region): linewidth=self.properties['line_width']) if valid_regions == 0: self.log.warning(f"No regions found for section {self.properties['section_name']}.\n") - # Set ylim: - ax.set_ylim(min_y - 0.05, ax.get_ylim()[1]) + # Set ylim (to be compatible with collapsed genes): + ax.set_ylim(min_y - 0.05, 1 + EPSILON) def _plot_small_arrow(self, ax, xpos, ypos_top, ypos_bottom, strand, bed): """