Skip to content

Commit

Permalink
Merge pull request #451 from lldelisle/new_style_deletion
Browse files Browse the repository at this point in the history
New display: deletions
  • Loading branch information
lldelisle authored May 2, 2024
2 parents d537fe8 + 79c856f commit 156784a
Show file tree
Hide file tree
Showing 18 changed files with 402 additions and 39 deletions.
4 changes: 1 addition & 3 deletions docs/content/all_possible_properties.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@

- **display**:

- for *bed*: collapsed, triangles, interleaved, stacked, squares

- for *gtf*: collapsed, triangles, interleaved, stacked
- for *bed, gtf*: collapsed, triangles, interleaved, stacked, squares, deletions

- **fontstyle**:

Expand Down
11 changes: 10 additions & 1 deletion docs/content/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ The second one display a relatively small region and uses vlines and vhighlight.

Examples with bed and gtf
-------------------------
Here is an example to explain the parameters for bed and gtf:

Here are all the possible 'display' options:

.. image:: ../../pygenometracks/tests/test_data/master_bed_displays.png

Here are all possible 'style' options (when display is collapsed, interleaved or stacked:

.. image:: ../../pygenometracks/tests/test_data/master_different_UTR.png

Here is an example to explain the parameters for bed and gtf in stacked display:

.. literalinclude:: ../../pygenometracks/tests/test_data/bed_and_gtf_tracks.ini
:language: INI
Expand Down
6 changes: 4 additions & 2 deletions docs/content/releases/3.9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ This version drops support for python 3.7.
Enhancement:
^^^^^^^^^^^^

- New style to display bed: ``exonarrows`` which displays arrows with orientation in the exons.
- For the UCSC stlyle, the color of arrows on introns in customizable
- pyGenomeTracks now uses font type 42 for pdf and ps which helps modification with illustrator.
- New display for bed: ``deletions`` which is helpful when you need to show a deletion with precise coordinates.
- New style to display bed: ``exonarrows`` which displays arrows with orientation in the exons.
- For the UCSC stlyle, the color of arrows on introns in customable
- Do not hesistate to check the updated documentation: `here <https://pygenometracks.readthedocs.io/en/latest/content/examples.html#examples-with-bed-and-gtf>`_

Bugfix:
^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion docs/content/tracks/auto/bed_deduced_from_code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Optional:

- **style**: `flybase` (default) or UCSC, tssarrow or exonarrows.

- **display**: `stacked` (default) or collapsed, triangles, interleaved or squares.
- **display**: `stacked` (default) or collapsed, triangles, interleaved, squares or deletions.

- **max_labels**: `60` (default) or any integer above 0

Expand Down
10 changes: 7 additions & 3 deletions docs/content/tracks/auto/bed_options_text.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ color = darkblue
# the display parameter defines how the bed file is plotted.
# Default is 'stacked' where regions are plotted on different lines so
# we can see all regions and all labels.
# The other options are ['collapsed', 'interleaved', 'triangles', 'squares']
# These 2 options assume that the regions do not overlap.
# The other options are ['collapsed', 'interleaved', 'triangles', 'squares', 'deletions']
# These 2 options assume that the regions do not overlap:
# `collapsed`: The bed regions are plotted one after the other in one line.
# `interleaved`: The bed regions are plotted in two lines, first up, then down, then up etc.
# If the bed file contains the exon
Expand Down Expand Up @@ -101,9 +101,13 @@ fontsize = 10
# for exonarrows, you can choose the proportion between the height of the introns and the one of exon
# (by default introns are half):
#height_intron = 0.5
# The two other display options are really different and no label can be display:
# The two following display options are really different and no label can be display:
# `triangles` display each region as a triangle, can be useful to overlay with a hic_matrix
# `squares` display each region as a square along the diagonal, can be useful to overlay with a hic_matrix_square
# The last display option do not expect overlapping feature:
# `deletions` display a line on the plotted region (color can be controlled by color_backbone)
# and a V shape breaking the line for each region in bed (color can be controled by color)
# Labels can be displayed on bottom centered on the region
# optional. If not given is guessed from the file ending.
file_type = bed

2 changes: 1 addition & 1 deletion docs/content/tracks/auto/gtf_deduced_from_code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Optional:

- **style**: `flybase` (default) or UCSC, tssarrow or exonarrows.

- **display**: `stacked` (default) or collapsed, triangles or interleaved.
- **display**: `stacked` (default) or collapsed, triangles, interleaved, squares or deletions.

- **max_labels**: `60` (default) or any integer above 0

Expand Down
10 changes: 7 additions & 3 deletions docs/content/tracks/auto/gtf_options_text.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ color = darkblue
# the display parameter defines how the gtf file is plotted.
# Default is 'stacked' where regions are plotted on different lines so
# we can see all regions and all labels.
# The other options are ['collapsed', 'interleaved', 'triangles', 'squares']
# These 2 last options assume that the regions do not overlap.
# The other options are ['collapsed', 'interleaved', 'triangles', 'squares', 'deletions']
# These 2 last options assume that the regions do not overlap:
# `collapsed`: The gtf regions are plotted one after the other in one line.
# `interleaved`: The gtf regions are plotted in two lines, first up, then down, then up etc.
# style to plot the genes when the display is 'stacked', 'collapsed' or 'interleaved'
Expand Down Expand Up @@ -98,9 +98,13 @@ fontsize = 10
# for exonarrows, you can choose the proportion between the height of the introns and the one of exon
# (by default introns are half):
#height_intron = 0.5
# The two other display options are really different and no label can be display:
# The two following display options are really different and no label can be display:
# `triangles` display each region as a triangle, can be useful to overlay with a hic_matrix
# `squares` display each region as a square along the diagonal, can be useful to overlay with a hic_matrix_square
# The last display option do not expect overlapping feature:
# `deletions` display a line on the plotted region (color can be controlled by color_backbone)
# and a V shape breaking the line for each region in bed (color can be controled by color)
# Labels can be displayed on bottom centered on the region
# optional. If not given is guessed from the file ending.
file_type = gtf

3 changes: 3 additions & 0 deletions pygenometracks/tests/generateAllOutput.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ bin/pgt --tracks ./pygenometracks/tests/test_data/gtf_no_exon.ini --region 381:0
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
bin/pgt --tracks ./pygenometracks/tests/test_data/bed_exonarrows_tracks.ini --region X:3000000-3300000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_bed_exonarrows.png
bin/pgt --tracks ./pygenometracks/tests/test_data/bed_deletions.ini --region chr1:0-500000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_bed_deletions.png
bin/pgt --tracks ./pygenometracks/tests/test_data/bed_deletions.ini --region chr1:0-210000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_bed_deletions_zoom.png
bin/pgt --tracks ./pygenometracks/tests/test_data/bed_displays.ini --region chrX:960000-1170000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_bed_displays.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
133 changes: 133 additions & 0 deletions pygenometracks/tests/test_bed_and_gtf_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,100 @@
with open(os.path.join(ROOT, "bed_exonarrows_tracks.ini"), 'w') as fh:
fh.write(browser_tracks)

browser_tracks = """
[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed default
height = 4
[spacer]
[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = deletions
display = deletions
height = 1
[spacer]
[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = deletions color = red labels = false
display = deletions
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]
"""
with open(os.path.join(ROOT, "bed_deletions.ini"), 'w') as fh:
fh.write(browser_tracks)

browser_tracks = """
[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = collapsed
display = collapsed
height = 4
[spacer]
[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = interleaved
display = interleaved
height = 4
[spacer]
[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = stacked
display = stacked
height = 4
[spacer]
[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = triangles
display = triangles
height = 4
[spacer]
[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = squares
display = squares
height = 4
[spacer]
[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = deletions
display = deletions
height = 1
[x-axis]
"""
with open(os.path.join(ROOT, "bed_displays.ini"), 'w') as fh:
fh.write(browser_tracks)

tolerance = 13 # default matplotlib pixed difference tolerance


Expand Down Expand Up @@ -1568,3 +1662,42 @@ def test_bed_exonarrows():
assert res is None, res

os.remove(outfile.name)


def test_plot_tracks_bed_deletions():
extension = '.png'
ini_file = os.path.join(ROOT, "bed_deletions.ini")
for region, expected_basename_file in [("chr1:0-500000", "master_bed_deletions"),
("chr1:0-210000", "master_bed_deletions_zoom")]:
outfile = NamedTemporaryFile(suffix='.png', prefix='pyGenomeTracks_test_',
delete=False)
args = f"--tracks {ini_file} --region {region} "\
"--trackLabelFraction 0.2 --width 38 --dpi 130 "\
f"--outFileName {outfile.name}".split()
pygenometracks.plotTracks.main(args)
output_file = outfile.name
expected_file = os.path.join(ROOT, expected_basename_file
+ extension)
res = compare_images(expected_file,
output_file, tolerance)
assert res is None, res

os.remove(output_file)


def test_plot_tracks_bed_displays():

outfile = NamedTemporaryFile(suffix='.png', prefix='pyGenomeTracks_test_',
delete=False)
ini_file = os.path.join(ROOT, 'bed_displays.ini')
region = "chrX:960000-1170000"
expected_file = os.path.join(ROOT, 'master_bed_displays.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)
38 changes: 38 additions & 0 deletions pygenometracks/tests/test_data/bed_deletions.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed default
height = 4

[spacer]

[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = deletions
display = deletions
height = 1

[spacer]

[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = deletions color = red labels = false
display = deletions
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]
25 changes: 25 additions & 0 deletions pygenometracks/tests/test_data/bed_deletions_tracks.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed default
height = 4

[spacer]

[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = deletions
display = deletions
height = 1

[spacer]

[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = deletions color = red labels = false
display = deletions
color = red
labels = false
height = 1

[x-axis]
48 changes: 48 additions & 0 deletions pygenometracks/tests/test_data/bed_displays.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = collapsed
display = collapsed
height = 4

[spacer]

[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = interleaved
display = interleaved
height = 4

[spacer]

[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = stacked
display = stacked
height = 4

[spacer]

[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = triangles
display = triangles
height = 4

[spacer]

[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = squares
display = squares
height = 4

[spacer]

[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed display = deletions
display = deletions
height = 1

[x-axis]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 156784a

Please sign in to comment.