Example #1
0
def main():
    p = OptionParser(__doc__)
    p.add_option("--levels",
                help="Reorder factors, comma-delimited [default: alphabetical]")
    p.add_option("--notch", default=False, action="store_true",
                 help="notched box plot [default: %default]")
    p.add_option("--title", default=" ",
                help="Title of the figure [default: %default]")
    p.add_option("--xlabel", help="X-axis label [default: %default]")
    p.add_option("--ylabel", help="Y-axis label [default: %default]")
    p.add_option("--fontsize", default=16,
                 help="Font size [default: %default]")
    opts, args = p.parse_args()

    if len(args) != 1:
        sys.exit(not p.print_help())

    datafile, = args
    header = open(datafile)
    levels = opts.levels
    xlabel = opts.xlabel
    ylabel = opts.ylabel
    lx, ly = header.next().rstrip().split('\t')

    lx = xlabel or lx
    ly = ylabel or ly

    if levels:
        levels = levels.split(",")
        levels = ", ".join("'{0}'".format(d) for d in levels)
    rtemplate = RTemplate(whisker_template, locals())
    rtemplate.run()
Example #2
0
def main():
    p = OptionParser(__doc__)
    p.add_option(
        "--levels", help="Reorder factors, comma-delimited [default: alphabetical]"
    )
    p.add_option(
        "--notch",
        default=False,
        action="store_true",
        help="notched box plot",
    )
    p.add_option("--title", default=" ", help="Title of the figure")
    p.add_option("--xlabel", help="X-axis label")
    p.add_option("--ylabel", help="Y-axis label")
    p.add_option("--fontsize", default=16, help="Font size")
    opts, args = p.parse_args()

    if len(args) != 1:
        sys.exit(not p.print_help())

    (datafile,) = args
    header = open(datafile)
    levels = opts.levels
    xlabel = opts.xlabel
    ylabel = opts.ylabel
    lx, ly = next(header).rstrip().split("\t")

    lx = xlabel or lx
    ly = ylabel or ly

    if levels:
        levels = levels.split(",")
        levels = ", ".join("'{0}'".format(d) for d in levels)
    rtemplate = RTemplate(whisker_template, locals())
    rtemplate.run()
Example #3
0
def histogram_multiple(numberfiles, vmin, vmax, xlabel, title,
                       bins=20, skip=0, ascii=False,
                       facet=False, fill="white", prefix=""):
    """
    Generate histogram using number from numberfile, and only numbers in the
    range of (vmin, vmax). First combining multiple files.
    """
    if ascii:
        return texthistogram(numberfiles, vmin, vmax, title=title,
                bins=bins, skip=skip)

    newfile = "_".join(op.basename(x).split(".")[0] for x in numberfiles)

    fw = open(newfile, "w")
    print >> fw, "{0}\tgrp".format(xlabel)
    for f in numberfiles:
        data, va, vb = get_data(f, vmin, vmax, skip=skip)
        vmin = min(vmin, va)
        vmax = max(vmax, vb)

        fp = open(f)
        tag = op.basename(f).split(".")[0]
        for row in fp:
            val = row.strip()
            print >> fw, "\t".join((val, tag))
    fw.close()

    numberfile = newfile
    outfile = numberfile + '.pdf'
    if prefix:
        outfile = prefix + outfile
    htemplate = histogram_multiple_template_b \
                    if facet else histogram_multiple_template_a
    rtemplate = RTemplate(htemplate, locals())
    rtemplate.run()
Example #4
0
def histogram(numberfile,
              vmin,
              vmax,
              xlabel,
              title,
              outfmt="pdf",
              bins=50,
              skip=0,
              ascii=False,
              base=0,
              fill="white"):
    """
    Generate histogram using number from numberfile, and only numbers in the
    range of (vmin, vmax)
    """
    if ascii:
        return texthistogram([numberfile],
                             vmin,
                             vmax,
                             title=title,
                             bins=bins,
                             skip=skip,
                             base=base)

    data, vmin, vmax = get_data(numberfile, vmin, vmax, skip=skip)
    outfile = numberfile + ".base{0}.{1}".format(base, outfmt) \
                if base else numberfile + ".pdf"
    template = histogram_log_template if base else histogram_template
    rtemplate = RTemplate(template, locals())
    rtemplate.run()
Example #5
0
def histogram_multiple(
    numberfiles,
    vmin,
    vmax,
    xlabel,
    title,
    outfmt="pdf",
    tags=None,
    bins=20,
    skip=0,
    ascii=False,
    facet=False,
    fill="white",
    prefix="",
):
    """
    Generate histogram using number from numberfile, and only numbers in the
    range of (vmin, vmax). First combining multiple files.
    """
    if ascii:
        return texthistogram(numberfiles,
                             vmin,
                             vmax,
                             title=title,
                             bins=bins,
                             skip=skip)

    newfile = "_".join(op.basename(x).split(".")[0] for x in numberfiles)

    fw = open(newfile, "w")
    print("{0}\tgrp".format(xlabel), file=fw)

    if tags:
        tags = tags.split(",")

    for i, f in enumerate(numberfiles):
        data, va, vb = get_data(f, vmin, vmax, skip=skip)
        vmin = min(vmin, va)
        vmax = max(vmax, vb)

        fp = open(f)
        if tags:
            tag = tags[i]
        else:
            tag = op.basename(f).rsplit(".", 1)[0]
        for row in fp:
            val = row.strip()
            print("\t".join((val, tag)), file=fw)
    fw.close()

    numberfile = newfile
    outfile = numberfile + "." + outfmt
    if prefix:
        outfile = prefix + outfile
    htemplate = (histogram_multiple_template_b
                 if facet else histogram_multiple_template_a)
    rtemplate = RTemplate(htemplate, locals())
    rtemplate.run()
Example #6
0
def histogram(numberfile, vmin, vmax, xlabel, title,
              bins=50, skip=0, ascii=False, log=0, fill="white"):
    """
    Generate histogram using number from numberfile, and only numbers in the
    range of (vmin, vmax)
    """
    if ascii:
        return texthistogram([numberfile], vmin, vmax, title=title,
                bins=bins, skip=skip, log=log)

    data, vmin, vmax = get_data(numberfile, vmin, vmax, skip=skip)
    template = histogram_log_template if log else histogram_template
    rtemplate = RTemplate(template, locals())
    rtemplate.run()
Example #7
0
def histogram(numberfile, vmin, vmax, xlabel, title, outfmt="pdf",
              bins=50, skip=0, ascii=False, base=0, fill="white"):
    """
    Generate histogram using number from numberfile, and only numbers in the
    range of (vmin, vmax)
    """
    if ascii:
        return texthistogram([numberfile], vmin, vmax, title=title,
                bins=bins, skip=skip, base=base)

    data, vmin, vmax = get_data(numberfile, vmin, vmax, skip=skip)
    outfile = numberfile + ".base{0}.{1}".format(base, outfmt) \
                if base else numberfile + ".pdf"
    template = histogram_log_template if base else histogram_template
    rtemplate = RTemplate(template, locals())
    rtemplate.run()
Example #8
0
def histogram(numberfile, vmin, vmax, xlabel, title,
              bins=50, skip=0, ascii=False, log=0, fill="white"):
    """
    Generate histogram using number from numberfile, and only numbers in the
    range of (vmin, vmax)
    """
    if ascii:
        return texthistogram([numberfile], vmin, vmax, title=title,
                bins=bins, skip=skip, log=log)

    outfile = numberfile + '.pdf'
    data, vmin, vmax = get_data(numberfile, vmin, vmax, skip=skip)
    base = log

    template = histogram_log_template if log else histogram_template
    rtemplate = RTemplate(template, locals())
    rtemplate.run()
Example #9
0
def generate_plot(filename, rplot="A50.rplot", rpdf="A50.pdf"):

    from jcvi.apps.r import RTemplate

    rplot_template = """
    library(ggplot2)

    data <- read.table("$rplot", header=T, sep="\t")
    g <- ggplot(data, aes(x=index, y=cumsize, group=fasta))
    g + geom_line(aes(colour=fasta)) +
    xlab("Contigs") + ylab("Cumulative size (Mb)") +
    opts(title="A50 plot", legend.position="top")

    ggsave(file="$rpdf")
    """

    rtemplate = RTemplate(rplot_template, locals())
    rtemplate.run()
Example #10
0
def generate_plot(filename, rplot="A50.rplot", rpdf="A50.pdf"):

    from jcvi.apps.r import RTemplate

    rplot_template = """
    library(ggplot2)

    data <- read.table("$rplot", header=T, sep="\t")
    g <- ggplot(data, aes(x=index, y=cumsize, group=fasta))
    g + geom_line(aes(colour=fasta)) +
    xlab("Contigs") + ylab("Cumulative size (Mb)") +
    opts(title="A50 plot", legend.position="top")

    ggsave(file="$rpdf")
    """

    rtemplate = RTemplate(rplot_template, locals())
    rtemplate.run()