diff --git a/hicexplorer/test/general/test_chicAggregateStatistic.py b/hicexplorer/test/general/test_chicAggregateStatistic.py index 110c581f..aaffeb2f 100644 --- a/hicexplorer/test/general/test_chicAggregateStatistic.py +++ b/hicexplorer/test/general/test_chicAggregateStatistic.py @@ -1,12 +1,13 @@ +from hicexplorer import chicAggregateStatistic +from tempfile import NamedTemporaryFile, mkdtemp +import os +import pytest import warnings warnings.simplefilter(action="ignore", category=RuntimeWarning) warnings.simplefilter(action="ignore", category=PendingDeprecationWarning) -import pytest -import os -from tempfile import NamedTemporaryFile, mkdtemp -from hicexplorer import chicAggregateStatistic -ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "test_data/cHi-C/") +ROOT = os.path.join(os.path.dirname(os.path.dirname( + os.path.abspath(__file__))), "test_data/cHi-C/") def are_files_equal(file1, file2, delta=2, skip=0): @@ -35,17 +36,20 @@ def test_regular_mode(): output_folder = mkdtemp(prefix="output_") args = "--interactionFile {} {} --targetFile {} --outFileNameSuffix {} \ - --outputFolder {}".format(ROOT + 'chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', - ROOT + 'chicViewpoint/output_1/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.txt ', - ROOT + 'chicSignificantInteractions/output_5_target/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_target.txt', - 'aggregated.txt', - output_folder).split() + --outputFolder {} -t {}".format(ROOT + 'chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', + ROOT + 'chicViewpoint/output_1/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.txt ', + ROOT + 'chicSignificantInteractions/output_5_target/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_target.txt', + 'aggregated.txt', + output_folder, 1).split() chicAggregateStatistic.main(args) - assert are_files_equal(ROOT + "chicAggregateStatistic/regular_mode/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt", output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt') - assert are_files_equal(ROOT + "chicAggregateStatistic/regular_mode/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt", output_folder + '/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt') + assert are_files_equal(ROOT + "chicAggregateStatistic/regular_mode/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt", + output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt') + assert are_files_equal(ROOT + "chicAggregateStatistic/regular_mode/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt", + output_folder + '/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt') - assert set(os.listdir(ROOT + "chicAggregateStatistic/regular_mode/")) == set(os.listdir(output_folder)) + assert set(os.listdir(ROOT + "chicAggregateStatistic/regular_mode/") + ) == set(os.listdir(output_folder)) def test_batch_mode(): @@ -54,23 +58,31 @@ def test_batch_mode(): outfile.close() args = "--interactionFile {} --targetFile {} --outFileNameSuffix {} \ - --outputFolder {} -iff {} -tff {} -w {} -bm".format(ROOT + 'chicViewpoint/fileNames_two_matrices.txt', - ROOT + 'chicSignificantInteractions/output_5_target_list.txt', - 'aggregated.txt', - output_folder, - ROOT + 'chicViewpoint/output_1', - ROOT + 'chicSignificantInteractions/output_5_target', - outfile.name).split() + --outputFolder {} -iff {} -tff {} -w {} -bm -t {}".format(ROOT + 'chicViewpoint/fileNames_two_matrices.txt', + ROOT + 'chicSignificantInteractions/output_5_target_list.txt', + 'aggregated.txt', + output_folder, + ROOT + 'chicViewpoint/output_1', + ROOT + 'chicSignificantInteractions/output_5_target', + outfile.name, 1).split() chicAggregateStatistic.main(args) - assert are_files_equal(ROOT + "chicAggregateStatistic/batch_mode_file_names.txt", outfile.name) + assert are_files_equal( + ROOT + "chicAggregateStatistic/batch_mode_file_names.txt", outfile.name) - assert are_files_equal(ROOT + "chicAggregateStatistic/batch_mode/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt", output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt') - assert are_files_equal(ROOT + "chicAggregateStatistic/batch_mode/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt", output_folder + '/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt') + assert are_files_equal(ROOT + "chicAggregateStatistic/batch_mode/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt", + output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt') + assert are_files_equal(ROOT + "chicAggregateStatistic/batch_mode/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt", + output_folder + '/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt') - assert are_files_equal(ROOT + "chicAggregateStatistic/batch_mode/FL-E13-5_chr1_chr1_4487435_4487435_Sox17_aggregated.txt", output_folder + '/FL-E13-5_chr1_chr1_4487435_4487435_Sox17_aggregated.txt') - assert are_files_equal(ROOT + "chicAggregateStatistic/batch_mode/MB-E10-5_chr1_chr1_4487435_4487435_Sox17_aggregated.txt", output_folder + '/MB-E10-5_chr1_chr1_4487435_4487435_Sox17_aggregated.txt') + assert are_files_equal(ROOT + "chicAggregateStatistic/batch_mode/FL-E13-5_chr1_chr1_4487435_4487435_Sox17_aggregated.txt", + output_folder + '/FL-E13-5_chr1_chr1_4487435_4487435_Sox17_aggregated.txt') + assert are_files_equal(ROOT + "chicAggregateStatistic/batch_mode/MB-E10-5_chr1_chr1_4487435_4487435_Sox17_aggregated.txt", + output_folder + '/MB-E10-5_chr1_chr1_4487435_4487435_Sox17_aggregated.txt') - assert are_files_equal(ROOT + "chicAggregateStatistic/batch_mode/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d_aggregated.txt", output_folder + '/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d_aggregated.txt') - assert are_files_equal(ROOT + "chicAggregateStatistic/batch_mode/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_aggregated.txt", output_folder + '/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_aggregated.txt') + assert are_files_equal(ROOT + "chicAggregateStatistic/batch_mode/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d_aggregated.txt", + output_folder + '/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d_aggregated.txt') + assert are_files_equal(ROOT + "chicAggregateStatistic/batch_mode/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_aggregated.txt", + output_folder + '/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_aggregated.txt') - assert set(os.listdir(ROOT + "chicAggregateStatistic/batch_mode/")) == set(os.listdir(output_folder)) + assert set(os.listdir(ROOT + "chicAggregateStatistic/batch_mode/") + ) == set(os.listdir(output_folder)) diff --git a/hicexplorer/test/general/test_chicDifferentialTest.py b/hicexplorer/test/general/test_chicDifferentialTest.py index 4cd8a775..256d6cc3 100644 --- a/hicexplorer/test/general/test_chicDifferentialTest.py +++ b/hicexplorer/test/general/test_chicDifferentialTest.py @@ -1,12 +1,13 @@ +from hicexplorer import chicDifferentialTest +from tempfile import NamedTemporaryFile, mkdtemp +import os +import pytest import warnings warnings.simplefilter(action="ignore", category=RuntimeWarning) warnings.simplefilter(action="ignore", category=PendingDeprecationWarning) -import pytest -import os -from tempfile import NamedTemporaryFile, mkdtemp -from hicexplorer import chicDifferentialTest -ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "test_data/cHi-C/") +ROOT = os.path.join(os.path.dirname(os.path.dirname( + os.path.abspath(__file__))), "test_data/cHi-C/") def are_files_equal(file1, file2, delta=2, skip=0): @@ -35,86 +36,114 @@ def test_regular_mode_fisher(): output_folder = mkdtemp(prefix="output_") - args = "--interactionFile {} {} --alpha {} --statisticTest {} --outputFolder {}\ + args = "--interactionFile {} {} --alpha {} --statisticTest {} --outputFolder {} -t {}\ ".format(ROOT + 'chicAggregateStatistic/batch_mode/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt', ROOT + 'chicAggregateStatistic/batch_mode/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt ', 0.5, 'fisher', - output_folder).split() + output_folder, 1).split() chicDifferentialTest.main(args) - assert are_files_equal(ROOT + "chicDifferentialTest/regular_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/regular_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/regular_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt') - assert set(os.listdir(ROOT + "chicDifferentialTest/regular_mode_fisher/")) == set(os.listdir(output_folder)) + assert are_files_equal(ROOT + "chicDifferentialTest/regular_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/regular_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/regular_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt') + assert set(os.listdir(ROOT + "chicDifferentialTest/regular_mode_fisher/") + ) == set(os.listdir(output_folder)) def test_regular_mode_chi2(): output_folder = mkdtemp(prefix="output_") - args = "--interactionFile {} {} --alpha {} --statisticTest {} --outputFolder {}\ + args = "--interactionFile {} {} --alpha {} --statisticTest {} --outputFolder {} -t {}\ ".format(ROOT + 'chicAggregateStatistic/batch_mode/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt', ROOT + 'chicAggregateStatistic/batch_mode/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_aggregated.txt ', 0.5, 'chi2', - output_folder).split() + output_folder, 1).split() chicDifferentialTest.main(args) - assert are_files_equal(ROOT + "chicDifferentialTest/regular_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/regular_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/regular_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt') - assert set(os.listdir(ROOT + "chicDifferentialTest/regular_mode_chi2/")) == set(os.listdir(output_folder)) + assert are_files_equal(ROOT + "chicDifferentialTest/regular_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/regular_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/regular_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt') + assert set(os.listdir(ROOT + "chicDifferentialTest/regular_mode_chi2/") + ) == set(os.listdir(output_folder)) def test_batch_mode_fisher(): output_folder = mkdtemp(prefix="output_") - args = "--interactionFile {} -iff {} --alpha {} --statisticTest {} --outputFolder {} -bm\ + args = "--interactionFile {} -iff {} --alpha {} --statisticTest {} --outputFolder {} -bm -t {}\ ".format(ROOT + 'chicAggregateStatistic/batch_mode_file_names.txt', ROOT + 'chicAggregateStatistic/batch_mode', 0.5, 'fisher', - output_folder).split() + output_folder, 1).split() chicDifferentialTest.main(args) - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_accepted.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_accepted.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_rejected.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_rejected.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_results.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_results.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_accepted.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_accepted.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_rejected.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_rejected.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_results.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_results.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_accepted.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_accepted.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_rejected.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_rejected.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_results.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_results.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_accepted.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_accepted.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_rejected.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_rejected.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_results.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_results.txt') - assert set(os.listdir(ROOT + "chicDifferentialTest/batch_mode_fisher/")) == set(os.listdir(output_folder)) + assert set(os.listdir(ROOT + "chicDifferentialTest/batch_mode_fisher/") + ) == set(os.listdir(output_folder)) def test_batch_mode_chi2(): output_folder = mkdtemp(prefix="output_") - args = "--interactionFile {} -iff {} --alpha {} --statisticTest {} --outputFolder {} -bm\ + args = "--interactionFile {} -iff {} --alpha {} --statisticTest {} --outputFolder {} -bm -t {}\ ".format(ROOT + 'chicAggregateStatistic/batch_mode_file_names.txt', ROOT + 'chicAggregateStatistic/batch_mode', 0.5, 'chi2', - output_folder).split() + output_folder, 1).split() chicDifferentialTest.main(args) - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_accepted.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_accepted.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_rejected.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_rejected.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_results.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_results.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_accepted.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_accepted.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_rejected.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_rejected.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_results.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_results.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_accepted.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_accepted.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_rejected.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_rejected.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_results.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_results.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_accepted.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_accepted.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_rejected.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_rejected.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_chi2/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_results.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_results.txt') - assert set(os.listdir(ROOT + "chicDifferentialTest/batch_mode_chi2/")) == set(os.listdir(output_folder)) + assert set(os.listdir(ROOT + "chicDifferentialTest/batch_mode_chi2/") + ) == set(os.listdir(output_folder)) def test_batch_mode_fisher_rejected_file(): @@ -122,26 +151,37 @@ def test_batch_mode_fisher_rejected_file(): output_folder = mkdtemp(prefix="output_") outfile = NamedTemporaryFile(suffix='.txt', delete=False) - args = "--interactionFile {} -iff {} --alpha {} --statisticTest {} --outputFolder {} -bm --rejectedFileNamesToFile {}\ + args = "--interactionFile {} -iff {} --alpha {} --statisticTest {} --outputFolder {} -bm --rejectedFileNamesToFile {} -t {}\ ".format(ROOT + 'chicAggregateStatistic/batch_mode_file_names.txt', ROOT + 'chicAggregateStatistic/batch_mode', 0.5, 'fisher', - output_folder, outfile.name + output_folder, outfile.name, 1 ).split() chicDifferentialTest.main(args) - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt') - - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_accepted.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_accepted.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_rejected.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_rejected.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_results.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_results.txt') - - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_accepted.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_accepted.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_rejected.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_rejected.txt') - assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_results.txt", output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_results.txt') - - assert are_files_equal(ROOT + "chicDifferentialTest/rejectedFilesList.txt", outfile.name) - - assert set(os.listdir(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/")) == set(os.listdir(output_folder)) + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_accepted.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_results.txt') + + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_accepted.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_accepted.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_rejected.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_H0_rejected.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_results.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_results.txt') + + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_accepted.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_accepted.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_rejected.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_H0_rejected.txt') + assert are_files_equal(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_results.txt", + output_folder + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_results.txt') + + assert are_files_equal( + ROOT + "chicDifferentialTest/rejectedFilesList.txt", outfile.name) + + assert set(os.listdir(ROOT + "chicDifferentialTest/batch_mode_fisher_outfile/") + ) == set(os.listdir(output_folder)) diff --git a/hicexplorer/test/general/test_chicPlotViewpoint.py b/hicexplorer/test/general/test_chicPlotViewpoint.py index e37f3954..bb6dfe0c 100644 --- a/hicexplorer/test/general/test_chicPlotViewpoint.py +++ b/hicexplorer/test/general/test_chicPlotViewpoint.py @@ -1,15 +1,16 @@ +from hicexplorer import chicPlotViewpoint +from matplotlib.testing.compare import compare_images +import matplotlib as mpl +from tempfile import NamedTemporaryFile, mkdtemp +import os +import pytest import warnings warnings.simplefilter(action="ignore", category=RuntimeWarning) warnings.simplefilter(action="ignore", category=PendingDeprecationWarning) -import pytest -import os -from tempfile import NamedTemporaryFile, mkdtemp -import matplotlib as mpl mpl.use('agg') -from matplotlib.testing.compare import compare_images -from hicexplorer import chicPlotViewpoint -ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "test_data/cHi-C/") +ROOT = os.path.join(os.path.dirname(os.path.dirname( + os.path.abspath(__file__))), "test_data/cHi-C/") tolerance = 50 @@ -41,10 +42,12 @@ def are_files_equal(file1, file2, delta=1, skip=0): def test_one_viewpoint(): outfile = NamedTemporaryFile(suffix='.png', delete=False) outfile.close() - args = "-if {} --range {} {} -o {}".format(ROOT + 'chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', 200000, 200000, outfile.name).split() + args = "-if {} --range {} {} -o {} -t {}".format( + ROOT + 'chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', 200000, 200000, outfile.name, 1).split() chicPlotViewpoint.main(args) - res = compare_images(ROOT + 'chicPlotViewpoint/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.png', outfile.name, tolerance) + res = compare_images( + ROOT + 'chicPlotViewpoint/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.png', outfile.name, tolerance) assert res is None, res # n - viewpoints, jpg @@ -53,13 +56,14 @@ def test_one_viewpoint(): def test_two_viewpoint_fileformat_dpi(): outfile = NamedTemporaryFile(suffix='.pdf', delete=False) outfile.close() - args = "-if {} {} --range {} {} -o {} --dpi {} --outputFormat {}".format( + args = "-if {} {} --range {} {} -o {} --dpi {} --outputFormat {} -t {}".format( ROOT + 'chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', ROOT + 'chicViewpoint/output_1/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.txt', - 200000, 200000, outfile.name, 100, 'pdf').split() + 200000, 200000, outfile.name, 100, 'pdf', 1).split() chicPlotViewpoint.main(args) - res = compare_images(ROOT + 'chicPlotViewpoint/two_viewpoint.pdf', outfile.name, tolerance) + res = compare_images( + ROOT + 'chicPlotViewpoint/two_viewpoint.pdf', outfile.name, tolerance) assert res is None, res # additional background model @@ -67,77 +71,86 @@ def test_two_viewpoint_fileformat_dpi(): def test_two_viewpoint_background(): outfile = NamedTemporaryFile(suffix='.png', delete=False) outfile.close() - args = "-if {} {} --range {} {} -o {} -bmf {}".format( + args = "-if {} {} --range {} {} -o {} -bmf {} -t {}".format( ROOT + 'chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', ROOT + 'chicViewpoint/output_1/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.txt', - 200000, 200000, outfile.name, ROOT + 'background.txt').split() + 200000, 200000, outfile.name, ROOT + 'background.txt', 1).split() chicPlotViewpoint.main(args) - res = compare_images(ROOT + 'chicPlotViewpoint/two_viewpoint_background.png', outfile.name, tolerance) + res = compare_images( + ROOT + 'chicPlotViewpoint/two_viewpoint_background.png', outfile.name, tolerance) assert res is None, res def test_two_viewpoint_background_significant(): outfile = NamedTemporaryFile(suffix='.png', delete=False) outfile.close() - args = "-if {} {} --range {} {} -o {} -bmf {} --significantInteractions {} {}".format( + args = "-if {} {} --range {} {} -o {} -bmf {} --significantInteractions {} {} -t {}".format( ROOT + 'chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', ROOT + 'chicViewpoint/output_1/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.txt', 200000, 200000, outfile.name, ROOT + 'background.txt', ROOT + 'chicSignificantInteractions/output_3/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt', - ROOT + 'chicSignificantInteractions/output_3/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt').split() + ROOT + 'chicSignificantInteractions/output_3/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt', 1).split() chicPlotViewpoint.main(args) - res = compare_images(ROOT + 'chicPlotViewpoint/two_viewpoint_background_significant.png', outfile.name, tolerance) + res = compare_images( + ROOT + 'chicPlotViewpoint/two_viewpoint_background_significant.png', outfile.name, tolerance) assert res is None, res def test_two_viewpoint_background_differential(): outfile = NamedTemporaryFile(suffix='.png', delete=False) outfile.close() - args = "-if {} {} --range {} {} -o {} -bmf {} --differentialTestResult {}".format( + args = "-if {} {} --range {} {} -o {} -bmf {} --differentialTestResult {} -t {}".format( ROOT + 'chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', ROOT + 'chicViewpoint/output_1/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.txt', 200000, 200000, outfile.name, ROOT + 'background.txt', - ROOT + 'chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt').split() + ROOT + 'chicDifferentialTest/batch_mode_fisher/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_H0_rejected.txt', 1).split() chicPlotViewpoint.main(args) - res = compare_images(ROOT + 'chicPlotViewpoint/two_viewpoint_background_differential.png', outfile.name, tolerance) + res = compare_images( + ROOT + 'chicPlotViewpoint/two_viewpoint_background_differential.png', outfile.name, tolerance) assert res is None, res def test_one_viewpoint_colormap_pvalue(): outfile = NamedTemporaryFile(suffix='.png', delete=False) outfile.close() - args = "-if {} --range {} {} --pValue --colorMapPvalue {} -o {} --pValue --colorMapPvalue plasma --maxPValue 0.5 --minPValue 0.1".format(ROOT + 'chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', 200000, 200000, 'plasma', outfile.name).split() + args = "-if {} --range {} {} --pValue --colorMapPvalue {} -o {} --pValue --colorMapPvalue plasma --maxPValue 0.5 --minPValue 0.1 -t {}".format( + ROOT + 'chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', 200000, 200000, 'plasma', outfile.name, 1).split() chicPlotViewpoint.main(args) - res = compare_images(ROOT + 'chicPlotViewpoint/two_viewpoint_pvalue.png', outfile.name, tolerance) + res = compare_images( + ROOT + 'chicPlotViewpoint/two_viewpoint_pvalue.png', outfile.name, tolerance) assert res is None, res def test_one_viewpoint_per_file_batch_mode(): output_folder = mkdtemp(prefix="output_") - args = "-if {} -iff {} --range {} {} --outputFolder {} -psn {} -bm".format(ROOT + 'chicViewpoint/fileNames_one_matrix.txt', - ROOT + 'chicViewpoint/output_4', - 200000, 200000, - output_folder, 1).split() + args = "-if {} -iff {} --range {} {} --outputFolder {} -psn {} -bm -t {}".format(ROOT + 'chicViewpoint/fileNames_one_matrix.txt', + ROOT + 'chicViewpoint/output_4', + 200000, 200000, + output_folder, 1, 1).split() chicPlotViewpoint.main(args) - res = compare_images(ROOT + 'chicPlotViewpoint/batchMode/one/Eya1_FL-E13-5_chr1_chr1_14300280.png', output_folder + '/Eya1_FL-E13-5_chr1_chr1_14300280.png', tolerance) + res = compare_images(ROOT + 'chicPlotViewpoint/batchMode/one/Eya1_FL-E13-5_chr1_chr1_14300280.png', + output_folder + '/Eya1_FL-E13-5_chr1_chr1_14300280.png', tolerance) assert res is None, res - res = compare_images(ROOT + 'chicPlotViewpoint/batchMode/one/Sox17_FL-E13-5_chr1_chr1_4487435.png', output_folder + '/Sox17_FL-E13-5_chr1_chr1_4487435.png', tolerance) + res = compare_images(ROOT + 'chicPlotViewpoint/batchMode/one/Sox17_FL-E13-5_chr1_chr1_4487435.png', + output_folder + '/Sox17_FL-E13-5_chr1_chr1_4487435.png', tolerance) assert res is None, res - res = compare_images(ROOT + 'chicPlotViewpoint/batchMode/one/Tfap2d_FL-E13-5_chr1_chr1_19093103.png', output_folder + '/Tfap2d_FL-E13-5_chr1_chr1_19093103.png', tolerance) + res = compare_images(ROOT + 'chicPlotViewpoint/batchMode/one/Tfap2d_FL-E13-5_chr1_chr1_19093103.png', + output_folder + '/Tfap2d_FL-E13-5_chr1_chr1_19093103.png', tolerance) assert res is None, res - assert set(os.listdir(ROOT + "chicPlotViewpoint/batchMode/one")) == set(os.listdir(output_folder)) + assert set(os.listdir(ROOT + "chicPlotViewpoint/batchMode/one") + ) == set(os.listdir(output_folder)) def test_two_viewpoints_per_file_batch_mode_significances_differential_pvalue(): output_folder = mkdtemp(prefix="output_") - args = "-if {} -iff {} --range {} {} --outputFolder {} -psn {} -bm --differentialTestResult {} -diff {} -si {} -siff {} -p -xf {} -bmf {}".format( + args = "-if {} -iff {} --range {} {} --outputFolder {} -psn {} -bm --differentialTestResult {} -diff {} -si {} -siff {} -p -xf {} -bmf {} -t {}".format( ROOT + 'chicViewpoint/fileNames_two_matrices.txt', ROOT + 'chicViewpoint/output_1', 200000, 200000, @@ -147,13 +160,17 @@ def test_two_viewpoints_per_file_batch_mode_significances_differential_pvalue(): ROOT + 'chicSignificantInteractions/output_5_significant_files.txt', ROOT + 'chicSignificantInteractions/output_5/', 1.5, - ROOT + 'background.txt').split() + ROOT + 'background.txt', 1).split() chicPlotViewpoint.main(args) - res = compare_images(ROOT + 'chicPlotViewpoint/batchMode/two/Eya1_FL-E13-5_MB-E10-5_chr1_chr1_14300280.png', output_folder + '/Eya1_FL-E13-5_MB-E10-5_chr1_chr1_14300280.png', tolerance) + res = compare_images(ROOT + 'chicPlotViewpoint/batchMode/two/Eya1_FL-E13-5_MB-E10-5_chr1_chr1_14300280.png', + output_folder + '/Eya1_FL-E13-5_MB-E10-5_chr1_chr1_14300280.png', tolerance) assert res is None, res - res = compare_images(ROOT + 'chicPlotViewpoint/batchMode/two/Sox17_FL-E13-5_MB-E10-5_chr1_chr1_4487435.png', output_folder + '/Sox17_FL-E13-5_MB-E10-5_chr1_chr1_4487435.png', tolerance) + res = compare_images(ROOT + 'chicPlotViewpoint/batchMode/two/Sox17_FL-E13-5_MB-E10-5_chr1_chr1_4487435.png', + output_folder + '/Sox17_FL-E13-5_MB-E10-5_chr1_chr1_4487435.png', tolerance) assert res is None, res - res = compare_images(ROOT + 'chicPlotViewpoint/batchMode/two/Tfap2d_FL-E13-5_MB-E10-5_chr1_chr1_19093103.png', output_folder + '/Tfap2d_FL-E13-5_MB-E10-5_chr1_chr1_19093103.png', tolerance) + res = compare_images(ROOT + 'chicPlotViewpoint/batchMode/two/Tfap2d_FL-E13-5_MB-E10-5_chr1_chr1_19093103.png', + output_folder + '/Tfap2d_FL-E13-5_MB-E10-5_chr1_chr1_19093103.png', tolerance) assert res is None, res - assert set(os.listdir(ROOT + "chicPlotViewpoint/batchMode/two")) == set(os.listdir(output_folder)) + assert set(os.listdir(ROOT + "chicPlotViewpoint/batchMode/two") + ) == set(os.listdir(output_folder)) diff --git a/hicexplorer/test/general/test_chicQualityControl.py b/hicexplorer/test/general/test_chicQualityControl.py index 1082b310..2309d66c 100644 --- a/hicexplorer/test/general/test_chicQualityControl.py +++ b/hicexplorer/test/general/test_chicQualityControl.py @@ -1,15 +1,16 @@ +from hicexplorer import chicQualityControl +from matplotlib.testing.compare import compare_images +import matplotlib as mpl +from tempfile import NamedTemporaryFile, mkdtemp +import os +import pytest import warnings warnings.simplefilter(action="ignore", category=RuntimeWarning) warnings.simplefilter(action="ignore", category=PendingDeprecationWarning) -import pytest -import os -from tempfile import NamedTemporaryFile, mkdtemp -import matplotlib as mpl mpl.use('agg') -from matplotlib.testing.compare import compare_images -from hicexplorer import chicQualityControl -ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "test_data/cHi-C/") +ROOT = os.path.join(os.path.dirname(os.path.dirname( + os.path.abspath(__file__))), "test_data/cHi-C/") def are_files_equal(file1, file2, delta=1, skip=0): @@ -41,19 +42,24 @@ def test_two_matrices(): outfile_sparsity = NamedTemporaryFile(suffix='.png', delete=False) outfile.close() - args = "--matrices {} {} --referencePoints {} --sparsity {} --outFileName {} --outFileNameHistogram {} --outFileNameSparsity {}".format(ROOT + 'FL-E13-5_chr1.cool', - ROOT + 'MB-E10-5_chr1.cool', - ROOT + 'referencePoints.bed', - 0.05, - outfile.name, outfile_histogram.name, outfile_sparsity.name).split() + args = "--matrices {} {} --referencePoints {} --sparsity {} --outFileName {} --outFileNameHistogram {} --outFileNameSparsity {} -t {}".format(ROOT + 'FL-E13-5_chr1.cool', + ROOT + 'MB-E10-5_chr1.cool', + ROOT + 'referencePoints.bed', + 0.05, + outfile.name, outfile_histogram.name, outfile_sparsity.name, 1).split() chicQualityControl.main(args) - assert are_files_equal(ROOT + "chicQualityControl/new_referencepoints.bed", outfile.name) - assert are_files_equal(ROOT + "chicQualityControl/new_referencepoints.bed_raw_filter", outfile.name + '_raw_filter', skip=2) - assert are_files_equal(ROOT + "chicQualityControl/new_referencepoints.bed_rejected_filter", outfile.name + '_rejected_filter', skip=2) + assert are_files_equal( + ROOT + "chicQualityControl/new_referencepoints.bed", outfile.name) + assert are_files_equal( + ROOT + "chicQualityControl/new_referencepoints.bed_raw_filter", outfile.name + '_raw_filter', skip=2) + assert are_files_equal(ROOT + "chicQualityControl/new_referencepoints.bed_rejected_filter", + outfile.name + '_rejected_filter', skip=2) - res = compare_images(ROOT + "chicQualityControl/histogram.png", outfile_histogram.name, 50) + res = compare_images( + ROOT + "chicQualityControl/histogram.png", outfile_histogram.name, 50) assert res is None, res - res = compare_images(ROOT + "chicQualityControl/sparsity.png", outfile_sparsity.name, 50) + res = compare_images( + ROOT + "chicQualityControl/sparsity.png", outfile_sparsity.name, 50) assert res is None, res diff --git a/hicexplorer/test/general/test_chicSignificantInteractions.py b/hicexplorer/test/general/test_chicSignificantInteractions.py index b25f163b..f9e50171 100644 --- a/hicexplorer/test/general/test_chicSignificantInteractions.py +++ b/hicexplorer/test/general/test_chicSignificantInteractions.py @@ -1,12 +1,13 @@ +from hicexplorer import chicSignificantInteractions +from tempfile import NamedTemporaryFile, mkdtemp +import os +import pytest import warnings warnings.simplefilter(action="ignore", category=RuntimeWarning) warnings.simplefilter(action="ignore", category=PendingDeprecationWarning) -import pytest -import os -from tempfile import NamedTemporaryFile, mkdtemp -from hicexplorer import chicSignificantInteractions -ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "test_data/cHi-C/") +ROOT = os.path.join(os.path.dirname(os.path.dirname( + os.path.abspath(__file__))), "test_data/cHi-C/") def are_files_equal(file1, file2, delta=1, skip=0): @@ -37,18 +38,21 @@ def test_xFold_one_interaction_file(): output_folder_target = mkdtemp(prefix="output_target_") outfile.close() - args = "--interactionFile {} --backgroundModelFile {} --range {} {} -suffix {} --outputFolder {} --xFoldBackground {} --pValue {} --targetFolder {}".format(ROOT + 'chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', - ROOT + 'background.txt', - 200000, 200000, - 'output_significant.txt', - output_folder, - 1.5, 0.2, output_folder_target).split() + args = "--interactionFile {} --backgroundModelFile {} --range {} {} -suffix {} --outputFolder {} --xFoldBackground {} --pValue {} --targetFolder {} -t {}".format(ROOT + 'chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', + ROOT + 'background.txt', + 200000, 200000, + 'output_significant.txt', + output_folder, + 1.5, 0.2, output_folder_target, 1).split() chicSignificantInteractions.main(args) - assert are_files_equal(ROOT + "chicSignificantInteractions/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt", output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt') + assert are_files_equal(ROOT + "chicSignificantInteractions/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt", + output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt') - assert set(os.listdir(ROOT + "chicSignificantInteractions/output_1/")) == set(os.listdir(output_folder)) - assert set(os.listdir(ROOT + "chicSignificantInteractions/output_1_target/")) == set(os.listdir(output_folder_target)) + assert set(os.listdir(ROOT + "chicSignificantInteractions/output_1/") + ) == set(os.listdir(output_folder)) + assert set(os.listdir(ROOT + "chicSignificantInteractions/output_1_target/") + ) == set(os.listdir(output_folder_target)) def test_loose_pValue_one_interaction_file(): @@ -57,18 +61,21 @@ def test_loose_pValue_one_interaction_file(): output_folder_target = mkdtemp(prefix="output_target_") outfile.close() - args = "--interactionFile {} --backgroundModelFile {} --range {} {} -suffix {} --outputFolder {} --loosePValue {} --pValue {} --targetFolder {}".format(ROOT + 'chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', - ROOT + 'background.txt', - 200000, 200000, - 'output_significant.txt', - output_folder, - 0.5, 0.2, output_folder_target).split() + args = "--interactionFile {} --backgroundModelFile {} --range {} {} -suffix {} --outputFolder {} --loosePValue {} --pValue {} --targetFolder {} -t {}".format(ROOT + 'chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', + ROOT + 'background.txt', + 200000, 200000, + 'output_significant.txt', + output_folder, + 0.5, 0.2, output_folder_target, 1).split() chicSignificantInteractions.main(args) - assert are_files_equal(ROOT + "chicSignificantInteractions/output_2/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt", output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt') + assert are_files_equal(ROOT + "chicSignificantInteractions/output_2/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt", + output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt') - assert set(os.listdir(ROOT + "chicSignificantInteractions/output_2/")) == set(os.listdir(output_folder)) - assert set(os.listdir(ROOT + "chicSignificantInteractions/output_2_target/")) == set(os.listdir(output_folder_target)) + assert set(os.listdir(ROOT + "chicSignificantInteractions/output_2/") + ) == set(os.listdir(output_folder)) + assert set(os.listdir(ROOT + "chicSignificantInteractions/output_2_target/") + ) == set(os.listdir(output_folder_target)) def test_loose_pValue_multiple_interaction_files(): @@ -77,88 +84,114 @@ def test_loose_pValue_multiple_interaction_files(): output_folder_target = mkdtemp(prefix="output_target_") outfile.close() - args = "--interactionFile {} {} --backgroundModelFile {} --range {} {} -suffix {} --outputFolder {} --xFoldBackground {} --pValue {} --targetFolder {} -csn 1".format(ROOT + 'chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', - ROOT + 'chicViewpoint/output_1/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.txt', - ROOT + 'background.txt', - 200000, 200000, - 'output_significant.txt', - output_folder, - 1.5, 0.2, output_folder_target).split() + args = "--interactionFile {} {} --backgroundModelFile {} --range {} {} -suffix {} --outputFolder {} --xFoldBackground {} --pValue {} --targetFolder {} -csn 1 -t {}".format(ROOT + 'chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', + ROOT + 'chicViewpoint/output_1/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.txt', + ROOT + 'background.txt', + 200000, 200000, + 'output_significant.txt', + output_folder, + 1.5, 0.2, output_folder_target, 1).split() chicSignificantInteractions.main(args) - assert are_files_equal(ROOT + "chicSignificantInteractions/output_3/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt", output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt') - assert are_files_equal(ROOT + "chicSignificantInteractions/output_3/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt", output_folder + '/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt') + assert are_files_equal(ROOT + "chicSignificantInteractions/output_3/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt", + output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt') + assert are_files_equal(ROOT + "chicSignificantInteractions/output_3/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt", + output_folder + '/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt') - assert set(os.listdir(ROOT + "chicSignificantInteractions/output_3/")) == set(os.listdir(output_folder)) - assert set(os.listdir(ROOT + "chicSignificantInteractions/output_3_target/")) == set(os.listdir(output_folder_target)) + assert set(os.listdir(ROOT + "chicSignificantInteractions/output_3/") + ) == set(os.listdir(output_folder)) + assert set(os.listdir(ROOT + "chicSignificantInteractions/output_3_target/") + ) == set(os.listdir(output_folder_target)) def test_batchMode_xFold_csn_1(): outfile = NamedTemporaryFile(suffix='.txt', delete=False) outfile_target_list = NamedTemporaryFile(suffix='.txt', delete=False) - outfile_significant_files_list = NamedTemporaryFile(suffix='.txt', delete=False) + outfile_significant_files_list = NamedTemporaryFile( + suffix='.txt', delete=False) output_folder = mkdtemp(prefix="output_") output_folder_target = mkdtemp(prefix="output_target_") outfile.close() args = "--interactionFile {} --interactionFileFolder {} --backgroundModelFile {} --range {} {} \ - -suffix {} --outputFolder {} --xFoldBackground {} --pValue {} --targetFolder {} --writeFileNamesToFile {} --targetFileList {} -bm -csn 1 ".format(ROOT + 'chicViewpoint/fileNames_one_matrix.txt', - ROOT + 'chicViewpoint/output_2', - ROOT + 'background.txt', - 200000, 200000, - 'output_significant.txt', - output_folder, - 1.5, 0.2, output_folder_target, - outfile_significant_files_list.name, - outfile_target_list.name).split() + -suffix {} --outputFolder {} --xFoldBackground {} --pValue {} --targetFolder {} --writeFileNamesToFile {} --targetFileList {} -bm -csn 1 -t {}".format(ROOT + 'chicViewpoint/fileNames_one_matrix.txt', + ROOT + 'chicViewpoint/output_2', + ROOT + 'background.txt', + 200000, 200000, + 'output_significant.txt', + output_folder, + 1.5, 0.2, output_folder_target, + outfile_significant_files_list.name, + outfile_target_list.name, 1).split() chicSignificantInteractions.main(args) - assert are_files_equal(ROOT + "chicSignificantInteractions/output_4/FL-E13-5_chr1_chr1_4487435_4487435_Sox17_output_significant.txt", output_folder + '/FL-E13-5_chr1_chr1_4487435_4487435_Sox17_output_significant.txt') - assert are_files_equal(ROOT + "chicSignificantInteractions/output_4/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt", output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt') - assert are_files_equal(ROOT + "chicSignificantInteractions/output_4/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d_output_significant.txt", output_folder + '/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d_output_significant.txt') + assert are_files_equal(ROOT + "chicSignificantInteractions/output_4/FL-E13-5_chr1_chr1_4487435_4487435_Sox17_output_significant.txt", + output_folder + '/FL-E13-5_chr1_chr1_4487435_4487435_Sox17_output_significant.txt') + assert are_files_equal(ROOT + "chicSignificantInteractions/output_4/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt", + output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt') + assert are_files_equal(ROOT + "chicSignificantInteractions/output_4/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d_output_significant.txt", + output_folder + '/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d_output_significant.txt') - assert are_files_equal(ROOT + "chicSignificantInteractions/output_4_target_list.txt", outfile_target_list.name) - assert are_files_equal(ROOT + "chicSignificantInteractions/output_4_significant_files.txt", outfile_significant_files_list.name) + assert are_files_equal( + ROOT + "chicSignificantInteractions/output_4_target_list.txt", outfile_target_list.name) + assert are_files_equal( + ROOT + "chicSignificantInteractions/output_4_significant_files.txt", outfile_significant_files_list.name) - assert set(os.listdir(ROOT + "chicSignificantInteractions/output_4/")) == set(os.listdir(output_folder)) - assert set(os.listdir(ROOT + "chicSignificantInteractions/output_4_target/")) == set(os.listdir(output_folder_target)) + assert set(os.listdir(ROOT + "chicSignificantInteractions/output_4/") + ) == set(os.listdir(output_folder)) + assert set(os.listdir(ROOT + "chicSignificantInteractions/output_4_target/") + ) == set(os.listdir(output_folder_target)) def test_batchMode_loose_pValue_csn_2(): outfile = NamedTemporaryFile(suffix='.txt', delete=False) outfile_target_list = NamedTemporaryFile(suffix='.txt', delete=False) - outfile_significant_files_list = NamedTemporaryFile(suffix='.txt', delete=False) + outfile_significant_files_list = NamedTemporaryFile( + suffix='.txt', delete=False) output_folder = mkdtemp(prefix="output_") output_folder_target = mkdtemp(prefix="output_target_") outfile.close() args = "--interactionFile {} --interactionFileFolder {} --backgroundModelFile {} --range {} {} \ - -suffix {} --outputFolder {} --loosePValue {} --pValue {} --targetFolder {} --writeFileNamesToFile {} --targetFileList {} -bm -csn 2 ".format(ROOT + 'chicViewpoint/fileNames_two_matrices.txt', - ROOT + 'chicViewpoint/output_1', - ROOT + 'background.txt', - 200000, 200000, - 'output_significant.txt', - output_folder, - 0.5, 0.2, output_folder_target, - outfile_significant_files_list.name, - outfile_target_list.name).split() + -suffix {} --outputFolder {} --loosePValue {} --pValue {} --targetFolder {} --writeFileNamesToFile {} --targetFileList {} -bm -csn 2 -t {}".format(ROOT + 'chicViewpoint/fileNames_two_matrices.txt', + ROOT + 'chicViewpoint/output_1', + ROOT + 'background.txt', + 200000, 200000, + 'output_significant.txt', + output_folder, + 0.5, 0.2, output_folder_target, + outfile_significant_files_list.name, + outfile_target_list.name, 1).split() chicSignificantInteractions.main(args) - assert are_files_equal(ROOT + "chicSignificantInteractions/output_5/FL-E13-5_chr1_chr1_4487435_4487435_Sox17_output_significant.txt", output_folder + '/FL-E13-5_chr1_chr1_4487435_4487435_Sox17_output_significant.txt') - assert are_files_equal(ROOT + "chicSignificantInteractions/output_5/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt", output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt') - assert are_files_equal(ROOT + "chicSignificantInteractions/output_5/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d_output_significant.txt", output_folder + '/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d_output_significant.txt') - assert are_files_equal(ROOT + "chicSignificantInteractions/output_5/MB-E10-5_chr1_chr1_4487435_4487435_Sox17_output_significant.txt", output_folder + '/MB-E10-5_chr1_chr1_4487435_4487435_Sox17_output_significant.txt') - assert are_files_equal(ROOT + "chicSignificantInteractions/output_5/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt", output_folder + '/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt') - assert are_files_equal(ROOT + "chicSignificantInteractions/output_5/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_output_significant.txt", output_folder + '/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_output_significant.txt') - - assert are_files_equal(ROOT + "chicSignificantInteractions/output_5_target/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_target.txt", output_folder_target + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_target.txt', skip=4) - assert are_files_equal(ROOT + "chicSignificantInteractions/output_5_target/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_target.txt", output_folder_target + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_target.txt', skip=4) - assert are_files_equal(ROOT + "chicSignificantInteractions/output_5_target/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_target.txt", output_folder_target + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_target.txt', skip=4) - - assert are_files_equal(ROOT + "chicSignificantInteractions/output_5_target_list.txt", outfile_target_list.name) - assert are_files_equal(ROOT + "chicSignificantInteractions/output_5_significant_files.txt", outfile_significant_files_list.name) - - assert set(os.listdir(ROOT + "chicSignificantInteractions/output_5/")) == set(os.listdir(output_folder)) - assert set(os.listdir(ROOT + "chicSignificantInteractions/output_5_target/")) == set(os.listdir(output_folder_target)) + assert are_files_equal(ROOT + "chicSignificantInteractions/output_5/FL-E13-5_chr1_chr1_4487435_4487435_Sox17_output_significant.txt", + output_folder + '/FL-E13-5_chr1_chr1_4487435_4487435_Sox17_output_significant.txt') + assert are_files_equal(ROOT + "chicSignificantInteractions/output_5/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt", + output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt') + assert are_files_equal(ROOT + "chicSignificantInteractions/output_5/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d_output_significant.txt", + output_folder + '/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d_output_significant.txt') + assert are_files_equal(ROOT + "chicSignificantInteractions/output_5/MB-E10-5_chr1_chr1_4487435_4487435_Sox17_output_significant.txt", + output_folder + '/MB-E10-5_chr1_chr1_4487435_4487435_Sox17_output_significant.txt') + assert are_files_equal(ROOT + "chicSignificantInteractions/output_5/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt", + output_folder + '/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_output_significant.txt') + assert are_files_equal(ROOT + "chicSignificantInteractions/output_5/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_output_significant.txt", + output_folder + '/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_output_significant.txt') + + assert are_files_equal(ROOT + "chicSignificantInteractions/output_5_target/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_target.txt", + output_folder_target + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_target.txt', skip=4) + assert are_files_equal(ROOT + "chicSignificantInteractions/output_5_target/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_target.txt", + output_folder_target + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_target.txt', skip=4) + assert are_files_equal(ROOT + "chicSignificantInteractions/output_5_target/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_target.txt", + output_folder_target + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_target.txt', skip=4) + + assert are_files_equal( + ROOT + "chicSignificantInteractions/output_5_target_list.txt", outfile_target_list.name) + assert are_files_equal( + ROOT + "chicSignificantInteractions/output_5_significant_files.txt", outfile_significant_files_list.name) + + assert set(os.listdir(ROOT + "chicSignificantInteractions/output_5/") + ) == set(os.listdir(output_folder)) + assert set(os.listdir(ROOT + "chicSignificantInteractions/output_5_target/") + ) == set(os.listdir(output_folder_target)) diff --git a/hicexplorer/test/general/test_chicViewpoint.py b/hicexplorer/test/general/test_chicViewpoint.py index c050e601..8f77afc5 100644 --- a/hicexplorer/test/general/test_chicViewpoint.py +++ b/hicexplorer/test/general/test_chicViewpoint.py @@ -1,12 +1,13 @@ +from hicexplorer import chicViewpoint +from tempfile import NamedTemporaryFile, mkdtemp +import os +import pytest import warnings warnings.simplefilter(action="ignore", category=RuntimeWarning) warnings.simplefilter(action="ignore", category=PendingDeprecationWarning) -import pytest -import os -from tempfile import NamedTemporaryFile, mkdtemp -from hicexplorer import chicViewpoint -ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "test_data/cHi-C/") +ROOT = os.path.join(os.path.dirname(os.path.dirname( + os.path.abspath(__file__))), "test_data/cHi-C/") def are_files_equal(file1, file2, delta=1, skip=0): @@ -35,40 +36,51 @@ def test_two_matrices(): outfile = NamedTemporaryFile(suffix='.txt', delete=False) output_folder = mkdtemp(prefix="output_") outfile.close() - args = "--matrices {} {} --referencePoints {} --backgroundModel {} --range {} {} -o {}".format(ROOT + 'FL-E13-5_chr1.cool', - ROOT + 'MB-E10-5_chr1.cool', - ROOT + 'referencePoints_chicViewpoint.bed', - ROOT + 'background.txt', - 200000, 200000, - output_folder).split() + args = "--matrices {} {} --referencePoints {} --backgroundModel {} --range {} {} -o {} -t {}".format(ROOT + 'FL-E13-5_chr1.cool', + ROOT + 'MB-E10-5_chr1.cool', + ROOT + 'referencePoints_chicViewpoint.bed', + ROOT + 'background.txt', + 200000, 200000, + output_folder, 1).split() chicViewpoint.main(args) - assert are_files_equal(ROOT + "chicViewpoint/output_1/FL-E13-5_chr1_chr1_4487435_4487435_Sox17.txt", output_folder + '/FL-E13-5_chr1_chr1_4487435_4487435_Sox17.txt', skip=4) - assert are_files_equal(ROOT + "chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt", output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', skip=4) - assert are_files_equal(ROOT + "chicViewpoint/output_1/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d.txt", output_folder + '/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d.txt', skip=4) - assert are_files_equal(ROOT + "chicViewpoint/output_1/MB-E10-5_chr1_chr1_4487435_4487435_Sox17.txt", output_folder + '/MB-E10-5_chr1_chr1_4487435_4487435_Sox17.txt', skip=4) - assert are_files_equal(ROOT + "chicViewpoint/output_1/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.txt", output_folder + '/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.txt', skip=4) - assert are_files_equal(ROOT + "chicViewpoint/output_1/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d.txt", output_folder + '/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d.txt', skip=4) + assert are_files_equal(ROOT + "chicViewpoint/output_1/FL-E13-5_chr1_chr1_4487435_4487435_Sox17.txt", + output_folder + '/FL-E13-5_chr1_chr1_4487435_4487435_Sox17.txt', skip=4) + assert are_files_equal(ROOT + "chicViewpoint/output_1/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt", + output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', skip=4) + assert are_files_equal(ROOT + "chicViewpoint/output_1/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d.txt", + output_folder + '/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d.txt', skip=4) + assert are_files_equal(ROOT + "chicViewpoint/output_1/MB-E10-5_chr1_chr1_4487435_4487435_Sox17.txt", + output_folder + '/MB-E10-5_chr1_chr1_4487435_4487435_Sox17.txt', skip=4) + assert are_files_equal(ROOT + "chicViewpoint/output_1/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.txt", + output_folder + '/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.txt', skip=4) + assert are_files_equal(ROOT + "chicViewpoint/output_1/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d.txt", + output_folder + '/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d.txt', skip=4) - assert set(os.listdir(ROOT + "chicViewpoint/output_1/")) == set(os.listdir(output_folder)) + assert set(os.listdir(ROOT + "chicViewpoint/output_1/") + ) == set(os.listdir(output_folder)) def test_one_matrix(): outfile = NamedTemporaryFile(suffix='.txt', delete=False) output_folder = mkdtemp(prefix="output_") outfile.close() - args = "--matrices {} --referencePoints {} --backgroundModel {} --range {} {} -o {}".format(ROOT + 'FL-E13-5_chr1.cool', - ROOT + 'referencePoints_chicViewpoint.bed', - ROOT + 'background.txt', - 200000, 200000, - output_folder).split() + args = "--matrices {} --referencePoints {} --backgroundModel {} --range {} {} -o {} -t {}".format(ROOT + 'FL-E13-5_chr1.cool', + ROOT + 'referencePoints_chicViewpoint.bed', + ROOT + 'background.txt', + 200000, 200000, + output_folder, 1).split() chicViewpoint.main(args) - assert are_files_equal(ROOT + "chicViewpoint/output_2/FL-E13-5_chr1_chr1_4487435_4487435_Sox17.txt", output_folder + '/FL-E13-5_chr1_chr1_4487435_4487435_Sox17.txt', skip=4) - assert are_files_equal(ROOT + "chicViewpoint/output_2/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt", output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', skip=4) - assert are_files_equal(ROOT + "chicViewpoint/output_2/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d.txt", output_folder + '/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d.txt', skip=4) + assert are_files_equal(ROOT + "chicViewpoint/output_2/FL-E13-5_chr1_chr1_4487435_4487435_Sox17.txt", + output_folder + '/FL-E13-5_chr1_chr1_4487435_4487435_Sox17.txt', skip=4) + assert are_files_equal(ROOT + "chicViewpoint/output_2/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt", + output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', skip=4) + assert are_files_equal(ROOT + "chicViewpoint/output_2/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d.txt", + output_folder + '/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d.txt', skip=4) - assert set(os.listdir(ROOT + "chicViewpoint/output_2/")) == set(os.listdir(output_folder)) + assert set(os.listdir(ROOT + "chicViewpoint/output_2/") + ) == set(os.listdir(output_folder)) def test_two_matrices_writeFileName(): @@ -77,23 +89,31 @@ def test_two_matrices_writeFileName(): output_folder = mkdtemp(prefix="output_") outfile.close() - args = "--matrices {} {} --referencePoints {} --backgroundModel {} --range {} {} -o {} -w {}".format(ROOT + 'FL-E13-5_chr1.cool', - ROOT + 'MB-E10-5_chr1.cool', - ROOT + 'referencePoints_chicViewpoint.bed', - ROOT + 'background.txt', - 200000, 200000, - output_folder, outfile_name_list.name).split() + args = "--matrices {} {} --referencePoints {} --backgroundModel {} --range {} {} -o {} -w {} -t {}".format(ROOT + 'FL-E13-5_chr1.cool', + ROOT + 'MB-E10-5_chr1.cool', + ROOT + 'referencePoints_chicViewpoint.bed', + ROOT + 'background.txt', + 200000, 200000, + output_folder, outfile_name_list.name, 1).split() chicViewpoint.main(args) - assert are_files_equal(ROOT + "chicViewpoint/fileNames_two_matrices.txt", outfile_name_list.name) - - assert are_files_equal(ROOT + "chicViewpoint/output_3/FL-E13-5_chr1_chr1_4487435_4487435_Sox17.txt", output_folder + '/FL-E13-5_chr1_chr1_4487435_4487435_Sox17.txt', skip=4) - assert are_files_equal(ROOT + "chicViewpoint/output_3/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt", output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', skip=4) - assert are_files_equal(ROOT + "chicViewpoint/output_3/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d.txt", output_folder + '/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d.txt', skip=4) - assert are_files_equal(ROOT + "chicViewpoint/output_3/MB-E10-5_chr1_chr1_4487435_4487435_Sox17.txt", output_folder + '/MB-E10-5_chr1_chr1_4487435_4487435_Sox17.txt', skip=4) - assert are_files_equal(ROOT + "chicViewpoint/output_3/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.txt", output_folder + '/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.txt', skip=4) - assert are_files_equal(ROOT + "chicViewpoint/output_3/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d.txt", output_folder + '/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d.txt', skip=4) - - assert set(os.listdir(ROOT + "chicViewpoint/output_3/")) == set(os.listdir(output_folder)) + assert are_files_equal( + ROOT + "chicViewpoint/fileNames_two_matrices.txt", outfile_name_list.name) + + assert are_files_equal(ROOT + "chicViewpoint/output_3/FL-E13-5_chr1_chr1_4487435_4487435_Sox17.txt", + output_folder + '/FL-E13-5_chr1_chr1_4487435_4487435_Sox17.txt', skip=4) + assert are_files_equal(ROOT + "chicViewpoint/output_3/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt", + output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', skip=4) + assert are_files_equal(ROOT + "chicViewpoint/output_3/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d.txt", + output_folder + '/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d.txt', skip=4) + assert are_files_equal(ROOT + "chicViewpoint/output_3/MB-E10-5_chr1_chr1_4487435_4487435_Sox17.txt", + output_folder + '/MB-E10-5_chr1_chr1_4487435_4487435_Sox17.txt', skip=4) + assert are_files_equal(ROOT + "chicViewpoint/output_3/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.txt", + output_folder + '/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.txt', skip=4) + assert are_files_equal(ROOT + "chicViewpoint/output_3/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d.txt", + output_folder + '/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d.txt', skip=4) + + assert set(os.listdir(ROOT + "chicViewpoint/output_3/") + ) == set(os.listdir(output_folder)) def test_one_matrix_writeFileName(): @@ -102,16 +122,21 @@ def test_one_matrix_writeFileName(): output_folder = mkdtemp(prefix="output_") outfile.close() - args = "--matrices {} --referencePoints {} --backgroundModel {} --range {} {} -o {} -w {}".format(ROOT + 'FL-E13-5_chr1.cool', - ROOT + 'referencePoints_chicViewpoint.bed', - ROOT + 'background.txt', - 200000, 200000, - output_folder, outfile_name_list.name).split() + args = "--matrices {} --referencePoints {} --backgroundModel {} --range {} {} -o {} -w {} -t {}".format(ROOT + 'FL-E13-5_chr1.cool', + ROOT + 'referencePoints_chicViewpoint.bed', + ROOT + 'background.txt', + 200000, 200000, + output_folder, outfile_name_list.name, 1).split() chicViewpoint.main(args) - assert are_files_equal(ROOT + "chicViewpoint/fileNames_one_matrix.txt", outfile_name_list.name) - - assert are_files_equal(ROOT + "chicViewpoint/output_4/FL-E13-5_chr1_chr1_4487435_4487435_Sox17.txt", output_folder + '/FL-E13-5_chr1_chr1_4487435_4487435_Sox17.txt', skip=4) - assert are_files_equal(ROOT + "chicViewpoint/output_4/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt", output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', skip=4) - assert are_files_equal(ROOT + "chicViewpoint/output_4/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d.txt", output_folder + '/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d.txt', skip=4) - - assert set(os.listdir(ROOT + "chicViewpoint/output_4/")) == set(os.listdir(output_folder)) + assert are_files_equal( + ROOT + "chicViewpoint/fileNames_one_matrix.txt", outfile_name_list.name) + + assert are_files_equal(ROOT + "chicViewpoint/output_4/FL-E13-5_chr1_chr1_4487435_4487435_Sox17.txt", + output_folder + '/FL-E13-5_chr1_chr1_4487435_4487435_Sox17.txt', skip=4) + assert are_files_equal(ROOT + "chicViewpoint/output_4/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt", + output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1.txt', skip=4) + assert are_files_equal(ROOT + "chicViewpoint/output_4/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d.txt", + output_folder + '/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d.txt', skip=4) + + assert set(os.listdir(ROOT + "chicViewpoint/output_4/") + ) == set(os.listdir(output_folder)) diff --git a/hicexplorer/test/general/test_chicViewpointBackgroundModel.py b/hicexplorer/test/general/test_chicViewpointBackgroundModel.py index b9749339..bcf9dd47 100644 --- a/hicexplorer/test/general/test_chicViewpointBackgroundModel.py +++ b/hicexplorer/test/general/test_chicViewpointBackgroundModel.py @@ -1,16 +1,17 @@ +import logging +from hicexplorer import chicViewpointBackgroundModel +import numpy as np +from sys import platform +from tempfile import NamedTemporaryFile +import os +import pytest import warnings warnings.simplefilter(action="ignore", category=RuntimeWarning) warnings.simplefilter(action="ignore", category=PendingDeprecationWarning) -import pytest -import os -from tempfile import NamedTemporaryFile -from sys import platform -import numpy as np -from hicexplorer import chicViewpointBackgroundModel -ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "test_data/cHi-C/") -import logging +ROOT = os.path.join(os.path.dirname(os.path.dirname( + os.path.abspath(__file__))), "test_data/cHi-C/") log = logging.getLogger(__name__) @@ -51,18 +52,19 @@ def are_files_equal(file1, file2, delta=1, skip=0, eps=0.1): def test_compute_background_functional(): outfile = NamedTemporaryFile(suffix='.txt', delete=False) outfile.close() - args = "--matrices {} {} --referencePoints {} -o {}".format(ROOT + 'FL-E13-5_chr1.cool', ROOT + 'MB-E10-5_chr1.cool', - ROOT + 'referencePoints.bed', outfile.name).split() + args = "--matrices {} {} --referencePoints {} -o {} -t {}".format(ROOT + 'FL-E13-5_chr1.cool', ROOT + 'MB-E10-5_chr1.cool', + ROOT + 'referencePoints.bed', outfile.name, 1).split() chicViewpointBackgroundModel.main(args) - assert are_files_equal(ROOT + 'background.txt', outfile.name, delta=700, skip=1) + assert are_files_equal(ROOT + 'background.txt', + outfile.name, delta=700, skip=1) def test_compute_background_number_of_lines(): outfile = NamedTemporaryFile(suffix='.txt', delete=False) outfile.close() - args = "--matrices {} {} --referencePoints {} -o {}".format(ROOT + 'FL-E13-5_chr1.cool', ROOT + 'MB-E10-5_chr1.cool', - ROOT + 'referencePoints.bed', outfile.name).split() + args = "--matrices {} {} --referencePoints {} -o {} -t {}".format(ROOT + 'FL-E13-5_chr1.cool', ROOT + 'MB-E10-5_chr1.cool', + ROOT + 'referencePoints.bed', outfile.name, 1).split() chicViewpointBackgroundModel.main(args) length_background = 0 diff --git a/hicexplorer/test/general/test_hicAdjustMatrix.py b/hicexplorer/test/general/test_hicAdjustMatrix.py index f74bcf85..f7ff41c7 100644 --- a/hicexplorer/test/general/test_hicAdjustMatrix.py +++ b/hicexplorer/test/general/test_hicAdjustMatrix.py @@ -10,7 +10,8 @@ warnings.simplefilter(action="ignore", category=PendingDeprecationWarning) -ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "test_data/") +ROOT = os.path.join(os.path.dirname( + os.path.dirname(os.path.abspath(__file__))), "test_data/") matrix = ROOT + 'small_test_matrix_50kb_res.h5' outfile = NamedTemporaryFile(suffix='.h5', prefix='test_matrix', delete=True) bed_file = ROOT + 'regions.bed' @@ -103,7 +104,8 @@ def test_trivial_run_xfail_regions(matrix, outFileName, action, regions): def test_keep(): - outfile = NamedTemporaryFile(suffix='.h5', prefix='test_matrix', delete=True) + outfile = NamedTemporaryFile( + suffix='.h5', prefix='test_matrix', delete=True) outfile.close() args = "--matrix {} --outFileName {} --regions {} --action {}".format( ROOT + 'small_test_matrix_50kb_res.h5', @@ -111,7 +113,8 @@ def test_keep(): ROOT + 'hicAdjustMatrix/keep_region.bed', "keep").split() hicAdjustMatrix.main(args) - test = hm.hiCMatrix(ROOT + "hicAdjustMatrix/small_test_matrix_50kb_res_keep.h5") + test = hm.hiCMatrix( + ROOT + "hicAdjustMatrix/small_test_matrix_50kb_res_keep.h5") new = hm.hiCMatrix(outfile.name) np.assert_almost_equal(test.matrix.data, new.matrix.data, decimal=5) np.assert_equal(test.cut_intervals, new.cut_intervals) diff --git a/hicexplorer/test/test_data/number_of_tests.txt b/hicexplorer/test/test_data/number_of_tests.txt index fb8a2105..a71e551f 100644 --- a/hicexplorer/test/test_data/number_of_tests.txt +++ b/hicexplorer/test/test_data/number_of_tests.txt @@ -1 +1 @@ -428 \ No newline at end of file +430 \ No newline at end of file