Skip to content

Commit

Permalink
remove sorting requirement + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lldelisle committed Jul 10, 2020
1 parent 9bc043d commit 1a47fd1
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 3 deletions.
1 change: 1 addition & 0 deletions pygenometracks/tests/generateAllOutput.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ bin/pgt --tracks ./pygenometracks/tests/test_data/bed_all_labels_inside.ini --re
bin/pgt --tracks ./pygenometracks/tests/test_data/bed_all_labels_inside.ini --region X:3215000-3240000 --trackLabelFraction 0.2 --width 38 --dpi 130 --trackLabelHAlign right --decreasingXAxis -o ./pygenometracks/tests/test_data/master_bed_all_label_inside_dec.png
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
bin/pgt --tracks ./pygenometracks/tests/test_data/bed_colormap_genes.ini --region X:3000000-3300000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_bed_colormap_genes.png
bin/pgt --tracks ./pygenometracks/tests/test_data/bed_shuffle.ini --BED ./pygenometracks/tests/test_data/regions_chr1XY.bed --trackLabelFraction 0.2 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_bed_shuffle.png

# test_bedGraphMatrixTrack:
bin/pgt --tracks ./pygenometracks/tests/test_data/bedgraph.ini --region X:2850000-3150000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_bedgraph.png
Expand Down
52 changes: 52 additions & 0 deletions pygenometracks/tests/test_bed_and_gtf_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,35 @@
with open(os.path.join(ROOT, "bed_colormap_genes.ini"), 'w') as fh:
fh.write(browser_tracks)

browser_tracks = """
[genes]
file = dm3_genes_withrgbandscore.bed.gz
title = bed color = Reds
color = Reds
height = 4
[spacer]
[genes]
file = dm3_genes_withrgbandscore_shuffled.bed.gz
title = bed color = Reds bed is not sorted
color = Reds
height = 4
[spacer]
[genes]
file = dm3_genes_withrgbandscore_shuffled.bed.gz
title = bed color = Reds global_max_row = true and bed is not sorted
color = Reds
global_max_row = true
height = 4
[x-axis]
"""
with open(os.path.join(ROOT, "bed_shuffle.ini"), 'w') as fh:
fh.write(browser_tracks)

tolerance = 13 # default matplotlib pixed difference tolerance


Expand Down Expand Up @@ -822,3 +851,26 @@ def test_plot_tracks_bed_scores():
assert res is None, res

os.remove(outfile.name)


def test_bed_shuffle():
extension = '.png'

outfile = NamedTemporaryFile(suffix=extension, prefix='pyGenomeTracks_test_',
delete=False)
ini_file = os.path.join(ROOT, "bed_shuffle.ini")
bed_file = os.path.join(ROOT, 'regions_chr1XY.bed')
args = f"--tracks {ini_file} --BED {bed_file} "\
"--trackLabelFraction 0.2 --width 38 --dpi 130 "\
f"--outFileName {outfile.name}".split()
pygenometracks.plotTracks.main(args)
for region in ['chr1:0-500000', 'chrX:2500000-2600000', 'chrY:0-1000000']:
region_str = region.replace(':', '-')
output_file = outfile.name[:-4] + '_' + region_str + extension
expected_file = os.path.join(ROOT, 'master_bed_shuffle_'
+ region_str + extension)
res = compare_images(expected_file,
output_file, tolerance)
assert res is None, res

os.remove(output_file)
25 changes: 25 additions & 0 deletions pygenometracks/tests/test_data/bed_shuffle.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

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

[spacer]

[genes]
file = dm3_genes_withrgbandscore_shuffled.bed.gz
title = bed color = Reds bed is not sorted
color = Reds
height = 4

[spacer]

[genes]
file = dm3_genes_withrgbandscore_shuffled.bed.gz
title = bed color = Reds global_max_row = true and bed is not sorted
color = Reds
global_max_row = true
height = 4

[x-axis]
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ file_type = hic_matrix
height = 5
show_masked_bins = true

[spacer]

[genes]
file = dm3_genes_withrgbandscore_shuffled.bed.gz
[x-axis]
Binary file modified pygenometracks/tests/test_data/dm3_genes_withrgbandscore.bed.gz
Binary file not shown.
Binary file not shown.
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.
3 changes: 0 additions & 3 deletions pygenometracks/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ def file_to_intervaltree(file_name, plot_regions=None):
file_h = opener(file_to_open)
line_number = 0
valid_intervals = 0
prev_chrom = None
prev_start = -1
prev_line = None
interval_tree = {}
min_value = float('Inf')
max_value = -float('Inf')
Expand Down

0 comments on commit 1a47fd1

Please sign in to comment.