Following is based on opening statement: "I create an algorithm that will give me the path of the shortest interactions between 2 proteins".
I would read data from file into dictionary or defaultdict so that key is node and values are edges.
With dictionary:
I would read data from file into dictionary or defaultdict so that key is node and values are edges.
With dictionary:
data = dict() with open('proteins.txt', 'r') as f: for row in f: k, v = row.strip().split() data.setdefault(k, set()).add(v)Or with defauldict:
data = defaultdict(set) with open('proteins.txt', 'r') as f: for row in f: k, v = row.strip().split() data[k].add(v)Now when I have data nicely structured I implement shortest path algorithm. You can find one from python. org: Python Patterns - Implementing Graphs.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.