Пример #1
0
def test_main_4(tmpdir, capsys):
    """
    Test for an empty input.
    """

    p_ctg_file = tmpdir.join('p_ctg.fa')
    p_tp_file = tmpdir.join('p_ctg_tiling_path')
    a_tp_file = tmpdir.join('a_ctg_tiling_path')
    a_ctg_file = tmpdir.join('a_ctg.fa')
    p_ctg_file.write('')
    p_tp_file.write('')
    a_tp_file.write('')
    a_ctg_file.write('')

    expected = {'nodes': {}, 'edges': {}, 'paths': {}}

    argv = ['prog',
            '--p-ctg-tiling-path', str(p_tp_file),
            '--a-ctg-tiling-path', str(a_tp_file),
            '--p-ctg-fasta', str(p_ctg_file),
            '--a-ctg-fasta', str(a_ctg_file),
            # '--write-contigs',
            '--min-p-len', '0',
            '--min-a-len', '0',
            # '--only-these-contigs'
            ]
    mod.main(argv)
    out, err = capsys.readouterr()

    result = json.loads(out)

    assert(result == expected)
Пример #2
0
def test_main_2(tmpdir, capsys):
    """
    Test output with sequences.
    """

    p_ctg_file = tmpdir.join('p_ctg.fa')
    p_tp_file = tmpdir.join('p_ctg_tiling_path')
    a_tp_file = tmpdir.join('a_ctg_tiling_path')
    a_ctg_file = tmpdir.join('a_ctg.fa')
    all_seqs, p_ctg_tps, a_ctg_tps, expected = setup_test(p_ctg_file, p_tp_file, a_ctg_file, a_tp_file)

    # This test expects that the nodes are initialized with sequences, so
    # set the reference to the generated sequences here.
    for key, node in expected['nodes'].iteritems():
        node['seq'] = all_seqs[key]

    argv = ['prog',
            '--p-ctg-tiling-path', str(p_tp_file),
            '--a-ctg-tiling-path', str(a_tp_file),
            '--p-ctg-fasta', str(p_ctg_file),
            '--a-ctg-fasta', str(a_ctg_file),
            '--write-contigs',
            '--min-p-len', '0',
            '--min-a-len', '0',
            # '--only-these-contigs'
            ]
    mod.main(argv)
    out, err = capsys.readouterr()

    result = json.loads(out)

    assert(result == expected)
Пример #3
0
def test_main_1(tmpdir, capsys):
    """
    Test without writing contig sequences.
    """

    p_ctg_file = tmpdir.join('p_ctg.fa')
    p_tp_file = tmpdir.join('p_ctg_tiling_path')
    a_tp_file = tmpdir.join('a_ctg_tiling_path')
    a_ctg_file = tmpdir.join('a_ctg.fa')
    all_seqs, p_ctg_tps, a_ctg_tps, expected = setup_test(p_ctg_file, p_tp_file, a_ctg_file, a_tp_file)

    argv = ['prog',
            '--p-ctg-tiling-path', str(p_tp_file),
            '--a-ctg-tiling-path', str(a_tp_file),
            '--p-ctg-fasta', str(p_ctg_file),
            '--a-ctg-fasta', str(a_ctg_file),
            # '--write-contigs',
            '--min-p-len', '0',
            '--min-a-len', '0',
            # '--only-these-contigs'
            ]
    mod.main(argv)
    out, err = capsys.readouterr()

    result = json.loads(out)

    assert(result == expected)
Пример #4
0
def test_main_3(tmpdir, capsys):
    """
    Test the whitelist.
    """

    p_ctg_file = tmpdir.join('p_ctg.fa')
    p_tp_file = tmpdir.join('p_ctg_tiling_path')
    a_tp_file = tmpdir.join('a_ctg_tiling_path')
    a_ctg_file = tmpdir.join('a_ctg.fa')
    all_seqs, p_ctg_tps, a_ctg_tps, expected = setup_test(
        p_ctg_file, p_tp_file, a_ctg_file, a_tp_file)

    only_these_contigs = set(['000002F'])
    whitelist_file = tmpdir.join('only_these_contigs')
    whitelist_file.write('\n'.join(only_these_contigs) + '\n')

    # Adjust the expected results.
    # Remove any node not in the whitelist.
    blacklist_nodes = [
        key for key in (list(p_ctg_tps.keys()) + list(a_ctg_tps.keys()))
        if key not in only_these_contigs
    ]
    for key in blacklist_nodes:
        expected['nodes'].pop(key, None)
    # Remove any edge not in the whitelist.
    blacklist_edges = [
        key for key, edge in expected['edges'].items()
        if edge['v'] not in only_these_contigs
        or edge['w'] not in only_these_contigs
    ]
    for key in blacklist_edges:
        expected['edges'].pop(key, None)

    argv = [
        'prog',
        '--p-ctg-tiling-path',
        str(p_tp_file),
        '--a-ctg-tiling-path',
        str(a_tp_file),
        '--p-ctg-fasta',
        str(p_ctg_file),
        '--a-ctg-fasta',
        str(a_ctg_file),
        # '--write-contigs',
        '--min-p-len',
        '0',
        '--min-a-len',
        '0',
        '--only-these-contigs',
        str(whitelist_file),
    ]
    mod.main(argv)
    out, err = capsys.readouterr()

    result = json.loads(out)

    assert (result == expected)
def test_main_3(tmpdir, capsys):
    """
    Test the whitelist.
    """

    p_ctg_file = tmpdir.join('p_ctg.fa')
    p_tp_file = tmpdir.join('p_ctg_tiling_path')
    a_tp_file = tmpdir.join('a_ctg_tiling_path')
    a_ctg_file = tmpdir.join('a_ctg.fa')
    all_seqs, p_ctg_tps, a_ctg_tps, expected = setup_test(p_ctg_file, p_tp_file, a_ctg_file, a_tp_file)

    only_these_contigs = set(['000002F'])
    whitelist_file = tmpdir.join('only_these_contigs')
    whitelist_file.write('\n'.join(only_these_contigs) + '\n')

    # Adjust the expected results.
    # Remove any node not in the whitelist.
    blacklist_nodes = [key for key in (p_ctg_tps.keys() + a_ctg_tps.keys()) if key not in only_these_contigs]
    for key in blacklist_nodes:
        expected['nodes'].pop(key, None)
    # Remove any edge not in the whitelist.
    blacklist_edges = [key for key, edge in expected['edges'].iteritems() if edge['v'] not in only_these_contigs or edge['w'] not in only_these_contigs]
    for key in blacklist_edges:
            expected['edges'].pop(key, None)

    argv = ['prog',
            '--p-ctg-tiling-path', str(p_tp_file),
            '--a-ctg-tiling-path', str(a_tp_file),
            '--p-ctg-fasta', str(p_ctg_file),
            '--a-ctg-fasta', str(a_ctg_file),
            # '--write-contigs',
            '--min-p-len', '0',
            '--min-a-len', '0',
            '--only-these-contigs', str(whitelist_file),
            ]
    mod.main(argv)
    out, err = capsys.readouterr()

    result = json.loads(out)

    assert(result == expected)
Пример #6
0
def test_help():
    try:
        mod.main(['prog', '--help'])
    except SystemExit:
        pass