Skip to content

Commit

Permalink
#46 Print tree for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
weka511 committed Mar 25, 2023
1 parent d86e6a2 commit 2909a92
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions newick.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ def recurse(nextid = start, parentid = -1): # one node

self.tree = recurse()[0]

def dfs(self, tree,visit,level=0):
id = tree['id']
name = tree['name']
children = tree['children']
parentid = tree['parentid']
visit(level,id,name,parentid,children)
for child in children:
self.dfs(child,visit,level+1)

def __str__(self):
result = []
def str_visit(level,id,name,parentid,children,result=result):
result.append( f'{"-"*level} {id} {name} {parentid}')
self.dfs(self.tree,str_visit)
return '\n'.join(result)

def create_adj(self):
adj = {}
def dfs(tree):
Expand Down

0 comments on commit 2909a92

Please sign in to comment.