def nextbacktree(t, i, q=None, lim=0, maxdepth=None): """ create a tree of ivy.tree.Nodes from table t, with records having fields next, back, parent, and depth """ db = t._db r = t[int(i)] limits = dict(orderby=t.next) if lim: limits["limitby"] = (0,lim) q2 = (t.next>r.next)&(t.back<r.back) if maxdepth: q2 &= (t.depth <= maxdepth) recs = db(q)(q2).select(**limits) #Node = ivy.tree.Node root = Node(); root.isroot = True root.rec = r; root.id = r.id i2n = {}; i2n[r.id] = root for r in recs: n = Node() n.rec = r; n.id = r.id; n.next = r.next; n.back = r.back if (((not maxdepth) and (r.next==r.back-1)) or (maxdepth and (n.depth == maxdepth))): n.isleaf = True i2n[r.id] = n i2n[r.parent].add_child(n) return root
def getNodeFromRowData( row ): node = Node() node.id = row[0]; node.next = row[1]; node.back = row[2]; node.length = row[3]; node.label = row[4] node.taxon = row[5]; return node
def getNodeFromRowData(row): node = Node() node.id = row[0] node.next = row[1] node.back = row[2] node.length = row[3] node.label = row[4] node.taxon = row[5] return node
def reindex_from_parents(t): db = t._db rec2node = dict([ (rec.id, Node(rec=rec, isleaf=True)) for rec in db(t.id>0).select() ]) root = None for r, n in rec2node.items(): if n.rec.parent is not None: p = rec2node[n.rec.parent] p.add_child(n) p.isleaf = False else: root = n index(root) for n in root: n.rec.update_record(next=n.next, back=n.back, depth=n.depth) return root
def nextbacktree(t, i, q=None, lim=0, maxdepth=None): """ create a tree of ivy.tree.Nodes from table t, with records having fields next, back, parent, and depth """ db = t._db r = t[int(i)] limits = dict(orderby=t.next) limits['orderby'] = t.next if lim: limits["limitby"] = (0, lim) q2 = (t.next > r.next) & (t.back < r.back) if maxdepth: q2 &= (t.depth <= maxdepth) recs = db(q)(q2).select(**limits) root = Node() root.isroot = True root.rec = r root.id = r.id root.next = r.next root.back = r.back i2n = {} i2n[r.id] = root for r in recs: n = Node() n.rec = r n.id = r.id n.next = r.next n.back = r.back n.parent = i2n[r.parent] if (((not maxdepth) and (r.next == r.back - 1)) or (maxdepth and (n.depth == maxdepth))): n.isleaf = True i2n[r.id] = n i2n[r.parent].add_child(n) return root
def nextbackgtree(t, i, q=None, lim=0, maxdepth=None): """ create a tree of ivy.tree.Nodes from table t, with records having fields next, back, parent, and depth """ db = t._db r = t[int(i)] limits = dict(orderby=t.next) if lim: limits["limitby"] = (0,lim) q2 = (t.next>r.next)&(t.back<r.back) if maxdepth: q2 &= (t.depth <= maxdepth) recs = db(q)(q2).select(**limits) #Node = ivy.tree.Node root = Node(); root.isroot = True root.rec = r; root.id = r.id; root.next = r.next; root.back = r.back; root.stree = r.stree; root.snode = r.snode i2n = {}; i2n[r.id] = root for r in recs: n = Node() if( not hasattr( r, 'id' ) ): r = r.gnode n.rec = r; n.id = r.id; n.next = r.next; n.back = r.back; n.stree = r.stree; n.snode = r.snode if (((not maxdepth) and (r.next==r.back-1)) or (maxdepth and (n.depth == maxdepth))): n.isleaf = True i2n[r.id] = n i2n[r.parent].add_child(n) return root