def test_loose_pValue_multiple_interaction_files(): outfile = NamedTemporaryFile(suffix='.bed', delete=False) output_folder = mkdtemp(prefix="output_") 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.bed', ROOT + 'chicViewpoint/output_1/MB-E10-5_chr1_chr1_14300280_14300280_Eya1.bed', ROOT + 'background.bed', 200000, 200000, 'output_significant.bed', output_folder, 1.5, 0.2, output_folder_target).split() chicSignificantInteractions.main(args) assert are_files_equal( ROOT + "chicSignificantInteractions/output_3/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.bed", output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.bed') assert are_files_equal( ROOT + "chicSignificantInteractions/output_3/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_output_significant.bed", output_folder + '/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_output_significant.bed') 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_loose_pValue_one_interaction_file_threshold_file(): outfile = NamedTemporaryFile(suffix='.txt', delete=False) output_folder = mkdtemp(prefix="output_") output_folder_target = mkdtemp(prefix="output_target_") outfile.close() 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, ROOT + 'thresholdFile_loose_pValue.txt', ROOT + 'thresholdFile_pValue.txt', 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 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_batchMode_xFold_csn_1_threshold_file(): outfile = NamedTemporaryFile(suffix='.txt', delete=False) outfile_target_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 -t {}".format( ROOT + 'chicViewpoint/fileNames_one_matrix.txt', ROOT + 'chicViewpoint/output_2', ROOT + 'background.txt', 200000, 200000, 'output_significant.txt', output_folder, ROOT + 'thresholdFile_xfold.txt', ROOT + 'thresholdFile_pValue.txt', 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_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))
def test_batchMode_loose_pValue_csn_2(): outfile = NamedTemporaryFile(suffix='.bed', delete=False) outfile_target_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.bed', 200000, 200000, 'output_significant.bed', output_folder, 0.5, 0.2, output_folder_target, outfile_significant_files_list.name, outfile_target_list.name).split() chicSignificantInteractions.main(args) assert are_files_equal( ROOT + "chicSignificantInteractions/output_5/FL-E13-5_chr1_chr1_4487435_4487435_Sox17_output_significant.bed", output_folder + '/FL-E13-5_chr1_chr1_4487435_4487435_Sox17_output_significant.bed') assert are_files_equal( ROOT + "chicSignificantInteractions/output_5/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.bed", output_folder + '/FL-E13-5_chr1_chr1_14300280_14300280_Eya1_output_significant.bed') assert are_files_equal( ROOT + "chicSignificantInteractions/output_5/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d_output_significant.bed", output_folder + '/FL-E13-5_chr1_chr1_19093103_19093103_Tfap2d_output_significant.bed') assert are_files_equal( ROOT + "chicSignificantInteractions/output_5/MB-E10-5_chr1_chr1_4487435_4487435_Sox17_output_significant.bed", output_folder + '/MB-E10-5_chr1_chr1_4487435_4487435_Sox17_output_significant.bed') assert are_files_equal( ROOT + "chicSignificantInteractions/output_5/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_output_significant.bed", output_folder + '/MB-E10-5_chr1_chr1_14300280_14300280_Eya1_output_significant.bed') assert are_files_equal( ROOT + "chicSignificantInteractions/output_5/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_output_significant.bed", output_folder + '/MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_output_significant.bed') assert are_files_equal( ROOT + "chicSignificantInteractions/output_5_target/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_target.bed", output_folder_target + '/FL-E13-5_MB-E10-5_chr1_chr1_4487435_4487435_Sox17_target.bed', skip=4) assert are_files_equal( ROOT + "chicSignificantInteractions/output_5_target/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_target.bed", output_folder_target + '/FL-E13-5_MB-E10-5_chr1_chr1_14300280_14300280_Eya1_target.bed', skip=4) assert are_files_equal( ROOT + "chicSignificantInteractions/output_5_target/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_target.bed", output_folder_target + '/FL-E13-5_MB-E10-5_chr1_chr1_19093103_19093103_Tfap2d_target.bed', 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))
def test_xFold(): outfile_significant = NamedTemporaryFile(suffix='.hdf5', delete=False) outfile_target = NamedTemporaryFile(suffix='.hdf5', delete=False) # output_folder = mkdtemp(prefix="output_") # output_folder_target = mkdtemp(prefix="output_target_") outfile_significant.close() outfile_target.close() args = "--interactionFile {} --backgroundModelFile {} --range {} {} --outFileNameSignificant {} --outFileNameTarget {} --xFoldBackground {} --pValue {} -t {} --combinationMode dual".format( ROOT + 'chicViewpoint/two_matrices.hdf5', ROOT + 'background.txt', 200000, 200000, outfile_significant.name, outfile_target.name, 1.5, 0.2, 1).split() chicSignificantInteractions.main(args) significantFileH5Object = h5py.File(outfile_significant.name, 'r') assert 'FL-E13-5_chr1' in significantFileH5Object assert 'MB-E10-5_chr1' in significantFileH5Object assert 'genes' in significantFileH5Object['FL-E13-5_chr1'] assert 'genes' in significantFileH5Object['MB-E10-5_chr1'] assert len(significantFileH5Object) == 2 assert significantFileH5Object.attrs['type'] == 'significant' assert len(significantFileH5Object.attrs['range']) == 2 assert significantFileH5Object.attrs['range'][0] == 200000 assert significantFileH5Object.attrs['range'][1] == 200000 # assert significantFileH5Object.attrs['averageContactBin'] == 5 assert significantFileH5Object.attrs['fixateRange'] == 500000 assert significantFileH5Object.attrs['mode_preselection'] == 'xfold' assert significantFileH5Object.attrs['mode_preselection_value'] == 1.5 assert significantFileH5Object.attrs['pvalue'] == 0.2 assert significantFileH5Object.attrs['combinationMode'] == 'dual' assert significantFileH5Object.attrs['truncateZeroPvalues'] == False assert significantFileH5Object.attrs['peakInteractionsThreshold'] == 5 for chromosome in significantFileH5Object['FL-E13-5_chr1']: assert len(significantFileH5Object['FL-E13-5_chr1'][chromosome]) == 3 for gene in significantFileH5Object['FL-E13-5_chr1'][chromosome]: assert len(significantFileH5Object['FL-E13-5_chr1'][chromosome] [gene]) == 12 for data in significantFileH5Object['FL-E13-5_chr1'][chromosome][ gene]: assert data in [ 'chromosome', 'end_list', 'gene', 'interaction_data_list', 'pvalue', 'raw', 'reference_point_end', 'reference_point_start', 'relative_position_list', 'start_list', 'sum_of_interactions', 'xfold' ] for chromosome in significantFileH5Object['MB-E10-5_chr1']: assert len(significantFileH5Object['MB-E10-5_chr1'][chromosome]) == 3 for gene in significantFileH5Object['MB-E10-5_chr1'][chromosome]: assert len(significantFileH5Object['MB-E10-5_chr1'][chromosome] [gene]) == 12 for data in significantFileH5Object['MB-E10-5_chr1'][chromosome][ gene]: assert data in [ 'chromosome', 'end_list', 'gene', 'interaction_data_list', 'pvalue', 'raw', 'reference_point_end', 'reference_point_start', 'relative_position_list', 'start_list', 'sum_of_interactions', 'xfold' ] significantFileH5Object.close() targetFileH5Object = h5py.File(outfile_target.name, 'r') assert 'FL-E13-5_chr1' in targetFileH5Object assert 'MB-E10-5_chr1' in targetFileH5Object['FL-E13-5_chr1'] # assert 'genes' in targetFileH5Object['FL-E13-5_chr1'] assert len(targetFileH5Object) == 1 assert len(targetFileH5Object['FL-E13-5_chr1']) == 1 assert targetFileH5Object.attrs['type'] == 'target' assert len(targetFileH5Object.attrs['range']) == 2 assert targetFileH5Object.attrs['range'][0] == 200000 assert targetFileH5Object.attrs['range'][1] == 200000 # assert targetFileH5Object.attrs['averageContactBin'] == 5 assert targetFileH5Object.attrs['fixateRange'] == 500000 assert targetFileH5Object.attrs['mode_preselection'] == 'xfold' assert targetFileH5Object.attrs['mode_preselection_value'] == 1.5 assert targetFileH5Object.attrs['pvalue'] == 0.2 assert targetFileH5Object.attrs['combinationMode'] == 'dual' assert targetFileH5Object.attrs['truncateZeroPvalues'] == False assert targetFileH5Object.attrs['peakInteractionsThreshold'] == 5 for matrix in targetFileH5Object['FL-E13-5_chr1']: assert len(targetFileH5Object['FL-E13-5_chr1'][matrix]) == 2 for chromosome in targetFileH5Object['FL-E13-5_chr1'][matrix]: assert len( targetFileH5Object['FL-E13-5_chr1'][matrix][chromosome]) == 3 for gene in targetFileH5Object['FL-E13-5_chr1'][matrix][chromosome]: assert len(targetFileH5Object['FL-E13-5_chr1'][matrix][chromosome] [gene]) == 5 for data in targetFileH5Object['FL-E13-5_chr1'][matrix][ chromosome][gene]: assert data in [ 'chromosome', 'end_list', 'gene', 'interaction_data_list', 'pvalue', 'raw', 'reference_point_end', 'reference_point_start', 'relative_position_list', 'start_list', 'sum_of_interactions', 'xfold' ] targetFileH5Object.close()