Example #1
0
def main():
    cmd_prefix = args.get(0) if args.get(0) else ""
    swga_cmd = colored.green(os.path.join(cmd_prefix,"swga"))
    puts(colored.blue('#'*70))
    with indent(2, quote=colored.blue("#")):
        puts(message.format(swga_cmd = swga_cmd,
                            prefix = colored.magenta(cmd_prefix)))
    puts(colored.blue('#'*70))
Example #2
0
 def pprint_args(self):
     if not self.args:
         return
     else:
         swga.message(colored.green("Command: " + self.name))
         with indent(2, quote='-'):
             for arg, val in self.args.iteritems():
                 if val is None or val == "":
                     val = colored.red("None")
                 swga.message(colored.blue("{}: {}".format(arg, val)))
Example #3
0
def summary(primer_db, fg_length, bg_length):

    db = swga.database.init_db(primer_db)
    db.connect()
    swga.database.create_tables(drop=False)

    avg_fg_bind, avg_bg_bind, nprimers = (
        Primer
        .select(fn.Avg(Primer.fg_freq),
                fn.Avg(Primer.bg_freq),
                fn.Count(Primer.seq))
        .scalar(as_tuple=True))

    if (avg_fg_bind is None) or (avg_bg_bind is None):
        raise swga.error(
            "Could not calculate summary statistics; database may be corrupt")

    fg_bind_ratio = avg_fg_bind / float(fg_length)
    bg_bind_ratio = avg_bg_bind / float(bg_length)
    nactive = Primer.select().where(Primer.active==True).count()

    min_tm, max_tm, avg_tm = (
        Primer
        .select(fn.Min(Primer.tm),
                fn.Max(Primer.tm),
                fn.Avg(Primer.tm))
        .where(Primer.active==True)
        .scalar(as_tuple=True))

    nsets = Set.select(fn.Count(Set._id)).scalar()

    if nsets > 0:
        bs = Set.select().order_by(Set.score).limit(1).get()
        bs_primers = ", ".join(swga.database.get_primers_for_set(bs._id)).strip()
        best_set = bs._id
        bs_size = bs.set_size
        bs_score = bs.score
        bs_stats = "- "+"\n - ".join(
            fmtkv(k, v)
            for k, v in bs.__dict__['_data'].items()
            if k not in ["_id", "pids", "score"]
        )

    version_header = (
        "---------------------\n"
        "==== SWGA v{version} ====\n"
        "---------------------\n"
        .format(version=swga.__version__)
    )

    summary_msg = """
    {version_header}

    PRIMER SUMMARY
    ---------------
    There are {nprimers} primers in the database.

    {nactive} are marked as active (i.e., they passed filter steps and will be used to find sets of compatible primers.) {ifzero_primers_msg}

    The average number of foreground genome binding sites is {avg_fg_bind:.0f}.
       (avg binding / genome_length = {fg_bind_ratio:05f})
    The average number of background genome binding sites is {avg_bg_bind:.0f}.
       (avg binding / genome_length = {bg_bind_ratio:05f})

    {melting_tmp_msg}


    SETS SUMMARY
    ---------------
    There are {nsets} sets in the database.
    {set_msg}---------------

    Report generated from {primer_db}
"""

    ifzero_primers_msg = colored.green(
        "Run `swga filter` to identify primers to use."
        if nactive == 0 else "")
    melting_tmp_msg = (
        """The melting temp of the primers ranges between {min_tm:.2f}C and {max_tm:.2f}C with an average of {avg_tm:.2f}C."""
        if nactive > 0 and min_tm and max_tm else
        "No melting temps have been calculated yet.")
    ifzero_sets_msg = colored.green(
        "Run `swga find_sets` after identifying valid primers to begin collecting sets.\n")

    set_msg = ("""
    The best scoring set is #{best_set}, with {bs_size} primers and a score of {bs_score:03f}.\nVarious statistics:
    {bs_stats}
The primers in Set {best_set} are:
    {bs_primers}
    """ if nsets > 0 else ifzero_sets_msg)



    primer_db = os.path.abspath(primer_db)
    nprimers = colored.blue(nprimers, bold=True)
    nactive = colored.blue(nactive, bold=True)
    nsets = colored.blue(nsets, bold=True)
    set_msg = set_msg.format(**locals())
    melting_tmp_msg = melting_tmp_msg.format(**locals())
    version_header = colored.green(version_header)
    summary_msg = summary_msg.format(**locals())

    with indent(2):
        puts(max_width(summary_msg, 80))