def allignDAG(v,w,local=False): mat = loadMatrix('BLOSUM62.txt') graph = createDAG(v, w, mat, 5) print(len(graph)) source = '0,0' sink = str(len(v))+','+str(len(w)) if local: for node in graph: graph[source].append((node,0)) graph[node].append((sink,0)) print(len(graph)) s, path = dag(source,sink , graph) vv="" ww="" i=0 j=0 for p in range(len(path)-1): p_this = path[p] p_next = path[p+1] mvmt = movement(p_this, p_next) if mvmt=='d': vv+=v[i] ww+="-" i+=1 elif mvmt=='r': vv+="-" ww+=w[j] j+=1 elif mvmt=='g': vv+=v[i] ww+=w[j] i+=1 j+=1 # vv+=v[i] # ww+=w[j] # s+= mat[(v[i],w[j])] return s,vv,ww
def testDAG(self): source = '0' sink = '4' lines=["0->1:7", "0->2:4", "2->3:2", "1->4:1", "3->4:3"] graph={} for line in lines: toks = line.split("->") key = toks[0] value = toks[1].split(":") vv = (value[0],int(value[1])) if key in graph: graph[key].append(vv) else: graph[key]=[vv] w,path = dag(source, sink, graph) assert w == 9 assert "->".join(path) == "0->2->3->4"