好的,我有这个程序以 Newick 格式稀疏代码,它提取名称和距离以用于系统发育树图中。我的问题是,在这个代码分支中,当程序读取 newickNode 函数时,它将名称和距离分配给“节点”变量,然后将其返回到“节点”类以进行打印,但似乎只打印第一个节点'A',并跳过其他3个。
无论如何要完成newickNode中的for循环以读取其他3个节点并与第一个节点相应地打印它们?
class Node:
def __init__(self, name, distance, parent=None):
self.name = name
self.distance = distance
self.children = []
self.parent = parent
def displayNode(self):
print "Name:",self.name,",Distance:",self.distance,",Children:",self.children,",Parent:",self.parent
def newickNode(newickString, parent=None):
String = newickString[1:-1].split(',')
for x in String:
splitString = x.split(':')
nodeName = splitString[0]
nodeDistance = float(splitString[1])
node = Node(nodeName, nodeDistance, parent)
return node
Node1 = newickNode('(A:0.1,B:0.2,C:0.3,D:0.4)')
Node1.displayNode()
谢谢!