libbdsg icon indicating copy to clipboard operation
libbdsg copied to clipboard

When I use python bdsg to deal with a packedgraph, I found a question.

Open pioneer-pi opened this issue 1 year ago • 3 comments

image

  1. I want to use follow_edges to get all the nodes which connect to node2, but i only get node3.(In fact, node3 and node4 are both its' connecting edges). I wonder if i misunderstand the follow_edges? Do you have any function to get all nodes connect to a specific node.
  2. Dose bdsg give a way to get all the possible path from the start node to the end node? Thanks for you replying!!!

pioneer-pi avatar Dec 23 '23 13:12 pioneer-pi

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 avatar Dec 23 '23 19:12 jeizenga

@jeizenga Thanks for you replying. I use the example code in https://bdsg.readthedocs.io/en/master/rst/tutorial.html : image

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.

pioneer-pi avatar Dec 25 '23 02:12 pioneer-pi

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?

jeizenga avatar Jan 02 '24 03:01 jeizenga