def permute_mutation_data(G, genes, patients, seed, Q=100): if fortranBindings: # Compute the desired pieces of the graph structure A = biadjacency_matrix(G, row_order=genes, column_order=patients, dtype=np.int32) if sp.sparse.issparse(A): A = A.todense() A = np.asarray(A, dtype=np.int32) # Set up and call the permute matrix function B = bipartite_edge_swap(A, nswap=len(G.edges()) * Q, max_tries=2**31 - 1, seed=seed, verbose=False) H = nx.Graph() H.add_nodes_from( genes + patients) # some patients/genes may have zero mutations H.add_edges_from([(genes[u], patients[v]) for u, v in zip(*np.where(B == 1))]) else: H = G.copy() random.seed(seed) bipartite_double_edge_swap(H, genes, patients, nswap=Q * len(G.edges())) return graph_to_mutation_data(H, genes, patients)
def call_bipartite_edge_swap( G, xs, ys, Q ): # Compute the desired pieces of the graph structure A = np.array(bipartite.biadjacency_matrix(G, row_order=xs, column_order=ys, dtype=np.int32)) # Set up and call the permute matrix function max_tries = 2**31-1 seed = random.randint(0, 2**31-1) nswap = len(G.edges()) * Q B = bipartite_edge_swap(A, nswap, max_tries, seed=seed, verbose=True) H = nx.Graph() H.add_edges_from([ (xs[u], ys[v]) for u, v in zip(*np.where(B == 1)) ]) return H
def call_bipartite_edge_swap( G, xs, ys, Q ): # Compute the desired pieces of the graph structure A = np.array(bipartite.biadjacency_matrix(G, row_order=xs, column_order=ys, dtype=np.int32)) # Set up and call the permute matrix function max_tries = 2**31-1 seed = random.randint(0, 2**31-1) nswap = len(G.edges()) * Q B = bipartite_edge_swap(A, nswap, max_tries, seed=seed, verbose=True) H = nx.Graph() H.add_edges_from([ (xs[u], ys[v]) for u, v in zip(*np.where(B == 1)) ]) return H
def permute_mutation_data(G, genes, patients, seed, Q=100): if fortranBindings: # Compute the desired pieces of the graph structure A = np.array(biadjacency_matrix(G, row_order=genes, column_order=patients, dtype=np.int32), dtype=np.int32) # Set up and call the permute matrix function B = bipartite_edge_swap(A, nswap=len(G.edges()) * Q, max_tries=2**31-1, seed=seed, verbose=False) H = nx.Graph() H.add_nodes_from( genes + patients ) # some patients/genes may have zero mutations H.add_edges_from([ (genes[u], patients[v]) for u, v in zip(*np.where(B == 1)) ]) else: H = G.copy() random.seed(seed) bipartite_double_edge_swap(H, genes, patients, nswap=Q * len( G.edges() )) return graph_to_mutation_data(H, genes, patients)
def call_bipartite_edge_swap( G, xs, ys, Q ): # Compute the desired pieces of the graph structure xs.sort(G.degree, reverse=True) ys.sort(G.degree, reverse=True) x_degrees = [ G.degree(x) for x in xs ] y_degrees = [ G.degree(y) for y in ys ] A = np.array(bipartite.biadjacency_matrix(G, row_order=xs, column_order=ys, dtype=np.int32)) # Set up and call the permute matrix function max_tries = 1e75 seed = random.randint(0, 2**32-1) nswap = len(G.edges()) * Q B = bipartite_edge_swap(A, x_degrees, y_degrees, nswap, max_tries, seed) H = nx.Graph() H.add_edges_from([ (xs[u], ys[v]) for u, v in zip(*np.where(B == 1)) ]) return H
def call_bipartite_edge_swap(G, xs, ys, Q): # Compute the desired pieces of the graph structure xs.sort(G.degree, reverse=True) ys.sort(G.degree, reverse=True) x_degrees = [G.degree(x) for x in xs] y_degrees = [G.degree(y) for y in ys] A = np.array( bipartite.biadjacency_matrix(G, row_order=xs, column_order=ys, dtype=np.int32)) # Set up and call the permute matrix function max_tries = 1e75 seed = random.randint(0, 2**32 - 1) nswap = len(G.edges()) * Q B = bipartite_edge_swap(A, x_degrees, y_degrees, nswap, max_tries, seed) H = nx.Graph() H.add_edges_from([(xs[u], ys[v]) for u, v in zip(*np.where(B == 1))]) return H
def permute_mutation_data(G, genes, patients, seed, Q=100): print if fortranBindings: # Compute the desired pieces of the graph structure xs = sorted(genes, key=G.degree, reverse=True) ys = sorted(patients, key=G.degree, reverse=True) x_degrees = [ G.degree(x) for x in xs ] y_degrees = [ G.degree(y) for y in ys ] A = np.array(biadjacency_matrix(G, row_order=xs, column_order=ys, dtype=np.int32)) # Set up and call the permute matrix function B = bipartite_edge_swap(A, x_degrees, y_degrees, len(G.edges()) * Q, 1e9, seed=seed) H = nx.Graph() H.add_nodes_from( genes + patients ) # some patients/genes may have zero mutations H.add_edges_from([ (xs[u], ys[v]) for u, v in zip(*np.where(B == 1)) ]) else: H = G.copy() random.seed(seed) bipartite_double_edge_swap(H, genes, patients, nswap=Q * len( G.edges() )) return graph_to_mutation_data(H, genes, patients)