def cyclePartition(graph): a = prt.adj(graph) n = graph.nodes() r = prt.reach(a) l = prt.levels(r,n) c = prt.cycles(graph, l) return c
def cyclePartition(graph): a = prt.adj(graph) n = graph.nodes() r = prt.reach(a) l = prt.levels(r, n) c = prt.cycles(graph, l) return c
def distance(graph): #Must be bettered if more than one cycle, works on Yeast adj = prt.adj(graph); B = prt.binAddI(adj); D = prt.binSub(B, np.identity(len(adj),float)) prevS = B for i in range(2,len(adj),1): curS = prt.binPrd(B, prevS) D = D + i*(curS-prevS) prevS = curS return D
def distance(graph): adj = prt.adj(graph); B = prt.binAddI(adj); D = prt.binSub(B, np.identity(len(adj),float)) prevS = B for i in range(2,len(adj),1): curS = prt.binPrd(B, prevS) D = D + i*(curS-prevS) prevS = curS return D
def distance(graph): #Must be bettered if more than one cycle, works on Yeast adj = prt.adj(graph) B = prt.binAddI(adj) D = prt.binSub(B, np.identity(len(adj), float)) prevS = B for i in range(2, len(adj), 1): curS = prt.binPrd(B, prevS) D = D + i * (curS - prevS) prevS = curS return D
def distance(graph): adj = prt.adj(graph); B = prt.binary_add_identity(adj) D = prt.binary_substraction(B, np.identity(len(adj),float)) prev_S = B for i in range(2,len(adj),1): cur_S = prt.binary_product(B, prev_S) D = D + i*(cur_S-prev_S) prev_S = cur_S return D
def SILS(graph): A = prt.adj(graph) A = np.asarray(A) loops = geodetic(graph) nodes = graph.nodes() #make an adjacency matrix for the loop edges = [] #list of adjacency matrices for each loop for loop in loops: # For every loop, add edges to a matrix in adjacency-style l = len(loop) E = np.zeros(A.shape) for j in range(0,l-1): sourceName = loop[j] destName = loop[j+1] source = nodes.index(sourceName) dest = nodes.index(destName) E[source,dest] = 1 firstName = loop[0] lastName = loop[l-1] first = nodes.index(firstName) last = nodes.index(lastName) E[last,first] = 1 edges.append(E) B = np.zeros(A.shape); S = loops SILS = [] # Here comes the construction of the SILS while S: #figure out which loops do not contribute any new edges copy_s = S[:] edges_copy = [] for j, element in enumerate(edges): # Counting the number of contributions the loop can introduce entry = S[j] test = element - B test[test<0] = 0 new_edges = np.sum(test) if new_edges==0: copy_s.remove(entry) else: edges_copy.append(element) S = copy_s edges = edges_copy #of the remaining loops, determine the contribution of edges numberOfNewEdges = [] for element in edges: test = element - B test[test<0] = 0 new_edges = int(np.sum(test)) numberOfNewEdges.append(new_edges) if numberOfNewEdges: # The loop with minimum contribution should be added m = numberOfNewEdges.index(min(numberOfNewEdges)) # Add edges to the SILS edge collection B = B + edges[m] SILS.append(S[m]) # Remove the items from the loop collection S.pop(m) edges.pop(m) return SILS
def SILS(graph): A = prt.adj(graph) A = np.asarray(A) loops = geodetic(graph) nodes = graph.nodes() # Make an adjacency matrix for the loop. edges = [] # List of adjacency matrices for each loop. for loop in loops: # For every loop, add edges to a matrix in adjacency-style. l = len(loop) E = np.zeros(A.shape) for j in range(0,l-1): source_name = loop[j] dest_name = loop[j+1] source = nodes.index(source_name) dest = nodes.index(dest_name) E[source,dest] = 1 first_name = loop[0] last_name = loop[l-1] first = nodes.index(first_name) last = nodes.index(last_name) E[last,first] = 1 edges.append(E) B = np.zeros(A.shape); S = loops SILS = [] # Here comes the construction of the SILS. while S: # Figure out which loops do not contribute any new edges. copy_s = S[:] edges_copy = [] for j, element in enumerate(edges): # Counting the number of contributions the loop can introduce. entry = S[j] test = element - B test[test<0] = 0 new_edges = np.sum(test) if new_edges==0: copy_s.remove(entry) else: edges_copy.append(element) S = copy_s edges = edges_copy # Of the remaining loops, determine the contribution of edges. number_of_new_edges = [] for element in edges: test = element - B test[test<0] = 0 new_edges = int(np.sum(test)) number_of_new_edges.append(new_edges) if number_of_new_edges: # The loop with minimum contribution should be added m = number_of_new_edges.index(min(number_of_new_edges)) # Add edges to the SILS edge collection B = B + edges[m] SILS.append(S[m]) # Remove the items from the loop collection S.pop(m) edges.pop(m) return SILS
def uniqueConsEdges(graph, sils): # Get graph information needed. A = prt.adj(graph) A = np.asarray(A) nodes = graph.nodes() # Make an adjacency matrix for every loop in sils edges = [] # List of adjacency-style matrices for each loop for loop in sils: # For every loop, add unique consecutive edges to a matrix in adjacency-style l = len(loop) E = np.zeros(A.shape) # If length of loop is 2 the else procedure would give problems if l == 2: for node in loop: index = nodes.index(node) E[index, index] = 1 else: for j in range(0, l - 2): sourceName = loop[j] destName = loop[j + 2] # This line is different, plus 2 this time. source = nodes.index(sourceName) dest = nodes.index(destName) E[source, dest] = 1 secondName = loop[1] firstName = loop[0] lastName = loop[l - 1] lastButOneName = loop[l - 2] second = nodes.index(secondName) first = nodes.index(firstName) last = nodes.index(lastName) lastButOne = nodes.index(lastButOneName) E[lastButOne, first] = 1 E[last, second] = 1 edges.append(E) # Sum occurrence of consecutive edges in loops. sumConsEdges = np.zeros(A.shape) for entry in edges: sumConsEdges = np.add(sumConsEdges, entry) # When sum is one, the edge is in only one loop, so get indices. indicesConsEdges = np.where(sumConsEdges == 1) uniqueConsLoops = [] # Construct the loop list and node indices list. for i in range(0, int(len(indicesConsEdges[0] - 1))): rowNo = int(indicesConsEdges[0][i]) columnNo = int(indicesConsEdges[1][i]) j = 0 for edge in edges: if edge[rowNo, columnNo] == 1: uniqueConsLoops.append(sils[j]) j = j + 1 return indicesConsEdges, uniqueConsLoops
def uniqueEdges(graph, sils): A = prt.adj(graph) A = np.asarray(A) nodes = graph.nodes() #make an adjacency matrix for every loop in sils edges = [] #list of adjacency matrices for each loop for loop in sils: # For every loop, add edges to a matrix in adjacency-style l = len(loop) E = np.zeros(A.shape) for j in range(0, l - 1): sourceName = loop[j] destName = loop[j + 1] source = nodes.index(sourceName) dest = nodes.index(destName) E[source, dest] = 1 firstName = loop[0] lastName = loop[l - 1] first = nodes.index(firstName) last = nodes.index(lastName) E[last, first] = 1 edges.append(E) # Sum occurrence of edges in loops sumEdges = np.zeros(A.shape) for entry in edges: # sumEdges += entry sumEdges = np.add(sumEdges, entry) # When sum is one, the edge is in only one loop, so get indices. # a = np.argwhere(sumEdges==1) # for entry in a: # row, column = entry indicesEdges = np.where(sumEdges == 1) uniqueLoops = [] for p in range(int(len(indicesEdges[0] - 1))): rowNo = int(indicesEdges[0][p]) columnNo = int(indicesEdges[1][p]) for q, edge in enumerate(edges): if edge[rowNo, columnNo] == 1: uniqueLoops.append(sils[q]) # # When sum is two, the edge can be used to switch off two loops # extraIndicesEdges = np.where(sumEdges == 2) # # extraLoops = [] # for i in range(0,int(len(extraIndicesEdges[0]-1))): # twoLoops = [] # rowNo = int(extraIndicesEdges[0][i]) # columnNo = int(extraIndicesEdges[1][i]) # j = 0 # for edge in edges: # if edge[rowNo,columnNo] == 1: # twoLoops.append(sils[j]) # j = j+1 # extraLoops.append(twoLoops) return indicesEdges, uniqueLoops
def unique_edges(graph,sils): A = prt.adj(graph) A = np.asarray(A) nodes = graph.nodes() # Make an adjacency matrix for every loop in SILS. edges = [] # List of adjacency matrices for each loop for loop in sils: # For every loop, add edges to a matrix in adjacency-style. l = len(loop) E = np.zeros(A.shape) for j in range(0,l-1): source_name = loop[j] dest_name = loop[j+1] source = nodes.index(source_name) dest = nodes.index(dest_name) E[source,dest] = 1 first_name = loop[0] last_name = loop[l-1] first = nodes.index(first_name) last = nodes.index(last_name) E[last,first] = 1 edges.append(E) # Sum occurrence of edges in loops. sum_edges = np.zeros(A.shape) for entry in edges: # sumEdges += entry sum_edges = np.add(sum_edges,entry) # When sum is one, the edge is in only one loop, so get indices. indices_edges = np.where(sum_edges == 1) unique_loops = [] for p in range(int(len(indices_edges[0]-1))): rowNo = int(indices_edges[0][p]) columnNo = int(indices_edges[1][p]) for q,edge in enumerate(edges): if edge[rowNo,columnNo] == 1: unique_loops.append(sils[q]) # # When sum is two, the edge can be used to switch off two loops # extraIndicesEdges = np.where(sumEdges == 2) # # extraLoops = [] # for i in range(0,int(len(extraIndicesEdges[0]-1))): # twoLoops = [] # rowNo = int(extraIndicesEdges[0][i]) # columnNo = int(extraIndicesEdges[1][i]) # j = 0 # for edge in edges: # if edge[rowNo,columnNo] == 1: # twoLoops.append(sils[j]) # j = j+1 # extraLoops.append(twoLoops) return indices_edges,unique_loops
def unique_cons_edges(graph,sils): # Get graph information needed. A = prt.adj(graph) A = np.asarray(A) nodes = graph.nodes() # Make an adjacency matrix for every loop in sils edges = [] # List of adjacency-style matrices for each loop for loop in sils: # For every loop, add unique consecutive edges to a matrix in adjacency-style l = len(loop) E = np.zeros(A.shape) # If length of loop is 2 the else procedure would give problems if l == 2: for node in loop: index = nodes.index(node) E[index,index] = 1 else: for j in range(0,l-2): source_name = loop[j] dest_name = loop[j+2] # This line is different, plus 2 this time. source = nodes.index(source_name) dest = nodes.index(dest_name) E[source,dest] = 1 second_name = loop[1] first_name = loop[0] last_name = loop[l-1] last_but_one_name = loop[l-2] second = nodes.index(second_name) first = nodes.index(first_name) last = nodes.index(last_name) last_but_one = nodes.index(last_but_one_name) E[last_but_one,first] = 1 E[last,second] = 1 edges.append(E) # Sum occurrence of consecutive edges in loops. sum_cons_edges = np.zeros(A.shape) for entry in edges: sum_cons_edges = np.add(sum_cons_edges,entry) # When sum is one, the edge is in only one loop, so get indices. indices_cons_edges = np.where(sum_cons_edges == 1) unique_cons_loops = [] # Construct the loop list and node indices list. for i in range(0,int(len(indices_cons_edges[0]-1))): rowNo = int(indices_cons_edges[0][i]) columnNo = int(indices_cons_edges[1][i]) j = 0 for edge in edges: if edge[rowNo,columnNo] == 1: unique_cons_loops.append(sils[j]) j = j+1 return indices_cons_edges,unique_cons_loops