1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| import networkx as nx
text = """ADSL MDH1 0 0 0 141 50 800 153 843 ---> EXP
BNYD GHFC 0 0 0 82 153 900 203 929 ---> EXP
ADSL APRT 156 0 0 485 376 900 868 995 ---> EXP
HDGV BNDY 0 0 0 82 153 900 203 929 ---> EXP
NXF2 XPO5 0 0 0 82 153 900 203 929 ---> EXP
NXF2 RAE1 0 0 0 62 507 800 627 960 ---> EXP
MDH1 HDGV 0 0 0 82 153 900 203 929 ---> EXP"""
# Build a graph of the protein interactions
graph = nx.Graph()
for line in text.split('\n'):
p1, p2 = line.split(' ')[:2]
# Create nodes
graph.add_nodes_from([p1, p2])
# Create edge
graph.add_edge(p1, p2)
print('All nodes:\n', list(graph.nodes))
sp = dict(nx.all_pairs_shortest_path(graph))
print('All nodes leading to BNDY:\n', sp['BNDY'])
print('All paths from ADSL to BNDY: \n', list(nx.all_simple_paths(graph, 'ADSL', 'BNDY', cutoff=3))) |
Partager