Skip to content

Commit

Permalink
fix genes inverted
Browse files Browse the repository at this point in the history
  • Loading branch information
lldelisle committed Jan 20, 2023
1 parent c310cf3 commit ce42498
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/content/releases/3.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Bugfix:
- The installation instructions have been updated
- Fixed a small bug in links track with "use_middle" enabled, where midpoints could have different ordering than start points (Thanks to @Jeff1995 ).
- Fix a bug when plotting gtf in the middle of a large intron
- Fix plot genes with ``orientation = inverted``

Relax version control on matplotlib:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions pygenometracks/tests/generateAllOutput.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ bin/pgt --tracks ./pygenometracks/tests/test_data/bed_genes_rgb.ini --region chr
bin/pgt --tracks ./pygenometracks/tests/test_data/gtf_merge_overlapping_exons.ini --region chr2:74,704,000-74,710,000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_gtf_merge_overlapping_exons.png
bin/pgt --tracks ./pygenometracks/tests/test_data/gtf_no_exon.ini --region 381:0-1000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_gtf_no_exon.png
bin/pgt --tracks ./pygenometracks/tests/test_data/gtf_long_intron.ini --region chr4:147085588-147087450 --trackLabelFraction 0.2 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_gtf_long_intron.png
bin/pgt --tracks ./pygenometracks/tests/test_data/bed_inverted.ini --region chrX:0-2500000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_bed_inverted.png

# non_classical_bed
bin/pgt --tracks pygenometracks/tests/test_data/bed_unusual_formats.ini --region X:20000-40000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o pygenometracks/tests/test_data/master_bed_unusual_formats.png
Expand Down
41 changes: 41 additions & 0 deletions pygenometracks/tests/test_bed_and_gtf_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,29 @@
with open(os.path.join(ROOT, "gtf_long_intron.ini"), 'w') as fh:
fh.write(browser_tracks)

browser_tracks = """
[genes 2]
file = dm3_genes.bed.gz
height = 7
title = genes
[spacer]
height = 0.05
[x-axis]
where = top
[spacer]
height = 0.05
[genes 2bis]
file = dm3_genes.bed.gz
height = 7
orientation = inverted
title = genes orientation = inverted
"""
with open(os.path.join(ROOT, "bed_inverted.ini"), 'w') as fh:
fh.write(browser_tracks)

tolerance = 13 # default matplotlib pixed difference tolerance

Expand Down Expand Up @@ -1412,3 +1435,21 @@ def test_plot_gtf_long_intron():
assert res is None, res

os.remove(outfile.name)


def test_bed_inverted():

outfile = NamedTemporaryFile(suffix='.png', prefix='pyGenomeTracks_test_',
delete=False)
ini_file = os.path.join(ROOT, 'bed_inverted.ini')
region = "chrX:0-2500000"
expected_file = os.path.join(ROOT, 'master_bed_inverted.png')
args = f"--tracks {ini_file} --region {region} "\
"--trackLabelFraction 0.2 --width 38 --dpi 130 "\
f"--outFileName {outfile.name}".split()
pygenometracks.plotTracks.main(args)
res = compare_images(expected_file,
outfile.name, tolerance)
assert res is None, res

os.remove(outfile.name)
20 changes: 20 additions & 0 deletions pygenometracks/tests/test_data/bed_inverted.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

[genes 2]
file = dm3_genes.bed.gz
height = 7
title = genes

[spacer]
height = 0.05

[x-axis]
where = top

[spacer]
height = 0.05

[genes 2bis]
file = dm3_genes.bed.gz
height = 7
orientation = inverted
title = genes orientation = inverted
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 6 additions & 9 deletions pygenometracks/tracks/BedTrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,7 @@ def plot(self, ax, chrom_region, start_region, end_region):
self.plot_triangles(ax, genes_overlap)
elif self.properties['display'] == 'squares':
self.plot_squares(ax, genes_overlap)
if self.properties['orientation'] == 'inverted':
ax.set_ylim(start_region, end_region)
else:
ax.set_ylim(end_region, start_region)

ax.set_ylim(end_region, start_region)
else:
self.counter = 0
self.current_small_relative = self.properties['arrowhead_fraction'] * (end_region - start_region)
Expand Down Expand Up @@ -626,6 +622,10 @@ def is_right_to(a, b):
ax.set_ylim(2 + epsilon, ymax)
elif self.properties['display'] == 'collapsed':
ax.set_ylim(1 + epsilon, ymax)

if self.properties['orientation'] == 'inverted':
ylims = ax.get_ylim()
ax.set_ylim(ylims[1], ylims[0])

def plot_label(self, label_ax, width_dpi, h_align='left'):
if h_align == 'left':
Expand Down Expand Up @@ -1052,10 +1052,7 @@ def plot_triangles(self, ax, genes_overlap):
if valid_regions == 0:
self.log.warning(f"No regions found for section {self.properties['section_name']}.\n")

if self.properties['orientation'] == 'inverted':
ax.set_ylim(ymax, 0)
else:
ax.set_ylim(0, ymax)
ax.set_ylim(0, ymax)

def plot_squares(self, ax, genes_overlap):
"""
Expand Down

0 comments on commit ce42498

Please sign in to comment.