コード例 #1
0
def svg():
    tlist = get_treelist()
    try:
        i = int(request.vars.i)
        t = tlist.trees[i]
    except:
        session.flash = "no tree '%s'" % i
        redirect("index")

    opts = t.printopts
    node, mapping = drawtree.traverse(t.root, opts)
    thicken_branches(node)
    node.set_attr("vpad", opts.vpad, 1)
    off = t.printopts.border
    node.translate(off, off)
    d = drawtree.draw(node, opts)
    #d.scale(1.9,1.9)
    x1, y1, x2, y2 = d.getBounds()
    d.width = (x2 - x1) * 0.63
    d.height = (y2 - y1) * 0.598
    response.headers["Content-Type"] = "image/svg"
    f = t.printopts.title + ".svg"
    s = "attachment; filename=%s" % f
    response.headers["Content-Disposition"] = s
    return drawtree.render_svg(d, opts)
コード例 #2
0
def pdf2svg():
    tlist = get_treelist()
    try:
        i = int(request.vars.i)
        t = tlist.trees[i]
        if request.vars.ladderize:
            t.root.order_subtrees_by_size(recurse=True,
                                          reverse=bool(request.vars.rev))
    except:
        session.flash = "no tree '%s'" % i
        redirect("index")

    fname = "tred-" + response.session_id
    opts = t.printopts
    v = request.vars

    if v.parsevars:
        t.labelfilter = v.labelfilter or ""
        t.labeltype = v.labeltype or t.labeltype
        t.labelsort = v.labelsort or t.labelsort

        opts.title = v.title or opts.title or "%s-%s" % (t.source, t.name)
        opts.pagesize = v.pagesize or opts.pagesize or "letter"
        #print opts.pagesize
        opts.draw_phylogram = v.draw_phylogram and t.phylogram
        opts.baseheight = float(v.baseheight or 0) or opts.baseheight
        opts.unitwidth = float(v.unitwidth or 0) or opts.unitwidth
        opts.border = float(v.border or 0) or opts.border
        opts.vpad = float(v.vpad or 1.1)
        if v.draw_intlabels and "intlabel" not in opts.visible:
            opts.visible.append("intlabel")
        if (not v.draw_intlabels) and "intlabel" in opts.visible:
            opts.visible.remove("intlabel")

    node, mapping = drawtree.traverse(t.root, opts)
    thicken_branches(node)

    node.set_attr("vpad", opts.vpad, 1)
    d = drawtree.draw(node, opts)
    t.drawing = d
    buf = drawtree.render_pdf(d, opts)

    proc = subprocess.Popen(("/usr/bin/pstoedit", "-f", "plot-svg"),
                            stdin=subprocess.PIPE,
                            stdout=subprocess.PIPE)
    out, err = proc.communicate(buf.getvalue())
    out = out.split("\n")
    out[2] = '<svg version="1.1" baseProfile="full" id="body" '\
             'width="%s" height="%s" viewBox="0 0 1 1" '\
             'preserveAspectRatio="none" '\
             'xmlns="http://www.w3.org/2000/svg" '\
             'xmlns:xlink="http://www.w3.org/1999/xlink" '\
             'xmlns:ev="http://www.w3.org/2001/xml-events">' \
             % (d.width, d.height)
    out[5] = ""
    response.headers["Content-Type"] = "image/svg"
    f = t.printopts.title + ".svg"
    s = "attachment; filename=%s" % f
    response.headers["Content-Disposition"] = s
    return "\n".join(out)
コード例 #3
0
ファイル: default.py プロジェクト: rhr/tred
def svg():
    tlist = get_treelist()
    try:
        i = int(request.vars.i)
        t = tlist.trees[i]
    except:
        session.flash = "no tree '%s'" % i
        redirect("index")

    opts = t.printopts
    node, mapping = drawtree.traverse(t.root, opts)
    thicken_branches(node)
    node.set_attr("vpad", opts.vpad, 1)
    off = t.printopts.border
    node.translate(off, off)
    d = drawtree.draw(node, opts)
    # d.scale(1.9,1.9)
    x1, y1, x2, y2 = d.getBounds()
    d.width = (x2 - x1) * 0.63
    d.height = (y2 - y1) * 0.598
    response.headers["Content-Type"] = "image/svg"
    f = t.printopts.title + ".svg"
    s = "attachment; filename=%s" % f
    response.headers["Content-Disposition"] = s
    return drawtree.render_svg(d, opts)
コード例 #4
0
ファイル: default.py プロジェクト: rhr/tred
def pdf2svg():
    tlist = get_treelist()
    try:
        i = int(request.vars.i)
        t = tlist.trees[i]
        if request.vars.ladderize:
            t.root.order_subtrees_by_size(recurse=True, reverse=bool(request.vars.rev))
    except:
        session.flash = "no tree '%s'" % i
        redirect("index")

    fname = "tred-" + response.session_id
    opts = t.printopts
    v = request.vars

    if v.parsevars:
        t.labelfilter = v.labelfilter or ""
        t.labeltype = v.labeltype or t.labeltype
        t.labelsort = v.labelsort or t.labelsort

        opts.title = v.title or opts.title or "%s-%s" % (t.source, t.name)
        opts.pagesize = v.pagesize or opts.pagesize or "letter"
        # print opts.pagesize
        opts.draw_phylogram = v.draw_phylogram and t.phylogram
        opts.baseheight = float(v.baseheight or 0) or opts.baseheight
        opts.unitwidth = float(v.unitwidth or 0) or opts.unitwidth
        opts.border = float(v.border or 0) or opts.border
        opts.vpad = float(v.vpad or 1.1)
        if v.draw_intlabels and "intlabel" not in opts.visible:
            opts.visible.append("intlabel")
        if (not v.draw_intlabels) and "intlabel" in opts.visible:
            opts.visible.remove("intlabel")

    node, mapping = drawtree.traverse(t.root, opts)
    thicken_branches(node)

    node.set_attr("vpad", opts.vpad, 1)
    d = drawtree.draw(node, opts)
    t.drawing = d
    buf = drawtree.render_pdf(d, opts)

    proc = subprocess.Popen(("/usr/bin/pstoedit", "-f", "plot-svg"), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    out, err = proc.communicate(buf.getvalue())
    out = out.split("\n")
    out[2] = (
        '<svg version="1.1" baseProfile="full" id="body" '
        'width="%s" height="%s" viewBox="0 0 1 1" '
        'preserveAspectRatio="none" '
        'xmlns="http://www.w3.org/2000/svg" '
        'xmlns:xlink="http://www.w3.org/1999/xlink" '
        'xmlns:ev="http://www.w3.org/2001/xml-events">' % (d.width, d.height)
    )
    out[5] = ""
    response.headers["Content-Type"] = "image/svg"
    f = t.printopts.title + ".svg"
    s = "attachment; filename=%s" % f
    response.headers["Content-Disposition"] = s
    return "\n".join(out)
コード例 #5
0
def pdfsingle():
    tlist = get_treelist()
    try:
        i = int(request.vars.i)
        t = tlist.trees[i]
        if request.vars.ladderize:
            t.root.order_subtrees_by_size(recurse=True,
                                          reverse=bool(request.vars.rev))
    except:
        session.flash = "no tree '%s'" % i
        redirect("index")

    fname = "tred-" + response.session_id
    opts = t.printopts
    v = request.vars

    if v.parsevars:
        t.labelfilter = v.labelfilter or ""
        t.labeltype = v.labeltype or t.labeltype
        t.labelsort = v.labelsort or t.labelsort

        opts.title = v.title or opts.title or "%s-%s" % (t.source, t.name)
        opts.pagesize = v.pagesize or opts.pagesize or "letter"
        #print opts.pagesize
        opts.draw_phylogram = v.draw_phylogram and t.phylogram
        opts.baseheight = float(v.baseheight or 0) or opts.baseheight
        opts.unitwidth = float(v.unitwidth or 0) or opts.unitwidth
        opts.border = float(v.border or 0) or opts.border
        opts.vpad = float(v.vpad or 1.1)
        if v.draw_intlabels and "intlabel" not in opts.visible:
            opts.visible.append("intlabel")
        if (not v.draw_intlabels) and "intlabel" in opts.visible:
            opts.visible.remove("intlabel")

    node, mapping = drawtree.traverse(t.root, opts)
    thicken_branches(node)

    node.set_attr("vpad", opts.vpad, 1)
    d = drawtree.draw(node, opts)
    t.drawing = d
    buf = drawtree.render_pdf(d, opts)

    response.headers["Content-Type"] = "application/x-pdf"
    f = t.printopts.title + ".pdf"
    s = "attachment; filename=%s" % f
    response.headers["Content-Disposition"] = s
    return buf.getvalue()
コード例 #6
0
ファイル: default.py プロジェクト: rhr/tred
def pdfsingle():
    tlist = get_treelist()
    try:
        i = int(request.vars.i)
        t = tlist.trees[i]
        if request.vars.ladderize:
            t.root.order_subtrees_by_size(recurse=True, reverse=bool(request.vars.rev))
    except:
        session.flash = "no tree '%s'" % i
        redirect("index")

    fname = "tred-" + response.session_id
    opts = t.printopts
    v = request.vars

    if v.parsevars:
        t.labelfilter = v.labelfilter or ""
        t.labeltype = v.labeltype or t.labeltype
        t.labelsort = v.labelsort or t.labelsort

        opts.title = v.title or opts.title or "%s-%s" % (t.source, t.name)
        opts.pagesize = v.pagesize or opts.pagesize or "letter"
        # print opts.pagesize
        opts.draw_phylogram = v.draw_phylogram and t.phylogram
        opts.baseheight = float(v.baseheight or 0) or opts.baseheight
        opts.unitwidth = float(v.unitwidth or 0) or opts.unitwidth
        opts.border = float(v.border or 0) or opts.border
        opts.vpad = float(v.vpad or 1.1)
        if v.draw_intlabels and "intlabel" not in opts.visible:
            opts.visible.append("intlabel")
        if (not v.draw_intlabels) and "intlabel" in opts.visible:
            opts.visible.remove("intlabel")

    node, mapping = drawtree.traverse(t.root, opts)
    thicken_branches(node)

    node.set_attr("vpad", opts.vpad, 1)
    d = drawtree.draw(node, opts)
    t.drawing = d
    buf = drawtree.render_pdf(d, opts)

    response.headers["Content-Type"] = "application/x-pdf"
    f = t.printopts.title + ".pdf"
    s = "attachment; filename=%s" % f
    response.headers["Content-Disposition"] = s
    return buf.getvalue()
コード例 #7
0
def printer():
    tlist = get_treelist()
    try:
        i = int(request.vars.i)
    except TypeError:
        redirect("index")
    try:
        t = tlist.trees[i]
    except IndexError:
        session.flash = "no tree '%s'" % i
        redirect("index")

    if request.vars.ladderize:
        t.root.order_subtrees_by_size(recurse=True,
                                      reverse=bool(request.vars.rev))
        t.newick = newick.tostring(t.root) + ";"

    fname = "tred-" + response.session_id
    opts = t.printopts
    v = request.vars

    if v.parsevars:
        t.labelfilter = v.labelfilter or ""
        t.labeltype = v.labeltype or t.labeltype
        t.labelsort = v.labelsort or t.labelsort

        opts.title = v.title or opts.title or "%s-%s" % (t.source, t.name)
        opts.pagesize = v.pagesize or opts.pagesize or "letter"
        #print opts.pagesize
        opts.draw_phylogram = v.draw_phylogram and t.phylogram
        opts.baseheight = float(v.baseheight or 0) or opts.baseheight
        opts.unitwidth = float(v.unitwidth or 0) or opts.unitwidth
        opts.border = float(v.border or 0) or opts.border
        opts.vpad = float(v.vpad or 1.1)
        if v.draw_intlabels and "intlabel" not in opts.visible:
            opts.visible.append("intlabel")
        if (not v.draw_intlabels) and "intlabel" in opts.visible:
            opts.visible.remove("intlabel")

    node, mapping = drawtree.traverse(t.root, opts)
    thicken_branches(node)

    node.set_attr("vpad", opts.vpad, 1)
    d = drawtree.draw(node, opts)
    t.drawing = d
    buf = StringIO()
    npages, scalefact = drawtree.render_multipage(d, opts, buf)
    f = open("/tmp/%s.pdf" % fname, "w")
    f.write(buf.getvalue())
    f.close()
    # use graphicsmagick convert (page numbers *.png.0, *.png.1, ...)
    commands.getoutput("rm /tmp/%s*.png*" % fname)
    cmd = "convert /tmp/%s.pdf /tmp/%s.png" % (fname, fname)
    exit, out = commands.getstatusoutput(cmd)
    # pngs = glob.glob("/tmp/%s*.png*" % fname)
    if npages > 1:
        pngs = ['%s.png.%s' % (fname, i) for i in range(npages)]
    else:
        pngs = ['%s.png' % fname]
    if scalefact < 1.0:
        response.flash = "To fit the page width, "\
                         "the drawing has been scaled by %0.2f" % scalefact
    return dict(tree=t, pngs=pngs)
コード例 #8
0
ファイル: default.py プロジェクト: rhr/tred
def printer():
    tlist = get_treelist()
    try:
        i = int(request.vars.i)
    except TypeError:
        redirect("index")
    try:
        t = tlist.trees[i]
    except IndexError:
        session.flash = "no tree '%s'" % i
        redirect("index")

    if request.vars.ladderize:
        t.root.order_subtrees_by_size(recurse=True, reverse=bool(request.vars.rev))
        t.newick = newick.tostring(t.root) + ";"

    fname = "tred-" + response.session_id
    opts = t.printopts
    v = request.vars

    if v.parsevars:
        t.labelfilter = v.labelfilter or ""
        t.labeltype = v.labeltype or t.labeltype
        t.labelsort = v.labelsort or t.labelsort

        opts.title = v.title or opts.title or "%s-%s" % (t.source, t.name)
        opts.pagesize = v.pagesize or opts.pagesize or "letter"
        # print opts.pagesize
        opts.draw_phylogram = v.draw_phylogram and t.phylogram
        opts.baseheight = float(v.baseheight or 0) or opts.baseheight
        opts.unitwidth = float(v.unitwidth or 0) or opts.unitwidth
        opts.border = float(v.border or 0) or opts.border
        opts.vpad = float(v.vpad or 1.1)
        if v.draw_intlabels and "intlabel" not in opts.visible:
            opts.visible.append("intlabel")
        if (not v.draw_intlabels) and "intlabel" in opts.visible:
            opts.visible.remove("intlabel")

    node, mapping = drawtree.traverse(t.root, opts)
    thicken_branches(node)

    node.set_attr("vpad", opts.vpad, 1)
    d = drawtree.draw(node, opts)
    t.drawing = d
    buf = StringIO()
    npages, scalefact = drawtree.render_multipage(d, opts, buf)
    f = open("/tmp/%s.pdf" % fname, "w")
    f.write(buf.getvalue())
    f.close()
    # use graphicsmagick convert (page numbers *.png.0, *.png.1, ...)
    commands.getoutput("rm /tmp/%s*.png*" % fname)
    cmd = "convert /tmp/%s.pdf /tmp/%s.png" % (fname, fname)
    exit, out = commands.getstatusoutput(cmd)
    # pngs = glob.glob("/tmp/%s*.png*" % fname)
    if npages > 1:
        pngs = ["%s.png.%s" % (fname, i) for i in range(npages)]
    else:
        pngs = ["%s.png" % fname]
    if scalefact < 1.0:
        response.flash = "To fit the page width, " "the drawing has been scaled by %0.2f" % scalefact
    return dict(tree=t, pngs=pngs)