Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pioneer-pi opened this issue Dec 23, 2023 · 3 comments
Open

Comments

@pioneer-pi
Copy link

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!!!
@jeizenga
Copy link
Contributor

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.

@pioneer-pi
Copy link
Author

@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.

@jeizenga
Copy link
Contributor

jeizenga commented Jan 2, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants