|
| 1 | +import deeptools.plotCorrelation as pc |
| 2 | + |
| 3 | +import os.path |
| 4 | +from os import unlink |
| 5 | +from matplotlib.testing.compare import compare_images |
| 6 | + |
| 7 | + |
| 8 | +ROOT = os.path.dirname(os.path.abspath(__file__)) + "/test_data/" |
| 9 | +COR_DATA_IN1 = ROOT + "multiBamSummary_result1.npz" |
| 10 | +COR_PLOT_1 = ROOT + "plotCorrelation_result1.png" |
| 11 | +COR_PLOT_2 = ROOT + "plotCorrelation_result2.png" |
| 12 | + |
| 13 | + |
| 14 | +def test_correlation_plot_with_minimal_options(): |
| 15 | + """ |
| 16 | + Test minimal command line args for correlation plot |
| 17 | + with output as correlation matrix along with matrix |
| 18 | + """ |
| 19 | + out_matrix = '/tmp/correlation_matrix.tsv' |
| 20 | + out_png = '/tmp/correlation_plot1.png' |
| 21 | + args = "--corData {} -p heatmap -c pearson -o {} --outFileCorMatrix {}".format(COR_DATA_IN1, out_png, out_matrix).split() |
| 22 | + pc.main(args) |
| 23 | + |
| 24 | + _foo = open(out_matrix, "r") |
| 25 | + resp = _foo.readlines()[2] |
| 26 | + _foo.close() |
| 27 | + expected = "'bowtie2 test1.bam'\t1.0000\t1.0000\n" |
| 28 | + assert expected in resp, f"'{expected}' not found in '{resp}'" |
| 29 | + |
| 30 | + res = compare_images(COR_PLOT_1, out_png, 50) |
| 31 | + assert res is None, "Plots do not match" |
| 32 | + unlink(out_png) |
| 33 | + |
| 34 | + |
| 35 | +def test_correlation_plot_scatter(): |
| 36 | + """ |
| 37 | + Test command line args for correlation plot with output as scatter plot |
| 38 | + """ |
| 39 | + out_png2 = '/tmp/correlation_plot2.png' |
| 40 | + args = "--corData {} -p scatterplot -c pearson -o {}".format(COR_DATA_IN1, out_png2).split() |
| 41 | + pc.main(args) |
| 42 | + |
| 43 | + res = compare_images(COR_PLOT_2, out_png2, 50) |
| 44 | + assert res is None, "Plots do not match" |
| 45 | + unlink(out_png2) |
0 commit comments