Open pioneer-pi opened 8 months ago
follow_edges
should iterate over the adjacent nodes on one side of the argument, one at a time. You should see both n3
and n4
from a single call, and if you want to also see n1
, you'll need to make another call in the opposite direction. I could maybe give you more advice if you shared the code you're using to construct the graph and to iterate over the edges.
@jeizenga Thanks for you replying. I use the example code in https://bdsg.readthedocs.io/en/master/rst/tutorial.html :
from bdsg.bdsg import HashGraph
gr = HashGraph()
seq = ["CGA", "TTGG", "CCGT", "C", "GT", "GATAA", "CGG", "ACA", "GCCG", "ATATAAC"]
n = []
for s in seq:
n.append(gr.create_handle(s))
gr.create_edge(n[0], n[1])
gr.create_edge(n[1], n[2])
gr.create_edge(n[2], n[3])
gr.create_edge(n[2], n[4])
gr.create_edge(n[3], n[5])
gr.create_edge(n[5], n[6])
# Connect the end of n5 to the start of n8
gr.create_edge(n[5], n[8])
gr.create_edge(n[6], n[7])
gr.create_edge(n[6], n[8])
gr.create_edge(n[7], n[9])
gr.create_edge(n[8], n[9])
# Connect the end of n8 back around to the start of n5
gr.create_edge(n[8], n[5])
#Trversing the edges
def next_node_list(handle):
lis = []
gr.follow_edges(handle, False, lambda y: lis.append(y))
return lis
print(f'n0: {gr.get_sequence(n[0])}')
next_node = next_node_list(n[0])[0]
print(f'n1: {gr.get_sequence(next_node)}')
next_node = next_node_list(next_node)[0]
print(f'n2: {gr.get_sequence(next_node)}')
next_node_list_follow_n2 = next_node_list(next_node) # I check the next_node list, found only one handle(node3) in it, It should have node3 and node4.
I check the next_node_list_follow_n2
, found only one handle(node3) in it, It should have node3 and node4.
It looks like you're missing an edge from n4 to n5 relative to the image, but that wouldn't be responsible for the unexpected behavior. How are you checking that next_node_list_follow_n2
doesn't have both handles?