Exemplo n.º 1
0
def main(argv, cfg_file):
    cmd = Command('score', cfg_file=cfg_file)
    cmd.parse_args(argv)
    swga.database.init_db(cmd.primer_db)
    primers = swga.primers.read_primer_list(
        cmd.input,
        cmd.fg_genome_fp,
        cmd.bg_genome_fp)
    if len(primers) == 0:
        swga.error("No primers specified exist in database, aborting.",
                   exception=False)
    chr_ends = swga.locate.chromosome_ends(cmd.fg_genome_fp)

    # Evaluate the user-defined scoring function
    score_fun = functools.partial(
        swga.score.default_score_set,
        expression=cmd.score_expression)

    score_set(
        set_id=0,
        primers=primers,
        chr_ends=chr_ends,
        score_fun=score_fun,
        score_expression=cmd.score_expression,
        bg_genome_len=cmd.bg_genome_len,
        bg_dist_mean=None,
        max_fg_bind_dist=0,
        interactive=True)
Exemplo n.º 2
0
def main(argv, cfg_file):
    cmd = Command('count', cfg_file=cfg_file)
    cmd.parse_args(argv)
    database.init_db(cmd.primer_db, create_if_missing=True)
    if cmd.input:
        kmers = swga.primers.parse_kmer_file(cmd.input)
        count_specific_kmers(kmers, **cmd.args)
    else:
        count_kmers(**cmd.args)
Exemplo n.º 3
0
def main(argv, cfg_file):
    cmd = Command("activate", cfg_file=cfg_file)
    cmd.parse_args(argv)

    swga.database.init_db(cmd.primer_db)

    primers = swga.primers.read_primer_list(cmd.input, cmd.fg_genome_fp, cmd.bg_genome_fp)

    try:
        swga.primers.update_Tms(primers)
        swga.primers.update_locations(primers, cmd.fg_genome_fp)
        n_activated = swga.primers.activate2(primers)
        swga.message("Marked {} primers as active.".format(n_activated))
    except AttributeError as e:
        swga.warn("Error updating database: '{}'".format(e.message))
        swga.warn(
            "Sometimes this happens if you're using a database created with "
            "an older version of swga. Please try creating a new workspace "
            "with `swga init` in another folder and adding these primers to "
            "that database instead."
        )
Exemplo n.º 4
0
def main(argv, cfg_file):
    cmd = Command('filter', cfg_file=cfg_file)
    cmd.parse_args(argv)

    swga.database.init_db(cmd.primer_db)

    # If we have an input file, use that. Otherwise pull from db
    if cmd.input:
        with open(cmd.input, 'rb') as infile:
            primers = swga.primers.read_primer_list(
                infile,
                cmd.fg_genome_fp,
                cmd.bg_genome_fp)
    else:
        cmd.skip_filtering = False
        primers = Primer.select()

    # Undo all active marks, if any
    deactivate_all_primers()

    if not cmd.skip_filtering:
        primers = filter_primers(
            primers,
            cmd.min_fg_bind,
            cmd.max_bg_bind,
            cmd.fg_length,
            cmd.bg_length,
            cmd.min_tm,
            cmd.max_tm,
            cmd.max_primers)

    swga.primers.update_locations(primers, cmd.fg_genome_fp)
    n_active = activate_primers(primers)
    if n_active < cmd.max_primers:
        swga.warn(
            "Fewer than {} primers were selected ({} passed all the filters). "
            "You may want to try less restrictive filtering parameters."
            .format(cmd.max_primers, n_active))
Exemplo n.º 5
0
def main(argv, cfg_file):
    cmd = Command('export', cfg_file=cfg_file)
    cmd.parse_args(argv)
    header = not cmd.no_header
    what = cmd.what
    database.init_db(cmd.primer_db)

    if what in ['set', 'sets']:
        sets = get_items(Set, cmd.ids, cmd.order_by, cmd.limit, cmd.descending)
        export(Set, sets, cmd.output, header)

    if what in ['primer', 'primers']:
        primers = get_items(
            Primer, cmd.ids, cmd.order_by, cmd.limit, cmd.descending)
        export(Primer, primers, cmd.output, header)

    if "bed" in what:
        outpath = cmd.output_folder if cmd.output_folder else os.getcwd()
        sets = get_items(Set, cmd.ids, cmd.order_by, cmd.limit, cmd.descending)
        if what == "bedfile":
            for set in sets:
                swga.message(
                    "Exporting set {} and associated primers as bedfiles..."
                    .format(set._id))
                bedfile = BedFile(set, cmd.fg_genome_fp)
                bedfile.write(outpath)
        elif what == "bedgraph":
            for set in sets:
                swga.message("Exporting set {} as bedgraph...".format(set._id))
                bedgraph = BedGraph(
                    set=set,
                    fg_genome_fp=cmd.fg_genome_fp,
                    opts_str=cmd.opts_str,
                    window_size=cmd.window_size,
                    step_size=cmd.step_size)
                bedgraph.write(outpath)
Exemplo n.º 6
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)
Exemplo n.º 7
0
def main(argv, cfg_file):
    cmd = Command('summary', cfg_file=cfg_file)
    cmd.parse_args(argv, quiet=True)
    summary(**cmd.args)