def test_find_sets(tmpdir):
    graph = '''p sp 6 7
n 1 1
n 2 2
n 3 1
n 4 4
n 5 5
n 6 6
e 1 2
e 1 3
e 2 3
e 2 4
e 4 5
e 4 6
e 5 6
'''
    fp = tmpdir.join("testgraph")
    fp.write(graph)
    sets = find_sets(
        min_bg_bind_dist=2,
        min_size=3,
        max_size=3,
        bg_genome_len=10,
        graph_fp=fp)
    output = list(sets)
    assert len(output) == 1
    ids, bg_dist_mean = swga.score.read_set_finder_line(output[0])
    assert ids == [1, 2, 3]
    assert bg_dist_mean == 2.5
Exemple #2
0
def main(argv, cfg_file):
    cmd = Command('find_sets', cfg_file=cfg_file)
    score_cmd = Command('score', cfg_file=cfg_file)
    cmd.parse_args(argv)
    score_cmd.parse_args(argv)

    init_db(cmd.primer_db)

    # We need to clear all the previously-used sets each time due to uniqueness
    # constraints
    allsets = Set.select()
    if allsets.count() > 0:
        if not cmd.force:
            click.confirm("Remove all previously-found sets?", abort=True)
        for s in progress.bar(allsets, expected_size=allsets.count()):
            s.primers.clear()
            s.delete_instance()

    make_graph(cmd.max_dimer_bp, graph_fname)

    swga.message("Now finding sets. If nothing appears, try relaxing your parameters.")
    if cmd.workers <= 1:
        setlines = setfinder.find_sets(
            cmd.min_bg_bind_dist,
            cmd.min_size,
            cmd.max_size,
            cmd.bg_genome_len,
            graph_fp=graph_fname)
    else:
        setlines = setfinder.mp_find_sets(
            nprocesses=cmd.workers,
            graph_fp=graph_fname,
            min_bg_bind_dist=cmd.min_bg_bind_dist,
            min_size=cmd.min_size,
            max_size=cmd.max_size,
            bg_genome_len=cmd.bg_genome_len)

    score_sets(
        setlines,
        cmd.fg_genome_fp,
        score_cmd.score_expression,
        cmd.max_fg_bind_dist,
        cmd.max_sets)