Skip to content

Commit

Permalink
Merge pull request #257 from lldelisle/increaseCoverage
Browse files Browse the repository at this point in the history
Increase coverage
  • Loading branch information
lldelisle authored Jul 16, 2020
2 parents 302e3df + 2ed17f2 commit 810fa31
Show file tree
Hide file tree
Showing 77 changed files with 1,738 additions and 141 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pip-log.txt

# Unit test / coverage reports
.coverage
coverage.*
.tox
nosetests.xml
htmlcov
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![PyPI Version](https://img.shields.io/pypi/v/pyGenomeTracks.svg?style=plastic)](https://pypi.org/project/pyGenomeTracks/) [![bioconda-badge](https://img.shields.io/conda/vn/bioconda/pyGenomeTracks.svg?style=plastic)](https://anaconda.org/bioconda/pygenometracks)
[![bioconda-badge](https://img.shields.io/badge/install%20with-bioconda-brightgreen.svg?style=plastic)](http://bioconda.github.io)
[![Build Status](https://travis-ci.org/deeptools/pyGenomeTracks.svg?branch=master)](https://travis-ci.org/deeptools/pyGenomeTracks)

![Coverage](./docs/coverage.svg)

pyGenomeTracks
==============
Expand Down
21 changes: 21 additions & 0 deletions docs/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 0 additions & 10 deletions pygenometracks/readBed.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,6 @@ def get_no_comment_line(self):
self.line_number += 1
return line

def next(self):
"""
:return: bedInterval object
"""
line = self.get_no_comment_line()

bed = self.get_bed_interval(line)

return bed

def __next__(self):
"""
:return: bedInterval object
Expand Down
8 changes: 0 additions & 8 deletions pygenometracks/readGtf.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ def __init__(self, file_path, prefered_name="transcript_name",
def __iter__(self):
return self

def next(self):
"""
:return: bedInterval object
"""
bed = self.get_bed_interval()

return bed

def __next__(self):
"""
:return: bedInterval object
Expand Down
13 changes: 13 additions & 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_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
bin/pgt --tracks ./pygenometracks/tests/test_data/bed_vlines.ini --BED ./pygenometracks/tests/test_data/regionsXfakeChr.bed --trackLabelFraction 0.5 --width 38 --dpi 130 --trackLabelHAlign center -o ./pygenometracks/tests/test_data/master_bed_vlines.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 All @@ -22,6 +23,7 @@ bin/pgt --tracks pygenometracks/tests/test_data/invalid_blockCount.ini --region
bin/pgt --tracks pygenometracks/tests/test_data/invalid_CDScoo.ini --region chrX:15000-24000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o pygenometracks/tests/test_data/master_invalid_CDScoo.png
bin/pgt --tracks pygenometracks/tests/test_data/invalid_blocks.ini --region chrX:15000-24000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o pygenometracks/tests/test_data/master_invalid_blocks.png
bin/pgt --tracks pygenometracks/tests/test_data/invalid_score.ini --region chrX:15000-24000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o pygenometracks/tests/test_data/master_invalid_score.png
bin/pgt --tracks pygenometracks/tests/test_data/bed_different_UTR.ini --region chr1:0-500 --trackLabelFraction 0.2 --width 38 --dpi 130 -o pygenometracks/tests/test_data/master_different_UTR.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 All @@ -31,13 +33,17 @@ bin/pgt --tracks ./pygenometracks/tests/test_data/bedgraph_useMid.ini --BED ./py
bin/pgt --tracks ./pygenometracks/tests/test_data/bedgraph_useMid.ini --region chr2:73,800,000-75,744,000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_bedgraph_useMid.pdf
bin/pgt --tracks ./pygenometracks/tests/test_data/operation_bdg.ini --region X:2700000-3100000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_operation_bdg.png
bin/pgt --tracks ./pygenometracks/tests/test_data/bedgraph_withNA.ini --region X:2700000-3100000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_bedgraph_withNA.png
bin/pgt --tracks ./pygenometracks/tests/test_data/bedgraph_negative.ini --region X:2700000-3100000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_negative.png

# test bigWigTrack:
bin/pgt --tracks ./pygenometracks/tests/test_data/bigwig.ini --region X:2700000-3100000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_bigwig.png
bin/pgt --tracks ./pygenometracks/tests/test_data/alpha.ini --region X:2700000-3100000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_alpha.png
bin/pgt --tracks ./pygenometracks/tests/test_data/hlines.ini --region X:2700000-3100000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_hlines.png
bin/pgt --tracks ./pygenometracks/tests/test_data/operation.ini --region X:2700000-3100000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_operation.png
bin/pgt --tracks ./pygenometracks/tests/test_data/operation.ini --region fakeChr:2700000-3100000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_operation_fakeChr.png
bin/pgt --tracks ./pygenometracks/tests/test_data/grid.ini --region X:2700000-3100000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_grid.png
bin/pgt --tracks ./pygenometracks/tests/test_data/example_bigwig.ini --region X:2,500,000-3,000,000 -o ./pygenometracks/tests/test_data/master_example_bigwig.png
bin/pgt --tracks ./pygenometracks/tests/test_data/example_op.ini --region 2L:0-1000 -o ./pygenometracks/tests/test_data/master_operation_2L.png

# test_epilogosTrack:
bin/pgt --tracks ./pygenometracks/tests/test_data/epilogos.ini --region X:3100000-3150000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_epilogos.png
Expand All @@ -52,7 +58,12 @@ bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_small_test.
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_small_test.ini --region 1:0-200000 --trackLabelFraction 0.23 --width 38 -o ./pygenometracks/tests/test_data/master_plot_hic_small_test.png
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_small_test.ini --region chrM:0-20000 --trackLabelFraction 0.23 --width 38 -o ./pygenometracks/tests/test_data/master_plot_hic_small_test_chrM.png
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_small_test.ini --region chr1:0-5000 --trackLabelFraction 0.23 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_hic_small_test_small_region.png
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_small_test.ini --region Y:90000000-100000000 --trackLabelFraction 0.23 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_hic_small_test_above_chrY.png
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_small_test_2.ini --region chr1:0-100000 --trackLabelFraction 0.23 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_hic_small_test_2.png
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_one_interaction_cool.ini --BED ./pygenometracks/tests/test_data/regions_chr1XY.bed --trackLabelFraction 0.23 --width 38 -o ./pygenometracks/tests/test_data/master_plot_hic_one_interaction_withBED.png
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_one_interaction_cool.ini --region chrY:0-1000000 --trackLabelFraction 0.23 --width 38 -o ./pygenometracks/tests/test_data/master_plot_hic_one_interaction_withRegion_chrY-0-1000000.png
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_one_interaction_diag_h5.ini --region chrY:0-1000000 --trackLabelFraction 0.23 --width 38 -o ./pygenometracks/tests/test_data/master_plot_hic_one_interaction_diag_chrY-0-1000000.png
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_small_test_3.ini --region chr1:0-200000 --trackLabelFraction 0.23 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_hic_small_test_3.png

# test_logScale:
bin/pgt --tracks ./pygenometracks/tests/test_data/log1p.ini --region X:2700000-3100000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_log1p.png
Expand Down Expand Up @@ -84,10 +95,12 @@ bin/pgt --tracks ./pygenometracks/tests/test_data/title.ini --region X:3000000-3
bin/pgt --tracks ./pygenometracks/tests/test_data/title.ini --region X:3000000-3500000 --trackLabelFraction 0.5 --trackLabelHAlign right --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_title_0.5_ral.png
bin/pgt --tracks ./pygenometracks/tests/test_data/title.ini --region X:3000000-3500000 --trackLabelFraction 0.5 --trackLabelHAlign center --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_title_0.5_cal.png
bin/pgt --tracks ./pygenometracks/tests/test_data/title.ini --region X:3000000-3500000 --trackLabelFraction 0.5 --trackLabelHAlign center --width 38 --dpi 250 -o ./pygenometracks/tests/test_data/master_title_0.5_cal_d250.png
bin/pgt --tracks ./pygenometracks/tests/test_data/title.ini --region X:3000000-3500000 --height 10 --title force_height -o ./pygenometracks/tests/test_data/master_title_force_height.png

# tests arcs
bin/pgt --tracks ./pygenometracks/tests/test_data/short_long_arcs.ini --region chr11:40000000-46000000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o pygenometracks/tests/test_data/master_short_long_arcs.png
bin/pgt --tracks ./pygenometracks/tests/test_data/arcs_use_middle.ini --region X:3000000-3300000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o pygenometracks/tests/test_data/master_arcs_use_middle.png
bin/pgt --tracks ./pygenometracks/tests/test_data/arcs_no_score.ini --region X:3000000-3300000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o pygenometracks/tests/test_data/master_arcs_no_score.png

# tests scaleBar
bin/pgt --tracks pygenometracks/tests/test_data/scale_bar.ini --region X:3200000-3300000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o pygenometracks/tests/test_data/master_scale_bar_zoom.png
Expand Down
160 changes: 149 additions & 11 deletions pygenometracks/tests/test_arcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from tempfile import NamedTemporaryFile
import os.path
import pygenometracks.plotTracks
from pygenometracks.utilities import InputError
mpl.use('agg')

ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)),
Expand Down Expand Up @@ -99,6 +100,9 @@
with open(os.path.join(ROOT, "short_long_arcs.ini"), 'w') as fh:
fh.write(browser_tracks)

with open(os.path.join(ROOT, "short_long_arcs_incorrect.ini"), 'w') as fh:
fh.write(browser_tracks.replace('compact_arcs_level = 2', 'compact_arcs_level = 2\nylim=1000000'))

browser_tracks = """
[x-axis]
where = top
Expand Down Expand Up @@ -160,25 +164,101 @@
with open(os.path.join(ROOT, "arcs_use_middle.ini"), 'w') as fh:
fh.write(browser_tracks)


browser_tracks = """
[arcs]
title = loop with scores
file = test_high_score.arcs
color = cividis
height = 2
links_type = loops
[arcs]
title = arcs with scores
file = test_high_score.arcs
color = cividis
height = 2
min_value = 0
max_value = 80
[arcs]
title = arcs without scores
file = test_noscore.arcs
color = blue
line_width = 0.5
height = 2
"""
with open(os.path.join(ROOT, "arcs_no_score.ini"), 'w') as fh:
fh.write(browser_tracks)


browser_tracks = """
[arcs]
title = loop with scores
file = test_high_score.arcs
color = cividis
height = 2
links_type = loops
[arcs]
title = arcs with scores
file = test_high_score.arcs
color = cividis
height = 2
min_value = 0
max_value = 80
[arcs]
title = arcs without scores
file = test_noscore.arcs
color = cividis
height = 2
"""
with open(os.path.join(ROOT, "arcs_no_score_incorrect.ini"), 'w') as fh:
fh.write(browser_tracks)

with open(os.path.join(ROOT, "arcs_no_score_invalid_score.ini"), 'w') as fh:
fh.write(browser_tracks.replace('test_noscore.arcs',
'arcs_invalid_score.arcs'))

with open(os.path.join(ROOT, "arcs_no_score_invalid_score2.ini"), 'w') as fh:
fh.write(browser_tracks.replace('test_noscore.arcs',
'arcs_invalid_score2.arcs'))

for suf in ['', '2']:
browser_tracks = f"""
[arcs]
file = arcs_invalid{suf}.arcs
"""
with open(os.path.join(ROOT, f"arcs_invalid{suf}.ini"), 'w') as fh:
fh.write(browser_tracks)

tolerance = 13 # default matplotlib pixed difference tolerance


def test_short_long_arcs():

outfile = NamedTemporaryFile(suffix='.png', prefix='pyGenomeTracks_test_',
delete=False)
ini_file = os.path.join(ROOT, "short_long_arcs.ini")
region = "chr11:40000000-46000000"
expected_file = os.path.join(ROOT, 'master_short_long_arcs.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
for suf in ['', '_incorrect']:
ini_file = os.path.join(ROOT, f"short_long_arcs{suf}.ini")
region = "chr11:40000000-46000000"
expected_file = os.path.join(ROOT, 'master_short_long_arcs.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)
os.remove(outfile.name)

# Remove incorrect ini file
if 'incorrect' in ini_file:
os.remove(ini_file)


def test_use_middle_arcs():
Expand All @@ -197,3 +277,61 @@ def test_use_middle_arcs():
assert res is None, res

os.remove(outfile.name)


def test_arcs_no_score():

outfile = NamedTemporaryFile(suffix='.png', prefix='pyGenomeTracks_test_',
delete=False)
for suf in ['', '_incorrect', '_invalid_score', '_invalid_score2']:
ini_file = os.path.join(ROOT, f"arcs_no_score{suf}.ini")
region = "X:3000000-3300000"
expected_file = os.path.join(ROOT, 'master_arcs_no_score.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)
# Remove the incorrect ini files or using invalid files
if 'incorrect' in ini_file or 'invalid' in ini_file:
os.remove(ini_file)


def test_arcs_invalid():

outfile = NamedTemporaryFile(suffix='.png', prefix='pyGenomeTracks_test_',
delete=True)
ini_file = os.path.join(ROOT, "arcs_invalid.ini")
region = "X:3000000-3300000"
args = f"--tracks {ini_file} --region {region} "\
"--trackLabelFraction 0.2 --width 38 --dpi 130 "\
f"--outFileName {outfile.name}".split()
try:
pygenometracks.plotTracks.main(args)
except InputError as e:
assert 'not enough values to unpack (expected 6, got 5)' in str(e)
else:
raise Exception("The arcs_invalid should fail.")
os.remove(ini_file)


def test_arcs_invalid2():

outfile = NamedTemporaryFile(suffix='.png', prefix='pyGenomeTracks_test_',
delete=True)
ini_file = os.path.join(ROOT, "arcs_invalid2.ini")
region = "X:3000000-3300000"
args = f"--tracks {ini_file} --region {region} "\
"--trackLabelFraction 0.2 --width 38 --dpi 130 "\
f"--outFileName {outfile.name}".split()
try:
pygenometracks.plotTracks.main(args)
except InputError as e:
assert 'One of the fields is not an integer.' in str(e)
else:
raise Exception("The arcs_invalid2 should fail.")
os.remove(ini_file)
Loading

0 comments on commit 810fa31

Please sign in to comment.