Пример #1
0
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()
    hicConvertFormat.main(args)
Пример #2
0
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)
Пример #3
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()
    hicConvertFormat.main(args)

    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
Пример #4
0
def test_hicConvertFormat_h5_to_cool():

    # original_matrix = ''
    outfile = NamedTemporaryFile(suffix='.cool', delete=False)
    outfile.close()

    args = "--matrices {} --outFileName {} --inputFormat h5 --outputFormat cool".format(original_matrix_h5, outfile.name).split()
    hicConvertFormat.main(args)

    test = hm.hiCMatrix(original_matrix_cool)
    # print(outfile.name)
    new = hm.hiCMatrix(outfile.name)
    nt.assert_array_almost_equal(test.matrix.data, new.matrix.data, decimal=DELTA_DECIMAL)
Пример #5
0
def test_hicConvertFormat_h5_to_cool_enforce_integer():

    outfile = NamedTemporaryFile(suffix='.cool', delete=False)
    outfile.close()

    args = "--matrices {} --outFileName {} --inputFormat h5 --outputFormat cool ".format(
        original_matrix_h5, outfile.name).split()
    hicConvertFormat.main(args)

    test = hm.hiCMatrix(original_matrix_cool)
    new = hm.hiCMatrix(outfile.name)
    nt.assert_array_almost_equal(test.matrix.data, new.matrix.data, decimal=0)
    assert issubclass(test.matrix.data.dtype.type, np.integer)
Пример #6
0
def test_trivial_functionality(
    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)
    outFileName.close()

    args = "--matrices {} --outFileName {} --inputFormat {} --outputFormat {} {}".format(
        matrices,
        outFileName.name,
        inputFormat,
        outputFormat,
        resolutions,
    ).split()

    hicConvertFormat.main(args)

    test = hm.hiCMatrix(matrices)

    new = hm.hiCMatrix(outFileName.name)
    nt.assert_array_almost_equal(test.matrix.data,
                                 new.matrix.data,
                                 decimal=DELTA_DECIMAL)

    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_)
    os.unlink(outFileName.name)
Пример #7
0
def test_hicConvertFormat_hicpro_to_cool():

    outfile = NamedTemporaryFile(suffix='.cool', delete=False)
    outfile.close()
    hicprofile = ROOT + '/test_matrix.hicpro'
    bedfile = ROOT + '/test_matrix.bed'
    args = "--matrices {} --outFileName {} --inputFormat hicpro --outputFormat cool --bedFileHicpro {}".format(hicprofile, outfile.name, bedfile).split()
    hicConvertFormat.main(args)

    # test = hm.hiCMatrix(original_matrix_cool)
    # print(outfile.name)
    new = hm.hiCMatrix(outfile.name)

    matrixFileHandlerInput = MatrixFileHandler(pFileType='hicpro', pMatrixFile=hicprofile,
                                               pBedFileHicPro=bedfile)

    _matrix, cut_intervals, nan_bins, \
        distance_counts, correction_factors = matrixFileHandlerInput.load()

    new.matrix = triu(new.matrix)
    nt.assert_array_almost_equal(new.matrix.data, _matrix.data, decimal=0)
Пример #8
0
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)

    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_cool_specific_trivial_run(
    matrices,
    outputFormat,
    correction_name,
    correction_division,
    store_applied_correction,
    chromosome,
    enforce_integer,
    load_raw_values,
):
    """
        Cool input format supports some specific options like correction_name, correction_division...
        Therefore, cool input format is explicitly tested in a single test function.
    """
    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="test_ConvertFormat_trivial_run_cool.{}".format(outputFormat),
        delete=False)
    outFileName.close()

    args = "--matrices {} --outFileName {} --outputFormat {} --inputFormat {} --correction_name {} {} {} --chromosome {} {} {}".format(
        matrices,
        outFileName.name,
        outputFormat,
        inputFormat,
        correction_name,
        correction_division,
        store_applied_correction,
        chromosome,
        enforce_integer,
        load_raw_values,
    ).split()

    hicConvertFormat.main(args)