def html(): i = int(request.args(0) or 0) root = build.stree(db, i) nodes = list(root.iternodes()) for node in nodes: label = node.rec.label or node.label if node.rec.ott_node: label = db.ott_node[node.rec.ott_node].name node.label = label modal = PluginMModal(id="mymodal", title="Edit node properties", content="") mid = modal.id cid = "c" + mid def onclick(nid): u = URL(c="snode", f="update_snode.load", args=[nid]) return "hbranch_clicked(%s, '%s', '%s', '%s');" % (nid, u, mid, cid) if auth.has_membership(role="contributor"): f = onclick else: f = "" div, mapping, w, h = tree.render_html(root, session, request, db, onclick=f) return dict(tree=div, root=root, modal=modal, w=w, h=h)
def newick(): """ return newick string for stree.id = request.args(0) optional request.variables are 'lfmt' (leaf format) and 'ifmt' (internal node format), which are comma-separated table.field values to be pulled out of the node.rec Row objects. These are converted to strings, joined by '_', and attached to nodes as labels to be written in the newick string. """ treeid = int(request.args(0) or 0) assert treeid root = build.stree(db, treeid) lfmt = [ x.split('.') for x in (request.vars['lfmt'] or 'snode.id,otu.label').split(',') if x ] ifmt = [ x.split('.') for x in (request.vars['ifmt'] or '').split(',') if x ] def proc(node, table, field): try: s = str(getattr(getattr(node.rec, table), field)) except AttributeError: s = '' return '_'.join(s.split()) for n in root: n.label = '' if n.isleaf: n.label = '_'.join([ proc(n, t, f) for t, f in lfmt ]) else: if ifmt: n.label = '_'.join([ proc(n, t, f) for t, f in ifmt ]) n.label = n.label.replace('(','--').replace(')','--') return dict(newick=root.write())
def treediv(): i = int(request.args(0) or 0) root = build.stree(db, i) nodes = list(root.iternodes()) for node in nodes: label = node.rec.label or node.label if node.rec.ott_node: label = db.ott_node[node.rec.ott_node].name node.label = label def onclick(nid): u = URL(c="snode", f="update_snode.load", args=[nid]) return ("hbranch_clicked(%s, '%s', 'modal', 'modal_content');" % (nid, u)) if auth.has_membership(role="contributor"): f = onclick else: f = "" wscale = float(request.vars.wscale or 0.9) div, mapping, w, h = tree.render_html(root, session, request, db, onclick=f, wscale=wscale) return div.xml()
def newick(): """ return newick string for stree.id = request.args(0) optional request.variables are 'lfmt' (leaf format) and 'ifmt' (internal node format), which are comma-separated table.field values to be pulled out of the node.rec Row objects. These are converted to strings, joined by '_', and attached to nodes as labels to be written in the newick string. """ treeid = int(request.args(0) or 0) assert treeid root = build.stree(db, treeid) lfmt = [ x.split('.') for x in (request.vars['lfmt'] or 'snode.id,otu.label').split(',') if x ] ifmt = [x.split('.') for x in (request.vars['ifmt'] or '').split(',') if x] def proc(node, table, field): try: s = str(getattr(getattr(node.rec, table), field)) except AttributeError: s = '' return '_'.join(s.split()) for n in root: n.label = '' if n.isleaf: n.label = '_'.join([proc(n, t, f) for t, f in lfmt]) else: if ifmt: n.label = '_'.join([proc(n, t, f) for t, f in ifmt]) n.label = n.label.replace('(', '--').replace(')', '--') return dict(newick=root.write())
def forcenodepos(): t = request.args(0) i = int(request.args(1)) if t == "stree": r = build.stree(db, i) elif t == "gtree": r = build.gtree(db, i) nodes = [ dict(index=i, id=n.id, label=n.label) for i, n in enumerate(r) ] id2i = dict([ (n.id, i) for i, n in enumerate(r) ]) links = [ dict(source=i, target=id2i[n.parent.id]) for i, n in enumerate(r) if n.parent ] return dict(nodes=nodes, links=links)
def nodepos(): t = request.args(0) i = int(request.args(1)) if t == "stree": root = build.stree(db, i) elif t == "gtree": root = build.gtree(db, i) n2c = layout.calc_node_positions(root, 0.95, 0.95, scaled=False) return response.json( [ dict(id=k.id, x=v.x, y=v.y, px=n2c[k.parent].x if n2c.get(k.parent) else None, py=n2c[k.parent].y if n2c.get(k.parent) else None) for k,v in n2c.items() ] )
def forcenodepos(): t = request.args(0) i = int(request.args(1)) if t == "stree": r = build.stree(db, i) elif t == "gtree": r = build.gtree(db, i) nodes = [dict(index=i, id=n.id, label=n.label) for i, n in enumerate(r)] id2i = dict([(n.id, i) for i, n in enumerate(r)]) links = [ dict(source=i, target=id2i[n.parent.id]) for i, n in enumerate(r) if n.parent ] return dict(nodes=nodes, links=links)
def nodepos(): t = request.args(0) i = int(request.args(1)) if t == "stree": root = build.stree(db, i) elif t == "gtree": root = build.gtree(db, i) n2c = layout.calc_node_positions(root, 0.95, 0.95, scaled=False) return response.json([ dict(id=k.id, x=v.x, y=v.y, px=n2c[k.parent].x if n2c.get(k.parent) else None, py=n2c[k.parent].y if n2c.get(k.parent) else None) for k, v in n2c.items() ])
def load_html(): i = int(request.args(0) or 0) root = build.stree(db, i) nodes = list(root.iternodes()) for node in nodes: label = node.rec.label or node.label if node.rec.ott_node: label = db.ott_node[node.rec.ott_node].name node.label = label def onclick(nid): u = URL(c="snode",f="update_snode.load", args=[nid]) return ("hbranch_clicked(%s, '%s', 'modal', 'modal_content');" % (nid, u)) if auth.has_membership(role="contributor"): f = onclick else: f = "" div, mapping, w, h = tree.render_html(root, session, request, db, onclick=f) return dict(tree=div)
def treediv(): i = int(request.args(0) or 0) root = build.stree(db, i) nodes = list(root.iternodes()) for node in nodes: label = node.rec.label or node.label if node.rec.taxon: label = db.taxon[node.rec.taxon].name node.label = label def onclick(nid): u = URL(c="snode",f="update_snode.load", args=[nid]) return ("hbranch_clicked(%s, '%s', 'modal', 'modal_content');" % (nid, u)) if auth.has_membership(role="contributor"): f = onclick else: f = "" wscale = float(request.vars.wscale or 0.9) div, mapping, w, h = tree.render_html(root, session, request, db, onclick=f, wscale=wscale) return div.xml()
def html(): i = int(request.args(0) or 0) root = build.stree(db, i) nodes = list(root.iternodes()) for node in nodes: label = node.rec.label or node.label if node.rec.ott_node: label = db.ott_node[node.rec.ott_node].name node.label = label modal = PluginMModal(id="mymodal", title="Edit node properties", content="") mid = modal.id; cid = "c"+mid def onclick(nid): u = URL(c="snode",f="update_snode.load", args=[nid]) return "hbranch_clicked(%s, '%s', '%s', '%s');" % (nid, u, mid, cid) if auth.has_membership(role="contributor"): f = onclick else: f = "" div, mapping, w, h = tree.render_html(root, session, request, db, onclick=f) return dict(tree=div, root=root, modal=modal, w=w, h=h)
def suggest(): i = int(request.args(0) or 0) root = build.stree(db, i)
def modalTreeObj(): return dict( tree = build.stree( db, request.args[0] ) )
def modalTreeObj(): return dict(tree=build.stree(db, request.args[0]))