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 26 27 28 29 30 31 32
|
import sys
sys.setrecursionlimit(1000)
from collections import defaultdict
dd = defaultdict(set)
with open("testchaines3.txt","r") as f1:
for lignes in f1:
lignes=lignes.rstrip('\n').split(" ")
prot1=lignes[0]
prot2=lignes[1]
dd[prot1].add(prot2)
#print(dd)
proteine1 = (input("Enter the first protein in the chain : "))
proteine2 = (input("Enter the last protein in the chain : "))
def chain(proteine1, proteine2, maillon, pathway, limite=10):
next_= maillon.get(pathway[-1], None)
if len(pathway)<limite:
for m in next_:
if m not in pathway:
if m==proteine2 and pathway[0]==proteine1:
pathway.append(m)
yield pathway
if m != proteine2:
yield from chain(proteine1, proteine2, maillon, pathway + [m])
pass
for k in dd:
for z in chain(proteine1,proteine2, dd, pathway = [k]):
print (' '.join(z)) |
Partager