def test_hicConvertFormat_h5_to_homer(): outfile = NamedTemporaryFile(suffix='.homer', delete=False) outfile.close() args = "--matrices {} --outFileName {} --inputFormat cool --outputFormat homer ".format( original_matrix_cool_chr4, outfile.name).split() # hicConvertFormat.main(args) compute(hicConvertFormat.main, args, 5) test = hm.hiCMatrix(original_matrix_cool_chr4) f = gzip.open(outfile.name, 'rb') file_content = f.read() outfile2 = NamedTemporaryFile(suffix='.homer', delete=False) outfile2.close() with open(outfile2.name, 'wb') as matrix_file: matrix_file.write(file_content) matrixFileHandlerInput = MatrixFileHandler(pFileType='homer', pMatrixFile=outfile2.name) _matrix, cut_intervals, nan_bins, \ distance_counts, correction_factors = matrixFileHandlerInput.load() nt.assert_array_almost_equal(test.matrix.data, _matrix.data, decimal=0)
def test_plotSVL(): plot = NamedTemporaryFile(suffix='.png', delete=False) outputFileName = NamedTemporaryFile(suffix='.txt', delete=False) outputFileNameData = NamedTemporaryFile(suffix='.txt', delete=False) plot.close() outputFileName.close() outputFileNameData.close() matrix = ROOT + "small_test_matrix_50kb_res.h5" matrix2 = ROOT + "small_test_matrix_50kb_res.h5" args = "--matrices {} {} --plotFileName {} --outFileName {} --outFileNameData {} --dpi 300"\ .format(matrix, matrix2, plot.name, outputFileName.name, outputFileNameData.name).split() # hicPlotSVL.main(args) compute(hicPlotSVL.main, args, 5) log.debug('--plotFileName {} --outFileName {} --outFileNameData {} '.format(plot.name, outputFileName.name, outputFileNameData.name)) log.debug('matrix {} {}'.format(matrix, matrix2)) log.debug('matrix {} {}'.format(matrix.split('/')[-1], matrix2.split('/')[-1])) assert are_files_equal(ROOT + 'hicPlotSVL/data.txt', outputFileNameData.name, delta=2) assert are_files_equal(ROOT + 'hicPlotSVL/p_values.txt', outputFileName.name, delta=2) # res = compare_images(ROOT + 'hicPlotSVL/plot.png', plot.name, tol=50) # assert res is None, res os.unlink(plot.name) os.unlink(outputFileName.name) os.unlink(outputFileNameData.name)
def test_trivial_run( matrices, outputFormat, resolutions, ): """ Test for all commandline arguments. Options for cool input format are testet seperately. """ from pathlib import Path # get suffix of input matrix without the dot inputFormat = Path(matrices).suffix[1:] # create file corresponding to output format outFileName = NamedTemporaryFile(suffix=".{}".format(outputFormat), delete=True) args = "--matrices {} --outFileName {} --inputFormat {} --outputFormat {} {}".format( matrices, outFileName.name, inputFormat, outputFormat, resolutions, ).split() # hicConvertFormat.main(args) compute(hicConvertFormat.main, args, 5)
def test_find_TADs_fdr(): # full test case with build of the matrix and search for tads matrix = ROOT + "small_test_matrix.h5" tad_folder = mkdtemp(prefix="test_case_find_tads_fdr") args = "--matrix {} --minDepth 60000 --maxDepth 180000 --numberOfProcessors 2 --step 20000 \ --outPrefix {}/test_multiFDR --minBoundaryDistance 20000 \ --correctForMultipleTesting fdr --thresholdComparisons 0.1".format( matrix, tad_folder).split() # hicFindTADs.main(args) compute(hicFindTADs.main, args, 5) new = hm.hiCMatrix(tad_folder + "/test_multiFDR_zscore_matrix.h5") test = hm.hiCMatrix(ROOT + 'find_TADs/FDR/multiFDR_zscore_matrix.h5') nt.assert_equal(test.matrix.data, new.matrix.data) nt.assert_equal(test.cut_intervals, new.cut_intervals) print(tad_folder + "/test_multiFDR_boundaries.bed") assert are_files_equal(ROOT + "find_TADs/FDR/multiFDR_boundaries.bed", tad_folder + "/test_multiFDR_boundaries.bed") assert are_files_equal(ROOT + "find_TADs/FDR/multiFDR_domains.bed", tad_folder + "/test_multiFDR_domains.bed") assert are_files_equal(ROOT + "find_TADs/FDR/multiFDR_tad_score.bm", tad_folder + "/test_multiFDR_tad_score.bm") assert are_files_equal(ROOT + "find_TADs/FDR/multiFDR_boundaries.gff", tad_folder + "/test_multiFDR_boundaries.gff") # assert are_files_equal assert are_files_equal(ROOT + "find_TADs/FDR/multiFDR_score.bedgraph", tad_folder + "/test_multiFDR_score.bedgraph") shutil.rmtree(tad_folder)
def test_find_TADs_none(): # reduced test case, the z-score matrix is given to decrease run time matrix = ROOT + "small_test_matrix.h5" tad_folder = mkdtemp(prefix="test_case_find_tads_none") shutil.copy(ROOT + "find_TADs/None/multiNone_tad_score.bm", tad_folder + "/test_multiNone_tad_score.bm") shutil.copy(ROOT + 'find_TADs/None/multiNone_zscore_matrix.h5', tad_folder + "/test_multiNone_zscore_matrix.h5") args = "--matrix {} --minDepth 60000 --maxDepth 180000 --numberOfProcessors 2 --step 20000 \ --outPrefix {}/test_multiNone --minBoundaryDistance 20000 \ --correctForMultipleTesting None --thresholdComparisons 1.0".format( matrix, tad_folder).split() # hicFindTADs.main(args) compute(hicFindTADs.main, args, 5) assert are_files_equal(ROOT + "find_TADs/None/multiNone_boundaries.bed", tad_folder + "/test_multiNone_boundaries.bed") assert are_files_equal(ROOT + "find_TADs/None/multiNone_domains.bed", tad_folder + "/test_multiNone_domains.bed") assert are_files_equal(ROOT + "find_TADs/None/multiNone_boundaries.gff", tad_folder + "/test_multiNone_boundaries.gff") assert are_files_equal(ROOT + "find_TADs/None/multiNone_score.bedgraph", tad_folder + "/test_multiNone_score.bedgraph") shutil.rmtree(tad_folder)
def test_hicAggregateContacts_cooler(): outfile_aggregate_plots = NamedTemporaryFile(suffix='.png', prefix='hicaggregate_test_', delete=False) outfile_aggregate_matrix = NamedTemporaryFile(suffix='.tab', prefix='hicaggregate_test_', delete=False) args = "--matrix {root}/Li_et_al_2015.cool --BED {root}/hicAggregateContacts/test_regions.bed " \ "--outFileName {out_agg} --numberOfBins 30 --range 50000:900000 --disable_bbox_tight --dpi 100 "\ "--mode intra-chr --perChr --outFilePrefixMatrix {out_mat}".\ format(root=ROOT, out_agg=outfile_aggregate_plots.name, out_mat=outfile_aggregate_matrix.name) test_image_agg = ROOT + 'hicAggregateContacts/master_aggregate_intra_perChr.png' # noqa: F841 test_matrix_agg = ROOT + 'hicAggregateContacts/master_aggregate_intra_perChr.tab' # hicexplorer.hicAggregateContacts.main(args.split()) compute(hicexplorer.hicAggregateContacts.main, args.split(), 5) res = compare_images(test_image_agg, outfile_aggregate_plots.name, tolerance) assert res is None, res assert are_files_equal(test_matrix_agg, outfile_aggregate_matrix.name) os.remove(outfile_aggregate_plots.name) os.remove(outfile_aggregate_matrix.name)
def test_normalize_smallest_cool(capsys): outfile_one = NamedTemporaryFile(suffix='.cool', delete=False) outfile_one.close() outfile_two = NamedTemporaryFile(suffix='.cool', delete=False) outfile_two.close() args = "--matrices {} {} --normalize smallest -o {} {}".format( matrix_one_cool, matrix_two_cool, outfile_one.name, outfile_two.name).split() # hicNormalize.main(args) compute(hicNormalize.main, args, 5) test_one = hm.hiCMatrix(ROOT + "/smallest_one.cool") test_two = hm.hiCMatrix(ROOT + "/smallest_two.cool") new_one = hm.hiCMatrix(outfile_one.name) new_two = hm.hiCMatrix(outfile_two.name) nt.assert_equal(test_one.matrix.data, new_one.matrix.data) nt.assert_equal(test_one.cut_intervals, new_one.cut_intervals) nt.assert_equal(test_two.matrix.data, new_two.matrix.data) nt.assert_equal(test_two.cut_intervals, new_two.cut_intervals) os.unlink(outfile_one.name) os.unlink(outfile_two.name)
def test_build_matrix_restrictionCutFile_two( sam1, sam2, outFile, qcFolder, outBam, binSize, restrictionCutFile, minDistance, maxDistance, maxLibraryInsertSize, restrictionSequence, danglingSequence, region, removeSelfLigation, minMappingQuality, threads, inputBufferSize): # test more args for restrictionCutFile option region = genomicRegion(region) args = "-s {} {} --restrictionCutFile {} --outFileName {} --QCfolder {} " \ "--restrictionSequence {} " \ "--danglingSequence {} " \ "--minDistance {} " \ "--maxLibraryInsertSize {} --threads {} " \ "--region {} --removeSelfLigation {} ".format(bam_R1, bam_R2, restrictionCutFile, outFile.name, qcFolder, restrictionSequence, danglingSequence, minDistance, maxLibraryInsertSize, threads, region, removeSelfLigation).split() # hicBuildMatrix.main(args) compute(hicBuildMatrix.main, args, 5) os.unlink(outFile.name) shutil.rmtree(qcFolder)
def test_hicConvertFormat_h5_to_ginteractions(): outfile = NamedTemporaryFile(suffix='.ginteractions', delete=False) outfile.close() args = "--matrices {} --outFileName {} --inputFormat h5 --outputFormat ginteractions ".format( original_matrix_h5, outfile.name).split() compute(hicConvertFormat.main, args, 5)
def test_build_matrix_chromosome_sizes(capsys): outfile = NamedTemporaryFile(suffix='.h5', delete=False) outfile.close() outfile_bam = NamedTemporaryFile(suffix='.bam', delete=False) outfile.close() qc_folder = mkdtemp(prefix="testQC_") args = "-s {} {} --outFileName {} -bs 5000 -b {} --QCfolder {} --threads 4 --chromosomeSizes {} \ --restrictionSequence GATC --danglingSequence GATC -rs {}".format( sam_R1, sam_R2, outfile.name, outfile_bam.name, qc_folder, ROOT + 'hicBuildMatrix/dm3.chrom.sizes', dpnii_file).split() # hicBuildMatrix.main(args) compute(hicBuildMatrix.main, args, 5) test = hm.hiCMatrix( ROOT + "hicBuildMatrix/chromosome_sizes/small_test_chromosome_size.h5") new = hm.hiCMatrix(outfile.name) nt.assert_equal(test.matrix.data, new.matrix.data) nt.assert_equal(test.cut_intervals, new.cut_intervals) # print("MATRIX NAME:", outfile.name) print(set(os.listdir(ROOT + "QC/"))) assert are_files_equal(ROOT + "QC/QC.log", qc_folder + "/QC.log") assert set(os.listdir(ROOT + "QC/")) == set(os.listdir(qc_folder)) # accept delta of 60 kb, file size is around 4.5 MB assert abs( os.path.getsize(ROOT + "hicBuildMatrix/chromosome_sizes/test.bam") - os.path.getsize(outfile_bam.name)) < 64000 os.unlink(outfile.name) shutil.rmtree(qc_folder)
def test_plot_region_interaction_file(): outfile = NamedTemporaryFile(suffix='.png', prefix='viewpoint4', delete=False) outfile_interactions = NamedTemporaryFile(suffix='.bedgraph', prefix='viewpoint_interactons', delete=False) matrix = ROOT + 'Li_et_al_2015.h5' args = "--matrix {} --region X:3000000-3500000 -rp X:3200000-3300000 --outFileName {} -i {} --dpi 300".format( matrix, outfile.name, outfile_interactions.name).split() # hicPlotViewpoint.main(args) compute(hicPlotViewpoint.main, args, 5) res = compare_images(ROOT + 'hicPlotViewpoint/li_viewpoint_32-33Mb.png', outfile.name, tol=40) assert res is None, res assert are_files_equal( ROOT + 'hicPlotViewpoint/li_32-33mb_interactions.bedgraph', outfile_interactions.name) os.remove(outfile.name) os.remove(outfile_interactions.name)
def test_build_matrix_restrictionCutFile_eight(sam1, sam2, outFile, qcFolder, outBam, binSize, restrictionCutFile, minDistance, maxDistance, maxLibraryInsertSize, restrictionSequence, danglingSequence, region, removeSelfLigation, minMappingQuality, threads, inputBufferSize): # added skipDuplicationCheck args = "-s {} {} --restrictionCutFile {} --outFileName {} --QCfolder {} " \ "--restrictionSequence {} " \ "--danglingSequence {} " \ "--minDistance {} " \ "--maxLibraryInsertSize {} --threads {} " \ "--removeSelfLigation {} --keepSelfCircles " \ "--minMappingQuality {} --inputBufferSize {} " \ "--doTestRun --skipDuplicationCheck ".format(bam_R1, bam_R2, restrictionCutFile, outFile.name, qcFolder, restrictionSequence, danglingSequence, minDistance, maxLibraryInsertSize, threads, removeSelfLigation, minMappingQuality, inputBufferSize).split() # hicBuildMatrix.main(args) compute(hicBuildMatrix.main, args, 5) # os.unlink(outFile.name) shutil.rmtree(qcFolder)
def test_main_one_file(): outfile_domains = NamedTemporaryFile(suffix='.txt', delete=True) args = "-d {} -om {} ".format( ROOT + 'hicMergeDomains/10kbtad_domains.bed', outfile_domains.name).split() # hicMergeDomains.main(args) compute(hicMergeDomains.main, args, 5)
def test_build_matrix_restriction_enzyme(capsys): outfile = NamedTemporaryFile(suffix='.h5', delete=False) outfile.close() outfile_bam = NamedTemporaryFile(suffix='.bam', delete=False) outfile.close() qc_folder = mkdtemp(prefix="testQC_") args = "-s {} {} --outFileName {} -bs 5000 -b {} --QCfolder {} --threads 4 --danglingSequence GATC AGCT --restrictionSequence GATC AAGCTT -rs {} {}".format( sam_R1, sam_R2, outfile.name, outfile_bam.name, qc_folder, dpnii_file, ROOT + 'hicFindRestSite/hindIII.bed').split() # hicBuildMatrix.main(args) compute(hicBuildMatrix.main, args, 5) test = hm.hiCMatrix(ROOT + "small_test_matrix_parallel_two_rc.h5") new = hm.hiCMatrix(outfile.name) nt.assert_equal(test.matrix.data, new.matrix.data) nt.assert_equal(test.cut_intervals, new.cut_intervals) # print("MATRIX NAME:", outfile.name) print(set(os.listdir(ROOT + "QC_multi_restriction/"))) assert are_files_equal(ROOT + "QC_multi_restriction/QC.log", qc_folder + "/QC.log") assert set(os.listdir(ROOT + "QC_multi_restriction/")) == set( os.listdir(qc_folder)) # accept delta of 60 kb, file size is around 4.5 MB assert abs( os.path.getsize(ROOT + "small_test_matrix_result.bam") - os.path.getsize(outfile_bam.name)) < 64000 os.unlink(outfile.name) shutil.rmtree(qc_folder)
def test_trivial_run(matrices, labels, plotsize1, plotsize2, perchr, skipDiagonal, maxdepth, chromosomeExclude): """ Simple test for general behaviour with all commandline args. """ outfile_new = NamedTemporaryFile(suffix='.png', prefix='plotFile', delete=False) outFileData_new = NamedTemporaryFile(suffix='.txt', prefix='dataFile', delete=False) args = "--matrices {} --plotFile {} {} --plotsize {} {} {} --outFileData {} --maxdepth {} --chromosomeExclude {}".format( matrices, outfile_new.name, labels, plotsize1, plotsize2, perchr, outFileData_new.name, maxdepth, chromosomeExclude, ).split() # with open("test.txt", 'a') as fo: # fo.write(str(args)) # fo.write("\n") # hicPlotDistVsCounts.main(args) compute(hicPlotDistVsCounts.main, args, 5)
def test_hicAggregateContacts_clustering_cool(): outfile_aggregate_plots = NamedTemporaryFile(suffix='.png', prefix='hicaggregate_test_', delete=False) outfile_heatmaps = NamedTemporaryFile(suffix='.png', prefix='hicaggregate_heatmap_', delete=False) args = "--matrix {root}/Li_et_al_2015.cool --BED {root}/hicAggregateContacts/test_regions.bed " \ "--outFileName {out_agg} --numberOfBins 30 --range 50000:900000 --hclust 4 " \ "--diagnosticHeatmapFile {out_heat} --howToCluster diagonal --disable_bbox_tight --dpi 100 " \ "--BED2 {root}/hicAggregateContacts/test_regions.bed".format(root=ROOT, out_agg=outfile_aggregate_plots.name, out_heat=outfile_heatmaps.name) test_image_agg = ROOT + 'hicAggregateContacts/master_aggregate_hclust4.png' test_image_heatmap = ROOT + 'hicAggregateContacts/master_heatmap.png' # hicexplorer.hicAggregateContacts.main(args.split()) compute(hicexplorer.hicAggregateContacts.main, args.split(), 5) res = compare_images(test_image_agg, outfile_aggregate_plots.name, tolerance) assert res is None, res res = compare_images(test_image_heatmap, outfile_heatmaps.name, tolerance) assert res is None, res os.remove(outfile_aggregate_plots.name) os.remove(outfile_heatmaps.name)
def test_main_h5(): outfile_loop_h5 = NamedTemporaryFile(suffix='.bedgraph', delete=True) args = "--matrix {} -o {} -pit 1 -p 0.5 -pp 0.5 -t 4 -tpc 4".format( ROOT + "small_test_matrix.h5", outfile_loop_h5.name).split() # hicDetectLoops.main(args) compute(hicDetectLoops.main, args, 5)
def test_build_matrix_rf_multi(): outfile = NamedTemporaryFile(suffix='.h5', delete=False) outfile.close() qc_folder = mkdtemp(prefix="testQC_") args = "-s {} {} -rs {} {} --outFileName {} --QCfolder {} " \ "--restrictionSequence GATC AAGCTT " \ "--danglingSequence GATC AGCT " \ "--minDistance 150 " \ "--maxLibraryInsertSize 1500 --threads 4".format(sam_R1, sam_R2, dpnii_file, ROOT + 'hicFindRestSite/hindIII.bed', outfile.name, qc_folder).split() # --danglingSequence GATC AGCT --restrictionSequence GATC AAGCTT # hicBuildMatrix.main(args) compute(hicBuildMatrix.main, args, 5) test = hm.hiCMatrix(ROOT + "small_test_rf_matrix_multiple.h5") new = hm.hiCMatrix(outfile.name) nt.assert_equal(test.matrix.data, new.matrix.data) nt.assert_equal(test.cut_intervals, new.cut_intervals) print(set(os.listdir(ROOT + "QC_rc_multiple/"))) assert are_files_equal(ROOT + "QC_rc_multiple/QC.log", qc_folder + "/QC.log") assert set(os.listdir(ROOT + "QC_rc_multiple/")) == set( os.listdir(qc_folder)) os.unlink(outfile.name) shutil.rmtree(qc_folder)
def test_build_matrix_cooler(): outfile = NamedTemporaryFile(suffix='.cool', delete=False) outfile.close() outfile_bam = NamedTemporaryFile(suffix='.bam', delete=False) outfile.close() qc_folder = mkdtemp(prefix="testQC_") args = "-s {} {} --outFileName {} -bs 5000 -b {} --QCfolder {} --threads 4 \ --restrictionSequence GATC --danglingSequence GATC -rs {}".format( sam_R1, sam_R2, outfile.name, outfile_bam.name, qc_folder, dpnii_file).split() # hicBuildMatrix.main(args) compute(hicBuildMatrix.main, args, 5) test = hm.hiCMatrix(ROOT + "small_test_matrix_parallel.h5") new = hm.hiCMatrix(outfile.name) nt.assert_equal(test.matrix.data, new.matrix.data) # nt.assert_equal(test.cut_intervals, new.cut_intervals) nt.assert_equal(len(new.cut_intervals), len(test.cut_intervals)) cut_interval_new_ = [] cut_interval_test_ = [] for x in new.cut_intervals: cut_interval_new_.append(x[:3]) for x in test.cut_intervals: cut_interval_test_.append(x[:3]) nt.assert_equal(cut_interval_new_, cut_interval_test_) # print(set(os.listdir(ROOT + "QC/"))) assert are_files_equal(ROOT + "QC/QC.log", qc_folder + "/QC.log") assert set(os.listdir(ROOT + "QC/")) == set(os.listdir(qc_folder)) os.unlink(outfile.name) shutil.rmtree(qc_folder)
def test_plot_single_point_interaction_file_two_matrices(): outfile = NamedTemporaryFile(suffix='.png', prefix='viewpoint2', delete=False) outfile_interactions_one = NamedTemporaryFile( suffix='.bedgraph', prefix='viewpoint_interactons_Li_et_al_2015.h5', delete=False) outfile_interactions_two = NamedTemporaryFile( suffix='.bedgraph', prefix='viewpoint_interactons_Li_et_al_2015_twice.h5', delete=False) matrix = ROOT + 'Li_et_al_2015.h5' + ' ' + ROOT + 'Li_et_al_2015_twice.h5' args = "--matrix {} --region X:3000000-3500000 -rp X:3200000 --outFileName {} -i {} --dpi 300".format( matrix, outfile.name, 'viewpoint_interactons').split() # hicPlotViewpoint.main(args) compute(hicPlotViewpoint.main, args, 5) res = compare_images(ROOT + '/hicPlotViewpoint/li_viewpoint_32Mb_twice.png', outfile.name, tol=40) assert res is None, res assert are_files_equal( ROOT + '/hicPlotViewpoint/li_32mb_interactions_one.bedgraph', outfile_interactions_one.name) assert are_files_equal( ROOT + '/hicPlotViewpoint/li_32mb_interactions_two.bedgraph', outfile_interactions_two.name) os.remove(outfile.name) os.remove(outfile_interactions_one.name) os.remove(outfile_interactions_two.name)
def test_hicConvertFormat_h5_to_hicpro(): outfile = NamedTemporaryFile(suffix='.hicpro', delete=False) outfile_bed = NamedTemporaryFile(suffix='.bed', delete=False) outfile.close() args = "--matrices {} --outFileName {} --inputFormat h5 --outputFormat hicpro --bedFileHicpro {}".format( original_matrix_h5, outfile.name, outfile_bed.name).split() compute(hicConvertFormat.main, args, 5)
def test_cool_all_multi_core_all_multichr_chromosome_not_in_matrix(): outfile_pref = NamedTemporaryFile(prefix='differential_tad', delete=True) args = "--targetMatrix {} --controlMatrix {} --tadDomains {} -t {} -o {} -m {} -mr {}".format( ROOT + "GSM2644945_Untreated-R1.100000_chr1.cool", ROOT + "GSM2644947_Auxin2days-R1.100000_chr1.cool", ROOT + "untreated_R1_domains_chr1_chr2.bed", 4, outfile_pref.name, 'all', 'all').split() compute(hicDifferentialTAD.main, args, 5)
def test_hicAggregateContacts_chromosome_not_given(): outfile_aggregate_plots = NamedTemporaryFile(suffix='.png', prefix='hicaggregate_test_', delete=False) args = "--matrix {root}/Li_et_al_2015.h5 --BED {root}/hicAggregateContacts/test_regions_region_not_given.bed " \ "--outFileName {out_agg} --numberOfBins 30 --range 50000:900000 --disable_bbox_tight --dpi 100 "\ "--mode intra-chr --perChr ".format(root=ROOT, out_agg=outfile_aggregate_plots.name) compute(hicexplorer.hicAggregateContacts.main, args.split(), 5)
def test_pca_bigwig_gene_density_intermediate_matrices_norm(): pca1 = NamedTemporaryFile(suffix='.bw', delete=False) pca2 = NamedTemporaryFile(suffix='.bw', delete=False) pearson_matrix = NamedTemporaryFile(suffix='.cool', delete=False) obs_exp_matrix = NamedTemporaryFile(suffix='.cool', delete=False) pca1.close() pca2.close() pearson_matrix.close() obs_exp_matrix.close() matrix = ROOT + "small_test_matrix.h5" gene_track = ROOT + 'dm3_genes.bed.gz' chromosomes = 'chrX chrXHet' args = "--matrix {} --outputFileName {} {} -f bigwig -noe 2 \ --extraTrack {} --chromosomes {} --pearsonMatrix {} --obsexpMatrix {} \ --method dist_norm --ligation_factor"\ .format(matrix, pca1.name, pca2.name, gene_track, chromosomes, pearson_matrix.name, obs_exp_matrix.name).split() # hicPCA.main(args) compute(hicPCA.main, args, 5) chrom_list = ['chrX', 'chrXHet'] assert are_files_equal_bigwig(ROOT + "hicPCA/pca1_gene_track.bw", pca1.name, chrom_list) assert are_files_equal_bigwig(ROOT + "hicPCA/pca2_gene_track.bw", pca2.name, chrom_list) test_pearson = hm.hiCMatrix(ROOT + "hicPCA/pearson_norm.cool") new_pearson = hm.hiCMatrix(pearson_matrix.name) test_obs_exp = hm.hiCMatrix(ROOT + "hicPCA/obsexp_norm.cool") new_obs_exp = hm.hiCMatrix(obs_exp_matrix.name) # load h5 matrices to compare if they are store the same data test_obs_exp_h5 = hm.hiCMatrix(ROOT + "hicPCA/obsexp_norm.h5") test_pearson_h5 = hm.hiCMatrix(ROOT + "hicPCA/pearson_norm.h5") nt.assert_array_almost_equal(test_pearson.matrix.data, new_pearson.matrix.data, decimal=DELTA_DECIMAL) nt.assert_array_almost_equal(test_obs_exp.matrix.data, new_obs_exp.matrix.data, decimal=DELTA_DECIMAL) nt.assert_array_almost_equal(test_pearson_h5.matrix.data, new_pearson.matrix.data, decimal=DELTA_DECIMAL) nt.assert_array_almost_equal(test_obs_exp_h5.matrix.data, new_obs_exp.matrix.data, decimal=DELTA_DECIMAL) os.unlink(pca1.name) os.unlink(pca2.name) os.unlink(obs_exp_matrix.name) os.unlink(pearson_matrix.name)
def test_main_one_file_protein(): outfile_domains = NamedTemporaryFile(suffix='.txt', delete=True) args = "-d {} -om {} -p {} ".format( ROOT + 'hicMergeDomains/10kbtad_domains.bed', outfile_domains.name, ROOT + 'hicMergeDomains/ctcf_sorted.bed').split() # hicMergeDomains.main(args) compute(hicMergeDomains.main, args, 5) are_files_equal(outfile_domains.name, ROOT + 'hicMergeDomains/one_file', delta=2)
def test_build_matrix_fail(capsys): outfile = NamedTemporaryFile(suffix='', delete=False) outfile.close() outfile_bam = NamedTemporaryFile(suffix='.bam', delete=False) outfile.close() qc_folder = mkdtemp(prefix="testQC_") args = "-s {} {} --outFileName {} -bs 5000 -b {} --QCfolder {} --threads 4 ".format( sam_R1, sam_R2, outfile_bam.name, outfile.name, qc_folder).split() # hicBuildMatrix.main(args) compute(hicBuildMatrix.main, args, 5)
def test_main_cool_chromosomes_threads_inner_threads(): outfile_loop_cool = NamedTemporaryFile(suffix='.bedgraph', delete=True) args = "--matrix {} -o {} --maxLoopDistance 3000000 -pit 1 -w 5 -pw 2 -p 0.5 -pp 0.55 --chromosomes 1 2 --threads 2 --threadsPerChromosome 4".format( ROOT + "hicDetectLoops/GSE63525_GM12878_insitu_primary_2_5mb.cool", outfile_loop_cool.name).split() # hicDetectLoops.main(args) compute(hicDetectLoops.main, args, 5) assert are_files_equal(ROOT + "hicDetectLoops/loops.bedgraph", outfile_loop_cool.name, delta=0)
def test_hicConvertFormat_h5_to_mcool(): outfile = NamedTemporaryFile(suffix='.cool', delete=False) outfile.close() args = "--matrices {} --outFileName {} --inputFormat h5 --outputFormat mcool -r 10000 100000 200000 ".format( original_matrix_h5, outfile.name).split() compute(hicConvertFormat.main, args, 5) new1 = hm.hiCMatrix(outfile.name + '::/resolutions/10000') # noqa: F841 new2 = hm.hiCMatrix(outfile.name + '::/resolutions/100000') # noqa: F841 new3 = hm.hiCMatrix(outfile.name + '::/resolutions/200000') # noqa: F841
def test_compute_background_functional(): outfile = NamedTemporaryFile(suffix='.txt', delete=False) outfile.close() 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) compute(chicViewpointBackgroundModel.main, args, 5) assert are_files_equal(ROOT + 'background.txt', outfile.name, delta=700, skip=1)
def test_trivial_run_xfail(matrix, outFileName, chromosomes, action): """ Test checks if all commandline args work in general. """ args = "--matrix {} --outFileName {} --chromosomes {} --action {}".format( matrix, outFileName.name, chromosomes, action, ).split() # hicAdjustMatrix.main(args) compute(hicAdjustMatrix.main, args, 5)