Skip to content

Commit

Permalink
Merge pull request #163 from deeptools/master-patch
Browse files Browse the repository at this point in the history
Master patch
  • Loading branch information
joachimwolff authored Dec 28, 2017
2 parents ee161a2 + 21b22e0 commit 8e5298c
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 31 deletions.
2 changes: 1 addition & 1 deletion docs/content/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Requirements
* Python 2.7 or 3.6
* numpy >= 1.12.1
* scipy >= 0.19.0
* matplotlib >= 2.0.0
* matplotlib == 2.1.1
* pysam >= 0.11.2
* intervaltree >= 2.1.0
* biopython >= 1.68
Expand Down
17 changes: 16 additions & 1 deletion hicexplorer/hicCorrectMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,17 @@ def value_to_mad(self, value):
return the mad value for a given value
based on the data
"""

log.debug("self.median: {}".format(self.median))
diff = value - self.median
log.debug("diff: {}".format(diff))
log.debug("self.med_abs_deviation: {}".format(self.med_abs_deviation))
log.debug("self.mad_b_value: {}".format(self.mad_b_value))
log.debug("all together: {}".format(self.mad_b_value * diff / self.med_abs_deviation))
# workaround for 'Axis limits cannot be NaN or Inf' bug in version 2.1.1
# prevent dividing by 0!!!
if self.med_abs_deviation == 0.0:
return self.mad_b_value * diff

return self.mad_b_value * diff / self.med_abs_deviation

def mad_to_value(self, mad):
Expand Down Expand Up @@ -391,6 +400,12 @@ def plot_histogram(row_sum_values, mad_values, ax1, title=None):
# update second axis values by mapping the min max
# of the main axis to the translated values
# into modified z score.

# workaround for 'Axis limits cannot be NaN or Inf' bug in version 2.1.1
log.debug("ax1.get_xlim(): {}".format(ax1.get_xlim()))
log.debug("np.array(ax1.get_xlim()): {}".format(np.array(ax1.get_xlim())))
log.debug("mad_values.value_to_mad(np.array(ax1.get_xlim())): {}".format(mad_values.value_to_mad(np.array(ax1.get_xlim()))))

ax2.set_xlim(mad_values.value_to_mad(np.array(ax1.get_xlim())))

# get first local mininum value
Expand Down
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.
11 changes: 7 additions & 4 deletions hicexplorer/test/test_hicPlotDistVsCounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import matplotlib as mpl
mpl.use('agg')
from matplotlib.testing.compare import compare_images
import os.path


Expand All @@ -15,10 +14,14 @@ def test_plot():

outfile = NamedTemporaryFile(suffix='.png', prefix='plotFile', delete=False)
matrix = ROOT + 'small_test_matrix_50kb_res.h5'
args = "--matrices {} --plotFile {}".format(matrix, outfile.name).split()
args = "--matrices {} --plotFile {} --plotsize 6 4".format(matrix, outfile.name).split()
hicPlotDistVsCounts.main(args)

res = compare_images(ROOT + 'hicPlotDistVsCounts/dist_vs_counts.png', outfile.name, tol=40)
assert res is None, res
# don't using matplotlib compare images not anymore
# because matplotlib is, depending on version, implementation or context,
# slightly different images
size_new = os.path.getsize(outfile.name)
size_reference = os.path.getsize(ROOT + 'hicPlotDistVsCounts/dist_vs_counts.png',)
assert abs(size_new - size_reference) < 3000

os.remove(outfile.name)
47 changes: 24 additions & 23 deletions hicexplorer/test/test_hicPlotMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
mem = virtual_memory()
memory = mem.total / 2**30
import hicexplorer.hicPlotMatrix
tolerance = 13 # default matplotlib pixed difference tolerance
tolerance = 60 # default matplotlib pixed difference tolerance
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/test_data/"

# memory in GB the test computer needs to have to run the test case
LOW_MEMORY = 2
MID_MEMORY = 7
HIGH_MEMORY = 20
HIGH_MEMORY = 200

REMOVE_OUTPUT = True
# DIFF = 60


@pytest.mark.skipif(MID_MEMORY > memory,
Expand Down Expand Up @@ -137,7 +138,7 @@ def test_hicPlotMatrix_cool_region1_region2():
args = "--matrix {0}/Li_et_al_2015.cool --region chrX:3000000-3500000 --region2 chrX:3100000-3600000 " \
"--outFileName {1} ".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_chrX30-35-chrX31-36_cool.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_chrX30-35-chrX31-36_cool.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -152,7 +153,7 @@ def test_hicPlotMatrix_cool_region1():
args = "--matrix {0}/Li_et_al_2015.cool --region X:3000000-3500000 " \
"--outFileName {1} ".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_chrX30-35_cool.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_chrX30-35_cool.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -167,7 +168,7 @@ def test_hicPlotMatrix_cool_log1p():
args = "--matrix {0}/Li_et_al_2015.cool --log1p " \
"--outFileName {1} ".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_cool_log1p.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_cool_log1p.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -182,7 +183,7 @@ def test_hicPlotMatrix_cool_log():
args = "--matrix {0}/Li_et_al_2015.cool --log " \
"--outFileName {1} ".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_cool_log.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_cool_log.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -197,7 +198,7 @@ def test_hicPlotMatrix_cool_full():
args = "--matrix {0}/Li_et_al_2015.cool " \
"--outFileName {1} ".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_cool.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_cool.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -212,7 +213,7 @@ def test_hicPlotMatrix_h5_log1p():
args = "--matrix {0}/Li_et_al_2015.h5 --log1p " \
"--outFileName {1} ".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_h5_log1p.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_h5_log1p.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -227,7 +228,7 @@ def test_hicPlotMatrix_h5_log():
args = "--matrix {0}/Li_et_al_2015.h5 --log " \
"--outFileName {1} ".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_h5_log.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_h5_log.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -242,7 +243,7 @@ def test_hicPlotMatrix_h5_full():
args = "--matrix {0}/Li_et_al_2015.h5 " \
"--outFileName {1} ".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_h5.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_h5.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -257,7 +258,7 @@ def test_hicPlotMatrix_cool_log_region1_region2():
args = "--matrix {0}/Li_et_al_2015.cool --region chrX:3000000-3500000 --region2 chrX:3100000-3600000 " \
"--outFileName {1} --log ".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_chrX30-35-chrX31-36_cool_log.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_chrX30-35-chrX31-36_cool_log.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -272,7 +273,7 @@ def test_hicPlotMatrix_cool_log_region1_region2_without_cool_suffix():
args = "--matrix {0}/Li_et_al_2015 --region chrX:3000000-3500000 --region2 chrX:3100000-3600000 " \
"--outFileName {1} --log ".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_chrX30-35-chrX31-36_cool_log.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_chrX30-35-chrX31-36_cool_log.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -287,7 +288,7 @@ def test_hicPlotMatrix_cool_log1p_region1_region2():
args = "--matrix {0}/Li_et_al_2015.cool --region chrX:3000000-3500000 --region2 chrX:3100000-3600000 " \
"--outFileName {1} --log1p ".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_chrX30-35-chrX31-36_cool_log1p.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_chrX30-35-chrX31-36_cool_log1p.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -302,7 +303,7 @@ def test_hicPlotMatrix_perChr():
args = "--matrix {0}/small_test_matrix_50kb_res.h5 --perChr " \
"--outFileName {1} ".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_matrix_50kb_res_perChr.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_matrix_50kb_res_perChr.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -317,7 +318,7 @@ def test_hicPlotMatrix_perChr_without_h5_suffix():
args = "--matrix {0}/small_test_matrix_50kb_res --perChr " \
"--outFileName {1} ".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_matrix_50kb_res_perChr.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_matrix_50kb_res_perChr.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -332,7 +333,7 @@ def test_hicPlotMatrix_cool_perChr_log():
args = "--matrix {0}/small_test_matrix_50kb_res.h5 --perChr " \
"--outFileName {1} --log ".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_matrix_50kb_res_perChr_log.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_matrix_50kb_res_perChr_log.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -347,7 +348,7 @@ def test_hicPlotMatrix_cool_perChr_log1p_chromosomeOrder():
args = "--matrix {0}/small_test_matrix_50kb_res.h5 --perChr " \
"--outFileName {1} --log1p --chromosomeOrder chr2L chr3L chr3R chr2R".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_matrix_perChr_log1p_chromosomeOrder.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_matrix_perChr_log1p_chromosomeOrder.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -362,7 +363,7 @@ def test_hicPlotMatrix_perChr_pca1_bigwig():
args = "--matrix {0}/hicTransform/pearson_small_50kb.h5 --perChr " \
"--outFileName {1} --pca {2}".format(ROOT, outfile.name, ROOT + "hicPCA/pca1.bw").split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_matrix_50kb_pearson_pca1_plot.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_matrix_50kb_pearson_pca1_plot.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -377,7 +378,7 @@ def test_hicPlotMatrix_perChr_pca2_bedgraph():
args = "--matrix {0}/hicTransform/pearson_small_50kb.h5 --perChr " \
"--outFileName {1} --pca {2}".format(ROOT, outfile.name, ROOT + "hicPCA/pca2.bedgraph").split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_matrix_50kb_pearson_pca2_plot.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_matrix_50kb_pearson_pca2_plot.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -392,7 +393,7 @@ def test_hicPlotMatrix_region_pca1_colormap_bedgraph():
args = "--matrix {0}/hicTransform/pearson_small_50kb.h5 --region chr2L " \
"--outFileName {1} --pca {2} --colorMap hot".format(ROOT, outfile.name, ROOT + "hicPCA/pca1.bedgraph").split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_50kb_pearson_pca1_plot_region__colormap_hot_chr2L.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_50kb_pearson_pca1_plot_region__colormap_hot_chr2L.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -407,7 +408,7 @@ def test_hicPlotMatrix_region_start_end_pca1_colormap_bedgraph():
args = "--matrix {0}/hicTransform/pearson_small_50kb.h5 --region chr2L:15000000-20000000 " \
"--outFileName {1} --pca {2} --colorMap hot".format(ROOT, outfile.name, ROOT + "hicPCA/pca1.bedgraph").split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_50kb_pearson_pca1_plot_region__colormap_hot_chr2L_15mb-20mb.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_50kb_pearson_pca1_plot_region__colormap_hot_chr2L_15mb-20mb.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -422,7 +423,7 @@ def test_hicPlotMatrix_region_pca1_colormap_bigwig():
args = "--matrix {0}/hicTransform/pearson_small_50kb.h5 --region chr2L " \
"--outFileName {1} --pca {2} --colorMap hot".format(ROOT, outfile.name, ROOT + "hicPCA/pca1.bw").split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_50kb_pearson_pca1_plot_region__colormap_hot_chr2L_bw.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_50kb_pearson_pca1_plot_region__colormap_hot_chr2L_bw.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
Expand All @@ -437,7 +438,7 @@ def test_hicPlotMatrix_region_start_end_pca1_colormap_bigwig():
args = "--matrix {0}/hicTransform/pearson_small_50kb.h5 --region chr2L:15000000-20000000 " \
"--outFileName {1} --pca {2} --colorMap hot".format(ROOT, outfile.name, ROOT + "hicPCA/pca1.bw").split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_50kb_pearson_pca1_plot_region__colormap_hot_chr2L_15mb-20mb_bw.png', outfile.name, tol=40)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_50kb_pearson_pca1_plot_region__colormap_hot_chr2L_15mb-20mb_bw.png', outfile.name, tol=tolerance)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy >= 1.12.1
scipy >= 0.19.0
matplotlib = 2.0.0
matplotlib == 2.1.1
pysam >= 0.11.2
intervaltree >= 2.1.0
biopython >= 1.68
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def checkProgramIsInstalled(self, program, args, where_to_download,

install_requires_py = ["numpy >= 1.12.1",
"scipy >= 0.19.0",
"matplotlib == 2.0.0",
"matplotlib == 2.1.1",
"pysam >= 0.11.2.2",
"intervaltree >= 2.1.0",
"biopython >= 1.68",
Expand Down

0 comments on commit 8e5298c

Please sign in to comment.